Files
ai-agent-book/slides/lesson-05.md
T
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

7.3 KiB

theme, title, info, author, transition, mdc, lineNumbers, monaco, aspectRatio, canvasWidth, layout, class
theme title info author transition mdc lineNumbers monaco aspectRatio canvasWidth layout class
seriph Lesson 05 — What Does the Model Actually See? English video course for AI Agents in Depth Bojie Li slide-left true false false 16/9 980 cover cover
Build · Chapter 2 · Context Engineering

What Does the Model Actually See?

Messages, tool calls, and the Agent core loop

Lesson 05 of 42 · 18 minutes · Context: The Ceiling of Agent Capability; API-Level Context Structure

Build · Chapter 2 · Context Engineering

Problems this chapter will solve

Lesson 05

What Does the Model Actually See?

Lesson 06

Why Can One Timestamp Make an Agent Slow?

Lesson 07

Why Do Better Prompts Need Structure, Not More Rules?

Lesson 08

How Can an Agent Know What It Needs to Learn?

Lesson 09

How Can an Agent Stay Oriented in a Long Task?


Why this problem matters

Roles

System, user, assistant, and tool messages have different semantics.

Ordering

A tool result must follow the tool call it answers.

Composition

Every call rebuilds a view from static and dynamic context.


Three ideas to keep in view

Context is a list

Messages—not an abstract cloud of memory

Tool call

An assistant message proposing a structured action

Tool result

A new observation appended to the trajectory


The book's visual model

Message sequence for two tool calls
Message sequence for two tool calls

Single turn vs. Agent loop

Single turn

  • One request
  • One response
  • No environmental feedback

Agent loop

  • Repeated requests
  • Tool calls and results
  • Growing trajectory
The API structure is the runtime state machine.

Context at the API boundary

messages = [{"role": "user", "content": task}]
while True:
    reply = client.responses.create(messages=messages, tools=tools)
    messages.append(reply)
    if reply.final: break
    messages.append(run_tool(reply.tool_call))

Test the claim

2-13 min

Run local tool calling and watch messages grow

Observe: Assistant tool call, tool result, and final answer

Demo budget: 3 minutes · one contiguous terminal block

class: course-terminal

Live demo

Switching to the terminal

$ uv run python chapter2/local_llm_serving/main.py --backend ollama --mode single --task "What is the weather in Tokyo?"
Run the command(s), narrate decisions, and point to the observation—not just the output.

What the evidence supports

Finding 1

The model only knows a tool exists because its schema is in context.

Finding 2

Tool results are observations, not hidden side effects.

Finding 3

A malformed message sequence changes the task state the model perceives.


layout: center

Where the claim stops

Boundary condition

Framework abstractions are convenient, but debugging requires inspecting raw API messages.

layout: center

Engineering takeaway

Design rule

Log the exact message list and tool schemas for every reproducible Agent failure.

Continue the experiment


layout: center class: text-center

Pause and apply

Your turn

Which part of your Agent state exists outside the message list, and how is it reintroduced?

layout: center class: text-center

Next · Lesson 06
Rearranging that list can change both latency and cost.