Quick Start
User Interaction Flow
Handoff
Main struct for defining agent-to-agent transfers.Methods
| Method | Signature | Description |
|---|---|---|
new(target) | fn new(impl Into<String>) -> Self | Create handoff to target agent |
tool_name(name) | fn tool_name(self, impl Into<String>) -> Self | Override tool name |
tool_description(desc) | fn tool_description(self, impl Into<String>) -> Self | Override description |
config(cfg) | fn config(self, HandoffConfig) -> Self | Set configuration |
get_tool_name() | fn get_tool_name(&self) -> String | Get resolved tool name |
check_safety(source, chain) | fn check_safety(&self, &str, &HandoffChain) -> Result<()> | Verify safety |
HandoffConfig
Configuration for handoff behavior and safety.Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
context_policy | ContextPolicy | Summary | How to share context |
max_context_tokens | usize | 4000 | Max tokens in context |
max_context_messages | usize | 10 | Max messages in context |
preserve_system | bool | true | Keep system messages |
timeout_seconds | f64 | 300.0 | Execution timeout |
max_concurrent | usize | 3 | Max concurrent handoffs |
detect_cycles | bool | true | Enable cycle detection |
max_depth | usize | 10 | Max handoff chain depth |
async_mode | bool | false | Enable async execution |
Builder Methods
| Method | Signature | Description |
|---|---|---|
new() | fn new() -> Self | Create with defaults |
context_policy(policy) | fn context_policy(self, ContextPolicy) -> Self | Set policy |
max_depth(n) | fn max_depth(self, usize) -> Self | Set max depth |
detect_cycles(b) | fn detect_cycles(self, bool) -> Self | Enable/disable |
timeout_seconds(t) | fn timeout_seconds(self, f64) -> Self | Set timeout |
ContextPolicy
Controls how context is shared during handoffs.| Policy | Use Case |
|---|---|
Full | When specialist needs complete history |
Summary | Default - reduces tokens, maintains context |
LastN | Recent context only, good for long conversations |
Custom | Special formatting or filtering |
HandoffResult
Result returned from handoff execution.Factory Methods
| Method | Signature | Description |
|---|---|---|
success(response) | fn success(impl Into<String>) -> Self | Create success result |
failure(error) | fn failure(impl Into<String>) -> Self | Create failure result |
Builder Methods
| Method | Signature | Description |
|---|---|---|
with_target(agent) | fn with_target(self, impl Into<String>) -> Self | Set target agent |
with_source(agent) | fn with_source(self, impl Into<String>) -> Self | Set source agent |
with_duration(seconds) | fn with_duration(self, f64) -> Self | Set duration |
Safety Features
Cycle Detection
Prevents infinite loops between agents.Depth Limits
Limits how deep handoff chains can go.Best Practices
Use Summary context by default
Use Summary context by default
Reduces token usage while preserving essential context for the specialist.
Set appropriate depth limits
Set appropriate depth limits
Use 3-5 for most workflows. Higher values may indicate design issues.
Always enable cycle detection
Always enable cycle detection
Keep
detect_cycles: true to prevent infinite loops in complex agent networks.Use descriptive tool names
Use descriptive tool names
Override tool names to make LLM decisions clearer:
transfer_to_code_reviewer.
