Week 4 slides: many agents

← → to move, F for full screen, N for speaker notes

AI in Research · Week 4 · October 21, 2026

Many agents

When one agent hands work to another, who decides, what they share, and how they stay out of each other's way.

This week

Subagents, workflows vs agents, peer agents and how they talk, sandboxes for many agents, and when many agents help or hurt

Homework 4 · due Oct 28

An email MCP server. Your agent gets its own inbox and says hello to the class agent.

class.xhelio.ai/week-4

Week 4 · Recap of week 302

Last week: the layers around one loop

Tools

What it can do

Built-in tools and MCP servers: a tool is a prompt and a function. Every schema rides along on every call.

Instructions

What it is told

AGENTS.md for a few rules, skills for procedures, plugins to bundle them. A short index in context, the library on disk.

Control

What it may do

Permissions, sandboxes and hooks: the only layers that enforce, because they run outside the context.

Codex and Claude Code are your loop plus these layers. This week: many loops.

Week 4 · Recap of week 303

Last week's question: when does it enter the context?

WhenWhatSo
Always, every callsystem prompt, tool and MCP schemas, AGENTS.md, skill descriptionskeep it short: you pay on every trip
On demanda skill's body and files, deferred tools, notes, a subagent's reportmake the index entry good, or it is never opened
Neverpermission rules, hooks, the sandbox, a subagent's own workthe only layers that enforce

A subagent appears in two rows: its report comes back, its work never does. That is today's starting point.

Week 4 · Recap of week 304

Last week's warning, and your homework

The lethal trifecta

Private data + untrusted content + a way out = anyone who can put text in front of your agent can make it send your data away.

Remove one leg. With many agents, every message from another agent is untrusted content too.

Homework 3 · due today

Two MCP servers as plugins: Telegram, and one for your research. Your harness loads them, and you ask it a research question from your phone.

Only your chat ID gets in; you approve every command by reply.

This week's homework adds a third plugin, email, so your agent can talk to other agents.

Week 4 · Today05

Four lines from one agent to many

why split workdefining onefan-outthe catch workflow or agent?five patternsa research pipeline topologieshow agents talkpeer teamsA2Adoes it help? worktreescontainers, microVMshow we graded week 2 1 Subagents2 Workflows3 Peer agents4 Sandboxes oneagenthomework4
Week 4 · 1 Subagents06

Why hand work to another agent?

A clean context

Read a lot, report a little

The subagent reads 50 files or 30 papers; only its summary enters the main agent's context.

Parallel

Several at once

Independent searches run side by side: minutes instead of an hour.

Specialized

Its own prompt, tools, model

A read-only explorer on a cheap model; a reviewer that can't edit.

The price: more tokens, and everything the subagent learned but didn't write in its report is lost.

Week 4 · 1 Subagents07

A subagent is a file

.claude/agents/paper-scout.md · Claude Code

--- name: paper-scout description: Finds and summarizes papers on a narrow question. Use for literature searches. tools: WebSearch, WebFetch, Read model: haiku --- You search the literature for one question. Return at most 10 papers: citation, one-line finding, and how sure you are it's relevant. Never cite a paper you did not open.

.codex/agents/paper-scout.toml · Codex

name = "paper-scout" description = """Finds and summarizes papers on a narrow question.""" model = "gpt-6.1-sol" developer_instructions = """ You search the literature for one question. Return at most 10 papers: citation, one-line finding, and how sure you are it's relevant. Never cite a paper you did not open. """

Like a skill, the description is what the main agent sees, and it decides when to call it. The body is the subagent's system prompt.

Week 4 · 1 Subagents08

What a subagent call contains, exactly

1 · The lead's tool call

{"name": "Agent", "input": { "subagent_type": "paper-scout", "description": "Find papers", "prompt": "Papers since 2019 on switchbacks vs distance from the Sun. Return citation, finding, relevance."}}

2 · The subagent's first call

system: paper-scout.md body + its own tools user: the prompt, only # not included: # the lead's chat, # files it read, # what the user said

3 · What comes back

{"type": "tool_result", "content": "1. Bale et al. 2021 ... 2. ..."} # its final message # only; its 40 # searches are # thrown away

The prompt is the only bridge between the two contexts, in both directions. Write it like a brief to a new colleague.

Week 4 · 1 Subagents09

Fan-out: one lead, many searchers

+90%

Anthropic's research system, a lead agent with parallel subagents, against one agent alone on their research evaluation.

Lead: Claude Opus 4. Subagents: Claude Sonnet 4. June 2025.

The bill

Agents use about 4× the tokens of a chat; multi-agent systems about 15×.

The reason it works

On their browsing benchmark, token use alone explained 80% of the difference in performance. More agents is a way to spend more tokens in parallel.

Anthropic Engineering, "How we built our multi-agent research system", June 13, 2025

Week 4 · 1 Subagents10

The catch: every hand-off loses something

"Share context, and share full agent traces, not just individual messages."

"Actions carry implicit decisions, and conflicting decisions carry bad results."

Walden Yan, Cognition, "Don't Build Multi-Agents", June 2025

Their example

"Build a Flappy Bird clone", split in two. One subagent draws a background in the style of Super Mario; the other builds a bird that looks and moves nothing like it.

Each did its part well. Neither knew what the other had decided.

Rule of thumb: give subagents jobs that are independent, and say exactly what to return.

Week 4 · 2 Workflows11

Who decides the next step: your code, or the model?

"Workflows are systems where LLMs and tools are orchestrated through predefined code paths. Agents, on the other hand, are systems where LLMs dynamically direct their own processes and tool usage."

Erik Schluntz and Barry Zhang, Anthropic, "Building effective agents", December 2024

Workflow

Your script fixes the steps; the model fills each one in.

Predictable, cheap, easy to test. Can't handle the unexpected.

Agent

The model chooses the steps, in a loop, until it decides it's done.

Flexible. Harder to predict, test and budget.

Their advice: "find the simplest solution possible, and only increase complexity when needed."

Week 4 · 2 Workflows12

Five patterns, from the same post

1 Chaining2 Routing3 Parallelization 4 Orchestrator–workers5 Evaluator–optimizer each call's output feeds the nextclassify, then send to a specialistsplit, run at once, combine a model plans the subtasks at run timeone writes, one critiques, repeat outlinedraftpolish classifymathcode splitABCcombine orchestratorworkerworkerworkersynthesis generatorevaluator draftfeedback stop when it passes
Week 4 · 2 Workflows13

A literature review, built from the patterns

questions = llm("Split this topic into 5 search questions", topic) # 1 chaining results = parallel(agent("paper-scout", q) for q in questions) # 3 parallelization draft = llm("Write a 1-page review from these notes", results) for _ in range(3): # 5 evaluator–optimizer critique = llm("Check every claim against its source. List errors.", draft, results) if "no errors" in critique: break draft = llm("Fix these errors", draft, critique)

Code decides the shape: 5 searches, at most 3 rounds of checking. Repeatable, and its cost is bounded.

Agents only where the work is open-ended: each paper-scout chooses its own searches.

Most useful research systems look like this: a workflow with agents inside.

Week 4 · 3 Peer agents14

Three shapes for a team of agents

HierarchyPeersPipeline a lead hands out tasks and reads reportssubagents, orchestrator–workers anyone can message anyoneagent teams, mailboxes, a shared board each passes its output ona workflow; review chains

Hierarchies are easiest to control. Peers are more flexible, and need a shared place to agree on who does what.

Week 4 · 3 Peer agents15

How agents talk to each other

ChannelHow it worksGood for
A tool call and its resultthe lead calls a subagent; the report comes back as the tool resulthierarchies, one hand-off
Shared filesa plan, a task list, notes, git commits and lock files in one folder or repolong jobs; anyone can read the state
Messagesa mailbox per agent: send, check, reply. Email is the oldest version.peers; agents that run at different times
A shared MCP servera board every agent connects to: post a task, claim it, reportcoordination across machines and harnesses
A2Aa standard protocol between agents from different vendorsagents you don't control

Every one of these ends the same way: text in the receiving agent's context.

Week 4 · 3 Peer agents16

Peer teams in practice: Claude Code's agent teams

team lead shared task listpending · in progress · done teammateteammateteammate messages, agent to agent

Each teammate is a full session with its own context. They claim tasks from a shared list (with file locks) and message each other by name.

The docs: start with 3–5 teammates; "three focused teammates often outperform five scattered ones". Good for research, review, and competing hypotheses; bad for editing the same file.

Experimental since February 2026 (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1). A message from another agent can't approve a permission prompt.

Week 4 · 3 Peer agents17

Two big experiments, two answers on coordination

Anthropic · Feb 2026

16 Claudes write a C compiler

No orchestrator. Each agent in its own container, all pushing to one git repo; a task is claimed by writing a lock file.

~2,000 sessions, 2 weeks, just under $20,000: 100,000 lines of Rust that build Linux on three architectures and pass 99% of most compiler test suites. The key: near-perfect tests, with GCC as the oracle.

Cursor · Jan 2026

Hundreds of agents build a browser

Flat peers with locks stalled: "Twenty agents slowed to the throughput of two or three."

What worked: planners that create tasks, workers that just do them without talking to each other, and a judge that decides each cycle whether to go on, with fresh starts against drift. Over a million lines in about a week.

Both kept agents from talking much. The shared truth was the repository and the tests, not the conversation.

Nicholas Carlini, "Building a C compiler with a team of parallel Claudes", Feb 5, 2026 · Wilson Lin, Cursor, "Scaling long-running autonomous coding", Jan 14, 2026

Week 4 · 3 Peer agents18

A2A: the problem it solves

Your agent needs help from an agent someone else runs: a data center's archive agent, another lab's analysis agent, a vendor's.

You can't see its prompt, tools or memory, and you shouldn't. As an MCP tool it would be one call and one answer. But it may need an hour, ask you a question, send progress, and return files.

A2A, in its own words

"An application-level protocol for agents to discover each other, negotiate interaction modalities, and" work together on tasks, while staying opaque to each other.

Google, April 2025 · IBM's ACP merged in, August 2025 · version 1.0, March 2026 · Linux Foundation's Agentic AI Foundation, August 2026 · 150+ organizations

Week 4 · 3 Peer agents19

A2A and MCP: complementary, not competing

MCPA2A
Connectsan agent to tools and dataan agent to another agent
The other sidea function: does what it's askedan agent: own model, tools, judgment
Unit of worka tool call: one request, one resulta task: a lifecycle, may ask for input, stream, push updates
Discoverytools/list from a server you configuredan Agent Card at a well-known URL
Transportstdio or Streamable HTTPHTTP: JSON-RPC, gRPC or HTTP+JSON
Typical placeinside your harnessacross teams and organizations

The spec: "An A2A Client agent might request an A2A Server agent to perform a complex task. The Server agent, in turn, might use MCP to interact with several underlying tools."

Week 4 · 3 Peer agents20

Exactly what is in A2A 1.0

PartWhat it defines
1 · Data modelAgentCard, Task, Message, Part, Artifact, written as Protocol Buffers; a2a.proto is the normative definition
2 · Operationseleven abstract operations: send, stream, get, list, cancel, subscribe, push notifications, extended card
3 · Bindingsthe same operations over JSON-RPC 2.0, gRPC or HTTP+JSON (REST); custom bindings allowed
StreamingServer-Sent Events for live updates on a task
Push notificationsthe server POSTs updates to a webhook you registered: for tasks that take hours
Securityschemes declared on the card: API key, HTTP auth, OAuth 2.0, OpenID Connect, mutual TLS; cards can be signed (JWS)
Versioning, extensionsA2A-Version: 1.0 on each request; opt-in extensions declared in capabilities

a2a-protocol.org/latest/specification (v1.0.0)

Week 4 · 3 Peer agents21

The Agent Card: an agent's business card

https://agent.example.edu/.well-known/agent-card.json

{ "name": "Solar Wind Archive Agent", "description": "Finds and summarizes OMNI solar wind data", "version": "1.2.0", "supportedInterfaces": [{ "url": "https://agent.example.edu/a2a", "protocolBinding": "JSONRPC", "protocolVersion": "1.0" }], "capabilities": { "streaming": true, "pushNotifications": true }, "defaultInputModes": ["text/plain"], "defaultOutputModes": ["text/plain", "text/csv"], "skills": [{ "id": "omni-summary", "name": "Solar wind summary", "description": "Summarize solar wind for a date range", "tags": ["heliophysics"], "examples": ["May 10-12, 2024"] }], "securitySchemes": { "oauth": { ... } } }

Served at a well-known URL, so any client can find out what the agent does, where to reach it, and how to log in.

Skills play the role of MCP tool descriptions: the client's model reads them to decide whether to delegate.

Cards can be signed, and a fuller card can be served only after login.

Week 4 · 3 Peer agents22

The eleven operations

JSON-RPC methodWhat it does
SendMessagesend a message; get back a Task, or a direct Message for quick answers
SendStreamingMessagethe same, with a live stream of updates
GetTask · ListTasksa task's state, artifacts and history; your tasks, paginated
CancelTaskask to stop (not guaranteed)
SubscribeToTaskreopen a stream on a task that is still running
Create · Get · List · Delete
TaskPushNotificationConfig
manage the webhooks the agent calls with updates
GetExtendedAgentCarda fuller card, only after you authenticate

Compare MCP's core: tools/list and tools/call. A2A's extra operations are all about tasks that outlive one request.

Week 4 · 3 Peer agents23

A task's life

SUBMITTEDWORKINGINPUT_REQUIREDAUTH_REQUIRED COMPLETEDFAILEDCANCELEDREJECTED agent acceptsyou answeryou log inartifacts readyterminal states:no more changesdeclined at once

A Task has an id, a contextId grouping related tasks, a status (state, message, time), its artifacts and its history.

Week 4 · 3 Peer agents24

One task on the wire

Request · JSON-RPC binding

POST https://agent.example.edu/a2a A2A-Version: 1.0 {"jsonrpc": "2.0", "id": 1, "method": "SendMessage", "params": {"message": { "messageId": "m-41", "role": "ROLE_USER", "parts": [{"text": "Summarize solar wind for May 10-12, 2024"}]}}}

Result · a Task

{"jsonrpc": "2.0", "id": 1, "result": {"task": { "id": "t-9f2", "contextId": "c-17", "status": {"state": "TASK_STATE_COMPLETED"}, "artifacts": [{ "artifactId": "a-1", "name": "summary", "parts": [{"text": "Peak 980 km/s on May 11 ..."}]}]}}}

A Part holds exactly one of text, raw (file bytes), url or data (JSON). A long task would come back WORKING; you'd stream it, poll GetTask, or wait for your webhook.

Week 4 · 3 Peer agents25

Does it help? It depends on the task's shape

Parallel task

+81%

A coordinated team on a finance task that splits into independent lookups.

Sequential task

−39 to −70%

Every multi-agent design on a step-by-step planning task.

Errors

17×

Independent agents amplified errors 17.2×; a central coordinator held it to 4.4×.

And once one agent already scores above about 45%, adding agents gave negative returns. On SWE-bench Verified, every multi-agent design was slightly worse.

Google Research, Google DeepMind and MIT, "Towards a Science of Scaling Agent Systems", arXiv 2512.08296 (v3, April 2026): 260 configurations, 6 benchmarks, 3 model families

Week 4 · 3 Peer agents26

How teams of agents fail

1,642 traces from 7 open-source multi-agent frameworks: 41% to 87% of tasks failed. Fourteen failure modes in three groups:

GroupShareMost common
System design44%repeating steps; not knowing when to stop
Agents misaligned32%saying one thing, doing another; drifting off task
Verification24%checking wrongly, or not at all

Cemri et al., "Why Do Multi-Agent LLM Systems Fail?", NeurIPS 2025

The echo chamber

Agents that debate tend to agree, not correct: in one 2026 study peers' arguments flipped correct answers up to 70% of the time.

Most of debate's gain comes from simple majority voting (NeurIPS 2025). Disagreements are settled by tools and tests, not more talk.

Week 4 · 3 Peer agents27

When many agents are worth it

Worth it

  • Breadth: many independent searches or reads
  • Context too big for one agent
  • A separate checker that didn't write the work
  • A shared, testable target (a test suite, a CRC, a verifier)

Not worth it

  • Tightly coupled work: one paper, one figure, one design
  • Steps that must happen in order
  • A small budget: expect several times the tokens
  • No way to check the combined result

Start with one agent. Add a second when you can name the job it does that the first can't.

Week 4 · 4 Sandboxes28

Many agents need walls between them

Files

Their own copy

Two agents editing one folder overwrite each other. Give each a git worktree or a fresh clone.

Processes

Their own machine

A runaway command, a full disk or a bad install stays inside a container or microVM.

Secrets

No real keys inside

A proxy outside the box adds the key, limits what can be called, and counts it.

Week 3's sandbox protected your computer from one agent. With many agents it also protects them from each other, and your budget from all of them.

Week 4 · 4 Sandboxes29

Git worktrees: one repository, many desks

git worktree add ../fit-a -b try-powerlaw git worktree add ../fit-b -b try-broken-powerlaw # two agents, two folders, two branches, one history cd ../fit-a && claude -p "Fit a power law ..." & cd ../fit-b && codex exec "Fit a broken power law ..." & wait git diff try-powerlaw try-broken-powerlaw # compare, then merge one

Claude Code: claude --worktree, or isolation: worktree on a subagent. The Codex app creates worktrees for parallel tasks.

Each agent gets its own folder and branch, sharing one repository.

Nobody overwrites anybody. You compare and merge at the end, like reviewing two students' versions.

Week 4 · 4 Sandboxes30

Containers, gVisor, microVMs: how thick is the wall?

What separates the agent from the hostExamples
Containerits own files and processes, but the same kernel as the host: one kernel bug can escapeDocker; Claude Managed Agents and Codex cloud run one per task
gVisora user-space kernel between the agent and the real oneModal Sandboxes (default)
MicroVMits own kernel behind hardware virtualization; boots in under 125 ms with under 5 MiB overheadFirecracker: E2B, Vercel Sandbox; Cloudflare Sandbox SDK

Common features: snapshots and resume, an egress firewall with a domain allow list, keys injected at the network boundary.

The SDKs plug in: OpenAI's Agents SDK and Claude Managed Agents can run their agents in these providers' sandboxes.

Firecracker (firecracker-microvm.github.io) · each provider's docs, checked October 2026

Week 4 · 4 Sandboxes31

How we tested your week 2 harnesses

Lead agentone prompt per PR subagent → container → harness #9subagent → container → harness #10subagent → container → harness #11subagent → container → harness #12subagent → container → harness #13subagent → container → harness #14 Key proxyadds the key, caps calls Model

Parallel: six testers, about 5 minutes each, all at once.

Isolated: your code ran in a throwaway container, never on our computer.

No real key inside: each harness got a label, not a key; 96 model calls in total.

Week 4 · 4 Sandboxes32

An agent you can call like a function

claude -p "Summarize results.csv" --output-format json codex exec "Summarize results.csv" --json # fan out from Python: one agent per file, at most 4 at once from concurrent.futures import ThreadPoolExecutor def review(path): return subprocess.run(["codex", "exec", f"Check {path} for unit errors"], capture_output=True, text=True, timeout=900).stdout with ThreadPoolExecutor(4) as pool: reports = list(pool.map(review, glob("analysis/*.py")))

Headless mode: no chat, a prompt in and a result out.

The SDKs do the same from code: Claude Agent SDK, Codex SDK, OpenAI Agents SDK.

codex exec is read-only by default. Give each a time limit and a budget.

Week 4 · Wrap-up33

The whole picture

DesignWho decides the stepsWhat they shareTypical failure
One agentthe modelone contextthe context fills up
Workflowyour codewhat your code passes oncan't handle the unexpected
Lead + subagentsthe lead modeltask text down, reports uplossy reports, duplicated work
Peer teameach agent, plus a shared boardmessages, files, a task listconflicting decisions, waiting forever
Across vendors (A2A)each agent's ownertasks and artifactstrust: whose agent is it?

Each row up is cheaper and more predictable; each row down can do more. Pick the highest row that does the job.

Week 4 · Homework34

Homework 4: give your agent an inbox

  1. A new Gmail account just for your agent, with an app password. Never your own or UCLA mail.
  2. An email MCP server as a plugin: check the inbox, read, send. Every email is untrusted text.
  3. Your agent says hello to the class agent in this format, then reads its reply.

to: lingtai2026@gmail.com

Subject: [AIR-2026 hello] <github-username> class: AI in Research 2026 github: <github-username> agent: <your agent's name> harness: <your harness repo> model: <the model it runs on> plugins: telegram, <research plugin>, email research: <one sentence> reply-to: <your agent's Gmail> <A note by your agent, at most 100 words.>

Missed weeks 2–3? Use Claude Code, Codex or OpenClaw; your own loop teaches you more. Due Wed Oct 28 · class.xhelio.ai/week-4/homework

Week 4 · Wrap-up35

Takeaways

  • A subagent buys a clean context and parallelism; every hand-off loses what wasn't in the report.
  • Decide who decides: code for the fixed steps, a model where the work is open-ended.
  • Peers need a shared place to agree: files, messages, a board. Every message is tokens, and untrusted.
  • Many agents pay for breadth and independent checks, at several times the tokens; not for coupled work.
  • Run them with walls: a worktree each, a sandbox each, and no real key inside.

Reading: class.xhelio.ai/week-4/reading