Skip to content

Commit b0edcbb

Browse files
committed
fix: updated agent docs
1 parent f4f405d commit b0edcbb

File tree

4 files changed

+690
-298
lines changed

4 files changed

+690
-298
lines changed

web/src/content/agents/agent-reference.mdx

Lines changed: 186 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ When creating agent templates, you define all aspects of the agent from scratch.
2525

2626
<AgentTemplateSchemaDisplay />
2727

28+
### Core Configuration
29+
30+
#### `id` (string, required)
31+
32+
Unique identifier for this agent. Must contain only lowercase letters, numbers, and hyphens.
33+
34+
```json
35+
"id": "code-reviewer"
36+
```
37+
38+
#### `displayName` (string, required)
39+
40+
Human-readable name for the agent.
41+
42+
```json
43+
"displayName": "Code Review Specialist"
44+
```
45+
46+
#### `spawnerPrompt` (string, optional)
47+
48+
Prompt for when and why to spawn this agent. Include the main purpose and use cases.
49+
This field is key if the agent is intended to be spawned by other agents.
50+
51+
```json
52+
"spawnerPrompt": "Spawn this agent for thorough code review, focusing on bugs, security issues, and best practices"
53+
```
54+
2855
### Model Configuration
2956

3057
#### `model` (string, required)
@@ -43,22 +70,42 @@ How the agent's output is handled.
4370

4471
**Options:**
4572

46-
- `"last_message"` - Return only the final message
47-
- `"report"` - Return a structured report
73+
- `"last_message"` - Return only the final message (default)
4874
- `"all_messages"` - Return all messages from the conversation
75+
- `"structured_output"` - Return a structured JSON object (use with `outputSchema`)
4976

5077
```json
5178
"outputMode": "last_message"
5279
```
5380

54-
#### `includeMessageHistory` (boolean, optional, default: true)
81+
#### `includeMessageHistory` (boolean, optional, default: false)
5582

56-
Whether to include conversation history when spawning this agent.
83+
Whether to include conversation history from the parent agent when spawning this agent.
5784

5885
```json
5986
"includeMessageHistory": true
6087
```
6188

89+
#### `outputSchema` (object, optional)
90+
91+
JSON Schema for structured output (when `outputMode` is `"structured_output"`). Defines the expected shape of the JSON object the agent will return.
92+
93+
```json
94+
"outputMode": "structured_output",
95+
"outputSchema": {
96+
"type": "object",
97+
"properties": {
98+
"summary": { "type": "string" },
99+
"issues": {
100+
"type": "array",
101+
"items": { "type": "string" }
102+
},
103+
"score": { "type": "number" }
104+
},
105+
"required": ["summary", "issues"]
106+
}
107+
```
108+
62109
### Tools and Capabilities
63110

64111
#### `toolNames` (array, optional, default: ["end_turn"])
@@ -91,19 +138,24 @@ List of tools the agent can use.
91138

92139
#### `spawnableAgents` (array, optional, default: [])
93140

94-
Other agents this agent can spawn.
141+
Other agents this agent can spawn. Use the fully qualified agent ID from the agent store (publisher/name@version) or the agent ID from a local agent file.
95142

96-
**Available Built-in Agents:**
143+
> **⚠️ Important:** When referencing built-in agents, you **must** specify both publisher and version (e.g., `codebuff/reviewer@0.0.1`). Omit publisher/version only for local agents defined in your `.agents/` directory.
97144
98-
- `CodebuffAI/base` - Main coding assistant
99-
- `CodebuffAI/reviewer` - Code review agent
100-
- `CodebuffAI/thinker` - Deep thinking agent
101-
- `CodebuffAI/researcher` - Research and documentation agent
102-
- `CodebuffAI/planner` - Planning and architecture agent
103-
- `CodebuffAI/file_picker` - File discovery agent
145+
**Referencing Agents:**
146+
- Published/built-in agents: `"codebuff/file-picker@0.0.1"` (publisher and version required!)
147+
- Local agents: `"my-custom-agent"` (just the agent ID)
148+
149+
**Available Built-in Agents:**
150+
- `codebuff/base` - Main coding assistant
151+
- `codebuff/reviewer` - Code review agent
152+
- `codebuff/thinker` - Deep thinking agent
153+
- `codebuff/researcher` - Research and documentation agent
154+
- `codebuff/planner` - Planning and architecture agent
155+
- `codebuff/file-picker` - File discovery agent
104156

105157
```json
106-
"spawnableAgents": ["CodebuffAI/researcher", "CodebuffAI/reviewer"]
158+
"spawnableAgents": ["codebuff/researcher@0.0.1", "my-local-agent"]
107159
```
108160

109161
### Prompt Configuration
@@ -124,19 +176,75 @@ All prompt fields support two formats:
124176
}
125177
```
126178

127-
#### Required Prompts
179+
#### Prompt Fields (all optional)
180+
181+
#### `systemPrompt` (string or object, optional)
182+
183+
Background information for the agent. Fairly optional - prefer using `instructionsPrompt` for agent instructions.
184+
185+
#### `instructionsPrompt` (string or object, optional)
186+
187+
Instructions for the agent. **This is the best way to shape the agent's behavior** and is inserted after each user input.
188+
189+
#### `stepPrompt` (string or object, optional)
190+
191+
Prompt inserted at each agent step. Powerful for changing behavior but usually not necessary for smart models.
128192

129-
#### `systemPrompt` (string or object, required)
193+
### Programmatic Control
130194

131-
Core instructions that define the agent's behavior and personality.
195+
#### `handleSteps` (generator function, optional)
132196

133-
#### `instructionsPrompt` (string or object, required)
197+
**🚀 This is what makes Codebuff agents truly powerful!** Unlike traditional prompt-based agents, `handleSteps` lets you write actual code to control agent behavior.
134198

135-
Instructions for how to process user input.
199+
Programmatically control the agent's execution using a TypeScript generator function. This enables:
200+
- **Dynamic decision making** based on tool results
201+
- **Complex orchestration** between multiple tools and agents
202+
- **Conditional branching** based on file contents or agent responses
203+
- **Iterative refinement** until desired results are achieved
204+
- **State management** across multiple steps
136205

137-
#### `stepPrompt` (string or object, required)
138206

139-
Instructions for each step of the agent's execution.
207+
**What You Can Yield:**
208+
209+
| Yield Value | What It Does |
210+
|------------|-------------|
211+
| Tool call object | Execute a specific tool and get its result |
212+
| `'STEP'` | Run agent's LLM for one generation step |
213+
| `'STEP_ALL'` | Let agent run until completion |
214+
| `return` | End the agent's turn immediately |
215+
216+
**Tool Call Pattern:**
217+
```typescript
218+
const { toolResult, toolError } = yield {
219+
toolName: 'read_files',
220+
input: { paths: ['file.ts'] }
221+
}
222+
// Now you can use toolResult to make decisions!
223+
```
224+
225+
**Example:**
226+
```typescript
227+
handleSteps: function* ({ agentState, prompt, params }) {
228+
// First, read some files
229+
const { toolResult } = yield {
230+
toolName: 'read_files',
231+
input: { paths: ['src/index.ts', 'src/config.ts'] }
232+
}
233+
// Then spawn a thinker agent
234+
yield {
235+
toolName: 'spawn_agents',
236+
input: {
237+
agents: [{
238+
agent_type: 'thinker',
239+
prompt: 'Analyze this code structure'
240+
}]
241+
}
242+
}
243+
244+
// Let the agent take over from here
245+
yield 'STEP_ALL'
246+
}
247+
```
140248

141249
### Schema Validation
142250

@@ -157,86 +265,81 @@ JSON Schema definitions for validating prompt and params when spawning the agent
157265
"type": "string",
158266
"enum": ["markdown", "html"]
159267
}
160-
}
161-
}
162-
}
163268
```
164269

165-
### Parent Instructions
166-
167-
#### `parentInstructions` (object, optional)
168-
169-
Defines instructions that this agent provides to other agents when they are spawned. This allows agents to guide the behavior of their sub-agents without creating full overrides.
170-
171-
**How it works:**
172-
173-
- When an agent spawns another agent, the system looks for any `parentInstructions` targeting that agent type
174-
- These instructions are automatically injected into the spawned agent's `userInputPrompt`
175-
- Multiple agents can provide instructions for the same target agent - all will be included
176-
177-
**Structure:**
270+
**Real-World Example:**
271+
```typescript
272+
// 1. Dynamically find relevant files
273+
const { toolResult: searchResults } = yield {
274+
toolName: 'code_search',
275+
input: { pattern: params.searchPattern || 'TODO' }
276+
}
178277

179-
```json
180-
"parentInstructions": {
181-
"researcher": "Instruction text for researcher to know when to spawn your agent",
182-
"another-agent": "Different instruction for another-agent to know when to spawn your agent"
278+
// 2. Parse results and decide what to read
279+
const files = JSON.parse(searchResults || '[]')
280+
if (files.length > 0) {
281+
const { toolResult: fileContents } = yield {
282+
toolName: 'read_files',
283+
input: { paths: files.slice(0, 10) }
284+
}
285+
286+
// 3. Conditionally spawn different agents based on content
287+
if (fileContents?.includes('security')) {
288+
yield {
289+
toolName: 'spawn_agents',
290+
input: {
291+
agents: [{
292+
agent_type: 'security-reviewer',
293+
prompt: `Review security implications in: ${files.join(', ')}`
294+
}]
295+
}
296+
}
297+
}
183298
}
184-
```
185-
186-
**When to use:**
187299

188-
- **Conditional guidance**: Provide context-specific instructions based on the spawning scenario
189-
- **Workflow coordination**: Ensure spawned agents follow specific patterns or requirements
190-
- **Domain expertise**: Share specialized knowledge with relevant sub-agents
191-
- **Quality control**: Add validation or review requirements for specific agent types
192-
193-
**Validation:**
194-
195-
- Agent types in `parentInstructions` must be valid (either built-in or custom agents)
196-
- Invalid agent types will cause validation errors during agent loading
197-
198-
**Best practices:**
199-
200-
- Keep instructions concise and actionable
201-
- Focus on behavior modifications rather than complete workflow changes
202-
- Test instructions with different spawning scenarios
203-
- Consider the cumulative effect when multiple agents provide instructions for the same target
204-
- Remember that `parentInstructions` can only be defined in new agent templates, not in override files
300+
// 4. Let the LLM handle the rest with context
301+
**Why This Matters:**
302+
- Traditional agents rely solely on prompts and hope the LLM makes the right decisions
303+
- With `handleSteps`, you have **deterministic control** over the agent's workflow
304+
- You can implement complex logic that would be impossible with prompts alone
305+
- Results from one tool directly inform the next action programmatically
205306

206307
### Agent Example
207-
208-
```json
209-
{
210-
"id": "documentation-writer",
211-
"version": "1.0.0",
212-
"override": false,
213-
214-
"name": "Documentation Writer",
215-
"purpose": "Specialized agent for creating comprehensive documentation",
216-
"model": "anthropic/claude-4-sonnet-20250522",
217-
"outputMode": "last_message",
218-
"includeMessageHistory": true,
219-
220-
"toolNames": [
308+
**.agents/documentation-writer.ts**
309+
import { AgentDefinition } from './types/agent-definition'
310+
const definition: AgentDefinition = {
311+
id: "documentation-writer",
312+
version: "1.0.0",
313+
publisher: "mycompany",
314+
315+
displayName: "Documentation Writer",
316+
spawnerPrompt: "Spawn this agent for creating comprehensive documentation, API docs, or user guides",
317+
model: "anthropic/claude-4-sonnet-20250522",
318+
outputMode: "last_message",
319+
includeMessageHistory: true,
320+
321+
toolNames: [
221322
"read_files",
222323
"write_file",
223324
"code_search",
224325
"spawn_agents",
225326
"end_turn"
226327
],
227-
"spawnableAgents": ["CodebuffAI/researcher"],
328+
spawnableAgents: ["codebuff/researcher@0.0.1"],
228329

229-
"inputSchema": {
230-
"prompt": {
231-
"type": "string",
232-
"description": "What documentation to create or update"
330+
inputSchema: {
331+
prompt: {
332+
type: "string",
333+
description: "What documentation to create or update"
233334
}
234335
},
235336

236-
"systemPrompt": {
237-
"path": "./doc-writer-system.md"
337+
systemPrompt: {
338+
path: "./prompts/doc-writer-system.md"
238339
},
239-
"instructionsPrompt": "Create comprehensive documentation based on the user's request. Research existing code first.",
240-
"stepPrompt": "Continue working on the documentation. Use end_turn when complete."
340+
instructionsPrompt: "Create comprehensive documentation based on the user's request. Research existing code first.",
341+
stepPrompt: "Continue working on the documentation. Use end_turn when complete."
241342
}
343+
344+
export default definition
242345
```

0 commit comments

Comments
 (0)