Files
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

8.1 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 39 — When Should Agents Share the Same Context? English video course for AI Agents in Depth Bojie Li slide-left true false false 16/9 980 cover cover
Expand · Chapter 10 · Multi-Agent Collaboration

When Should Agents Share the Same Context?

Shared trajectories, isolated contexts, role switching, and handoffs

Lesson 39 of 42 · 17 minutes · Classification Framework; Shared vs. Non-Shared Context; Multi-Stage Role Switching

Expand · Chapter 10 · Multi-Agent Collaboration

Problems this chapter will solve

Lesson 39

When Should Agents Share the Same Context?

Lesson 40

Who Should Coordinate Independent Agents?

Lesson 41

When Is Multi-Agent Actually Better Than One Agent?

Lesson 42

How Do Agent Teams Fail—and What Should We Build Next?


Why this problem matters

Continuity

Shared history preserves details and user decisions.

Isolation

Separate contexts reduce interference and permission leakage.

Scale

Independent contexts enable parallel work beyond one window.


Three ideas to keep in view

Shared context

New prompt/tools, same complete trajectory

Non-shared context

Independent trajectory + explicit communication

IPC analogy

Files as shared memory; calls/messages as message passing


The book's visual model

Shared-context and non-shared-context multi-Agent architectures
Shared-context and non-shared-context multi-Agent architectures

Shared context vs. Non-shared context

Shared context

  • Near-zero handoff loss
  • Mostly serial roles
  • History grows and biases

Non-shared context

  • Modular and parallel
  • Selective disclosure
  • Handoff can omit evidence
Share when loss is unacceptable; isolate when scale, focus, or security dominates.

A role is prompt + tools + visible state

stage = router.choose(task_state)
agent = Agent(prompt=stage.prompt, tools=stage.tools)
if stage.shared:
    agent.resume(full_trajectory)
else: agent.start(handoff_package)

Test the claim

10-11 min

Inspect staged prompts, tools, and fallback gates

Observe: Requirements, implementation, review, and revision boundaries

10-21 min

Inspect role-specific handoff capabilities

Observe: Distinct prompts, tools, transfer edges, and shared session state

Demo budget: 2 minutes · one contiguous terminal block

class: course-terminal

Live demo

Switching to the terminal

$ cd chapter10/staged-system-prompt && python demo.py --list-stages

$ cd chapter10/multi-role-transfer && python demo.py --list-roles
Run the command(s), narrate decisions, and point to the observation—not just the output.

What the evidence supports

Finding 1

Changing prompt and tools can create a specialist while preserving one trajectory.

Finding 2

Shared context removes handoff compression but can carry framing bias across roles.

Finding 3

Independent Agents require an explicit data plane and control plane.


layout: center

Where the claim stops

Boundary condition

Calling predefined stages 'multi-Agent' is useful architecturally, but the execution remains a workflow with a known path.

layout: center

Engineering takeaway

Design rule

Choose context sharing before topology: it determines information loss, isolation, parallelism, and token growth.

Continue the experiment


layout: center class: text-center

Pause and apply

Your turn

Which detail would be too dangerous to omit from a handoff—and which detail should not cross the boundary?

layout: center class: text-center

Next · Lesson 40
Choose who coordinates independent Agents and how artifacts and messages move between them.