Skip to content

Commit 26e84af

Browse files
committed
Move initial agents dir files to common
1 parent 7762897 commit 26e84af

File tree

13 files changed

+520
-17
lines changed

13 files changed

+520
-17
lines changed

.agents/README.md renamed to common/src/templates/initial-agents-dir/README.md

File renamed without changes.

.agents/examples/01-basic-diff-reviewer.ts renamed to common/src/templates/initial-agents-dir/examples/01-basic-diff-reviewer.ts

File renamed without changes.

.agents/examples/02-intermediate-git-committer.ts renamed to common/src/templates/initial-agents-dir/examples/02-intermediate-git-committer.ts

File renamed without changes.

.agents/examples/03-advanced-file-explorer.ts renamed to common/src/templates/initial-agents-dir/examples/03-advanced-file-explorer.ts

File renamed without changes.

.agents/my-custom-agent.ts renamed to common/src/templates/initial-agents-dir/my-custom-agent.ts

File renamed without changes.
Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
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 in .agents/your-agent.ts:
8+
* import { AgentDefinition, ToolName, ModelName } from './types/agent-definition'
9+
*
10+
* const definition: AgentDefinition = {
11+
* // ... your agent configuration with full type safety ...
12+
* }
13+
*
14+
* export default definition
15+
*/
16+
17+
// ============================================================================
18+
// Agent Definition and Utility Types
19+
// ============================================================================
20+
21+
export interface AgentDefinition {
22+
/** Unique identifier for this agent. Must contain only lowercase letters, numbers, and hyphens, e.g. 'code-reviewer' */
23+
id: string
24+
25+
/** Version string (if not provided, will default to '0.0.1' and be bumped on each publish) */
26+
version?: string
27+
28+
/** Publisher ID for the agent. Must be provided if you want to publish the agent. */
29+
publisher?: string
30+
31+
/** Human-readable name for the agent */
32+
displayName: string
33+
34+
/** AI model to use for this agent. Can be any model in OpenRouter: https://openrouter.ai/models */
35+
model: ModelName
36+
37+
// ============================================================================
38+
// Tools and Subagents
39+
// ============================================================================
40+
41+
/** Tools this agent can use. */
42+
toolNames?: ToolName[]
43+
44+
/** Other agents this agent can spawn, like 'codebuff/file-picker@0.0.1'.
45+
*
46+
* Use the fully qualified agent id from the agent store, including publisher and version: 'codebuff/file-picker@0.0.1'
47+
* (publisher and version are required!)
48+
*
49+
* Or, use the agent id from a local agent file in your .agents directory: 'file-picker'.
50+
*/
51+
spawnableAgents?: string[]
52+
53+
// ============================================================================
54+
// Input and Output
55+
// ============================================================================
56+
57+
/** The input schema required to spawn the agent. Provide a prompt string and/or a params object or none.
58+
* 80% of the time you want just a prompt string with a description:
59+
* inputSchema: {
60+
* prompt: { type: 'string', description: 'A description of what info would be helpful to the agent' }
61+
* }
62+
*/
63+
inputSchema?: {
64+
prompt?: { type: 'string'; description?: string }
65+
params?: JsonSchema
66+
}
67+
68+
/** Whether to include conversation history from the parent agent in context.
69+
*
70+
* Defaults to false.
71+
* Use this if the agent needs to know all the previous messages in the conversation.
72+
*/
73+
includeMessageHistory?: boolean
74+
75+
/** How the agent should output a response to its parent (defaults to 'last_message')
76+
*
77+
* last_message: The last message from the agent, typcically after using tools.
78+
*
79+
* all_messages: All messages from the agent, including tool calls and results.
80+
*
81+
* json: Make the agent output a JSON object. Can be used with outputSchema or without if you want freeform json output.
82+
*/
83+
outputMode?: 'last_message' | 'all_messages' | 'structured_output'
84+
85+
/** JSON schema for structured output (when outputMode is 'structured_output') */
86+
outputSchema?: JsonSchema
87+
88+
// ============================================================================
89+
// Prompts
90+
// ============================================================================
91+
92+
/** Prompt for when and why to spawn this agent. Include the main purpose and use cases.
93+
*
94+
* This field is key if the agent is intended to be spawned by other agents. */
95+
spawnPurposePrompt?: string
96+
97+
/** Background information for the agent. Fairly optional. Prefer using instructionsPrompt for agent instructions. */
98+
systemPrompt?: string
99+
100+
/** Instructions for the agent.
101+
*
102+
* IMPORTANT: Updating this prompt is the best way to shape the agent's behavior.
103+
* This prompt is inserted after each user input. */
104+
instructionsPrompt?: string
105+
106+
/** Prompt inserted at each agent step.
107+
*
108+
* Powerful for changing the agent's behavior, but usually not necessary for smart models.
109+
* Prefer instructionsPrompt for most instructions. */
110+
stepPrompt?: string
111+
112+
// ============================================================================
113+
// Handle Steps
114+
// ============================================================================
115+
116+
/** Programmatically step the agent forward and run tools.
117+
*
118+
* You can either yield:
119+
* - A tool call object with toolName and args properties.
120+
* - 'STEP' to run agent's model and generate one assistant message.
121+
* - 'STEP_ALL' to run the agent's model until it uses the end_turn tool or stops includes no tool calls in a message.
122+
*
123+
* Or use 'return' to end the turn.
124+
*
125+
* Example 1:
126+
* function* handleSteps({ agentStep, prompt, params}) {
127+
* const { toolResult } = yield {
128+
* toolName: 'read_files',
129+
* args: { paths: ['file1.txt', 'file2.txt'] }
130+
* }
131+
* yield 'STEP_ALL'
132+
* }
133+
*
134+
* Example 2:
135+
* handleSteps: function* ({ agentState, prompt, params }) {
136+
* while (true) {
137+
* yield {
138+
* toolName: 'spawn_agents',
139+
* args: {
140+
* agents: [
141+
* {
142+
* agent_type: 'thinker',
143+
* prompt: 'Think deeply about the user request',
144+
* },
145+
* ],
146+
* },
147+
* }
148+
* yield 'STEP'
149+
* }
150+
* }
151+
*/
152+
handleSteps?: (
153+
context: AgentStepContext,
154+
) => Generator<
155+
ToolCall | 'STEP' | 'STEP_ALL',
156+
void,
157+
{ agentState: AgentState; toolResult: string | undefined }
158+
>
159+
}
160+
161+
// ============================================================================
162+
// Supporting Types
163+
// ============================================================================
164+
165+
export interface AgentState {
166+
agentId: string
167+
parentId: string
168+
messageHistory: Message[]
169+
}
170+
171+
/**
172+
* Message in conversation history
173+
*/
174+
export interface Message {
175+
role: 'user' | 'assistant'
176+
content: string
177+
}
178+
179+
/**
180+
* Context provided to handleSteps generator function
181+
*/
182+
export interface AgentStepContext {
183+
agentState: AgentState
184+
prompt?: string
185+
params?: Record<string, any>
186+
}
187+
188+
/**
189+
* Tool call object for handleSteps generator
190+
*/
191+
export type ToolCall<T extends ToolName = ToolName> = {
192+
[K in T]: {
193+
toolName: K
194+
args?: Tools.GetToolParams<K>
195+
}
196+
}[T]
197+
198+
/**
199+
* JSON Schema definition (for prompt schema or output schema)
200+
*/
201+
export interface JsonSchema {
202+
type: string
203+
properties?: Record<string, any>
204+
required?: string[]
205+
[key: string]: any
206+
}
207+
208+
// ============================================================================
209+
// Available Tools
210+
// ============================================================================
211+
212+
/**
213+
* File operation tools
214+
*/
215+
export type FileTools =
216+
| 'read_files'
217+
| 'write_file'
218+
| 'str_replace'
219+
| 'find_files'
220+
221+
/**
222+
* Code analysis tools
223+
*/
224+
export type CodeAnalysisTools = 'code_search' | 'find_files'
225+
226+
/**
227+
* Terminal and system tools
228+
*/
229+
export type TerminalTools = 'run_terminal_command' | 'run_file_change_hooks'
230+
231+
/**
232+
* Web and browser tools
233+
*/
234+
export type WebTools = 'web_search' | 'read_docs'
235+
236+
/**
237+
* Agent management tools
238+
*/
239+
export type AgentTools = 'spawn_agents' | 'set_messages' | 'add_message'
240+
241+
/**
242+
* Planning and organization tools
243+
*/
244+
export type PlanningTools = 'think_deeply'
245+
246+
/**
247+
* Output and control tools
248+
*/
249+
export type OutputTools = 'set_output' | 'end_turn'
250+
251+
/**
252+
* Common tool combinations for convenience
253+
*/
254+
export type FileEditingTools = FileTools | 'end_turn'
255+
export type ResearchTools = WebTools | 'write_file' | 'end_turn'
256+
export type CodeAnalysisToolSet = FileTools | CodeAnalysisTools | 'end_turn'
257+
258+
// ============================================================================
259+
// Available Models (see: https://openrouter.ai/models)
260+
// ============================================================================
261+
262+
/**
263+
* AI models available for agents. Pick from our selection of recommended models or choose any model in OpenRouter.
264+
*
265+
* See available models at https://openrouter.ai/models
266+
*/
267+
export type ModelName =
268+
// Recommended Models
269+
270+
// OpenAI
271+
| 'openai/gpt-5'
272+
| 'openai/gpt-5-mini'
273+
| 'openai/gpt-5-nano'
274+
275+
// Anthropic
276+
| 'anthropic/claude-4-sonnet-20250522'
277+
| 'anthropic/claude-opus-4.1'
278+
279+
// Gemini
280+
| 'google/gemini-2.5-pro'
281+
| 'google/gemini-2.5-flash'
282+
| 'google/gemini-2.5-flash-lite'
283+
284+
// X-AI
285+
| 'x-ai/grok-4-07-09'
286+
287+
// Qwen
288+
| 'qwen/qwen3-coder'
289+
| 'qwen/qwen3-coder:fast'
290+
| 'qwen/qwen3-235b-a22b-2507'
291+
| 'qwen/qwen3-235b-a22b-2507:fast'
292+
| 'qwen/qwen3-235b-a22b-thinking-2507'
293+
| 'qwen/qwen3-235b-a22b-thinking-2507:fast'
294+
| 'qwen/qwen3-30b-a3b'
295+
| 'qwen/qwen3-30b-a3b:fast'
296+
297+
// DeepSeek
298+
| 'deepseek/deepseek-chat-v3-0324'
299+
| 'deepseek/deepseek-chat-v3-0324:fast'
300+
| 'deepseek/deepseek-r1-0528'
301+
| 'deepseek/deepseek-r1-0528:fast'
302+
303+
// Other open source models
304+
| 'moonshotai/kimi-k2'
305+
| 'moonshotai/kimi-k2:fast'
306+
| 'z-ai/glm-4.5'
307+
| 'z-ai/glm-4.5:fast'
308+
| (string & {})
309+
310+
import type * as Tools from './tools'
311+
export type { Tools }
312+
type ToolName = Tools.ToolName

0 commit comments

Comments
 (0)