Key Insight: The agent loop turns a chatbot into an agent — call tools until done.
- 4 tools:
run_command,read_file,write_file,web_search - The agent loop — keeps calling Claude until it stops requesting tools
- Content serialization for safe session storage
- Tool dispatch pattern
- How tool definitions work in the Anthropic API
- The agent loop pattern (the most important pattern in AI agents)
- How to serialize mixed content (text + tool calls) for persistence
- The execute/dispatch pattern for routing tool calls
| Tool | Description | Example Use |
|---|---|---|
run_command |
Execute a shell command | "List files in the current directory" |
read_file |
Read file contents | "Show me the contents of bot.py" |
write_file |
Create/overwrite a file | "Create a hello.py script" |
web_search |
Search the web (placeholder) | "Search for Python best practices" |
- Completed module 03
- Anthropic API key and Telegram bot token in
.env
make 04-tools-agent-loop
# or
uv run python 04-tools-agent-loop/bot.py- The bot takes actions — Ask it to create a file and it actually does
- Multiple tool calls — Complex tasks may trigger several tool calls in sequence
- The loop — Watch the console output to see tool calls being executed
| File | Lines | Description |
|---|---|---|
bot.py |
~200 lines | Bot with tools and agent loop |
Ready for safety? -> 05: Permission Controls