Overview

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.

FAQ

What is the main role of an LLM in an AI agent?An LLM acts as the agent’s “brain” or decision-making core. It interprets user requests, reasons about what to do next, chooses tools when needed, and helps synthesize final answers.
Why does the book recommend starting agent development with closed LLMs?Closed LLMs are easier to use for rapid experimentation because they only require an API key, avoid infrastructure setup, and usually provide the best current performance for reasoning and tool use. They also include production-ready features like tool calling and structured output.
When should you consider switching from closed LLMs to open LLMs?Open LLMs become worth considering after you have validated your agent design. They can reduce costs at high scale, improve control and stability through self-hosting, and help when data must stay inside your infrastructure.
What LLM capabilities are especially important for building agents?Key capabilities include tool calling, structured output, long context support, and flexibility to adapt to fast-changing model ecosystems. These features help agents interact with external systems, produce machine-readable outputs, and manage complex contexts.
Why is LiteLLM useful in agent development?LiteLLM provides a unified interface for many LLM providers. This lets you switch models by changing the model name instead of rewriting provider-specific code, making experimentation and migration much easier.
Why do LLM APIs require manual conversation history management?LLM APIs are stateless, meaning each request is independent and does not remember previous calls. To maintain continuity, developers must send the full relevant message history with each request.
What is structured output, and why is it important for agents?Structured output makes the model return data in a defined format such as JSON. It is important because agents often need outputs that other programs can reliably parse, such as tool names, arguments, extracted fields, or evaluation results.
What is the difference between user prompts and system prompts?User prompts come from the user and change every turn. System prompts are developer-defined instructions that persist across the conversation and control the agent’s identity, behavior, boundaries, and tool usage rules.
How should system prompts guide an agent’s behavior?They should encourage the agent to act autonomously when intent is clear, use tools proactively, avoid unnecessary tool calls, respect boundaries, and ask clarification questions only when the request is truly ambiguous.
What did the GAIA benchmark reveal about LLM limitations?GAIA showed that many seemingly simple real-world tasks still require tools like web search, file reading, or calculation. Even strong LLMs solved only a limited portion of the problems without tools, proving that agents need external capabilities to be genuinely useful.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build an AI Agent (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build an AI Agent (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build an AI Agent (From Scratch) ebook for free