A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and uses that data in its response.
Chatbot vs Agent
| Chatbot | Agent | |
|---|---|---|
| Data source | Training only | APIs, files, search |
| Actions | Text only | Tool calls |
| Loops | Single request | Multiple iterations |
| Use case | Q&A | Task automation |
The ReAct Pattern
ReAct = Reasoning + Acting. An agent operates in a loop:
User question
โ
REASON: Claude analyzes โ is a tool needed?
โ
ACT: Tool call (get_weather, read_file, ...)
โ
OBSERVE: We receive the tool result
โ
REASON: Claude analyzes the result
โ
(repeat until we have a final answer)
โ
ANSWER: Final text response
A Simple Agent
import anthropic
client = anthropic.Anthropic()
TOOLS = [
{
"name": "get_time",
"description": "Returns the current time",
"input_schema": {"type": "object", "properties": {}}
}
]
def get_time() -> str:
from datetime import datetime
return datetime.now().strftime("%H:%M:%S")
def run_agent(question: str) -> str:
messages = [{"role": "user", "content": question}]
while True:
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=512,
tools=TOOLS,
messages=messages,
)
if response.stop_reason == "end_turn":
return next(b.text for b in response.content if hasattr(b, "text"))
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type == "tool_use":
if block.name == "get_time":
result = get_time()
results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": result
})
messages.append({"role": "user", "content": results})
print(run_agent("What time is it right now?"))
Common Agent Tools
- Web search โ up-to-date information
- File reading โ local documents
- HTTP requests โ external APIs
- Code execution โ computations
- Database โ data storage and retrieval
๐ฌ Comments (0)
No comments yet
Be the first to share your opinion about this article!