Skip to content

Commit 3b622ff

Browse files
committed
Merge branch 'main' into sdk-example
2 parents 8f0a9a0 + e6a6496 commit 3b622ff

File tree

136 files changed

+2611
-3757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+2611
-3757
lines changed

.agents/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Codebuff Agents
2+
3+
This directory contains your custom Codebuff agents. Each agent is a TypeScript file that defines an AI agent with specific capabilities and behavior.
4+
5+
## Getting Started
6+
7+
1. **Edit an existing agent**: Start with `my-custom-agent.ts` and modify it for your needs
8+
2. **Check out the examples and types**: See the examples and types directories to draw inspiration and learn what's possible.
9+
3. **Test your agent**: Run `codebuff --agent your-agent-name`
10+
4. **Publish your agent**: Run `codebuff publish your-agent-name`
11+
12+
## File Structure
13+
14+
- `types/` - TypeScript type definitions
15+
- `examples/` - Example agents for reference
16+
- `my-custom-agent.ts` - Your first custom agent (edit this!)
17+
- Add any new agents you wish to the .agents directory
18+
19+
## Agent Basics
20+
21+
Each agent file exports an `AgentDefinition` object with:
22+
23+
- `id`: Unique identifier (lowercase, hyphens only)
24+
- `displayName`: Human-readable name
25+
- `model`: AI model to use (see OpenRouter for options)
26+
- `toolNames`: Tools the agent can use
27+
- `instructionsPrompt`: Instructions for the agent's behavior
28+
- `spawnerPrompt`: When other agents should spawn this one
29+
- `spawnableAgents`: Which agents *this* agent can spawn
30+
31+
## Common Tools
32+
33+
- `read_files` - Read file contents
34+
- `write_file` - Create or modify files
35+
- `str_replace` - Make targeted edits
36+
- `run_terminal_command` - Execute shell commands
37+
- `code_search` - Search for code patterns
38+
- `spawn_agents` - Delegate to other agents
39+
- `end_turn` - Finish the response
40+
41+
See `types/tools.ts` for more information on each tool!
42+
43+
## Need Help?
44+
45+
- Check the type definitions in `types/agent-definition.ts`
46+
- Look at examples in the `examples/` directory
47+
- Join the Codebuff Discord community (https://discord.com/invite/mcWTGjgTj3)
48+
49+
Happy agent building! 🤖

.agents/agent-builder.ts

Lines changed: 85 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { publisher, version } from './constants'
1+
import type { AgentDefinition } from './types/agent-definition'
2+
// @ts-ignore - No default import, but we are importing as text so it's fine
3+
import agentDefinitionContent from './types/agent-definition' with { type: 'text' }
4+
// @ts-ignore - No default import, but we are importing as text so it's fine
5+
import toolsDefinitionContent from './types/tools' with { type: 'text' }
26

3-
import type { AgentConfig } from './types/agent-config'
4-
5-
const config: AgentConfig = {
7+
const definition: AgentDefinition = {
68
id: 'agent-builder',
7-
version,
8-
publisher,
9-
displayName: 'Bob the Agent Builder',
109
model: 'anthropic/claude-4-sonnet-20250522',
10+
displayName: 'Bob the Agent Builder',
11+
spawnerPrompt:
12+
'Enhanced base agent that can create custom agents and handle all coding tasks with deterministic agent creation behavior',
1113

1214
toolNames: [
1315
'write_file',
@@ -16,63 +18,92 @@ const config: AgentConfig = {
1618
'read_files',
1719
'code_search',
1820
'spawn_agents',
19-
'add_message',
2021
'end_turn',
2122
],
22-
subagents: [`codebuff/file-picker@${version}`],
2323

2424
inputSchema: {
2525
prompt: {
26-
description: 'What agent type you would like to create or edit.',
2726
type: 'string',
27+
description:
28+
'What agent type you would like to create or edit. Include as many details as possible.',
2829
},
2930
},
30-
includeMessageHistory: false,
31-
32-
parentPrompt:
33-
'Creates new agent templates for the codebuff mult-agent system',
34-
systemPrompt: `# Agent Builder
35-
36-
You are an expert agent builder specialized in creating new agent templates for the codebuff system. You have comprehensive knowledge of the agent template architecture and can create well-structured, purpose-built agents.
37-
38-
## Agent Template Patterns
39-
40-
1. **Base Agent Pattern**: Full-featured agents with comprehensive tool access
41-
2. **Specialized Agent Pattern**: Focused agents with limited tool sets
42-
3. **Thinking Agent Pattern**: Agents that spawn thinker sub-agents
43-
4. **Research Agent Pattern**: Agents that start with web search
4431

45-
## Best Practices
32+
systemPrompt: [
33+
'# Bob the Agent Builder',
34+
'',
35+
'You are an expert agent builder specialized in creating new agent templates for the codebuff system. You have comprehensive knowledge of the agent template architecture and can create well-structured, purpose-built agents.',
36+
'',
37+
'## Environment Setup Complete',
38+
'',
39+
'Your environment has been automatically prepared with:',
40+
'- Agent template type definitions in `.agents/types/agent-definition.ts`',
41+
'- Tool type definitions in `.agents/types/tools.ts`',
42+
'- Example agent files copied to `.agents/examples/` directory for reference',
43+
'- Documentation in `.agents/README.md`',
44+
'- Your own agent template in `.agents/my-custom-agent.ts`',
45+
'',
46+
'All necessary files are now available in your working directory.',
47+
'',
48+
'## Complete Agent Template Type Definitions',
49+
'',
50+
'Here are the complete TypeScript type definitions for creating custom Codebuff agents:',
51+
'```typescript',
52+
agentDefinitionContent,
53+
'```',
54+
'',
55+
'## Available Tools Type Definitions',
56+
'',
57+
'Here are the complete TypeScript type definitions for all available tools:',
58+
'',
59+
'```typescript',
60+
toolsDefinitionContent,
61+
'```',
62+
'',
63+
'## Agent Template Patterns:',
64+
'',
65+
'1. **Base Agent Pattern**: Full-featured agents with comprehensive tool access',
66+
'2. **Specialized Agent Pattern**: Focused agents with limited tool sets',
67+
'3. **Thinking Agent Pattern**: Agents that spawn thinker sub-agents',
68+
'4. **Research Agent Pattern**: Agents that start with web search',
69+
'',
70+
'## Best Practices:',
71+
'',
72+
'1. **Use as few fields as possible**: Leave out fields that are not needed to reduce complexity',
73+
'2. **Minimal Tools**: Only include tools the agent actually needs',
74+
'3. **Clear and Concise Prompts**: Write clear, specific prompts that have no unnecessary words',
75+
'4. **Consistent Naming**: Follow naming conventions (kebab-case for IDs)',
76+
'5. **Appropriate Model**: Choose the right model for the task complexity. Default is claude-4-sonnet-20250522 for medium-high complexity tasks, and openai/gpt-5 for all other tasks.',
77+
'',
78+
'## Your Task:',
79+
'When asked to create an agent template, you should:',
80+
"1. Understand the requested agent's purpose and capabilities",
81+
"2. Choose appropriate tools for the agent's function",
82+
'3. Write a comprehensive system prompt',
83+
`4. Create the complete agent template file in .agents`,
84+
'5. Ensure the template follows all conventions and best practices',
85+
'6. Use the AgentDefinition interface for the configuration',
86+
'7. Start the file with: import type { AgentDefinition } from "./types/agent-definition.d.ts"',
87+
'',
88+
'Create agent templates that are focused, efficient, and well-documented. Always import the AgentDefinition type and export a default configuration object.',
89+
].join('\n'),
4690

47-
1. **Use as few fields as possible**: Leave out fields that are not needed to reduce complexity
48-
2. **Minimal Tools**: Only include tools the agent actually needs
49-
3. **Clear and Concise Prompts**: Write clear, specific prompts that have no unnecessary words
50-
4. **Consistent Naming**: Follow naming conventions (kebab-case for IDs)
51-
5. **Appropriate Model**: Choose the right model for the task complexity
52-
53-
## Your Task
91+
instructionsPrompt: `You are helping to create or edit an agent template. The user will describe what kind of agent they want to create or how they want to modify an existing agent.
5492
55-
When asked to create an agent template, you should:
56-
1. Understand the requested agent\'s purpose and capabilities
57-
2. Choose appropriate tools for the agent\'s function
58-
3. Write a comprehensive system prompt
59-
4. Create the complete agent template file in .agents/
60-
5. Ensure the template follows all conventions and best practices
61-
6. Use the AgentConfig interface for the configuration
62-
7. Start the file with: import type { AgentConfig } from "./types/agent-config"
93+
## Environment Ready
6394
64-
Create agent templates that are focused, efficient, and well-documented. Always import the AgentConfig type and export a default configuration object.`,
65-
instructionsPrompt: `You are helping to create or edit an agent template. The user will describe what kind of agent they want to create or how they want to modify an existing agent.
95+
Your environment has been automatically set up with:
96+
- Type definitions in \`.agents/types/\`
97+
- Example agent files in \`.agents/examples/\` directory
98+
- All necessary scaffolding complete
6699
67-
## Example Agents for Reference
100+
You can now proceed directly to agent creation or editing.
68101
69-
You have access to three example agents in \`.agents/examples/\` that demonstrate different complexity levels:
102+
## Example Agents Available
70103
71-
1. **Level 1 - Code Reviewer**: Simple agent with basic tools (read_files, write_file, end_turn)
72-
2. **Level 2 - Test Generator**: Intermediate agent with subagents and handleSteps logic
73-
3. **Level 3 - Documentation Writer**: Advanced agent with comprehensive tools, multiple subagents, and complex orchestration
104+
Three example agents are now available in your \`.agents/examples/\` directory which are all diff reviewers of increasing complexity. These can serve as examples of well-made agents at different stages of complexity.
74105
75-
**IMPORTANT**: When creating new agents, first examine these examples to find connections and patterns that relate to the user's request. Look for:
106+
**IMPORTANT**: Examine these examples to find connections and patterns that relate to the user's request. Look for:
76107
- Similar tool combinations
77108
- Comparable complexity levels
78109
- Related functionality patterns
@@ -81,135 +112,21 @@ You have access to three example agents in \`.agents/examples/\` that demonstrat
81112
82113
Use these examples as inspiration and starting points, adapting their patterns to fit the user's specific needs.
83114
84-
For new agents, analyze their request and create a complete agent template that:
115+
## For New Agents
116+
117+
Analyze their request and create a complete agent template that:
85118
- Has a clear purpose and appropriate capabilities
86119
- Leaves out fields that are not needed
87120
- Uses only the tools it needs
88121
- Follows naming conventions
89122
- Is properly structured
90123
- Draws inspiration from relevant example agents
91124
92-
For editing existing agents:
93-
- First read the existing agent file they want to edit using read_files
94-
- Understand the current structure and functionality
95-
- Make the requested changes while preserving what works
96-
- Maintain best practices and ensure the agent still works effectively
97-
- Use str_replace for targeted edits or write_file for major restructuring
125+
## For Creating New Agents
98126
99-
When editing, always start by reading the current agent file to understand its structure before making changes. Ask clarifying questions if needed, then create or update the template file in the appropriate location.
127+
The agent builder is focused on creating new agent templates based on user specifications.
100128
101129
IMPORTANT: Always end your response with the end_turn tool when you have completed the agent creation or editing task.`,
102-
103-
// Generator function that defines the agent's execution flow
104-
handleSteps: function* ({ agentState, prompt, params }) {
105-
const AGENT_TEMPLATES_DIR = '.agents'
106-
const TYPES_DIR = `${AGENT_TEMPLATES_DIR}/types`
107-
const TEMPLATE_TYPES_PATH = `${TYPES_DIR}/agent-config.d.ts`
108-
const TOOL_DEFINITIONS_PATH = `${TYPES_DIR}/tools.d.ts`
109-
110-
// Step 1: Create directory structure
111-
yield {
112-
toolName: 'run_terminal_command',
113-
args: {
114-
command: `mkdir -p ${TYPES_DIR}`,
115-
process_type: 'SYNC',
116-
timeout_seconds: 10,
117-
},
118-
}
119-
120-
// Step 2: Read and write the agent config template
121-
const { toolResult: configResult } = yield {
122-
toolName: 'read_files',
123-
args: {
124-
paths: ['common/src/util/types/agent-config.ts'],
125-
},
126-
}
127-
128-
if (configResult) {
129-
yield {
130-
toolName: 'write_file',
131-
args: {
132-
path: TEMPLATE_TYPES_PATH,
133-
instructions: 'Create agent template type definitions file',
134-
content: configResult,
135-
},
136-
}
137-
}
138-
139-
// Step 3: Read and write the tools definitions
140-
const { toolResult: toolsResult } = yield {
141-
toolName: 'read_files',
142-
args: {
143-
paths: ['common/src/util/types/tools.d.ts'],
144-
},
145-
}
146-
147-
if (toolsResult) {
148-
yield {
149-
toolName: 'write_file',
150-
args: {
151-
path: TOOL_DEFINITIONS_PATH,
152-
instructions: 'Create tools type file',
153-
content: toolsResult,
154-
},
155-
}
156-
}
157-
158-
// Step 4: Copy example agents for reference
159-
const { toolResult: exampleAgentsResult } = yield {
160-
toolName: 'read_files',
161-
args: {
162-
paths: [
163-
'common/src/util/example-1.ts',
164-
'common/src/util/example-2.ts',
165-
'common/src/util/example-3.ts',
166-
],
167-
},
168-
}
169-
170-
if (exampleAgentsResult) {
171-
const exampleFiles = exampleAgentsResult.split('\n\n').filter(Boolean)
172-
173-
// Write example 1
174-
if (exampleFiles[0]) {
175-
yield {
176-
toolName: 'write_file',
177-
args: {
178-
path: `${AGENT_TEMPLATES_DIR}/example-1.ts`,
179-
instructions: 'Copy example 1 agent',
180-
content: exampleFiles[0],
181-
},
182-
}
183-
}
184-
185-
// Write example 2
186-
if (exampleFiles[1]) {
187-
yield {
188-
toolName: 'write_file',
189-
args: {
190-
path: `${AGENT_TEMPLATES_DIR}/example-2.ts`,
191-
instructions: 'Copy example 2 agent',
192-
content: exampleFiles[1],
193-
},
194-
}
195-
}
196-
197-
// Write example 3
198-
if (exampleFiles[2]) {
199-
yield {
200-
toolName: 'write_file',
201-
args: {
202-
path: `${AGENT_TEMPLATES_DIR}/example-3.ts`,
203-
instructions: 'Copy example 3 agent',
204-
content: exampleFiles[2],
205-
},
206-
}
207-
}
208-
}
209-
210-
// Step 5: Let the agent ask questions and understand what the user wants
211-
yield 'STEP_ALL'
212-
},
213130
}
214131

215-
export default config
132+
export default definition

0 commit comments

Comments
 (0)