When the task is too big for one, delegate to teammates
What You’ll Learn
- Why subagents are not enough for multi-agent work
- How to create persistent teammates with identity
- How teammates coordinate through async mailboxes
The Problem
Subagents are disposable. They exist for one prompt, return a summary, and vanish. Real team collaboration needs persistent teammates with identity, state, and durable communication channels.
The Solution
Persistent teammates with individual messages[] and JSONL-based mailboxes:
Lead agent Teammate A Teammate B
+------------------+ +------------------+ +------------------+
| messages=[...] | | messages=[...] | | messages=[...] |
| | mailbox | | | |
| delegate_to(A) --|---------->| read prompt | | |
| | | execute... | | |
| read from A <-|-----------| write result | | |
| | | | | |
| delegate_to(B) --|-------------------------------->| read prompt |
+------------------+ +------------------+ +------------------+
How It Works
-
Each teammate has a JSONL mailbox file. The lead writes prompts; teammates write responses.
-
Teammates run their own loops independently.
class Teammate:
def __init__(self, name: str, mailbox_path: Path):
self.name = name
self.mailbox = mailbox_path
self.messages = [{"role": "system",
"content": f"You are teammate {name}."}]
def check_mailbox(self) -> list:
with open(self.mailbox) as f:
return [json.loads(line) for line in f if line.strip()]
def respond(self, prompt: str) -> str:
self.messages.append({"role": "user", "content": prompt})
# ...run agent loop...
result = final_text
with open(self.mailbox, "a") as f:
f.write(json.dumps({"role": self.name,
"content": result}) + "\n")
return result
- The lead agent uses
delegate_to(name, prompt)to send work andcheck_mailbox(name)to read responses.
What Changed From s14
| Component | Before (s14) | After (s15) |
|---|---|---|
| Agents | One | Multiple, persistent |
| Communication | Subagent summary | JSONL mailboxes |
| Identity | None | Named, stateful |
Try It
cd learn-claude-code
python agents/s15_agent_teams.py
Create two teammates: tester and reviewerHave the tester run the test suite and report resultsHave the reviewer review the tester's findings
Key Takeaway
Teammates persist beyond one prompt. They have identity, state, and communicate through durable channels — not just one-shot subagent summaries.