Skip to content
63 changes: 9 additions & 54 deletions .agents/editor/editor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Message } from 'types/util-types'
import { publisher } from '../constants'
import {
PLACEHOLDER,
type SecretAgentDefinition,
} from '../types/secret-agent-definition'
import { type SecretAgentDefinition } from '../types/secret-agent-definition'

const editor: SecretAgentDefinition = {
id: 'editor',
Expand All @@ -28,7 +25,6 @@ const editor: SecretAgentDefinition = {
},
},
outputMode: 'structured_output',
includeMessageHistory: true,
toolNames: [
'read_files',
'write_file',
Expand All @@ -42,7 +38,10 @@ const editor: SecretAgentDefinition = {
],
spawnableAgents: ['file-explorer', 'web-researcher', 'docs-researcher'],

systemPrompt: `You are an expert code editor with deep understanding of software engineering principles.
includeMessageHistory: true,
inheritParentSystemPrompt: true,

instructionsPrompt: `You are an expert code editor with deep understanding of software engineering principles.

# Core Mandates

Expand All @@ -66,62 +65,18 @@ const editor: SecretAgentDefinition = {
- Remove unused variables, functions, and files as a result of your changes.
- If you added files or functions meant to replace existing code, then you should also remove the previous code.
- **Edit multiple files at once:** When you edit files, you must make as many tool calls as possible in a single message. This is faster and much more efficient than making all the tool calls in separate messages. It saves users thousands of dollars in credits if you do this!
<example>
Assistant: I will now implement feature X.

<codebuff_tool_call>
{
"toolName": "str_replace",
"input": {
"filePath": "src/components/Button.tsx",
"oldContent": "...",
"newContent": "...",
}
}
</codebuff_tool_call>

<codebuff_tool_call>
{
"toolName": "str_replace",
"input": {
"filePath": "src/components/Button.tsx",
"oldContent": "...",
"newContent": "...",
}
}
</codebuff_tool_call>

// ... 8 more str_replace tool calls ...

Let's see what the code looks like now.

User: <tool_result>
<tool>str_replace</tool>
<result>...</result>
</tool_result>

<tool_result>
<tool>str_replace</tool>
<result>...</result>
</tool_result>

// ... 8 more tool_result blocks ...
</example>
- **Summarize with set_output:** You must use the set_output tool before finishing and include a clear explanation of the changes made or an answer to the user prompt. Do not write a separate summary outside of the set_output tool.

${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,

instructionsPrompt: `Implement the requested changes, using your judgment as needed, but referring to the original <user-message> as the most important source of information.
Implement the requested changes, using your judgment as needed, but referring to the original <user-message> as the most important source of information.

# Instructions

- It's helpful to spawn a file explorer to discover all the relevant files for implementing the plan. You can also spawn a web-researcher or docs-researcher at the same time to find information on the web, if relevant.
- You must read all relevant files to understand the current state. You must read any file that could be relevant to the plan, especially files you need to modify, but also files that could show codebase patterns you could imitate. Try to read a lot of files in a single tool call. E.g. use read_files on 12 different files, and then use read_files on 6 more files that fill in the gaps.
- Read any relevant files that have not already been read. Or, spawn a file-explorer to find any other relevant parts of the codebase.
- Implement changes using str_replace or write_file.
- Verify your changes by running tests, typechecking, etc. Keep going until you are sure the changes are correct.
- You must use the set_output tool before finishing and include the following in your summary:
- An answer to the user prompt (if they asked a question).
- An explanation of the changes made.
- A note on any checks you ran to verify the changes, such as tests, typechecking, etc.
- A note on any checks you ran to verify the changes, such as tests, typechecking, etc., and the results of those checks.
- Do not include a section on the benefits of the changes, as we're most interested in the changes themselves and what still needs to be done.
- Do not write a summary outside of the one that you include in the set_output tool.
- As soon as you use set_output, you must end your turn using the end_turn tool.
Expand Down
27 changes: 16 additions & 11 deletions .agents/orchestrator/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const definition: SecretAgentDefinition = {
},
outputMode: 'last_message',
includeMessageHistory: true,
toolNames: ['spawn_agents', 'read_files', 'str_replace', 'write_file'],
toolNames: ['spawn_agents', 'read_files'],
spawnableAgents: [
'read-only-commander',
'researcher-file-explorer',
'researcher-web',
'researcher-docs',
'decomposing-planner',
'editor',
'reviewer-lite',
'reviewer-max',
'context-pruner',
],

Expand All @@ -55,33 +55,38 @@ const definition: SecretAgentDefinition = {
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
- **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user. If asked *how* to do something, explain first, don't just do it.

${PLACEHOLDER.FILE_TREE_PROMPT_SMALL}
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}

# Starting Git Changes

The following is the state of the git repository at the start of the conversation. Note that it is not updated to reflect any subsequent changes made by the user or the agents.

${PLACEHOLDER.GIT_CHANGES_PROMPT}
`,

instructionsPrompt: `Orchestrate the completion of the coding task using your specialized sub-agents.
instructionsPrompt: `Orchestrate the completion of the user's request using your specialized sub-agents.

## Simple workflow
## Example workflow

Use this workflow to solve a medium or complex coding task:
1. Spawn a researcher
2. Spawn a decomposing planner to come up with a plan.
3. Spawn an editor to implement the plan.
4. Spawn a reviewer to review the code. If changes are needed, go back to step 3, but only once.
5. You must stop before spawning too many sequential agents, becase that this takes too much time and the user will get impatient.
2. Read all the relevant files using the read_files tool.
3. Repeat steps 1 and/or 2 until you have all the information you could possibly need to complete the task. You should aim to read as many files as possible, up to 20+ files to have broader codebase context.
4. Spawn a decomposing planner to come up with a plan.
5. Spawn an editor to implement the plan. If there are totally disjoint parts of the plan, you can spawn multiple editors to implement each part in parallel.
6. Spawn a reviewer to review the code. If changes are needed, go back to step 5, but no more than once.
7. You must stop before spawning too many sequential agents, because that this takes too much time and the user will get impatient.

Feel free to modify this workflow as needed. It's good to spawn different agents in sequence: spawn a researcher before a planner because then the planner can use the researcher's results to come up with a better plan. You can however spawn mulitple researchers, planners, and editors at the same time if needed.

## Guidelines

- You can spawn agents to help you complete the task. Iterate by spawning more agents as needed.
- Spawn agents to help you complete the task. Iterate by spawning more agents as needed.
- Don't mastermind the task. Rely on your agents' judgement to research, plan, edit, and review the code.
- Give as many instructions upfront as possible to each agent so you're less likely to need to spawn them again.
- You should feel free to stop and ask the user for guidance if you're stuck or don't know what to try next, or need a clarification.
- When prompting an agent, realize that many agents can already see the entire conversation history, so you can be brief in prompting them without needing to include much context.
- Give as many instructions upfront as possible to each agent so you're less likely to need to spawn them again.
- When prompting an agent, realize that many agents can already see the entire conversation history, so you can be brief in prompting them without needing to include context.
- Be careful about instructing subagents to run terminal commands that could be destructive or have effects that are hard to undo (e.g. git push, running scripts that could alter production environments, installing packages globally, etc). Don't do any of these unless the user explicitly asks you to.
`,

Expand Down
1 change: 0 additions & 1 deletion .agents/planners/decomposing-planner-lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const definition: SecretAgentDefinition = {
spawnerPrompt:
'Creates a better implementation plan by decomposing the task into smaller plans in parallel and synthesizing them into a final plan. Includes full code changes.',
spawnableAgents: ['researcher-file-explorer', 'implementation-planner-lite'],
includeMessageHistory: false,
}

export default definition
31 changes: 12 additions & 19 deletions .agents/planners/decomposing-planner.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { publisher } from '../constants'
import {
PLACEHOLDER,
type SecretAgentDefinition,
} from '../types/secret-agent-definition'
import { type SecretAgentDefinition } from '../types/secret-agent-definition'

const definition: SecretAgentDefinition = {
id: 'decomposing-planner',
publisher,
model: 'anthropic/claude-sonnet-4.5',
displayName: 'Decomposing Planner',
displayName: 'Peter Plan',
spawnerPrompt:
'Creates the best possible implementation plan by decomposing the task into smaller plans in parallel and synthesizing them into a final plan. Includes full code changes.',
inputSchema: {
Expand All @@ -19,31 +16,27 @@ const definition: SecretAgentDefinition = {
},
},
outputMode: 'last_message',
includeMessageHistory: true,
toolNames: ['spawn_agents', 'read_files'],
spawnableAgents: ['file-explorer', 'implementation-planner'],
toolNames: ['spawn_agents'],
spawnableAgents: ['implementation-planner'],

systemPrompt: `You are an expert programmer, architect, and problem solver who excels at breaking down complex tasks.
includeMessageHistory: true,
inheritParentSystemPrompt: true,

${PLACEHOLDER.FILE_TREE_PROMPT}
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,
instructionsPrompt: `You are an expert programmer, architect, and problem solver who excels at breaking down complex tasks.

instructionsPrompt: `Instructions:
Instructions:

Step 1: Task Decomposition
- Spawn a file-explorer agent to explore the codebase and read all the relevant files
Step 1: Task Decomposition & Parallel Planning
- Carefully analyze the user's request
- Break it down into 3-5 focused subtasks that:
- Break it down into 2-10 focused subtasks that:
- Cover different aspects of the implementation (e.g., data layer, business logic, UI, testing)
- Are specific and actionable
- Together address the complete requirements

Step 2: Parallel Planning
- Spawn 3-5 implementation-planner agents in parallel (one spawn_agents call with multiple agents)
- Spawn 2-10 implementation-planner agents in parallel (one spawn_agents call with multiple agents)
- Give each agent a focused subtask from your decomposition
- Each subtask prompt should be specific about what that agent should focus on

Step 3: Synthesis
Step 2: Synthesis
- Review all the plans from the spawned agents
- Create a unified implementation plan that:
- Combines insights from all subtask plans
Expand Down
22 changes: 6 additions & 16 deletions .agents/planners/implementation-planner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { publisher } from '../constants'
import {
PLACEHOLDER,
type SecretAgentDefinition,
} from '../types/secret-agent-definition'
import { type SecretAgentDefinition } from '../types/secret-agent-definition'

const definition: SecretAgentDefinition = {
id: 'implementation-planner',
Expand All @@ -20,25 +17,18 @@ const definition: SecretAgentDefinition = {
},
outputMode: 'last_message',
includeMessageHistory: true,
inheritParentSystemPrompt: true,
toolNames: ['spawn_agents', 'read_files'],
spawnableAgents: [
'file-explorer',
'web-researcher',
'docs-researcher',
],
spawnableAgents: ['file-explorer', 'web-researcher', 'docs-researcher'],

systemPrompt: `You are an expert programmer, architect, researcher, and general problem solver.
instructionsPrompt: `You are an expert programmer, architect, researcher, and general problem solver.
You spawn agents to help you gather information, and then describe a full change to the codebase that will accomplish the task.

You do not have access to tools to modify files (e.g. the write_file or str_replace tools). You are describing all the code changes that should be made as a full implementation.

${PLACEHOLDER.FILE_TREE_PROMPT}
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,

instructionsPrompt: `Instructions:
Instructions:
- Spawn file-explorer twice to find all the relevant parts of the codebase. Use different prompts for each file-explorer to ensure you get all the relevant parts of the codebase. In parallel as part of the same spawn_agents tool call, you may also spawn a web-researcher or docs-researcher to search the web or technical documentation for relevant information.
- Read all the file paths that are relevant using the read_files tool.
- Read more and more files to get any information that could possibly help you make the best plan. It's good to read 20+ files.
- Read any relevant files that have not already been read.
- Think about the best way to accomplish the task.
- Finally, describe the full change to the codebase that will accomplish the task (or other steps, e.g. terminal commands to run). Use markdown code blocks to describe the changes for each file.

Expand Down
12 changes: 4 additions & 8 deletions .agents/reviewer/reviewer-factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { AGENT_PERSONAS } from '@codebuff/common/constants/agents'
import { closeXml } from '@codebuff/common/util/xml'

import type { SecretAgentDefinition } from '../types/secret-agent-definition'
import type { Model } from '@codebuff/common/old-constants'

Expand All @@ -15,11 +13,11 @@ export const reviewer = (model: Model): Omit<SecretAgentDefinition, 'id'> => ({
},
},
outputMode: 'last_message',
includeMessageHistory: true,
toolNames: ['end_turn', 'run_file_change_hooks'],
toolNames: ['run_file_change_hooks'],
spawnableAgents: [],

systemPrompt: `You are an expert programmer who can articulate very clear feedback on code changes.`,
inheritParentSystemPrompt: true,
includeMessageHistory: true,

instructionsPrompt: `Your task is to provide helpful feedback on the last file changes made by the assistant.

Expand All @@ -42,7 +40,5 @@ Next, you should critique the code changes made recently in the above conversati
- Make sure no sections were deleted that weren't supposed to be deleted.
- Make sure the new code matches the style of the existing code.

Be concise and to the point. After providing all your feedback, use the end_turn tool to end your response.`,

stepPrompt: `IMPORTANT: Don't forget to end your response with the end_turn tool: <end_turn>${closeXml('end_turn')}`,
Be concise and to the point.`,
})
16 changes: 12 additions & 4 deletions .agents/types/agent-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface AgentDefinition {
/** Whether to include conversation history from the parent agent in context.
*
* Defaults to false.
* Use this if the agent needs to know all the previous messages in the conversation.
* Use this when the agent needs to know all the previous messages in the conversation.
*/
includeMessageHistory?: boolean

Expand All @@ -121,6 +121,14 @@ export interface AgentDefinition {
* This field is key if the agent is intended to be spawned by other agents. */
spawnerPrompt?: string

/** Whether to inherit the parent agent's system prompt instead of using this agent's own systemPrompt.
*
* Defaults to false.
* Use this when you want to enable prompt caching by preserving the same system prompt prefix.
* Cannot be used together with the systemPrompt field.
*/
inheritParentSystemPrompt?: boolean

/** Background information for the agent. Fairly optional. Prefer using instructionsPrompt for agent instructions. */
systemPrompt?: string

Expand Down Expand Up @@ -289,7 +297,7 @@ export type ModelName =
| 'openai/gpt-5-nano'

// Anthropic
| 'anthropic/claude-sonnet-4'
| 'anthropic/claude-sonnet-4.5'
| 'anthropic/claude-opus-4.1'

// Gemini
Expand Down Expand Up @@ -326,8 +334,8 @@ export type ModelName =
// Other open source models
| 'moonshotai/kimi-k2'
| 'moonshotai/kimi-k2:nitro'
| 'z-ai/glm-4.5'
| 'z-ai/glm-4.5:nitro'
| 'z-ai/glm-4.6'
| 'z-ai/glm-4.6:nitro'
| (string & {})

export type { Tools }
Expand Down
Loading