What are AI Agents
AI agents represent the next evolution beyond simple chatbots. While a chatbot responds to one question at a time, an agent can autonomously plan, reason, use tools, and complete multi-step tasks.
Chatbot vs Agent
Chatbot:
User: "What's the weather in Tokyo?"
Bot: "I don't have real-time weather data." (limited to its knowledge)
Agent:
User: "What's the weather in Tokyo?"
Agent: [Thinks: I need to check the weather API]
[Action: Calls weather API for Tokyo]
[Observes: Temperature 22°C, partly cloudy]
Agent: "It's 22°C and partly cloudy in Tokyo right now."Key Properties of AI Agents
1. Autonomy
Agents make decisions about what actions to take without human intervention for each step.
2. Tool Use
Agents can call external tools — APIs, databases, search engines, code interpreters.
3. Planning
Agents break complex tasks into steps and execute them in order.
4. Memory
Agents maintain context across multiple steps, remembering what they've done and learned.
5. Reflection
Advanced agents evaluate their own outputs and adjust their approach.
The Agent Loop
Every AI agent follows this core loop:
┌─────────────────────────────────────────┐
│ │
│ Observe → Think → Act → Observe ... │
│ │
│ 1. OBSERVE: Receive input/results │
│ 2. THINK: Reason about next step │
│ 3. ACT: Execute an action/tool │
│ 4. Loop until task is complete │
│ │
└─────────────────────────────────────────┘The ReAct Pattern
The most common agent pattern — Reasoning + Acting:
User: "Find the tallest building in India and its height in feet."
Thought 1: I need to search for the tallest building in India.
Action 1: search("tallest building in India")
Observation 1: The tallest building in India is the Palais Royale
in Mumbai at 320 meters.
Thought 2: I need to convert 320 meters to feet.
Action 2: calculate(320 * 3.28084)
Observation 2: 1049.87 feet
Thought 3: I now have all the information needed.
Answer: The tallest building in India is the Palais Royale in Mumbai,
standing at approximately 1,050 feet (320 meters).Types of AI Agents
Simple (Router) Agent
Routes to the right tool based on the query:
"What time is it?" → Clock tool
"Search for X" → Search tool
"Calculate Y" → Calculator toolReAct Agent
Reasons step by step, using tools as needed (most common pattern).
Plan-and-Execute Agent
Creates a full plan upfront, then executes each step:
Plan:
1. Search for the company's stock price
2. Get the P/E ratio
3. Compare with industry average
4. Write analysis
Execute: [Steps 1-4 in sequence]Multi-Agent Systems
Multiple specialized agents collaborating on complex tasks (covered in a later topic).
Agent Components
┌─────────────────────────────────────┐
│ AI Agent │
│ │
│ ┌──────────┐ ┌───────────────┐ │
│ │ LLM │ │ Tools │ │
│ │ (Brain) │ │ - Search │ │
│ │ │ │ - Calculator │ │
│ └──────────┘ │ - Code exec │ │
│ │ - Database │ │
│ ┌──────────┐ │ - APIs │ │
│ │ Memory │ └───────────────┘ │
│ │ - Short │ │
│ │ - Long │ ┌───────────────┐ │
│ └──────────┘ │ Planner │ │
│ │ (Optional) │ │
│ └───────────────┘ │
└─────────────────────────────────────┘A Simple Agent in Python
from openai import OpenAI
import json
client = OpenAI()
# Define available tools
def search_web(query):
"""Simulate a web search."""
# In production, use a real search API
return f"Search results for '{query}': [relevant information]"
def calculate(expression):
"""Evaluate a math expression."""
try:
return str(eval(expression))
except Exception as e:
return f"Error: {e}"
def get_current_time():
"""Get the current time."""
from datetime import datetime
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Tool registry
tools = {
"search_web": search_web,
"calculate": calculate,
"get_current_time": get_current_time
}
# Tool definitions for the LLM
tool_definitions = [
{
"type": "function",
"function": {
"name": "search_web",
"description": "Search the web for information",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"}
},
"required": ["query"]
}
}
},
{
"type": "function",
"function": {
"name": "calculate",
"description": "Evaluate a mathematical expression",
"parameters": {
"type": "object",
"properties": {
"expression": {"type": "string", "description": "Math expression"}
},
"required": ["expression"]
}
}
},
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "Get the current date and time",
"parameters": {"type": "object", "properties": {}}
}
}
]
def run_agent(user_message, max_iterations=5):
"""Run the agent loop."""
messages = [
{
"role": "system",
"content": "You are a helpful assistant. Use the available tools "
"to answer questions accurately. Think step by step."
},
{"role": "user", "content": user_message}
]
for i in range(max_iterations):
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=tool_definitions,
tool_choice="auto"
)
message = response.choices[0].message
# If no tool calls, we have the final answer
if not message.tool_calls:
return message.content
# Process each tool call
messages.append(message)
for tool_call in message.tool_calls:
func_name = tool_call.function.name
args = json.loads(tool_call.function.arguments)
print(f" [Tool: {func_name}({args})]")
# Execute the tool
result = tools[func_name](**args)
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": str(result)
})
return "Agent reached maximum iterations without completing."
# Usage
answer = run_agent("What is 15% of 847, and what time is it right now?")
print(answer)Real-World Agent Use Cases
| Use Case | Tools Needed | Complexity |
|---|---|---|
| Research assistant | Web search, document reader | Medium |
| Code assistant | Code interpreter, file system | Medium |
| Data analyst | SQL queries, chart generation | Medium |
| Customer support | Knowledge base, CRM, email | High |
| DevOps automation | CLI, cloud APIs, monitoring | High |
| Personal assistant | Calendar, email, search, maps | High |
Agent Frameworks
| Framework | Language | Best For |
|---|---|---|
| LangChain | Python/JS | General purpose, most popular |
| LlamaIndex | Python | Data-centric agents |
| CrewAI | Python | Multi-agent collaboration |
| AutoGen | Python | Conversational agents |
| Claude Agent SDK | Python | Anthropic-native agents |
Key Takeaways
- Agents = LLM + Tools + Loop — They reason, act, and iterate
- The ReAct pattern is the foundation of most agents
- Tools are essential — Agents without tools are just chatbots
- Set iteration limits — Prevent infinite loops
- Start simple — Build a working agent with 2-3 tools before scaling
Next, we'll deep-dive into tool use and function calling — the mechanism that lets agents interact with the world.