Skip to content

Commit 9b5763e

Browse files
Add missing handleSteps function to agent builder to fix /agents command functionality
Implements the generator function that orchestrates agent template creation and editing workflow, including directory setup, type definitions copying, and handling both creation and edit modes. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 7af6696 commit 9b5763e

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

.agents/sonnet4-agent-builder.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,111 @@ const config: AgentConfig = {
6666
instructionsPrompt:
6767
'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\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\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.',
6868
stepPrompt: '',
69+
70+
// Generator function that defines the agent's execution flow
71+
handleSteps: function* ({ agentState, prompt, params }) {
72+
const AGENT_TEMPLATES_DIR = '.agents'
73+
const TYPES_DIR = `${AGENT_TEMPLATES_DIR}/types`
74+
const TEMPLATE_TYPES_PATH = `${TYPES_DIR}/agent-config.ts`
75+
const TOOL_DEFINITIONS_PATH = `${TYPES_DIR}/tools.d.ts`
76+
77+
// Step 1: Create directory structure
78+
yield {
79+
toolName: 'run_terminal_command',
80+
args: {
81+
command: `mkdir -p ${TYPES_DIR}`,
82+
process_type: 'SYNC',
83+
timeout_seconds: 10,
84+
},
85+
}
86+
87+
// Step 2: Read and write the agent config template
88+
const { toolResult: configResult } = yield {
89+
toolName: 'read_files',
90+
args: {
91+
paths: ['common/src/util/agent-config.ts'],
92+
},
93+
}
94+
95+
if (configResult?.result) {
96+
yield {
97+
toolName: 'write_file',
98+
args: {
99+
path: TEMPLATE_TYPES_PATH,
100+
instructions: 'Create agent template type definitions file',
101+
content: configResult.result,
102+
},
103+
}
104+
}
105+
106+
// Step 3: Read and write the tools definitions
107+
const { toolResult: toolsResult } = yield {
108+
toolName: 'read_files',
109+
args: {
110+
paths: ['common/src/util/tools.d.ts'],
111+
},
112+
}
113+
114+
if (toolsResult?.result) {
115+
yield {
116+
toolName: 'write_file',
117+
args: {
118+
path: TOOL_DEFINITIONS_PATH,
119+
instructions: 'Create tools type file',
120+
content: toolsResult.result,
121+
},
122+
}
123+
}
124+
125+
// Step 4: Add user message with requirements for agent creation or editing
126+
const isEditMode = params?.editMode === true
127+
128+
if (isEditMode) {
129+
// Edit mode - the prompt should already contain the edit request
130+
// No need to add additional message, the user prompt contains everything
131+
} else {
132+
// Creation mode - add structured requirements
133+
const requirements = {
134+
name: params?.name || 'Custom Agent',
135+
purpose:
136+
params?.purpose ||
137+
'A custom agent that helps with development tasks',
138+
specialty: params?.specialty || 'general development',
139+
model: params?.model || 'anthropic/claude-4-sonnet-20250522',
140+
}
141+
yield {
142+
toolName: 'add_message',
143+
args: {
144+
role: 'user',
145+
content: `Create a new agent template with the following specifications:
146+
147+
**Agent Details:**
148+
- Name: ${requirements.name}
149+
- Purpose: ${requirements.purpose}
150+
- Specialty: ${requirements.specialty}
151+
- Model: ${requirements.model}
152+
- Agent ID: ${requirements.name
153+
.toLowerCase()
154+
.replace(/[^a-z0-9]+/g, '-')
155+
.replace(/^-+|-+$/g, '')}
156+
157+
**Requirements:**
158+
- Create the agent template file in ${AGENT_TEMPLATES_DIR}
159+
- Always start the file with: import type { AgentConfig } from './types/agent-config'
160+
- Use the AgentConfig interface
161+
- Include appropriate tools based on the specialty
162+
- Write a comprehensive system prompt
163+
- Follow naming conventions and best practices
164+
- Export a default configuration object
165+
166+
Please create the complete agent template now.`,
167+
},
168+
}
169+
}
170+
171+
// Step 5: Complete agent creation process
172+
yield 'STEP_ALL'
173+
},
69174
}
70175

71176
export default config

0 commit comments

Comments
 (0)