Skip to content

Commit 166c458

Browse files
brandonkachencodebuff-teamjahooma
authored
[feat][render preview][codecane] agent builder (#221)
Co-authored-by: Codebuff <noreply@codebuff.com> Co-authored-by: James Grugett <jahooma@gmail.com>
1 parent 4e9927c commit 166c458

33 files changed

+2609
-635
lines changed

.agents/agent-template.d.ts

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
/**
2+
* Codebuff Agent Type Definitions
3+
*
4+
* This file provides TypeScript type definitions for creating custom Codebuff agents.
5+
* Import these types in your agent files to get full type safety and IntelliSense.
6+
*
7+
* Usage:
8+
* import { AgentConfig, ToolName, ModelName } from './agent-template'
9+
*
10+
* const config: AgentConfig = {
11+
* // Your agent configuration with full type safety
12+
* }
13+
*/
14+
15+
// ============================================================================
16+
// Core Agent Configuration Types
17+
// ============================================================================
18+
19+
export interface AgentConfig {
20+
/** Unique identifier for this agent. Use alphanumeric characters and hyphens only, e.g. 'code-reviewer' */
21+
id: string
22+
23+
/** Version string (if not provided, will default to '0.0.1' and be bumped on each publish) */
24+
version?: string
25+
26+
/** Human-readable name for the agent */
27+
displayName: string
28+
29+
/** AI model to use for this agent. Can be any model in OpenRouter: https://openrouter.ai/models */
30+
model: ModelName
31+
32+
// ============================================================================
33+
// Tools and Subagents
34+
// ============================================================================
35+
36+
/** Tools this agent can use. */
37+
toolNames?: ToolName[]
38+
39+
/** Other agents this agent can spawn. */
40+
subagents?: SubagentName[]
41+
42+
// ============================================================================
43+
// Prompts
44+
// ============================================================================
45+
46+
/** Prompt for when to spawn this agent as a subagent. Include the main purpose and use cases. */
47+
parentPrompt?: string
48+
49+
/** Background information for the agent. Prefer using instructionsPrompt for agent instructions. */
50+
systemPrompt?: string
51+
52+
/** Instructions for the agent.
53+
* IMPORTANT: Updating this prompt is the best way to shape the agent's behavior.
54+
* This prompt is inserted after each user input. */
55+
instructionsPrompt?: string
56+
57+
/** Prompt inserted at each agent step. Powerful for changing the agent's behavior,
58+
* but prefer instructionsPrompt for most instructions. */
59+
stepPrompt: string
60+
61+
/** Instructions for specific parent agents on when to spawn this agent as a subagent. */
62+
parentInstructions?: Record<SubagentName, string>
63+
64+
// ============================================================================
65+
// Input and Output
66+
// ============================================================================
67+
68+
/** The input schema required to spawn the agent. Provide a prompt string and/or a params object. */
69+
inputSchema?: {
70+
prompt?: { type: 'string'; description?: string }
71+
params?: JsonSchema
72+
}
73+
74+
/** Whether to include conversation history (defaults to true) */
75+
includeMessageHistory?: boolean
76+
77+
/** How the agent should output a response to its parent (defaults to 'last_message')
78+
* last_message: The last message from the agent, typcically after using tools.
79+
* all_messages: All messages from the agent, including tool calls and results.
80+
* json: Make the agent output a structured JSON object. Can be used with outputSchema or without if you want freeform json output.
81+
*/
82+
outputMode?: 'last_message' | 'all_messages' | 'json'
83+
84+
/** JSON schema for structured output (when outputMode is 'json') */
85+
outputSchema?: JsonSchema
86+
87+
// ============================================================================
88+
// Handle Steps
89+
// ============================================================================
90+
91+
/** Programmatically step the agent forward and run tools.
92+
*
93+
* You can either yield:
94+
* - A tool call object with toolName and args properties.
95+
* - 'STEP' to run agent's model and generate one assistant message.
96+
* - 'STEP_ALL' to run the agent's model until it uses the end_turn tool or stops includes no tool calls in a message.
97+
*
98+
* Or use 'return' to end the turn.
99+
*
100+
* Example:
101+
* function* handleSteps({ agentStep, prompt, params}) {
102+
* const { toolResult } = yield {
103+
* toolName: 'read_files',
104+
* args: { paths: ['file1.txt', 'file2.txt'] }
105+
* }
106+
* yield 'STEP_ALL'
107+
* }
108+
*/
109+
handleSteps?: (
110+
context: AgentStepContext
111+
) => Generator<
112+
ToolCall | 'STEP' | 'STEP_ALL',
113+
void,
114+
{ agentState: AgentState; toolResult: ToolResult | undefined }
115+
>
116+
}
117+
118+
// ============================================================================
119+
// Supporting Types
120+
// ============================================================================
121+
122+
export interface AgentState {
123+
agentId: string
124+
parentId: string
125+
messageHistory: Message[]
126+
}
127+
128+
/**
129+
* Message in conversation history
130+
*/
131+
export interface Message {
132+
role: 'user' | 'assistant' | 'system'
133+
content: string
134+
timestamp?: number
135+
}
136+
137+
/**
138+
* Result from executing a tool
139+
*/
140+
export interface ToolResult {
141+
success: boolean
142+
data?: any
143+
error?: string
144+
}
145+
146+
/**
147+
* Context provided to handleSteps generator function
148+
*/
149+
export interface AgentStepContext {
150+
agentState: AgentState
151+
prompt: string | undefined
152+
params: Record<string, any> | undefined
153+
}
154+
155+
/**
156+
* Tool call object for handleSteps generator
157+
*/
158+
export interface ToolCall {
159+
toolName: ToolName
160+
args?: Record<string, any>
161+
}
162+
163+
/**
164+
* JSON Schema definition (for prompt schema or output schema)
165+
*/
166+
export interface JsonSchema {
167+
type: string
168+
properties?: Record<string, any>
169+
required?: string[]
170+
[key: string]: any
171+
}
172+
173+
// ============================================================================
174+
// Available Tools
175+
// ============================================================================
176+
177+
/**
178+
* File operation tools
179+
*/
180+
export type FileTools =
181+
| 'read_files'
182+
| 'write_file'
183+
| 'str_replace'
184+
| 'find_files'
185+
186+
/**
187+
* Code analysis tools
188+
*/
189+
export type CodeAnalysisTools = 'code_search' | 'find_files'
190+
191+
/**
192+
* Terminal and system tools
193+
*/
194+
export type TerminalTools = 'run_terminal_command' | 'run_file_change_hooks'
195+
196+
/**
197+
* Web and browser tools
198+
*/
199+
export type WebTools = 'browser_logs' | 'web_search' | 'read_docs'
200+
201+
/**
202+
* Agent management tools
203+
*/
204+
export type AgentTools =
205+
| 'spawn_agents'
206+
| 'spawn_agents_async'
207+
| 'send_agent_message'
208+
| 'set_messages'
209+
| 'add_message'
210+
211+
/**
212+
* Planning and organization tools
213+
*/
214+
export type PlanningTools =
215+
| 'think_deeply'
216+
| 'create_plan'
217+
| 'add_subgoal'
218+
| 'update_subgoal'
219+
220+
/**
221+
* Output and control tools
222+
*/
223+
export type OutputTools = 'set_output' | 'end_turn'
224+
225+
/**
226+
* All available tools that agents can use
227+
*/
228+
export type ToolName =
229+
| FileTools
230+
| CodeAnalysisTools
231+
| TerminalTools
232+
| WebTools
233+
| AgentTools
234+
| PlanningTools
235+
| OutputTools
236+
237+
// ============================================================================
238+
// Available Models (see: https://openrouter.ai/models)
239+
// ============================================================================
240+
241+
/**
242+
* AI models available for agents (all models in OpenRouter are supported)
243+
*
244+
* See available models at https://openrouter.ai/models
245+
*/
246+
export type ModelName =
247+
// Verified OpenRouter Models
248+
| 'anthropic/claude-4-sonnet-20250522'
249+
| 'anthropic/claude-4-opus-20250522'
250+
| 'anthropic/claude-3.5-haiku-20241022'
251+
| 'anthropic/claude-3.5-sonnet-20240620'
252+
| 'openai/gpt-4o-2024-11-20'
253+
| 'openai/gpt-4o-mini-2024-07-18'
254+
| 'openai/o3'
255+
| 'openai/o4-mini'
256+
| 'openai/o4-mini-high'
257+
| 'google/gemini-2.5-pro'
258+
| 'google/gemini-2.5-flash'
259+
| 'x-ai/grok-4-07-09'
260+
| string
261+
262+
// ============================================================================
263+
// Spawnable Agents
264+
// ============================================================================
265+
266+
/**
267+
* Built-in agents that can be spawned by custom agents
268+
*/
269+
export type SubagentName =
270+
| 'file_picker'
271+
| 'file_explorer'
272+
| 'researcher'
273+
| 'thinker'
274+
| 'reviewer'
275+
| string
276+
277+
// ============================================================================
278+
// Utility Types
279+
// ============================================================================
280+
281+
/**
282+
* Common tool combinations for convenience
283+
*/
284+
export type FileEditingTools = FileTools | 'end_turn'
285+
export type ResearchTools = WebTools | 'write_file' | 'end_turn'
286+
export type CodeAnalysisToolSet = FileTools | CodeAnalysisTools | 'end_turn'

.agents/brainstormer.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import {
2+
AgentConfig,
3+
AgentStepContext,
4+
ToolResult,
5+
ToolCall,
6+
} from './agent-template'
7+
8+
const config: AgentConfig = {
9+
id: 'brainstormer',
10+
version: '1.0.0',
11+
displayName: 'Brian the Brainstormer',
12+
model: 'anthropic/claude-4-sonnet-20250522',
13+
14+
parentPrompt:
15+
'Acts as a creative thought partner, generating ideas and exploring alternative viewpoints to help think through problems.',
16+
17+
systemPrompt: `# Persona: Brian the Brainstormer - Creative Thought Partner
18+
19+
You are an expert brainstorming partner who excels at generating creative ideas, exploring alternative approaches, and helping users think through problems from multiple angles.
20+
21+
## Your Role
22+
23+
- **Idea Generator**: Propose creative and unconventional solutions
24+
- **Devil's Advocate**: Challenge assumptions and explore counterarguments
25+
- **Perspective Shifter**: Offer different viewpoints and approaches
26+
- **Question Asker**: Ask probing questions that unlock new thinking
27+
- **Pattern Connector**: Find unexpected connections between concepts
28+
29+
## Your Approach
30+
31+
- Think divergently before converging on solutions
32+
- Explore "what if" scenarios and edge cases
33+
- Consider multiple stakeholder perspectives
34+
- Balance practical constraints with creative possibilities
35+
- Use analogies and metaphors to spark new insights
36+
- Challenge the status quo respectfully
37+
38+
## Guidelines
39+
40+
- Be enthusiastic and encouraging about exploration
41+
- Offer 3-5 distinct alternatives when possible
42+
- Ask clarifying questions to understand context better
43+
- Build on the user's ideas while adding your own spin
44+
- Consider both short-term and long-term implications
45+
- Balance optimism with realistic assessment
46+
47+
Remember: Your goal is to expand thinking, not to provide definitive answers. Help the user see their problem space more clearly and discover new possibilities they might not have considered.`,
48+
49+
instructionsPrompt:
50+
'Act as a creative thought partner. Generate multiple perspectives, challenge assumptions, explore alternatives, and ask probing questions to help think through problems more thoroughly.',
51+
52+
stepPrompt:
53+
"Continue brainstorming and exploring ideas. When you're done, use the end_turn tool.",
54+
55+
inputSchema: {
56+
prompt: {
57+
type: 'string',
58+
description: 'The problem or topic to brainstorm about.',
59+
},
60+
},
61+
62+
includeMessageHistory: true,
63+
outputMode: 'last_message',
64+
65+
toolNames: ['end_turn'],
66+
67+
subagents: ['thinker', 'researcher'],
68+
69+
parentInstructions: {
70+
base: 'Spawn brainstormer when you need creative alternatives, want to challenge assumptions, or explore different approaches to implementation problems',
71+
base_lite:
72+
"Use brainstormer for quick creative insights when you're stuck or need fresh perspectives on simple problems",
73+
base_max:
74+
'Leverage brainstormer for deep creative exploration of complex problems with multiple potential solution paths',
75+
thinker:
76+
'Collaborate with brainstormer when analytical thinking needs creative angles or assumption challenging',
77+
researcher:
78+
'Use brainstormer to suggest creative search angles and alternative information sources for research',
79+
reviewer:
80+
'Engage brainstormer for creative problem-solving approaches to code review and innovative improvement suggestions',
81+
},
82+
}
83+
84+
export default config

0 commit comments

Comments
 (0)