Overview
AgentDefinition is the core type for creating custom Codebuff agents. It defines the agent’s behavior, available tools, model configuration, prompts, and execution logic.
Type Definition
Identity Properties
Unique identifier for this agent. Must contain only lowercase letters, numbers, and hyphens.Examples:
'code-reviewer', 'test-generator', 'doc-writer'Version string. If not provided, defaults to ‘0.0.1’ and is auto-bumped on each publish.Example:
'1.2.3'Publisher ID for the agent. Required if you want to publish the agent to the agent store.Example:
'my-company'Human-readable name for the agent shown in UI.Example:
'Code Review Assistant'Model Configuration
AI model to use for this agent. Can be any model from OpenRouter.Recommended models:
'anthropic/claude-sonnet-4.6'- Best for complex tasks'anthropic/claude-sonnet-4.5'- Balanced performance/cost'anthropic/claude-haiku-4.5'- Fast, cost-effective'openai/gpt-5.3'- OpenAI’s latest'google/gemini-2.5-pro'- Google’s flagship'deepseek/deepseek-chat-v3-0324'- Open source alternative
'meta-llama/llama-4-scout')Configuration for extended thinking/reasoning capabilities.OpenRouter reasoning tokens documentationExample:
Provider routing options for OpenRouter. Control which providers to use and fallback behavior.OpenRouter provider routing docsExample:
Tools and Subagents
MCP servers by name. Names cannot contain Example:
/.Model Context Protocol enables agents to connect to external tools and data sources.Tools this agent can use.Built-in tools:Example:
'read_files'- Read file contents'write_file'- Create/overwrite files'str_replace'- Find and replace in files'apply_patch'- Apply unified diff patches'code_search'- Search code using regex'glob'- Find files by pattern'list_directory'- List directory contents'run_terminal_command'- Execute shell commands'spawn_agents'- Spawn subagents'set_output'- Set structured output'end_turn'- End agent turn'skill'- Load skills'web_search'- Search the web'read_docs'- Read documentation
Other agents this agent can spawn as subagents.Published agents (use fully qualified ID with publisher and version):Local agents (use agent ID from your
.agents directory):Input and Output
The input schema required to spawn the agent.80% of agents only need a prompt:For structured inputs:
How the agent outputs a response to its parent. Defaults to
'last_message'.'last_message': Return only the final assistant message'all_messages': Return all messages including tool calls and results'structured_output': Return a JSON object (use withoutputSchema)
JSON schema for structured output (when
outputMode is 'structured_output').Example:Prompts
Prompt describing when and why to spawn this agent. Include the main purpose and use cases.This field is crucial if the agent is intended to be spawned by other agents.Example:
Whether to include conversation history from the parent agent. Defaults to
false.Set to true when the subagent needs context from previous messages.Whether to inherit the parent’s system prompt instead of using this agent’s own. Defaults to
false.Useful for enabling prompt caching by preserving the same system prompt prefix. Cannot be used together with systemPrompt.Background information for the agent. Fairly optional - prefer using
instructionsPrompt for behavior shaping.Example:Instructions for the agent. This is the most important prompt for shaping agent behavior.Inserted after each user input. Use this to define the agent’s task, constraints, and output format.Example:
Prompt inserted at each agent step.Powerful for changing behavior, but usually not necessary for smart models. Prefer
instructionsPrompt for most cases.Handle Steps
Programmatically control agent execution by yielding tool calls or step commands.Context:Yield types:Example 1: OrchestrationExample 2: Loop with subagents
{ toolName: string, input: any }- Execute a tool'STEP'- Run one model step'STEP_ALL'- Run until agent stops{ type: 'STEP_TEXT', text: string }- Add text to context{ type: 'GENERATE_N', n: number }- Generate N responses
Complete Example
Related Types
- CodebuffClient - Main SDK client
- RunOptions - Run configuration
- CustomTool - Custom tool definitions

