In the previous chapter, Recursive Agent Runtime, we learned how an AI can spawn "Sub-Agents" to help do work.
However, simply spawning agents isn't enough. If you hire three contractors to build a house but don't give them a blueprint or a schedule, you end up with three kitchens and no roof.
This chapter introduces the Task & Team Coordination layer. This is the shared "brain" that keeps all agentsโparents and childrenโaligned on what needs to be done.
Imagine a scenario: You ask the AI to "Refactor the entire database layer."
Without a shared plan:
To solve this, the system uses a persistent Task Board (similar to Trello or Jira) and organizes agents into Teams.
pending, in_progress, completed) and dependencies (Task B blocks Task A).When an AI starts a complex job, it doesn't just start coding. It follows this workflow:
in_progress, and complete them.
The agent uses the TeamCreate tool. This sets up a "Headquarters" for the project.
// Input to TeamCreate tool
{
"team_name": "database-refactor",
"description": "Migrating the user database to PostgreSQL",
"agent_type": "tech-lead"
}
Once the team exists, the agent breaks the problem down using TaskCreate.
// Input to TaskCreate tool
{
"subject": "Create migration script",
"description": "Write the SQL to alter the users table.",
"activeForm": "Writing SQL", // What is the agent doing right now?
"metadata": { "priority": "high" }
}
Any agent (Main or Sub) can look at the board using TaskList. This ensures everyone sees the same truth.
# Output from TaskList tool
#1 [completed] Analyze current schema (Alice)
#2 [in_progress] Create migration script (Bob)
#3 [pending] Update unit tests [blocked by #2]
Note how Task #3 is blocked. The system knows the Tester shouldn't start yet.
How does this work under the hood? It's not magic memory inside the AI model. It is a file-system based database.
Here is how agents interact with the system:
TeamCreateTool.ts)
When TeamCreate is called, we write a JSON file to disk. This file acts as the roster.
// Simplified from TeamCreateTool.ts
export const TeamCreateTool = buildTool({
name: "TeamCreate",
async call({ team_name, description, agent_type }, context) {
// 1. Define the Team Leader
const leadAgentId = formatAgentId("team-lead", team_name);
// 2. Create the Team File object
const teamFile = {
name: team_name,
description: description,
leadAgentId: leadAgentId,
members: [] // Other agents will be added here later
};
// 3. Save it to disk (The "Headquarters")
await writeTeamFileAsync(team_name, teamFile);
// 4. Initialize an empty Task List for this team
await ensureTasksDir(sanitizeName(team_name));
return { team_name, lead_agent_id: leadAgentId };
}
});
Explanation: We simply create a structured file. This file persists even if the AI crashes or is restarted. ensureTasksDir creates a folder where the sticky notes (tasks) will live.
TaskCreateTool.ts)Creating a task is just adding a file to that directory.
// Simplified from TaskCreateTool.ts
export const TaskCreateTool = buildTool({
name: "TaskCreate",
async call({ subject, description }, context) {
// 1. Create the task object in the database
// getTaskListId() figures out which Team we are currently in
const taskId = await createTask(getTaskListId(), {
subject,
description,
status: 'pending',
blocks: [], // Who does this task block?
blockedBy: [] // Who blocks this task?
});
// 2. Return the ID so the agent can reference it
return {
data: { task: { id: taskId, subject } }
};
}
});
Explanation: The system handles the ID generation (e.g., "1", "2", "3"). It automatically links the task to the current active Team.
TaskUpdateTool.ts)This is the most complex part. When a task is updated, we might need to notify people or unblock other tasks.
// Simplified from TaskUpdateTool.ts
export const TaskUpdateTool = buildTool({
name: "TaskUpdate",
async call({ taskId, status, owner }, context) {
// 1. Get current task data
const existingTask = await getTask(getTaskListId(), taskId);
// 2. Update status (e.g. pending -> completed)
if (status && status !== existingTask.status) {
await updateTask(getTaskListId(), taskId, { status });
// 3. If assigned to a new owner, send them a "Mailbox" message
if (owner) {
await writeToMailbox(owner, {
type: 'task_assignment',
text: `You have been assigned task #${taskId}`
});
}
}
// 4. Check for logic gaps (The "Nudge")
// If an agent closes 3 tasks but none were "Verification",
// the system warns them to double-check their work.
let verificationNudgeNeeded = checkForVerificationGap(status);
return {
success: true,
verificationNudgeNeeded
};
}
});
Explanation:
writeToMailbox. This concepts connects directly to the next chapter.verificationNudgeNeeded. This is a "safety rail." If an agent blindly marks tasks as done without verifying, the tool output basically says, "Hey, you finished a lot of work but didn't run any tests. Are you sure?"The Task & Team Coordination layer turns a chaotic group of AI agents into a disciplined workforce.
Now that our agents have a plan and a team, they need a way to talk to each other about the work. How do they send those "Mailbox" messages we saw in the code?
Next Chapter: Communication Channels
Generated by Code IQ