What is an AI Agent?
Let’s start with the basics. You’ve been using LLMs for single-shot tasks:Pseudocode
- Look up information the LLM doesn’t know (customer data, inventory levels)
- Take actions in external systems (create tickets, send emails, update databases)
- Remember context across multiple turns (maintain conversation state)
- Make decisions based on intermediate results (if X then Y)
- Perceive - Understand the current situation (user request, context, state)
- Think - Reason about what to do (using the LLM)
- Act - Execute actions using tools (function calls, API calls)
- Remember - Maintain state and context
- Repeat - Continue until task is complete
The Basic Agent Loop
Your First Agent: Simple Tool Use
Let’s build the simplest possible agent - one that can look up weather information. What just happened:- User asks about weather
- Agent sees it has a
get_weathertool available - Agent decides to use that tool
- We execute the tool and give result back to agent
- Agent uses the result to formulate final answer
When to Use Agents vs. Simple LLM Calls
Use a simple LLM call when:- ✅ Single question with immediate answer
- ✅ No external data needed
- ✅ No actions to take
- ✅ No context to maintain
- ✅ Need to look up external data (databases, APIs)
- ✅ Need to take actions (create records, send messages)
- ✅ Multi-turn conversation with context
- ✅ Multi-step reasoning required
- ✅ Decision making based on intermediate results
| Task | Approach | Why |
|---|---|---|
| ”Summarize this document” | Simple LLM | One-shot, no tools needed |
| ”What’s my account balance?” | Agent | Needs to query database |
| ”Cancel my subscription” | Agent | Needs to execute action |
| ”Help me debug this code” | Agent (if using tools) | May need to run code, search docs |
| ”Translate this text” | Simple LLM | One-shot, no tools needed |
Agent Limitations and Considerations
Agents are powerful but come with challenges: 1. Unpredictability- Same query might take different paths
- Agent might call tools in unexpected order
- Need to handle variability
- Multiple LLM calls per query (thinking → acting → thinking)
- Tools add latency and potential API costs
- Need to optimize for efficiency
- Tools can fail
- Agent might choose wrong tool
- Need robust error recovery
- Can’t just test input → output
- Must test tool selection, execution paths
- Need to mock tools for testing
Check Your Understanding
- Concept: What’s the difference between a simple LLM call and an agent?
- Application: User asks “Send an email to my team with today’s sales numbers.” Do you need an agent?