2 The brain of AI agents: LLMs
At the start of building an AI agent, the chapter frames the language model as the agent’s “brain” and asks the core practical questions that shape development: which model to choose, how to call it reliably, and where its abilities stop. It uses the example of a Research Agent to show that the model must do more than generate text; it must interpret requests, reason over information, and support decision-making in a way that can be turned into useful actions.
The chapter then explains how to choose between closed and open models, recommending closed LLMs first because they are easier to prototype with, offer stronger performance, and already include production-friendly features such as tool calling, structured output, and cost-saving optimizations. It shows how APIs are used through OpenAI-style chat completions and how LiteLLM provides a single interface for many providers, reducing vendor lock-in. It also emphasizes essential agent-facing API skills like managing conversation history in stateless calls, enforcing structured JSON-like outputs with schemas, and using asynchronous requests with rate limiting and retries to handle many calls efficiently.
Finally, the chapter focuses on prompt engineering and a benchmark-based reality check. It argues that system prompts should define the agent’s identity, boundaries, tone, and knowledge limits, while also guiding autonomous action: when intent is clear, the agent should act immediately; when it is ambiguous, it should ask only minimal questions. It then uses GAIA to test models on realistic tasks and shows that even strong LLMs solve only a small portion without external tools, often due to current-information needs, file access, or unreliable self-assessment. The takeaway is that LLMs are powerful but incomplete, and effective agents must combine them with tools and clear behavioral design.
Journey through the book – Chapter 2 in focus
LiteLLM, a unified wrapper that lets you call multiple LLM providers through a single style.
Summary
- When starting agent development, Closed LLMs offer practical advantages: out-of-the-box features like tool calling and structured output, stable APIs that let developers focus on agent logic, and top-tier performance for complex reasoning tasks. Open LLMs become relevant later for cost optimization.
- LiteLLM provides a unified interface across providers, enabling model flexibility in a rapidly evolving landscape. Key API patterns include conversation management, structured output with Pydantic, and asynchronous calls with rate limiting.
- System prompts define agent behavior: product identity, output format, behavioral boundaries, and knowledge limits. For agents, prompts should emphasize autonomous action and strategic tool use rather than asking for permission.
- GAIA benchmark reveals that even capable LLMs solve only 25% of "easy" problems without tools. 75% of problems require external capabilities like web search and file reading—motivating Chapter 3's focus on tools.
- Models show reasonable self-awareness of limitations when properly prompted, but training data knowledge is unreliable for precise, current, or verifiable answers. Agents need tools to access authoritative sources.
Build an AI Agent (From Scratch) ebook for free