Overview
Agents in AgentBuilder define conversational AI experiences with precise control over participants, prompts, tools, and stop conditions. This document provides the complete API specification.Agents are auto-discovered from the
agents/agents/ directory. Each file should export a default agent definition using defineAgent().defineAgent
ThedefineAgent function creates an agent configuration with full TypeScript support.
Function Signature
AgentDefinition Type
Configuration Options
Core Properties
Unique identifier for this agent. Use snake_case.Naming conventions:
- Use descriptive names:
customer_support,billing_specialist - Avoid:
agent1,bot,helper
Human-readable title. Deprecated in favor of
name.Specifies the conversation type.
| Type | Description | Side B Required |
|---|---|---|
'ai_human' | AI converses with human | No |
'dual_ai' | Two AIs converse | Yes |
Maximum total turns before conversation ends. Primarily used for
dual_ai to prevent infinite loops.Hard maximum: 250 turns regardless of this setting.Array of tags for categorization and filtering.Use cases:
- Filtering agents in UI
- Organizing agents by category
- Routing logic
Side Configuration
BothsideA and sideB use the SideConfig type:
Configuration for side A (always the AI for
ai_human agents).Configuration for side B. Required only for
dual_ai agents.For ai_human agents, side B represents the human and doesn’t need configuration.Tool Exposure
Whether to expose this agent as a callable tool for other prompts/agents.Enables agent handoffs and routing.
Description shown when agent is exposed as a tool. Required if
exposeAsTool: true.Should be specific about what the agent handles and when to use it.SideConfig
Configuration for individual sides (A or B).SideConfig Type
Side Properties
Reference to a prompt defined in
agents/prompts/.Human-readable label displayed in UI and logs.
When
true, the side’s turn ends when the AI returns text content without tool calls.Behavior:true: Turn ends after text response (conversational agents)false: Turn continues even after text (multi-step workflows)
Tool name that ends the turn when called.When specified, requires
stopToolResponseProperty.Property to extract from stop tool result.Required if
stopTool is specified.Maximum turns this side can take before stopping.
Tool that ends the entire conversation (not just the turn) when called.
Enable manual stop handling via hooks. When
true, automatic stop conditions are disabled.Stop Conditions
Multiple stop conditions can be configured. They are evaluated in priority order:Priority Order
endConversationTool- Highest priority, ends everythingstopTool- Ends current turnmaxTurns- Ends side’s participationstopOnResponse- Ends turn on text responsemaxSessionTurns- Ends conversation
Stop Condition Types
- Turn Stop Conditions
- Conversation End Conditions
Control when a single turn ends:
| Condition | Configuration | Description |
|---|---|---|
| Text Response | stopOnResponse: true | Stop when AI returns text without tools |
| Specific Tool | stopTool: 'tool_name' | Stop when specific tool is called |
| Max Turns | maxTurns: N | Stop after N turns by this side |
| Manual | manualStopCondition: true | Stop handled by hooks |
Type Definitions
Generated Types
After defining agents, AgentBuilder generates type-safe references:AgentDefinition Interface
Complete TypeScript definition:SideConfig Interface
Complete Examples
Basic Support Agent
Multi-Step Workflow Agent
Specialist Agent for Handoffs
Dual AI Debate Agent
Iterative Evaluation Agent
Execution Details
Message Role Encoding
Indual_ai agents, message roles encode side information:
| Side | Stored Role | From Own Perspective | From Other’s Perspective |
|---|---|---|---|
| Side A | assistant | assistant | user |
| Side B | user | assistant | user |
- Each AI sees its own messages as
assistantrole - Each AI sees the other’s messages as
userrole - Stored roles remain consistent for replay
Execution Flow
ai_human Execution
dual_ai Execution
File Structure
- One agent per file
- Default export required
- Use snake_case for file names
- No nested directories