agent-orchestrator-sdk
Orchestrate teams of LLM-powered agents in Rust. Coordinate multiple agent instances working together — one session acts as the team lead, coordinating work and assigning tasks. Teammates work independently, each with its own context, and communicate directly with each other.
The package is published as agent-orchestrator-sdk and imported in Rust code as agent_sdk.
Additional usage docs live under docs/ in the repository.
When to use agent teams
Agent teams are most effective when parallel exploration adds real value:
- Research and review: multiple teammates investigate different aspects simultaneously, then share and challenge findings
- New modules or features: teammates each own a separate piece without stepping on each other
- Debugging with competing hypotheses: teammates test different theories in parallel
- Cross-layer coordination: changes spanning frontend, backend, and tests — each owned by a different teammate
Agent teams use more tokens than a single session. For sequential tasks, same-file edits, or highly dependent work, a single AgentLoop is more effective.
Compare: single agent vs agent team
Single Agent (AgentLoop) |
Agent Team (AgentTeam) |
|
|---|---|---|
| Context | One context window | Each teammate has its own context |
| Communication | N/A | Teammates message each other directly |
| Coordination | Sequential tool calls | Shared task list with self-coordination |
| Best for | Focused tasks, quick operations | Complex work requiring parallel exploration |
| Token cost | Lower | Higher: each teammate is a separate agent |
Quick start
# Cargo.toml
[]
= "0.1"
= { = "1", = ["full"] }
# or OPENAI_API_KEY
Start your first agent team
Create a team, describe the teammates you want, add tasks, and run. The lead spawns teammates, they claim work from the shared task list, and coordinate on their own:
use AgentTeam;
use ;
use Task;
async
For simple tasks that don't need a team, use run_single:
let result = new
.run_single
.await?;
println!;
Interactive CLI
Architecture
┌─────────────────────────────────────────────┐
│ Team Lead │
│ Spawns teammates, coordinates work, │
│ approves plans, routes messages │
└──────────┬──────────────┬───────────────────┘
│ │
┌─────▼────┐ ┌─────▼────┐
│Teammate 1│ │Teammate 2│ ... (N parallel)
│AgentLoop │ │AgentLoop │
└─────┬────┘ └─────┬────┘
│ │
│ ┌─────────┘ Teammates can
│ │ message each other
┌─────▼────▼──────────────────────────┐
│ Shared Services │
│ TaskStore · MemoryStore · Mailbox │
└─────────────────────────────────────┘
An agent team consists of:
| Component | Role |
|---|---|
| Team lead | The main session that creates the team, spawns teammates, and coordinates work |
| Teammates | Separate agent instances that each work on assigned tasks independently |
| Task list | Shared list of work items that teammates claim and complete |
| Mailbox | Messaging system for communication between all agents |
| Memory | Shared key-value store for inter-agent coordination |
The lead is the intelligence — there is no separate planning step. You tell it what you want and it coordinates the team, just like Claude Code's agent teams.
Control your agent team
Specify teammates and roles
Each teammate gets its own context window and works independently:
new
.add_teammate
.add_teammate
.add_teammate
Add tasks with dependencies
Tasks are claimed by teammates from a shared task list. Dependencies are resolved automatically — blocked tasks unblock when their dependencies complete:
let schema = new
.with_priority;
let client = new
.with_dependencies // waits for schema
.with_priority;
let tests = new
.with_dependencies
.with_priority;
Task claiming uses file locking to prevent race conditions when multiple teammates try to claim the same task.
Require plan approval
For complex or risky work, require teammates to plan before implementing:
new
.add_teammate_with_plan_approval
The teammate generates a plan, sends it to the lead for review. The lead evaluates using the LLM and either approves (teammate implements) or rejects with feedback (teammate revises).
Teammate-to-teammate messaging
Teammates communicate directly through the message broker — not just through the lead:
use *;
// Direct message to another teammate
let msg = new
.with_payload;
broker.route?;
// Broadcast to all teammates
let broadcast = new
.with_payload;
broker.route?;
Shutdown negotiation
When the lead requests shutdown, teammates can accept or reject:
- Accept: teammate is idle, shuts down gracefully
- Reject: teammate is still working, provides a reason and keeps going
Enforce quality gates with hooks
Hooks run at key points in the agent lifecycle. Return Reject to block an action and send feedback:
use ;
;
| Hook | When it fires | Reject effect |
|---|---|---|
TeammateIdle |
Teammate has no more work | Keeps teammate active |
TaskCreated |
Task being added to store | Prevents task creation |
TaskCompleted |
Task being marked done | Prevents completion, task retries |
Monitor agent events
Subscribe to events for logging, UI, or metrics:
let = ;
spawn;
let result = new
.event_channel
// ...
.run
.await?;
Low-level API
AgentLoop (single agent)
The building block underneath everything. Use it for full control:
use Arc;
use ;
use ToolRegistry;
use ReadFileTool;
use Uuid;
let client = create_client?;
let mut tools = new;
tools.register;
let mut agent = new;
let result = agent.run.await?;
Custom tools
Implement the Tool trait to give agents new capabilities:
use async_trait;
use ;
use json;
;
Add tools to teammates via PromptBuilder::customize_tools.
TeamLead (direct control)
For full control over team orchestration:
use Arc;
use *;
use AgentConfig;
use HookRegistry;
use DefaultPromptBuilder;
use Uuid;
let lead = TeamLead ;
let summary = lead.run.await?;
Built-in tools
| Tool | Description |
|---|---|
read_file |
Read file contents with optional offset/limit |
write_file |
Write/create files in the work directory |
list_directory |
List files and directories |
search_files |
Search by glob pattern and/or content regex |
run_command |
Execute shell commands (configurable whitelist) |
read_memory / write_memory / list_memory |
Shared key-value memory |
get_task_context / list_completed_tasks |
Inspect other agents' work |
Configuration
LlmConfig
LlmConfig
AgentConfig
AgentConfig
Environment variables
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY / OPENAI_API_KEY |
API key (required) |
LLM_PROVIDER |
claude or openai (auto-detected from keys) |
LLM_MODEL / ANTHROPIC_MODEL / OPENAI_MODEL |
Model override |
ANTHROPIC_API_BASE_URL / OPENAI_API_BASE_URL |
Custom endpoint |
Best practices
Give teammates enough context
Teammates don't inherit the lead's conversation. Include details in task descriptions and context:
new
.with_context
Choose appropriate team size
Start with 3-5 teammates. 5-6 tasks per teammate keeps everyone productive. Three focused teammates often outperform five scattered ones.
Size tasks appropriately
- Too small: coordination overhead exceeds benefit
- Too large: teammates work too long without check-ins
- Just right: self-contained units that produce a clear deliverable
Avoid file conflicts
Two teammates editing the same file leads to overwrites. Break work so each teammate owns different files.
Examples
Project structure
src/
lib.rs # Public API re-exports
config.rs # LlmConfig, AgentConfig
error.rs # SdkError, TaskId, AgentId
types/ # ChatMessage, Task, Envelope, MemoryEntry, FileChange
traits/ # LlmClient, Tool, PromptBuilder traits
llm/ # Claude + OpenAI clients, rate limiter
agent/
team.rs # AgentTeam — high-level entry point
team_lead.rs # TeamLead orchestrator
teammate.rs # Teammate worker (plan mode, shutdown negotiation)
agent_loop.rs # ReAct loop (Reason + Act)
hooks.rs # Hook system (TeammateIdle, TaskCreated, TaskCompleted)
events.rs # AgentEvent enum
context.rs # Per-agent context
memory.rs # MemoryStore
task/ # TaskStore, dependency graph, file locking
mailbox/ # MessageBroker, file-based mailboxes
tools/ # Built-in tools (fs, search, command, memory, context)
bin/agent.rs # Interactive CLI
examples/
single_agent.rs # Direct AgentLoop usage
multi_agent.rs # Team with tasks
named_team.rs # Named teammates + hooks + plan approval
License
MIT