Skip to content

Commit 4dea9f2

Browse files
committed
New iteration of task researcher with gpt-5 pro & gpt-5-worker
1 parent 07f933f commit 4dea9f2

File tree

4 files changed

+259
-95
lines changed

4 files changed

+259
-95
lines changed

.agents/base2/base2-gpt-5-worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ The user asks you to implement a new feature. You respond in multiple steps:
3333
2a. Read all the relevant files using the read_files tool.
3434
3. Use the str_replace or write_file tool to make the changes.
3535
4. Test your changes by running appropriate validation commands for the project (e.g. typechecks, tests, lints, etc.). You may have to explore the project to find the appropriate commands.
36-
5. Inform the parent agent you're done with your edits, but that it should double-check your work.`,
36+
5. End your turn.`,
3737

38-
stepPrompt: `Don't forget to spawn agents that could help, especially: the file-picker-max and code-searcher to get codebase context.`,
38+
stepPrompt: undefined,
3939
}
4040

4141
export default definition

.agents/base2/task-researcher/base2-with-task-researcher.ts

Lines changed: 81 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { buildArray } from '@codebuff/common/util/array'
22

33
import { publisher } from '../../constants'
4-
import {
5-
PLACEHOLDER,
6-
type SecretAgentDefinition,
7-
} from '../../types/secret-agent-definition'
4+
import { type SecretAgentDefinition } from '../../types/secret-agent-definition'
85

96
import type { ToolCall } from 'types/agent-definition'
7+
import type { UserMessage } from 'types/util-types'
108

119
export const createBase2WithTaskResearcher: () => Omit<
1210
SecretAgentDefinition,
@@ -35,101 +33,43 @@ export const createBase2WithTaskResearcher: () => Omit<
3533
},
3634
outputMode: 'last_message',
3735
includeMessageHistory: false,
38-
toolNames: ['spawn_agents', 'read_files', 'str_replace', 'write_file'],
36+
toolNames: [
37+
'spawn_agents',
38+
'spawn_agent_inline',
39+
'read_files',
40+
'str_replace',
41+
'write_file',
42+
],
3943
spawnableAgents: buildArray(
40-
'task-researcher',
44+
'task-researcher2',
4145
'file-picker-max',
4246
'code-searcher',
4347
'directory-lister',
4448
'glob-matcher',
4549
'researcher-web',
4650
'researcher-docs',
4751
'commander',
48-
'code-reviewer',
49-
'validator',
52+
'planner-pro-with-files-input',
53+
'base2-gpt-5-worker',
5054
'context-pruner',
5155
),
5256

53-
systemPrompt: `You are Buffy, a strategic coding assistant that orchestrates complex coding tasks through specialized sub-agents.
54-
55-
# Layers
56-
57-
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.
58-
59-
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.
60-
61-
Continue to spawn layers of agents until have completed the user's request or require more information from the user.
62-
63-
## Spawning agents guidelines
64-
65-
66-
- **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:
67-
- **Task researcher:** For medium to complex requests, you should first spawn a task-researcher agent by itself to gather context about the user's request. Spawn this before any other agents.
68-
- Spawn file pickers, code-searcher, directory-lister, glob-matcher, commanders, and researchers before making edits.
69-
- Spawn generate-plan agent after you have gathered all the context you need (and not before!).
70-
- Only make edits after generating a plan.
71-
- Code reviewers/validators should be spawned after you have made your edits.
72-
- **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.
73-
- **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.
74-
75-
# Core Mandates
76-
77-
- **Tone:** Adopt a professional, direct, and concise tone suitable for a CLI environment.
78-
- **Understand first, act second:** Always gather context and read relevant files BEFORE editing files.
79-
- **Quality over speed:** Prioritize correctness over appearing productive. Fewer, well-informed agents are better than many rushed ones.
80-
- **Validate assumptions:** Use researchers, file pickers, and the read_files tool to verify assumptions about libraries and APIs before implementing.
81-
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
82-
- **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.
83-
- **Do what the user asks:** If the user asks you to do something, even running a risky terminal command, do it.
84-
- **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.
85-
86-
# Code Editing Mandates
87-
88-
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
89-
- **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.
90-
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
91-
- **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
92-
- **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!
93-
- **Minimal Changes:** Make as few changes as possible to satisfy the user request! Don't go beyond what the user has asked for.
94-
- **Code Reuse:** Always reuse helper functions, components, classes, etc., whenever possible! Don't reimplement what already exists elsewhere in the codebase.
95-
- **Front end development** We want to make the UI look as good as possible. Don't hold back. Give it your all.
96-
- Include as many relevant features and interactions as possible
97-
- Add thoughtful details like hover states, transitions, and micro-interactions
98-
- Apply design principles: hierarchy, contrast, balance, and movement
99-
- Create an impressive demonstration showcasing web development capabilities
100-
- **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.
101-
- **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).
102-
- **Code Hygiene:** Make sure to leave things in a good state:
103-
- Don't forget to add any imports that might be needed
104-
- Remove unused variables, functions, and files as a result of your changes.
105-
- If you added files or functions meant to replace existing code, then you should also remove the previous code.
106-
- **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!
107-
108-
${PLACEHOLDER.FILE_TREE_PROMPT_SMALL}
109-
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}
110-
111-
# Initial Git Changes
112-
113-
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.
114-
115-
${PLACEHOLDER.GIT_CHANGES_PROMPT}
116-
`,
117-
11857
instructionsPrompt: `Orchestrate the completion of the user's request using your specialized sub-agents. Take your time and be comprehensive.
11958
12059
## Example workflow
12160
12261
The user asks you to implement a new feature. You respond in multiple steps:
12362
124-
1. Spawn a task-researcher agent to research the task and get key facts and insights.
125-
2. Use the str_replace or write_file tool to make the changes.
126-
3. Spawn a code-reviewer to review the changes. Consider making changes suggested by the code-reviewer.
127-
4. Spawn a validator to run validation checks (tests, typechecks, etc.) to ensure the changes are correct.
63+
1. Spawn a task-researcher2 agent by itself to research the task and get key facts and insights.
64+
2. Spawn a planner-pro-with-files-input agent to generate a plan for the changes.
65+
3. Spawn a base2-gpt-5-worker agent to do the editing.
66+
4. Test your changes by running appropriate validation commands for the project (e.g. typechecks, tests, lints, etc.). You may have to explore the project to find the appropriate commands.
67+
5. Inform the user that you have completed the task in one sentence or a few short bullet points without a final summary. Don't create any summary markdown files, unless asked by the user.
12868
129-
You may not need to spawn the task-researcher if the user's request is trivial or if you have already gathered all the information you need from the conversation history.
69+
You may not need to spawn the task-researcher2 if the user's request is trivial or if you have already gathered all the information you need from the conversation history.
13070
`,
13171

132-
stepPrompt: `Don't forget to spawn agents that could help, especially: the task-researcher to research the task, code-reviewer to review changes, and the validator to run validation commands.`,
72+
stepPrompt: `Don't forget to spawn agents that could help, especially: the task-researcher2 to research the task, and base2-gpt-5-worker to do the editing. After completing the user request, summarize your changes in a sentence or a few short bullet points. Do not create any summary markdown files, unless asked by the user. Then, end your turn.`,
13373

13474
handleSteps: function* ({ params, logger }) {
13575
let steps = 0
@@ -148,10 +88,10 @@ You may not need to spawn the task-researcher if the user's request is trivial o
14888
const { stepsComplete, agentState } = yield 'STEP'
14989
if (stepsComplete) break
15090

151-
// Check tool results for spawning of a task researcher...
152-
// If found, reset messages to only include the task researcher's result and read the relevant files!
91+
// Check last tool result for spawning of a task researcher...
15392
const spawnAgentsToolResults = agentState.messageHistory
15493
.filter((message) => message.role === 'tool')
94+
.slice(-1)
15595
.filter((message) => message.content.toolName === 'spawn_agents')
15696
.map((message) => message.content.output)
15797
.flat()
@@ -162,36 +102,84 @@ You may not need to spawn the task-researcher if the user's request is trivial o
162102
}[]
163103

164104
const taskResearcherResult = spawnAgentsToolResults?.find(
165-
(result) => result.agentType === 'task-researcher',
105+
(result) => result.agentType === 'task-researcher2',
166106
)
167107
if (taskResearcherResult) {
108+
// If task researcher was spawned:
109+
// 1. Reset context from the last user message.
110+
// 2. Read all the relevant files using the read_files tool.
111+
// 3. Spawn a planner-pro agent with the appropriate context (prompt, research report, and relevantFiles).
112+
// 4. Spawn a base2-gpt-5-worker agent to implement the plan.
113+
// 4. Step all
114+
168115
const taskResearcherOutput = taskResearcherResult.value.value as {
169-
analysis: string
170-
keyFacts: string[]
116+
report: string
171117
relevantFiles: string[]
172-
userPrompt: string
173-
}
174-
const initialMessage = `<research>${taskResearcherOutput.keyFacts.join('\n')}</research>${taskResearcherOutput.userPrompt}`
175-
const message = {
176-
role: 'user',
177-
content: initialMessage,
178118
}
179-
const instructionsMessage = agentState.messageHistory.findLast(
119+
120+
const lastUserMessageIndex = agentState.messageHistory.findLastIndex(
180121
(message) =>
181122
message.role === 'user' &&
182-
message.keepLastTags?.[0] === 'INSTRUCTIONS_PROMPT',
123+
(typeof message.content === 'string'
124+
? message.content
125+
: message.content[0].type === 'text'
126+
? message.content[0].text
127+
: ''
128+
).includes('<user_message>'),
183129
)
130+
const lastUserMessage = agentState.messageHistory[
131+
lastUserMessageIndex
132+
] as UserMessage
133+
const userPrompt = !lastUserMessage
134+
? ''
135+
: typeof lastUserMessage.content === 'string'
136+
? lastUserMessage.content
137+
: lastUserMessage.content
138+
.filter((content) => content.type === 'text')
139+
.map((content) => content.text)
140+
.join()
141+
const userPromptText = userPrompt
142+
.split('<user_message>')[1]
143+
.split('</user_message>')[0]
144+
.trim()
145+
146+
const newMessages =
147+
agentState.messageHistory.slice(lastUserMessageIndex)
184148
yield {
185149
toolName: 'set_messages',
186150
input: {
187-
messages: [message, instructionsMessage],
151+
messages: newMessages,
188152
},
189153
includeToolCall: false,
190154
} satisfies ToolCall<'set_messages'>
155+
191156
yield {
192157
toolName: 'read_files',
193158
input: { paths: taskResearcherOutput.relevantFiles },
194159
} satisfies ToolCall<'read_files'>
160+
161+
yield {
162+
toolName: 'spawn_agents',
163+
input: {
164+
agents: [
165+
{
166+
agent_type: 'planner-pro-with-files-input',
167+
prompt: userPromptText,
168+
params: {
169+
researchReport: taskResearcherOutput.report,
170+
relevantFiles: taskResearcherOutput.relevantFiles,
171+
},
172+
},
173+
],
174+
},
175+
} satisfies ToolCall<'spawn_agents'>
176+
177+
yield {
178+
toolName: 'spawn_agent_inline',
179+
input: {
180+
agent_type: 'base2-gpt-5-worker',
181+
},
182+
}
195183
}
196184
// Continue loop!
197185
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import {
2+
PLACEHOLDER,
3+
type SecretAgentDefinition,
4+
} from '../types/secret-agent-definition'
5+
import { publisher } from '../constants'
6+
7+
const definition: SecretAgentDefinition = {
8+
id: 'planner-pro-with-files-input',
9+
model: 'openai/gpt-5-pro',
10+
publisher,
11+
displayName: 'Planner Pro',
12+
spawnerPrompt:
13+
'Uses deep thinking to generate an implementation plan for a user request.',
14+
inputSchema: {
15+
prompt: {
16+
type: 'string',
17+
description: 'A coding task to complete',
18+
},
19+
params: {
20+
type: 'object',
21+
properties: {
22+
researchReport: {
23+
type: 'string',
24+
description: 'A research report on the user request',
25+
},
26+
relevantFiles: {
27+
type: 'array',
28+
items: {
29+
type: 'string',
30+
description:
31+
'The path to a file that is relevant to the user request',
32+
},
33+
description:
34+
'The paths to files that are relevant to the user request',
35+
},
36+
},
37+
required: ['relevantFiles'],
38+
},
39+
},
40+
outputMode: 'last_message',
41+
spawnableAgents: [],
42+
43+
systemPrompt: `You are the planner-pro agent. You are an expert software engineer which is good at formulating surprisingly simple and clear plans.
44+
45+
IMPORTANT: You do not have access to any tools. You can only analyze and write out plans. Do not attempt to use any tools! Your goal is to generate the best plan for the user's request.
46+
47+
${PLACEHOLDER.FILE_TREE_PROMPT_SMALL}`,
48+
49+
instructionsPrompt: `Your task is to output the best plan to accomplish the user's request in a single message. Do not call any tools.
50+
51+
The plan should be an implementation plan for the coding agent to act on to satisfy the user's request. So you can give instructions to the coding agent that include at a high level what files to change and what commands/tools to run.
52+
53+
No need to write out all the code that should be changed. Just focus on the trickiest parts, the key decisions, and sketch the rest so that a smart coding agent can fill in the details.
54+
55+
You can excerpt key sections of the code using markdown code blocks, e.g.
56+
57+
path/to/file.ts
58+
\`\`\`
59+
// ... existing code ...
60+
[this is is the key section of code]
61+
// ... existing code ...
62+
\`\`\`
63+
64+
Here is a priority-ordered list of key principles for the plan. You must:
65+
- Satisfy all the original user requirements to the greatest extent possible.
66+
- Create the simplest and most straightforward plan to implement.
67+
- Make the plan maintainable, clear, and easy to understand.
68+
- Include the fewest dependencies and moving parts.
69+
- Reuse existing helper functions and other code whenever possible.
70+
- Modify the fewest files.
71+
72+
Please output the plan text itself, without labels or meta-commentary.`,
73+
74+
handleSteps: function* ({ params }) {
75+
yield {
76+
toolName: 'read_files',
77+
input: { paths: params?.relevantFiles || [] },
78+
}
79+
80+
yield 'STEP_ALL'
81+
},
82+
}
83+
84+
export default definition

0 commit comments

Comments
 (0)