Welcome back! In the previous chapter, Team-Task Context Binding, we set up a private office (directory) for our team and made sure the Lead Agent focuses on the right task board.
So, we have a Leader, we have an Office, and we have a Team Name.
But imagine hiring a manager, putting them in an office, and walking away without telling them how to manage. They might try to do all the work themselves, or worse, just stare at the wall.
This chapter is about the Swarm Workflow Guidelines. This is the "Employee Handbook" or "Standard Operating Procedures" (SOP) that we feed into the AI's brain. It teaches the Lead Agent exactly how to hire, assign tasks, and communicate.
Without specific guidelines, an AI Lead Agent is just a generic chatbot. It doesn't inherently know:
We solve this by injecting a comprehensive set of instructionsβcalled a System Promptβinto the Lead Agent. This prompt acts as the Workflow Guidelines.
It transforms the AI's mindset from "I am a helpful assistant" to "I am a Project Manager orchestrating a team."
The guidelines cover three main pillars of team management. Let's look at them simply.
The guidelines teach the Lead Agent that not all workers are the same. You wouldn't hire a demolition crew to paint a portrait.
The Instruction:
"When spawning teammates... choose the
subagent_typebased on what tools the agent needs... Never assign implementation work to Read-only agents."
The guidelines define a strict order of operations so the Lead Agent doesn't get confused.
This is the most important concept for beginners. In this system, when a sub-agent finishes a turn, it goes Idle.
The Instruction:
"Teammates go idle after every turnβthis is completely normal... Do not treat idle as an error."
How do we actually get these rules into the AI? We write them in a TypeScript file called prompt.ts.
When the TeamCreate tool initializes a leader, it reads this text and forces the AI to memorize it.
Here is the code that defines how to choose teammates. We keep it clear and directive.
// Inside prompt.ts
export function getPrompt(): string {
return `
## Choosing Agent Types for Teammates
- **Read-only agents**: Use for research/planning.
Cannot edit files.
- **Full-capability agents**: Use for implementation.
Can write files and use bash.
`
}
The AI reads this and knows: "If I need to fix a bug, I must hire a Full-capability agent."
We must explicitly tell the Lead Agent how to talk. If we don't, it might try to write a letter in a text file instead of sending a direct message.
// Continuing inside prompt.ts...
`
## Automatic Message Delivery
- Messages from teammates are delivered automatically.
- You do NOT need to check your inbox manually.
- Use the 'SendMessage' tool to reply.
- Do NOT use terminal tools to "spy" on your team.
`
This prevents the Lead Agent from wasting time running Linux commands just to see if a teammate said "Hello."
Let's visualize the decision-making process of the Lead Agent when it receives a user request.
User Request: "Build a snake game."
The most complex part of the guidelines is teaching patience. Here is how the code describes it to the AI.
// The "Patience" Clause
`
## Teammate Idle State
- Idle means they are waiting for input.
- Sending a message to an idle teammate wakes them up.
- BE PATIENT with idle teammates!
`
Why is this code text? We are programming the AI using natural language (English) because LLMs understand instructions better than binary code. This text is the code that controls the manager's personality.
Finally, the guidelines explain the mechanics of the "Task Board" we built in Chapter 3.
The Lead Agent needs to know how to officially give work to someone.
// The Assignment Clause
`
## Task Ownership
- Tasks are assigned using TaskUpdate with 'owner'.
- Teammates should claim unassigned tasks.
- Prefer tasks in ID order (lowest ID first).
`
Example of the Resulting Action: Because of this guideline, when the Lead Agent wants the "Coder" to work, it generates this exact tool call:
{
"tool": "TaskUpdate",
"args": {
"task_id": "1",
"owner": "Coder",
"status": "in_progress"
}
}
The AI only knows to fill the "owner" field because our guidelines told it to.
The Swarm Workflow Guidelines are the brain of the operation. Without them, we have tools and teams, but no behavior.
By writing a clear "Employee Handbook" into prompt.ts, we ensure:
Now our team is creating tasks, assigning them, and doing work. But waitβwhat happens if the server restarts? Or if we want to pause today and continue tomorrow?
We need a way to save the entire team's memory to the hard drive.
Next Chapter: Team State Persistence
Generated by Code IQ