AI Agents
What is an AI Agent?
An AI agent is an LLM that autonomously decides which actions to take (tools to call), observes results, and loops until it completes a goal. Unlike a single LLM call, agents can: • Break complex tasks into steps • Search the web, read files, write code • Correct their own mistakes • Use memory across turns
ReAct Pattern (Reason + Act)
The most widely used agent pattern: 1. Thought: 'I need to find the population of Tokyo' 2. Action: search('population of Tokyo 2024') 3. Observation: 'Tokyo population is approximately 13.96 million' 4. Thought: 'Now I can answer the question' 5. Final Answer: 'Tokyo has approximately 13.96 million people' This Thought → Action → Observation loop repeats until the task is done.
Agent Architecture
Core components: • LLM backbone — reasoning and decision making • Tools — search, code execution, file I/O, APIs, databases • Memory — short-term (conversation history), long-term (vector DB), episodic • Planning — task decomposition, reflection, self-correction • Orchestrator — manages the loop, handles errors, enforces limits
ReAct Agent from Scratch
Always set max_steps to prevent infinite loops. Log every tool call for debugging. Add retry logic for tool failures.
Finished reading? Mark it complete to earn your XP.