Overview
defineAgent creates an agent configuration that defines the structure and behavior of AI-powered conversations.
Type Definition
Parameters
Unique identifier for this agent. Used in API routes and thread creation.
Agent type:
ai_human- AI assistant converses with a human userdual_ai- Two AI participants converse with each other
Human-readable display title for the agent.
When
true, this agent can be called as a tool by other agents for handoffs.Description shown when agent is available as a tool. Required if
exposeAsTool is true.Array of tags for filtering and routing.
Maximum total turns for the entire conversation. Required for
dual_ai agents.Configuration for the primary AI participant.
Configuration for the secondary participant. Required for
dual_ai agents.SideConfig
Display name for this side (shown in logs and UI).
The prompt configuration to use. Must be defined in
agents/prompts/.Stop the turn when AI returns text without calling tools.
Stop the turn when this specific tool is called.
Property from stop tool result to use as response.
End the entire conversation when this tool is called.
Maximum turns allowed for this side.
Return Value
Returns the sameAgentConfig object passed in, enabling the build system to register it.
Examples
Simple AI-Human Agent
Customer Support Agent
Workflow Agent
Dual AI Agent
Agent as Tool (Handoff)
Stop Conditions
Stop conditions control when turns and conversations end:| Condition | Description |
|---|---|
stopOnResponse: true | Stop when AI returns text without tools |
stopTool: 'name' | Stop when specific tool is called |
maxTurns: N | Stop after N turns by this side |
endConversationTool: 'name' | End entire conversation when tool is called |
Retry Sequence with Fallbacks
When a request fails:- Primary model (attempt 1) → Failed? Retry…
- Primary model (attempt 2) → Failed? Try fallback…
- Fallback 1 (attempt 1) → Failed? Retry…
- Continue until success or all fallbacks exhausted
File Location
Agents are auto-discovered fromagents/agents/:
- Use snake_case for file names
- One agent per file
- Default export required
Generated Types
After running the build,StandardAgents.Agents type is generated for type-safe references.