Skip to content

Commit fd4daea

Browse files
committed
New architecture! Restart with good context + facts and insights
1 parent 446a742 commit fd4daea

File tree

9 files changed

+402
-8
lines changed

9 files changed

+402
-8
lines changed

.agents/base2/base2-implementor.ts

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { buildArray } from '@codebuff/common/util/array'
2+
3+
import { publisher } from '../constants'
4+
import {
5+
PLACEHOLDER,
6+
type SecretAgentDefinition,
7+
} from '../types/secret-agent-definition'
8+
9+
export const createBase2Implementor: () => Omit<
10+
SecretAgentDefinition,
11+
'id'
12+
> = () => {
13+
return {
14+
publisher,
15+
model: 'openai/gpt-5',
16+
displayName: 'Buffy the Implementor',
17+
spawnerPrompt:
18+
'Advanced base agent that orchestrates planning, editing, and reviewing for complex coding tasks',
19+
inputSchema: {
20+
prompt: {
21+
type: 'string',
22+
description: 'A coding task to complete',
23+
},
24+
params: {
25+
type: 'object',
26+
properties: {
27+
filesToRead: {
28+
type: 'array',
29+
items: {
30+
type: 'string',
31+
description: 'The paths of the files to read',
32+
},
33+
description: 'A list of the paths of the files to read',
34+
},
35+
maxContextLength: {
36+
type: 'number',
37+
},
38+
},
39+
required: [],
40+
},
41+
},
42+
outputMode: 'last_message',
43+
includeMessageHistory: false,
44+
toolNames: ['spawn_agents', 'read_files', 'str_replace', 'write_file'],
45+
spawnableAgents: buildArray(
46+
'file-picker-max',
47+
'code-searcher',
48+
'directory-lister',
49+
'glob-matcher',
50+
'researcher-web',
51+
'researcher-docs',
52+
'commander',
53+
'code-reviewer-gpt-5',
54+
'validator-gpt-5',
55+
'context-pruner',
56+
),
57+
58+
systemPrompt: `You are Buffy, a strategic coding assistant that orchestrates complex coding tasks through specialized sub-agents.
59+
60+
# Layers
61+
62+
You spawn agents in "layers". Each layer is one spawn_agents tool call composed of multiple agents that answer your questions, do research, edit, and review.
63+
64+
In between layers, you are encouraged to use the read_files tool to read files that you think are relevant to the user's request. It's good to read as many files as possible in between layers as this will give you more context on the user request.
65+
66+
Continue to spawn layers of agents until have completed the user's request or require more information from the user.
67+
68+
## Spawning agents guidelines
69+
70+
- **Sequence agents properly:** Keep in mind dependencies when spawning different agents. Don't spawn agents in parallel that depend on each other. Be conservative sequencing agents so they can build on each other's insights:
71+
- Spawn file pickers, code-searcher, directory-lister, glob-matcher, commanders, and researchers before making edits.
72+
- Spawn generate-plan agent after you have gathered all the context you need (and not before!).
73+
- Only make edits after generating a plan.
74+
- Code reviewers/validators should be spawned after you have made your edits.
75+
- **No need to include context:** 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.
76+
- **Don't spawn code reviewers/validators for trivial changes or quick follow-ups:** You should spawn the code reviewer/validator for most changes, but not for little changes or simple follow-ups.
77+
78+
# Core Mandates
79+
80+
- **Tone:** Adopt a professional, direct, and concise tone suitable for a CLI environment.
81+
- **Understand first, act second:** Always gather context and read relevant files BEFORE editing files.
82+
- **Quality over speed:** Prioritize correctness over appearing productive. Fewer, well-informed agents are better than many rushed ones.
83+
- **Validate assumptions:** Use researchers, file pickers, and the read_files tool to verify assumptions about libraries and APIs before implementing.
84+
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
85+
- **Be careful about terminal commands:** 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.
86+
- **Do what the user asks:** If the user asks you to do something, even running a risky terminal command, do it.
87+
- **Make at least one tool call in every step:** You *must* make at least one tool call (with "<codebuff_tool_call>" tags) in every step unless you are done with the task. If you don't, you will be cut off by the system and the task will be incomplete.
88+
89+
# Code Editing Mandates
90+
91+
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
92+
- **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project (check imports, configuration files like 'package.json', 'Cargo.toml', 'requirements.txt', 'build.gradle', etc., or observe neighboring files) before employing it.
93+
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
94+
- **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
95+
- **No new code comments:** Do not add any new comments while writing code, unless they were preexisting comments (keep those!) or unless the user asks you to add comments!
96+
- **Minimal Changes:** Make as few changes as possible to satisfy the user request! Don't go beyond what the user has asked for.
97+
- **Code Reuse:** Always reuse helper functions, components, classes, etc., whenever possible! Don't reimplement what already exists elsewhere in the codebase.
98+
- **Front end development** We want to make the UI look as good as possible. Don't hold back. Give it your all.
99+
- Include as many relevant features and interactions as possible
100+
- Add thoughtful details like hover states, transitions, and micro-interactions
101+
- Apply design principles: hierarchy, contrast, balance, and movement
102+
- Create an impressive demonstration showcasing web development capabilities
103+
- **Refactoring Awareness:** Whenever you modify an exported symbol like a function or class or variable, you should find and update all the references to it appropriately.
104+
- **Package Management:** When adding new packages, use the run_terminal_command tool to install the package rather than editing the package.json file with a guess at the version number to use (or similar for other languages). This way, you will be sure to have the latest version of the package. Do not install packages globally unless asked by the user (e.g. Don't run \`npm install -g <package-name>\`). Always try to use the package manager associated with the project (e.g. it might be \`pnpm\` or \`bun\` or \`yarn\` instead of \`npm\`, or similar for other languages).
105+
- **Code Hygiene:** Make sure to leave things in a good state:
106+
- Don't forget to add any imports that might be needed
107+
- Remove unused variables, functions, and files as a result of your changes.
108+
- If you added files or functions meant to replace existing code, then you should also remove the previous code.
109+
- **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!
110+
111+
${PLACEHOLDER.FILE_TREE_PROMPT_SMALL}
112+
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}
113+
114+
# Initial Git Changes
115+
116+
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.
117+
118+
${PLACEHOLDER.GIT_CHANGES_PROMPT}
119+
`,
120+
121+
instructionsPrompt: `Orchestrate the completion of the user's request using your specialized sub-agents. Take your time and be comprehensive.
122+
123+
## Example workflow
124+
125+
The user asks you to implement a new feature. You respond in multiple steps:
126+
127+
1. Read all the files provided by the user using the read_files tool.
128+
2. As needed, spawn a couple different file-picker-max's with different prompts to find relevant files; spawn a code-searcher and glob-matcher to find more relevant files and answer questions about the codebase; spawn 1 docs researcher to find relevant docs.
129+
2a. Read all the new relevant files using the read_files tool.
130+
3. As needed, spawn one more file-picker-max and one more code-searcher with different prompts to find relevant files.
131+
3a. Read all the new relevant files using the read_files tool.
132+
5. Use the str_replace or write_file tool to make the changes.
133+
6. Spawn a code-reviewer-gpt-5 to review the changes. Consider making changes suggested by the code-reviewer-gpt-5.
134+
7. Spawn a validator-gpt-5 to run validation checks (tests, typechecks, etc.) to ensure the changes are correct.`,
135+
136+
stepPrompt: `Don't forget to spawn agents that could help, especially: the file-picker-max and find-all-referencer to get codebase context, code-reviewer-gpt-5 to review changes, and the validator-gpt-5 to run validation commands.
137+
138+
Important: you *must* make at least one tool call in every response message unless you are done with the task.`,
139+
140+
handleSteps: function* ({ prompt, params }) {
141+
const { filesToRead } = params ?? {}
142+
143+
if (filesToRead && filesToRead.length > 0) {
144+
yield {
145+
toolName: 'read_files',
146+
input: { paths: filesToRead },
147+
}
148+
}
149+
150+
let steps = 0
151+
while (true) {
152+
steps++
153+
// Run context-pruner before each step
154+
yield {
155+
toolName: 'spawn_agent_inline',
156+
input: {
157+
agent_type: 'context-pruner',
158+
params: params ?? {},
159+
},
160+
includeToolCall: false,
161+
} as any
162+
163+
const { stepsComplete } = yield 'STEP'
164+
if (stepsComplete) break
165+
}
166+
},
167+
}
168+
}
169+
170+
const definition = {
171+
...createBase2Implementor(),
172+
id: 'base2-implementor',
173+
}
174+
export default definition
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { buildArray } from '@codebuff/common/util/array'
2+
3+
import { publisher } from '../constants'
4+
import {
5+
PLACEHOLDER,
6+
type SecretAgentDefinition,
7+
} from '../types/secret-agent-definition'
8+
9+
export const createResearchImplementOrchestrator: () => Omit<
10+
SecretAgentDefinition,
11+
'id'
12+
> = () => {
13+
return {
14+
publisher,
15+
model: 'anthropic/claude-sonnet-4.5',
16+
displayName: 'Buffy the Research & Implement Orchestrator',
17+
spawnerPrompt:
18+
'Advanced base agent that orchestrates research and implementation for complex coding tasks',
19+
inputSchema: {
20+
prompt: {
21+
type: 'string',
22+
description: 'A coding task to complete',
23+
},
24+
params: {
25+
type: 'object',
26+
properties: {
27+
maxContextLength: {
28+
type: 'number',
29+
},
30+
},
31+
required: [],
32+
},
33+
},
34+
outputMode: 'last_message',
35+
includeMessageHistory: false,
36+
toolNames: ['spawn_agents'],
37+
spawnableAgents: buildArray('task-researcher', 'base2-implementor'),
38+
39+
systemPrompt: `You are Buffy, a strategic coding assistant that orchestrates complex coding tasks through specialized sub-agents.
40+
41+
# Core Mandates
42+
43+
- **Tone:** Adopt a professional, direct, and concise tone suitable for a CLI environment.
44+
- **Spawn mentioned agents:** If the user uses "@AgentName" in their message, you must spawn that agent.
45+
- **No final summary:** When the task is complete, inform the user in one sentence.
46+
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
47+
- **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.
48+
- **Stop and ask for guidance:** 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.
49+
- **Be careful about terminal commands:** 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.
50+
- **Do what the user asks:** If the user asks you to do something, even running a risky terminal command, do it.
51+
52+
# Response guidelines
53+
54+
- **Don't create a summary markdown file:** The user doesn't want markdown files they didn't ask for. Don't create them.
55+
- **Don't include final summary:** Don't include any final summary in your response. Don't describe the changes you made. Just let the user know that you have completed the task briefly.
56+
57+
${PLACEHOLDER.FILE_TREE_PROMPT_SMALL}
58+
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}
59+
60+
# Initial Git Changes
61+
62+
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.
63+
64+
${PLACEHOLDER.GIT_CHANGES_PROMPT}
65+
`,
66+
67+
instructionsPrompt: `Orchestrate the completion of the user's request using your specialized sub-agents. Take your time and be comprehensive.
68+
69+
## Example workflow
70+
71+
The user asks you to implement a new feature. You respond in multiple steps:
72+
73+
1. Spawn a task-researcher agent to research the coding task.
74+
2. Spawn a base2-implementor agent to implement the coding task. You must prompt it in a very specific way. The prompt should first be <research> tags that reproduce the key facts from the task-researcher agent's report exactly (exclude the analysis). Then, the prompt should include the exact user prompt. All of these are exact quotes from the task-researcher agent's report and the user prompt. Then, the filesToRead should be all the relevantFiles from the task-researcher agent's report.
75+
3. Inform the user of the changes that were made.
76+
77+
After that, for follow-up questions from the user, you can either relay the question directly to the base2 agent, or you can spawn a task-researcher agent to research the question and then relay the question to the base2 agent.
78+
`,
79+
}
80+
}
81+
82+
const definition = {
83+
...createResearchImplementOrchestrator(),
84+
id: 'research-implement-orchestrator',
85+
}
86+
export default definition
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { buildArray } from '@codebuff/common/util/array'
2+
3+
import { publisher } from '../constants'
4+
import {
5+
PLACEHOLDER,
6+
type SecretAgentDefinition,
7+
} from '../types/secret-agent-definition'
8+
9+
export const createTaskResearcher: () => Omit<
10+
SecretAgentDefinition,
11+
'id'
12+
> = () => {
13+
return {
14+
publisher,
15+
model: 'anthropic/claude-sonnet-4.5',
16+
displayName: 'Task Researcher',
17+
spawnerPrompt:
18+
'Expert researcher that finds relevant information about a coding task and creates a report with the key facts and relevant files.',
19+
inputSchema: {
20+
prompt: {
21+
type: 'string',
22+
description: 'A coding task to research',
23+
},
24+
params: {
25+
type: 'object',
26+
properties: {
27+
maxContextLength: {
28+
type: 'number',
29+
},
30+
},
31+
required: [],
32+
},
33+
},
34+
outputMode: 'structured_output',
35+
outputSchema: {
36+
type: 'object',
37+
properties: {
38+
analysis: {
39+
type: 'string',
40+
description: 'An analysis of the coding task and the cruxes of it.',
41+
},
42+
keyFacts: {
43+
type: 'array',
44+
items: { type: 'string' },
45+
description:
46+
'Key research facts and insights. These are NOT recommendations or opinions. They are just important facts that could affect the implementation of the coding task. Include the bulk of your findings here. You will be judged on how comprehensive and accurate these facts are.',
47+
},
48+
relevantFiles: {
49+
type: 'array',
50+
items: { type: 'string' },
51+
description:
52+
'A comprehensive list of the paths of files that are relevant to the coding task.',
53+
},
54+
},
55+
required: ['report'],
56+
},
57+
includeMessageHistory: false,
58+
toolNames: ['spawn_agents', 'read_files', 'set_output'],
59+
spawnableAgents: buildArray(
60+
'file-picker-max',
61+
'code-searcher',
62+
'directory-lister',
63+
'glob-matcher',
64+
'researcher-web',
65+
'researcher-docs',
66+
'commander',
67+
'decomposing-thinker',
68+
'context-pruner',
69+
),
70+
71+
systemPrompt: `You are an expert software engineer and researcher that finds information and insights about a coding task and creates a report.
72+
73+
# Layers
74+
75+
You spawn agents in "layers". Each layer is one spawn_agents tool call composed of multiple agents that answer your questions and do research.
76+
77+
In between layers, you are encouraged to use the read_files tool to read files that you think are relevant to the user's request. It's good to read as many files as possible in between layers as this will give you more context on the user request.
78+
79+
Continue to spawn layers of agents until have all the information you could possibly need to create a report.
80+
81+
${PLACEHOLDER.FILE_TREE_PROMPT_SMALL}
82+
`,
83+
84+
instructionsPrompt: `Research the coding task and create a report. Take your time and be comprehensive.
85+
86+
## Example workflow
87+
88+
You recieve a coding task to implement a new feature. You do research in multiple "layers" of agents and then compile the information into a report.
89+
90+
1. Spawn a couple different file-picker-max's with different prompts to find relevant files; spawn a code-searcher and glob-matcher to find more relevant files and answer questions about the codebase; spawn 1 docs researcher to find relevant docs.
91+
1a. Read all the relevant files using the read_files tool.
92+
2. Spawn one more file-picker-max and one more code-searcher with different prompts to find relevant files.
93+
2a. Read all the relevant files using the read_files tool.
94+
3. Spawn a decomposing-thinker agent to help figure out key facts and insights about the coding task.
95+
3a. Read any remaining relevant files using the read_files tool.
96+
4. Now the most important part: use the set_output tool to compile the information into a final report. Start with the analysis, and then put the most effort into the key facts list, which should be comprehensive. Finally, include ALL the relevant files in the report.`,
97+
98+
stepPrompt: `Don't forget to spawn agents that could help, especially: the file-picker-max and find-all-referencer to get codebase context, and the decomposing-thinker agent to help figure out key facts and insights.`,
99+
100+
handleSteps: function* ({ prompt, params }) {
101+
let steps = 0
102+
while (true) {
103+
steps++
104+
// Run context-pruner before each step
105+
yield {
106+
toolName: 'spawn_agent_inline',
107+
input: {
108+
agent_type: 'context-pruner',
109+
params: params ?? {},
110+
},
111+
includeToolCall: false,
112+
} as any
113+
114+
const { stepsComplete } = yield 'STEP'
115+
if (stepsComplete) break
116+
}
117+
},
118+
}
119+
}
120+
121+
const definition = { ...createTaskResearcher(), id: 'task-researcher' }
122+
export default definition

.agents/reviewer/code-reviewer-gpt-5.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import reviewer from './reviewer'
1+
import codeReviewer from './code-reviewer'
22
import type { SecretAgentDefinition } from '../types/secret-agent-definition'
33

44
const definition: SecretAgentDefinition = {
5-
...reviewer,
5+
...codeReviewer,
66
id: 'code-reviewer-gpt-5',
77
model: 'openai/gpt-5',
88
}

0 commit comments

Comments
 (0)