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

  1. Each teammate has a JSONL mailbox file. The lead writes prompts; teammates write responses.

  2. 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
  1. The lead agent uses delegate_to(name, prompt) to send work and check_mailbox(name) to read responses.

What Changed From s14

ComponentBefore (s14)After (s15)
AgentsOneMultiple, persistent
CommunicationSubagent summaryJSONL mailboxes
IdentityNoneNamed, stateful

Try It

cd learn-claude-code
python agents/s15_agent_teams.py
  1. Create two teammates: tester and reviewer
  2. Have the tester run the test suite and report results
  3. Have 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.