Learn Claude Code
s09

Agent Teams

Collaboration

Teammates + Mailboxes

386 LOC10 toolsTeammateManager + file-based mailbox
When one agent can't finish, delegate to persistent teammates via async mailboxes

s01 > s02 > s03 > s04 > s05 > s06 > s07 > s08 > [ s09 ] s10 > s11 > s12

"When one can't do it all, call for teammates" -- multi-role agents collaborate via mailbox messaging.

Harness layer: Collaboration -- multi-agent communication, specialized division of labor.

Problem

s04's subagents are ephemeral: spawn → work → return → gone. No persistent identity, no conversation, no collaboration. Real teams need: persistent roles, bidirectional messaging, shared context.

Solution

Mailbox system: agents send/receive messages asynchronously. Role agents have persistent context.

Key Code

class Mailbox:
    def send(self, from_agent, to_agent, content): ...
    def receive(self, agent_name): ...

class RoleAgent:
    def __init__(self, name, role_prompt, mailbox): ...
    def step(self): ...  # Check inbox, reason, send messages

What's New (s04 → s09)

Components04s09
LifecycleEphemeralPersistent roles
CommunicationNone (return only)Bidirectional mailbox
RolesUndifferentiatedSpecialized

Deep Dive

Q1: Why Mailbox not shared messages array?

Async decoupling. Shared array causes context bloat and role confusion.

Q2: How does Orchestrator decide turn order?

Simple: fixed order. Advanced: dynamic scheduling based on inbox state. s10's FSM formalizes this.

Q3: What if agents disagree?

Max discussion rounds. Orchestrator decides or escalates to human.

Q4: Difference from s20?

s09 = multi-role in same process. s20 = multi-process parallel.

Q5: Max number of roles?

2-4 roles optimal. Beyond 5, coordination overhead exceeds specialization benefits.

Try It

cd learn-claude-code
python agents/s09_agent_teams.py

References