liveBook · Manning

Chapter 2: Core components: Large language models, prompting, and agents

What you will learn in chapter 2 of AI Agents in Action, Second Edition

The chapter introduction identifies the roles of the LLM, prompting, and OpenAI Agents SDK in an agent’s core architecture.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduction identifies the roles of the LLM, prompting, and OpenAI Agents SDK in an agent’s core architecture.

Key terms: large language model, prompting techniques, OpenAI Agents SDK, brain

2.1 Understanding large language models

This introduction presents LLMs as widespread tools for AI agents and notes that they can be useful without a complete understanding of their internal intelligence.

Key terms: large language models (LLMs), AI agents, black boxes, internal intelligence

2.1.1 LLMs: Probabilistic token machines

The section explains how LLMs learn to predict tokens and generate text, and distinguishes base training from alignment.

Key terms: tokenization, tokens, vocabulary, probability distribution, sampling, decoding strategy, base training, expected token, loss, backpropagation

2.1.2 What is a token?

This section explains how LLMs turn text into tokens, why token counts differ from text length, and why those counts matter for cost and output.

Key terms: tokenization, tokens, numerical indices, vocabulary, token count, JSON, regular text, overhead, input tokens, output tokens

2.1.3 Tuning temperature, top-p, and more

This section explains how generation parameters affect LLM output, how to tune them for an agent’s role, and why their effects require care.

Key terms: sampling, temperature, top-p, presence penalty, frequency penalty, max tokens, coder agent, creative writer agent, seed

2.2 Controlling LLMs with prompt engineering (agent persona)

This section explains why clear, well-structured prompts remain central to making agents reliable, even as LLMs improve.

Key terms: prompt engineering, persona, clear, well-structured prompts

2.2.1 Applying core prompt techniques

The section explains why transferable prompt techniques, clear structure, and cache-aware ordering make agent instructions more effective.

Key terms: prompt techniques, agent persona, base set of instructions, OpenAI Agents SDK, Markdown, unique delimiters, structure, loss feedback, prompt caching, static portion

2.2.2 Thinking like an LLM

This section explains how to write prompts as clear task instructions, express workflows in those instructions, and recognize a limit of prompting an LLM to repeat tasks.

Key terms: prompt, instructions, task, workflow, prompt instructions, decision-making, consolidated output task, task loops, LLM, agent

2.2.3 Avoiding common prompt pitfalls

This section cautions against over-engineering agent prompts and recommends splitting prompts that become too large or complicated.

Key terms: over-engineering, prompt instructions, smaller tasks

2.3 Building an agent with OpenAI Agents

The section places the OpenAI Agents SDK among varied agent frameworks and explains the appeal of shared protocols and a flexible SDK.

Key terms: frameworks, MCP, A2A, protocols, OpenAI Agents SDK, light, extensible, flexible

2.3.1 Building a minimal agent

This section introduces a minimal research planning agent and points out that its five-step output follows its prompt instructions.

Key terms: research planning agent, five-step plan, prompt instructions

2.3.2 Setting the agent model and other parameters

This section explains how model selection, temperature, and reasoning effort affect an agent’s consistency, cost, and speed.

Key terms: temperature, highest-probability token, output variation, exact model, SDK, defaults, reasoning-effort parameter, thinking, reasoning_effort, latency

2.3.3 Controlling inputs and typed outputs

This section shows how typed agent outputs make workflows more reliable, why a proposed task-output type fails strict JSON validation, and how typing simplifies prompts.

Key terms: typed outputs, inputs, Pydantic, data model, list of tasks, strict JSON schema, dict[int, str], extra properties, strict_json_schema=False, typing outputs

2.3.4 Tracing agents

Explains how to inspect OpenAI agent traces, name a workflow trace, and choose an external tracing layer when appropriate.

Key terms: tracing, OpenAI Traces, workflow, ResearchPlanModel, trace, framework-agnostic tracing, external tracing layer

2.4 Enhancing agents through tool integration

This section distinguishes a prompt-chaining workflow from an agent with agency and identifies tool choice as a way to give agents that agency.

Key terms: agency, research planner, prompt step, prompt chaining, tools, flexible and adaptable agents

2.4.1 Providing agents with tools

This section shows how to give an agent tools, guide their use, and limit the costs and risks they introduce.

Key terms: tools, actions, MCP, handoff, get_research_sources, research planning agent, prompt instructions, research sources, @function_tool, JSON tool description

2.4.2 Tracing agentic tool use

This section explains dependent and parallel tool calls and shows how OpenAI Traces makes an agent’s tool use visible for debugging.

Key terms: tool chaining, get_resource_url, parallel, sequential chains, latency, OpenAI Traces page, tool chains, inputs and outputs

2.5 Exercises

Five exercises guide the reader through building a Research Planner agent, comparing temperature settings, enforcing typed output, refining its prompt, and tracing a tool call.

2.6 Summary

This chapter summary connects token-aware model tuning, prompt and schema design, and observable tool use as foundations for reliable agents.

Where this is used later

Concepts explained in this chapter

← Chapter 1: The rise of AI agents Chapter 3: Actions with Model Context Protocol for AI agents →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.