Lesson 09 · cooperation

Multiple agents communicate through file mailboxes

From subagent to teammate: one-time → persistent; nameless → named; no communication → file mailbox.

⏱ ~12 min · 📝 3 interactive widgets · 🧑‍💻 Based on shareAI-lab · s09_agent_teams.py

What is the difference between Subagent and Teammate?

The subagent of S04 is simple and crude: spawn → run → return to summary → die. A one-off, no name, no two-way communication between father and son.

s09's teammate is an independent agent that has a name, can be awakened repeatedly, and can send and receive messages:

subagent (s04):  spawn -> execute -> return -> destroyed
teammate (s09):  spawn -> work -> idle -> work -> ... -> shutdown

The two mechanisms serve different purposes:

  • Subagent is suitable for "doing a specific exploration" (such as reviewing a PR).
  • Teammate is suitable for "continuously assuming a role" (such as a long-term reviewer who is woken up every time there is a new commit).

The mailbox is a JSONL file

How do team members communicate with each other? s09 uses the most primitive mechanism: append-only JSONL file.

.team/
  config.json # Team roster
  inbox/
    alice.jsonl # Letters to alice are appended here
    bob.jsonl
    lead.jsonl

send is open("alice.jsonl", "a").write(msg); read is to read the entire file, parse JSONL, and then clear truncate (drain semantics).

Why use files instead of memory queues? Documents are naturally durable. Agent restarts, processes crash, even machine restarts - the emails are still there. Plus it's readable and grep-able, and the debugging experience is very good.

Look at the complete process of a message from lead to alice

The following widget allows you to send a message to Alice and see what is happening on the disk at each step.

5 message types

s09 defines 5 message types (VALID_MSG_TYPES), but only the first two are implemented, and the last three are added in the s10 protocol class:

  • message — Normal text message.
  • broadcast — Send to all teammates except yourself.
  • shutdown_request / shutdown_response — Request/response graceful shutdown (s10).
  • plan_approval_response — Plan approval (s10).

Why is it declared but not implemented? Because s09 wants to make "protocol extension" open-the message type is an enumeration. To add a new one, you only need to add an entry in the dictionary and process it in _exec routing.

Interactive

Widget 1 · Mail Flow · A message from lead to alice

Click Send and trace each step on the file system: lead.send → append alice.jsonl → alice next read inbox → truncate.

Interactive

Widget 2 · Team Config · Who is online and what is their status?

.team/config.json is the team roster. Do a few operations (spawn / message / shutdown) and see how the configuration changes.

操作
.team/config.json

        
Interactive

Widget 3 · Subagent vs Teammate · Deciding Which to Use

6 mission scenarios, decide whether to use subagent (spawn-then-die) or teammate (spawn-then-live). Consider whether the task is a "one-and-done deal."

答对 0 / 6