AI Agents Specialization β Start HereΒΆ
Overview of the Agents track: function calling, ReAct, LangGraph, multi-agent systems, memory, and production deployment.
Agent ArchitectureΒΆ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI AGENT β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β User Input β
β β β
β ββββββββββββ β
β β LLM β β Planning & Reasoning β
β β Brain β β
β ββββββ¬ββββββ β
β β β
β β β
β ββββββββββββββββββββββββββββ β
β β Tool Selection β β
β ββββββ¬ββββββββββββββββββββββ β
β β β
β β β
β ββββββββββββββββββββββββββββ β
β β Tool Execution β β
β β - Web Search β β
β β - Database Query β β
β β - Code Execution β β
β β - API Calls β β
β ββββββ¬ββββββββββββββββββββββ β
β β β
β β β
β ββββββββββββ β
β β Memory β β Short & Long-term β
β ββββββββββββ β
β β β
β β β
β Final Response β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Quick Demo: Calculator AgentΒΆ
Letβs build a simple agent that can do math:
# Install dependencies (uncomment to run)
# !pip install openai
import json
import re
from typing import Dict, List, Any
class SimpleAgent:
"""A simple calculator agent"""
def __init__(self):
self.tools = {
"calculator": self.calculator,
"is_prime": self.is_prime
}
self.conversation_history = []
def calculator(self, expression: str) -> float:
"""Evaluate a mathematical expression"""
try:
# Safe evaluation (limited to math operations)
result = eval(expression, {"__builtins__": {}}, {})
return result
except Exception as e:
return f"Error: {str(e)}"
def is_prime(self, n: int) -> bool:
"""Check if a number is prime"""
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def run(self, query: str, max_iterations: int = 5) -> str:
"""Run the agent loop"""
print(f"π€ Agent received: {query}\n")
# Simple reasoning (in real agent, LLM does this)
iterations = 0
while iterations < max_iterations:
iterations += 1
print(f"--- Iteration {iterations} ---")
# Decide what to do (simplified)
if "sum" in query.lower() or "+" in query:
# Extract numbers
numbers = re.findall(r'\d+', query)
if len(numbers) >= 2:
expr = " + ".join(numbers)
print(f"π Thought: I need to calculate {expr}")
print(f"π§ Action: calculator({expr})")
result = self.calculator(expr)
print(f"π Result: {result}\n")
return f"The answer is {result}"
elif "prime" in query.lower():
# Extract number from query
numbers = re.findall(r'\d+', query)
if numbers:
num = int(numbers[0])
thought = f"I need to check if {num} is prime"
print(f"π Thought: {thought}")
print(f"π§ Action: is_prime({num})")
result = self.is_prime(num)
print(f"π Result: {result}\n")
if result:
return f"Yes, {num} is a prime number"
else:
return f"No, {num} is not a prime number"
# If we can't determine action, return
return "I'm not sure how to help with that."
return "Max iterations reached"
# Create and test agent
agent = SimpleAgent()
print("=" * 60)
response = agent.run("What is 23 + 45?")
print(f"β
Final Answer: {response}")
print("=" * 60)
ReAct PatternΒΆ
The ReAct (Reasoning + Acting) pattern is the core of modern agents:
1. THOUGHT: Analyze the problem
2. ACTION: Choose and execute a tool
3. OBSERVATION: See the result
4. REPEAT until solved
5. ANSWER: Provide final response
ExampleΒΆ
Query: βWhatβs the weather in the capital of France?β
Iteration 1:
THOUGHT: I need to find the capital of France first
ACTION: search(βcapital of Franceβ)
OBSERVATION: βParisβ
Iteration 2:
THOUGHT: Now I can get the weather for Paris
ACTION: get_weather(βParisβ)
OBSERVATION: β72Β°F, sunnyβ
Final Answer: βThe weather in Paris (capital of France) is 72Β°F and sunnyβ
Whatβs Next?ΒΆ
In the following notebooks, youβll learn:
Function Calling - OpenAI/Anthropic function calling
ReAct Pattern - Build reasoning agents
LangGraph - State machines for complex workflows
Multi-Agent Systems - Agent collaboration
Memory & State - Long-term memory systems
Production - Deploy and monitor agents
π Ready to build intelligent agents!
Key ConceptsΒΆ
1. Tools/FunctionsΒΆ
External capabilities the agent can use:
Web search
Database queries
Code execution
API calls
File operations
2. PlanningΒΆ
Breaking complex tasks into steps:
Task decomposition
Step sequencing
Error recovery
Parallel execution
3. MemoryΒΆ
Retaining context across interactions:
Short-term (conversation)
Long-term (knowledge base)
Episodic (past experiences)
Semantic (facts and concepts)
4. ReasoningΒΆ
Deciding what to do next:
Chain-of-thought
ReAct pattern
Tree-of-thought
Self-reflection