Skip to content

Commit 6ac3934

Browse files
committed
fix: renamed examples to be more generic
1 parent 9f6a382 commit 6ac3934

File tree

6 files changed

+243
-75
lines changed

6 files changed

+243
-75
lines changed

.agents/sonnet4-agent-builder.ts

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import type { AgentConfig } from './types/agent-config'
2+
3+
const config: AgentConfig = {
4+
id: 'sonnet4-agent-builder',
5+
displayName: 'Bob the Agent Builder',
6+
model: 'anthropic/claude-4-sonnet-20250522',
7+
inputSchema: {
8+
prompt: {
9+
description: 'What agent type you would like to create or edit.',
10+
type: 'string',
11+
},
12+
},
13+
outputMode: 'json',
14+
includeMessageHistory: false,
15+
toolNames: [
16+
'write_file',
17+
'str_replace',
18+
'run_terminal_command',
19+
'read_files',
20+
'code_search',
21+
'spawn_agents',
22+
'add_message',
23+
'set_output',
24+
'end_turn',
25+
],
26+
subagents: ['file-picker'],
27+
parentPrompt:
28+
'Creates new agent templates for the codebuff mult-agent system',
29+
systemPrompt:
30+
'# Agent Builder\n\nYou 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.\n\n## Agent Template Patterns\n\n1. **Base Agent Pattern**: Full-featured agents with comprehensive tool access\n2. **Specialized Agent Pattern**: Focused agents with limited tool sets\n3. **Thinking Agent Pattern**: Agents that spawn thinker sub-agents\n4. **Research Agent Pattern**: Agents that start with web search\n\n## Best Practices\n\n1. **Use as few fields as possible**: Leave out fields that are not needed to reduce complexity\n2. **Minimal Tools**: Only include tools the agent actually needs\n3. **Clear and Concise Prompts**: Write clear, specific prompts that have no unnecessary words\n4. **Consistent Naming**: Follow naming conventions (kebab-case for IDs)\n5. **Appropriate Model**: Choose the right model for the task complexity\n\n## Your Task\n\nWhen asked to create an agent template, you should:\n1. Understand the requested agent\'s purpose and capabilities\n2. Choose appropriate tools for the agent\'s function\n3. Write a comprehensive system prompt\n4. Create the complete agent template file in .agents/\n5. Ensure the template follows all conventions and best practices\n6. Use the AgentConfig interface for the configuration\n7. Start the file with: import type { AgentConfig } from "./types/agent-config"\n\nCreate agent templates that are focused, efficient, and well-documented. Always import the AgentConfig type and export a default configuration object.',
31+
instructionsPrompt:
32+
"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.\n\n## Example Agents for Reference\n\nYou have access to three example agents in `.agents/examples/` that demonstrate different complexity levels:\n\n1. **Level 1 - Code Reviewer**: Simple agent with basic tools (read_files, write_file, set_output, end_turn)\n2. **Level 2 - Test Generator**: Intermediate agent with subagents and handleSteps logic\n3. **Level 3 - Documentation Writer**: Advanced agent with comprehensive tools, multiple subagents, and complex orchestration\n\n**IMPORTANT**: When creating new agents, first examine these examples to find connections and patterns that relate to the user's request. Look for:\n- Similar tool combinations\n- Comparable complexity levels\n- Related functionality patterns\n- Appropriate model choices\n- Relevant prompt structures\n\nUse these examples as inspiration and starting points, adapting their patterns to fit the user's specific needs.\n\nFor new agents, analyze their request and create a complete agent template that:\n- Has a clear purpose and appropriate capabilities\n- Leaves out fields that are not needed\n- Uses only the tools it needs\n- Follows naming conventions\n- Is properly structured\n- Draws inspiration from relevant example agents\n\nFor editing existing agents:\n- First read the existing agent file they want to edit using read_files\n- Understand the current structure and functionality\n- Make the requested changes while preserving what works\n- Maintain best practices and ensure the agent still works effectively\n- Use str_replace for targeted edits or write_file for major restructuring\n\nWhen 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.\n\nIMPORTANT: Always end your response with the end_turn tool when you have completed the agent creation or editing task.",
33+
stepPrompt: '',
34+
35+
// Generator function that defines the agent's execution flow
36+
handleSteps: function* ({ agentState, prompt, params }) {
37+
const AGENT_TEMPLATES_DIR = '.agents'
38+
const TYPES_DIR = `${AGENT_TEMPLATES_DIR}/types`
39+
const TEMPLATE_TYPES_PATH = `${TYPES_DIR}/agent-config.d.ts`
40+
const TOOL_DEFINITIONS_PATH = `${TYPES_DIR}/tools.d.ts`
41+
42+
// Step 1: Create directory structure
43+
yield {
44+
toolName: 'run_terminal_command',
45+
args: {
46+
command: `mkdir -p ${TYPES_DIR}`,
47+
process_type: 'SYNC',
48+
timeout_seconds: 10,
49+
},
50+
}
51+
52+
// Step 2: Read and write the agent config template
53+
const { toolResult: configResult } = yield {
54+
toolName: 'read_files',
55+
args: {
56+
paths: ['common/src/util/types/agent-config.ts'],
57+
},
58+
}
59+
60+
if (configResult?.result) {
61+
yield {
62+
toolName: 'write_file',
63+
args: {
64+
path: TEMPLATE_TYPES_PATH,
65+
instructions: 'Create agent template type definitions file',
66+
content: configResult.result,
67+
},
68+
}
69+
}
70+
71+
// Step 3: Read and write the tools definitions
72+
const { toolResult: toolsResult } = yield {
73+
toolName: 'read_files',
74+
args: {
75+
paths: ['common/src/util/types/tools.d.ts'],
76+
},
77+
}
78+
79+
if (toolsResult?.result) {
80+
yield {
81+
toolName: 'write_file',
82+
args: {
83+
path: TOOL_DEFINITIONS_PATH,
84+
instructions: 'Create tools type file',
85+
content: toolsResult.result,
86+
},
87+
}
88+
}
89+
90+
// Step 4: Copy example agents for reference
91+
const { toolResult: exampleAgentsResult } = yield {
92+
toolName: 'read_files',
93+
args: {
94+
paths: [
95+
'common/src/util/example-1.ts',
96+
'common/src/util/example-2.ts',
97+
'common/src/util/example-3.ts',
98+
],
99+
},
100+
}
101+
102+
if (exampleAgentsResult?.result) {
103+
const exampleFiles = exampleAgentsResult.result
104+
.split('\n\n')
105+
.filter(Boolean)
106+
107+
// Write example 1
108+
if (exampleFiles[0]) {
109+
yield {
110+
toolName: 'write_file',
111+
args: {
112+
path: `${AGENT_TEMPLATES_DIR}/example-1.ts`,
113+
instructions: 'Copy example 1 agent',
114+
content: exampleFiles[0],
115+
},
116+
}
117+
}
118+
119+
// Write example 2
120+
if (exampleFiles[1]) {
121+
yield {
122+
toolName: 'write_file',
123+
args: {
124+
path: `${AGENT_TEMPLATES_DIR}/example-2.ts`,
125+
instructions: 'Copy example 2 agent',
126+
content: exampleFiles[1],
127+
},
128+
}
129+
}
130+
131+
// Write example 3
132+
if (exampleFiles[2]) {
133+
yield {
134+
toolName: 'write_file',
135+
args: {
136+
path: `${AGENT_TEMPLATES_DIR}/example-3.ts`,
137+
instructions: 'Copy example 3 agent',
138+
content: exampleFiles[2],
139+
},
140+
}
141+
}
142+
}
143+
144+
// Step 5: Let the agent ask questions and understand what the user wants
145+
yield 'STEP_ALL'
146+
},
147+
}
148+
149+
export default config

.agents/types/agent-config.d.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
* This file provides TypeScript type definitions for creating custom Codebuff agents.
55
* Import these types in your agent files to get full type safety and IntelliSense.
66
*
7-
* Usage:
8-
* import { AgentConfig, ToolName, ModelName } from './agent-config'
7+
* Usage in .agents/your-agent.ts:
8+
* import { AgentConfig, ToolName, ModelName } from './types/agent-config'
99
*
1010
* const config: AgentConfig = {
11-
* // Your agent configuration with full type safety
11+
* // ... your agent configuration with full type safety ...
1212
* }
13+
*
14+
* export default config
1315
*/
1416

15-
import type * as Tools from './tools'
16-
export type { Tools }
17-
type ToolName = Tools.ToolName
18-
1917
// ============================================================================
2018
// Core Agent Configuration Types
2119
// ============================================================================
@@ -43,26 +41,6 @@ export interface AgentConfig {
4341
/** Other agents this agent can spawn. */
4442
subagents?: SubagentName[]
4543

46-
// ============================================================================
47-
// Prompts
48-
// ============================================================================
49-
50-
/** Prompt for when to spawn this agent as a subagent. Include the main purpose and use cases.
51-
* This field is key if the agent is a subagent and intended to be spawned. */
52-
parentPrompt?: string
53-
54-
/** Background information for the agent. Fairly optional. Prefer using instructionsPrompt for agent instructions. */
55-
systemPrompt?: string
56-
57-
/** Instructions for the agent.
58-
* IMPORTANT: Updating this prompt is the best way to shape the agent's behavior.
59-
* This prompt is inserted after each user input. */
60-
instructionsPrompt?: string
61-
62-
/** Prompt inserted at each agent step. Powerful for changing the agent's behavior,
63-
* but usually not necessary for smart models. Prefer instructionsPrompt for most instructions. */
64-
stepPrompt?: string
65-
6644
// ============================================================================
6745
// Input and Output
6846
// ============================================================================
@@ -78,21 +56,50 @@ export interface AgentConfig {
7856
params?: JsonSchema
7957
}
8058

81-
/** Whether to include conversation history. Defaults to false.
59+
/** Whether to include conversation history from the parent agent in context.
60+
*
61+
* Defaults to false.
8262
* Use this if the agent needs to know all the previous messages in the conversation.
8363
*/
8464
includeMessageHistory?: boolean
8565

8666
/** How the agent should output a response to its parent (defaults to 'last_message')
67+
*
8768
* last_message: The last message from the agent, typcically after using tools.
69+
*
8870
* all_messages: All messages from the agent, including tool calls and results.
71+
*
8972
* json: Make the agent output a JSON object. Can be used with outputSchema or without if you want freeform json output.
9073
*/
9174
outputMode?: 'last_message' | 'all_messages' | 'json'
9275

9376
/** JSON schema for structured output (when outputMode is 'json') */
9477
outputSchema?: JsonSchema
9578

79+
// ============================================================================
80+
// Prompts
81+
// ============================================================================
82+
83+
/** Prompt for when to spawn this agent as a subagent. Include the main purpose and use cases.
84+
*
85+
* This field is key if the agent is a subagent and intended to be spawned. */
86+
parentPrompt?: string
87+
88+
/** Background information for the agent. Fairly optional. Prefer using instructionsPrompt for agent instructions. */
89+
systemPrompt?: string
90+
91+
/** Instructions for the agent.
92+
*
93+
* IMPORTANT: Updating this prompt is the best way to shape the agent's behavior.
94+
* This prompt is inserted after each user input. */
95+
instructionsPrompt?: string
96+
97+
/** Prompt inserted at each agent step.
98+
*
99+
* Powerful for changing the agent's behavior, but usually not necessary for smart models.
100+
* Prefer instructionsPrompt for most instructions. */
101+
stepPrompt?: string
102+
96103
// ============================================================================
97104
// Handle Steps
98105
// ============================================================================
@@ -298,3 +305,7 @@ export type SubagentName =
298305
| 'thinker'
299306
| 'reviewer'
300307
| (string & {})
308+
309+
import type * as Tools from './tools'
310+
export type { Tools }
311+
type ToolName = Tools.ToolName

backend/src/templates/agents/agent-aware-base.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,27 @@ export const agentAwareBase = (
5757
const exampleAgentContents: Record<string, string> = {}
5858

5959
try {
60-
const exampleAgentsDir = path.join(
61-
__dirname,
62-
'../../../../common/src/util/example-agents',
63-
)
64-
const files = fs.readdirSync(exampleAgentsDir)
60+
const exampleAgentsDir = path.join(__dirname, `${COMMON_UTIL_PATH}`)
61+
// Check if directory exists before trying to read it
62+
if (fs.existsSync(exampleAgentsDir)) {
63+
const files = fs.readdirSync(exampleAgentsDir)
6564

66-
files
67-
.filter((file) => file.endsWith('.ts'))
68-
.forEach((filename) => {
69-
try {
70-
const fullPath = path.join(exampleAgentsDir, filename)
71-
const content = fs.readFileSync(fullPath, 'utf8')
72-
exampleAgentContents[filename] = content
73-
} catch (error) {
74-
console.warn(`Could not read example agent ${filename}:`, error)
75-
}
76-
})
65+
files
66+
.filter((file) => file.endsWith('.ts') && file.startsWith('example-'))
67+
.forEach((filename) => {
68+
try {
69+
const fullPath = path.join(exampleAgentsDir, filename)
70+
const content = fs.readFileSync(fullPath, 'utf8')
71+
exampleAgentContents[filename] = content
72+
} catch (error) {
73+
console.warn(`Could not read example agent ${filename}:`, error)
74+
}
75+
})
76+
} else {
77+
console.warn(
78+
`Example agents directory does not exist: ${exampleAgentsDir}`,
79+
)
80+
}
7781
} catch (error) {
7882
console.warn('Could not read example agents directory:', error)
7983
}
@@ -216,9 +220,9 @@ You can now proceed directly to agent creation or editing.
216220
217221
Three example agents are now available in your \`.agents/\` directory:
218222
219-
1. **level-1-code-reviewer.ts**: Simple agent with basic tools (read_files, write_file, set_output, end_turn)
220-
2. **level-2-test-generator.ts**: Intermediate agent with subagents and handleSteps logic
221-
3. **level-3-documentation-writer.ts**: Advanced agent with comprehensive tools, multiple subagents, and complex orchestration
223+
1. **example-1.ts**: Simple agent with basic tools (read_files, write_file, set_output, end_turn)
224+
2. **example-2.ts**: Intermediate agent with subagents and handleSteps logic
225+
3. **example-3.ts**: Advanced agent with comprehensive tools, multiple subagents, and complex orchestration
222226
223227
**IMPORTANT**: Examine these examples to find connections and patterns that relate to the user's request. Look for:
224228
- Similar tool combinations
@@ -260,6 +264,7 @@ IMPORTANT: Always end your response with the end_turn tool when you have complet
260264
command: `mkdir -p ${TYPES_DIR}`,
261265
process_type: 'SYNC',
262266
timeout_seconds: 10,
267+
cb_easp: false,
263268
},
264269
}
265270

@@ -270,6 +275,7 @@ IMPORTANT: Always end your response with the end_turn tool when you have complet
270275
path: TEMPLATE_TYPES_PATH,
271276
instructions: 'Create agent template type definitions file',
272277
content: agentTemplateContent,
278+
cb_easp: false,
273279
},
274280
}
275281

@@ -280,6 +286,7 @@ IMPORTANT: Always end your response with the end_turn tool when you have complet
280286
path: TOOL_DEFINITIONS_PATH,
281287
instructions: 'Create tools type file',
282288
content: toolDefinitionsContent,
289+
cb_easp: false,
283290
},
284291
}
285292

@@ -290,6 +297,7 @@ IMPORTANT: Always end your response with the end_turn tool when you have complet
290297
role: 'assistant',
291298
content:
292299
"I'll read the example agent files to understand the patterns and then help you create your agent.",
300+
cb_easp: false,
293301
},
294302
}
295303

@@ -299,9 +307,10 @@ IMPORTANT: Always end your response with the end_turn tool when you have complet
299307
yield {
300308
toolName: 'write_file',
301309
args: {
302-
path: `${AGENT_TEMPLATES_DIR}/${filename}`,
310+
path: `${AGENT_TEMPLATES_DIR}${filename}`,
303311
instructions: `Copy example agent file ${filename}`,
304312
content: content,
313+
cb_easp: false,
305314
},
306315
}
307316
}

0 commit comments

Comments
 (0)