←→ 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?
When
What
So
Always, every call
system prompt, tool and MCP schemas, AGENTS.md, skill descriptions
keep it short: you pay on every trip
On demand
a skill's body and files, deferred tools, notes, a subagent's report
make the index entry good, or it is never opened
Never
permission rules, hooks, the sandbox, a subagent's own work
the 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
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
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
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
Channel
How it works
Good for
A tool call and its result
the lead calls a subagent; the report comes back as the tool result
hierarchies, one hand-off
Shared files
a plan, a task list, notes, git commits and lock files in one folder or repo
long jobs; anyone can read the state
Messages
a mailbox per agent: send, check, reply. Email is the oldest version.
peers; agents that run at different times
A shared MCP server
a board every agent connects to: post a task, claim it, report
coordination across machines and harnesses
A2A
a standard protocol between agents from different vendors
agents 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
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
MCP
A2A
Connects
an agent to tools and data
an agent to another agent
The other side
a function: does what it's asked
an agent: own model, tools, judgment
Unit of work
a tool call: one request, one result
a task: a lifecycle, may ask for input, stream, push updates
Discovery
tools/list from a server you configured
an Agent Card at a well-known URL
Transport
stdio or Streamable HTTP
HTTP: JSON-RPC, gRPC or HTTP+JSON
Typical place
inside your harness
across 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
Part
What it defines
1 · Data model
AgentCard, Task, Message, Part, Artifact, written as Protocol Buffers; a2a.proto is the normative definition
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:
Group
Share
Most common
System design
44%
repeating steps; not knowing when to stop
Agents misaligned
32%
saying one thing, doing another; drifting off task
Verification
24%
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 host
Examples
Container
its own files and processes, but the same kernel as the host: one kernel bug can escape
Docker; Claude Managed Agents and Codex cloud run one per task
gVisor
a user-space kernel between the agent and the real one
Modal Sandboxes (default)
MicroVM
its own kernel behind hardware virtualization; boots in under 125 ms with under 5 MiB overhead
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
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 oncefrom 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
Design
Who decides the steps
What they share
Typical failure
One agent
the model
one context
the context fills up
Workflow
your code
what your code passes on
can't handle the unexpected
Lead + subagents
the lead model
task text down, reports up
lossy reports, duplicated work
Peer team
each agent, plus a shared board
messages, files, a task list
conflicting decisions, waiting forever
Across vendors (A2A)
each agent's owner
tasks and artifacts
trust: 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
A new Gmail account just for your agent, with an app password. Never your own or UCLA mail.
An email MCP server as a plugin: check the inbox, read, send. Every email is untrusted text.
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.