Skip to content

Commit d59cb81

Browse files
committed
new orchestrator agent (very beta)
1 parent f70b29c commit d59cb81

File tree

10 files changed

+313
-10
lines changed

10 files changed

+313
-10
lines changed

.agents/agent-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ const researcherGrok4FastExampleContent = readFileSync(
2323
'utf8',
2424
)
2525
const implementationPlannerExampleContent = readFileSync(
26-
join(__dirname, 'implementation-planner', 'implementation-planner.ts'),
26+
join(__dirname, 'planners', 'implementation-planner.ts'),
2727
'utf8',
2828
)
2929
const planSelectorExampleContent = readFileSync(
30-
join(__dirname, 'implementation-planner', 'plan-selector.ts'),
30+
join(__dirname, 'planners', 'plan-selector.ts'),
3131
'utf8',
3232
)
3333
const implementationPlannerMaxExampleContent = readFileSync(
34-
join(__dirname, 'implementation-planner', 'implementation-planner-max.ts'),
34+
join(__dirname, 'planners', 'implementation-planner-max.ts'),
3535
'utf8',
3636
)
3737
const examplesAgentsContent = [

.agents/base2/gpt-5-high/editor-gpt-5-high.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import editor from '../editor'
1+
import editor from '../../editor/editor'
22

33
import type { SecretAgentDefinition } from '../../types/secret-agent-definition'
44

.agents/editor/editor-lite.ts

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import { Message } from 'types/util-types'
2+
import { publisher } from '../constants'
3+
import {
4+
PLACEHOLDER,
5+
type SecretAgentDefinition,
6+
} from '../types/secret-agent-definition'
7+
8+
const editor: SecretAgentDefinition = {
9+
id: 'editor-lite',
10+
publisher,
11+
model: 'x-ai/grok-code-fast-1',
12+
displayName: 'Fast Code Editor',
13+
spawnerPrompt:
14+
'Fast code editor with access to tools to find and edit files, run terminal commands. Can handle only easy coding tasks, unless working off of a plan. This is a great agent to spawn to implement a step-by-step plan!',
15+
inputSchema: {
16+
prompt: {
17+
type: 'string',
18+
description: 'The coding task to implement',
19+
},
20+
params: {
21+
type: 'object',
22+
properties: {
23+
maxContextLength: {
24+
type: 'number',
25+
},
26+
},
27+
required: [],
28+
},
29+
},
30+
outputMode: 'structured_output',
31+
includeMessageHistory: true,
32+
toolNames: [
33+
'read_files',
34+
'write_file',
35+
'str_replace',
36+
'run_terminal_command',
37+
'code_search',
38+
'spawn_agents',
39+
'add_message',
40+
'set_output',
41+
],
42+
spawnableAgents: ['file-explorer'],
43+
44+
systemPrompt: `You are an expert code editor with deep understanding of software engineering principles.
45+
46+
# Core Mandates
47+
48+
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
49+
- **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.
50+
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
51+
- **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
52+
- **No code comments:** *NEVER* add any comments while writing code, unless the user asks you to! *NEVER* talk to the user or describe your changes through comments. Do not edit comments that are separate from the code you are changing.
53+
- **Minimal Changes:** Make as few changes as possible to satisfy the user request! Don't go beyond what the user has asked for.
54+
- **Code Reuse:** Always reuse helper functions, components, classes, etc., whenever possible! Don't reimplement what already exists elsewhere in the codebase.
55+
- **Security First:** Always apply security best practices. Never introduce code that exposes, logs, or commits secrets, API keys, or other sensitive information.
56+
- **Front end development** We want to make the UI look as good as possible. Don't hold back. Give it your all.
57+
- Include as many relevant features and interactions as possible
58+
- Add thoughtful details like hover states, transitions, and micro-interactions
59+
- Apply design principles: hierarchy, contrast, balance, and movement
60+
- Create an impressive demonstration showcasing web development capabilities
61+
- **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.
62+
- **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).
63+
- **Code Hygiene:** Make sure to leave things in a good state:
64+
- Don't forget to add any imports that might be needed
65+
- Remove unused variables, functions, and files as a result of your changes.
66+
- If you added files or functions meant to replace existing code, then you should also remove the previous code.
67+
- **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.
68+
69+
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,
70+
71+
instructionsPrompt: `Implement the requested changes, using your judgment as needed, but referring to the original <user-message> as the most important source of information.
72+
73+
# Instructions
74+
75+
- It's helpful to spawn a file explorer to discover all the relevant files for implementing the plan.
76+
- 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.
77+
- Implement changes using str_replace or write_file.
78+
- You must use the set_output tool before finishing and include the following in your summary:
79+
- An answer to the user prompt (if they asked a question).
80+
- An explanation of the changes made.
81+
- A note on any checks you ran to verify the changes, such as tests, typechecking, etc.
82+
- 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.
83+
- Do not write a summary outside of the one that you include in the set_output tool.
84+
`,
85+
86+
handleSteps: function* ({ agentState: initialAgentState }) {
87+
const stepLimit = 35
88+
let stepCount = 0
89+
let agentState = initialAgentState
90+
let accumulatedEditToolResults: any[] = []
91+
92+
while (true) {
93+
stepCount++
94+
95+
const stepResult = yield 'STEP'
96+
agentState = stepResult.agentState // Capture the latest state
97+
98+
// Accumulate new tool messages from this step
99+
const { messageHistory } = agentState
100+
101+
// Extract and accumulate new edit tool results using helper function
102+
accumulatedEditToolResults.push(
103+
...getLatestEditToolResults(messageHistory),
104+
)
105+
106+
if (stepResult.stepsComplete) {
107+
break
108+
}
109+
110+
// If we've reached within one of the step limit, ask LLM to summarize progress
111+
if (stepCount === stepLimit - 1) {
112+
yield {
113+
toolName: 'add_message',
114+
input: {
115+
role: 'user',
116+
content:
117+
'You have reached the step limit. Please use the set_output tool now to summarize your progress so far including all specific actions you took (note that any file changes will be included automatically in the output), what you still need to solve, and provide any insights that could help complete the remaining work. Please end your turn after using the set_output tool with the end_turn tool.',
118+
},
119+
includeToolCall: false,
120+
}
121+
122+
// One final step to produce the summary
123+
const finalStepResult = yield 'STEP'
124+
agentState = finalStepResult.agentState
125+
126+
// Extract and accumulate final edit tool results using helper function
127+
accumulatedEditToolResults.push(
128+
...getLatestEditToolResults(agentState.messageHistory),
129+
)
130+
break
131+
}
132+
}
133+
134+
yield {
135+
toolName: 'set_output',
136+
input: {
137+
...agentState.output,
138+
edits: accumulatedEditToolResults,
139+
},
140+
}
141+
142+
function getLatestEditToolResults(messageHistory: Message[]) {
143+
const lastAssistantMessageIndex = messageHistory.findLastIndex(
144+
(message) => message.role === 'assistant',
145+
)
146+
147+
// Get all edit tool messages after the last assistant message
148+
const newToolMessages = messageHistory
149+
.slice(lastAssistantMessageIndex + 1)
150+
.filter((message) => message.role === 'tool')
151+
.filter(
152+
(message) =>
153+
message.content.toolName === 'write_file' ||
154+
message.content.toolName === 'str_replace',
155+
)
156+
157+
// Extract and return new edit tool results
158+
return (
159+
newToolMessages
160+
.flatMap((message) => message.content.output)
161+
.filter((output) => output.type === 'json')
162+
.map((output) => output.value)
163+
// Only successful edits!
164+
.filter(
165+
(toolResult) =>
166+
toolResult && !('errorMessage' in (toolResult as any)),
167+
)
168+
)
169+
}
170+
},
171+
}
172+
173+
export default editor
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { publisher } from '../constants'
2+
import {
3+
PLACEHOLDER,
4+
type SecretAgentDefinition,
5+
} from '../types/secret-agent-definition'
6+
7+
const definition: SecretAgentDefinition = {
8+
id: 'orchestrator',
9+
publisher,
10+
model: 'anthropic/claude-sonnet-4.5',
11+
displayName: 'Orchestrator',
12+
spawnerPrompt:
13+
'Advanced base agent that orchestrates planning, editing, and reviewing for complex coding tasks',
14+
inputSchema: {
15+
prompt: {
16+
type: 'string',
17+
description: 'A coding task to complete',
18+
},
19+
params: {
20+
type: 'object',
21+
properties: {
22+
maxContextLength: {
23+
type: 'number',
24+
},
25+
},
26+
required: [],
27+
},
28+
},
29+
outputMode: 'last_message',
30+
includeMessageHistory: true,
31+
toolNames: ['spawn_agents', 'read_files', 'str_replace', 'write_file'],
32+
spawnableAgents: [
33+
'read-only-commander',
34+
'researcher-grok-4-fast',
35+
'decomposing-planner-lite',
36+
'editor-lite',
37+
'reviewer-lite',
38+
'context-pruner',
39+
],
40+
41+
systemPrompt: `You are Buffy, a strategic coding assistant that orchestrates complex coding tasks through specialized sub-agents.
42+
43+
# Core Mandates
44+
45+
- **Tone:** Adopt a professional, direct, and concise tone suitable for a CLI environment.
46+
- **Orchestrate only** Coordinate between agents but do not implement code yourself.
47+
- **Rely on agents** Ask your spawned agents to complete a whole task. Instead of asking to see each relevant file and building up the plan yourself, ask an agent to come up with a plan or do the task or at least give you higher level information than what each section of code is. You shouldn't be trying to read each section of code yourself.
48+
- **Give as many instructions upfront as possible** When spawning agents, write a prompt that includes all your instructions for each agent so you don't need to spawn them again.
49+
- **Spawn mentioned agents:** If the users uses "@AgentName" in their message, you must spawn that agent. Spawn all the agents that the user mentions.
50+
- **Be concise:** Do not write unnecessary introductions or final summaries in your responses. Be concise and focus on efficiently completing the user's request, without adding explanations longer than 1 sentence.
51+
- **No final summary:** Never write a final summary of what work was done when the user's request is complete. Instead, inform the user in one sentence that the task is complete.
52+
- **Clarity over Brevity (When Needed):** While conciseness is key, prioritize clarity for essential explanations or when seeking necessary clarification if a request is ambiguous.
53+
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
54+
- **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.
55+
56+
# Starting Git Changes
57+
58+
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.
59+
60+
${PLACEHOLDER.GIT_CHANGES_PROMPT}
61+
`,
62+
63+
instructionsPrompt: `Orchestrate the completion of the coding task using your specialized sub-agents.
64+
65+
## Simple workflow
66+
67+
Use this workflow to solve a medium or complex coding task:
68+
1. Spawn a researcher
69+
2. Spawn a decomposing planner to come up with a plan.
70+
3. Spawn an editor to implement the plan.
71+
4. Spawn a reviewer to review the code. If changes are needed, go back to step 3, but only once.
72+
5. You must stop before spawning too many sequential agents, becase that this takes too much time and the user will get impatient.
73+
74+
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.
75+
76+
## Guidelines
77+
78+
- You can spawn agents to help you complete the task. Iterate by spawning more agents as needed.
79+
- Don't mastermind the task. Rely on your agents' judgement to research, plan, edit, and review the code.
80+
- Give as many instructions upfront as possible to each agent so you're less likely to need to spawn them again.
81+
- 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.
82+
- 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.
83+
- 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.
84+
`,
85+
86+
handleSteps: function* ({ prompt, params }) {
87+
let steps = 0
88+
while (true) {
89+
steps++
90+
// Run context-pruner before each step
91+
yield {
92+
toolName: 'spawn_agent_inline',
93+
input: {
94+
agent_type: 'context-pruner',
95+
params: params ?? {},
96+
},
97+
includeToolCall: false,
98+
} as any
99+
100+
const { stepsComplete } = yield 'STEP'
101+
if (stepsComplete) break
102+
}
103+
},
104+
}
105+
106+
export default definition
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { type SecretAgentDefinition } from '../types/secret-agent-definition'
2+
import decomposingPlanner from './decomposing-planner'
3+
4+
const definition: SecretAgentDefinition = {
5+
...decomposingPlanner,
6+
id: 'decomposing-planner-lite',
7+
displayName: 'Decomposing Planner Lite',
8+
model: 'anthropic/claude-sonnet-4.5',
9+
spawnerPrompt:
10+
'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.',
11+
spawnableAgents: ['file-explorer', 'implementation-planner-lite'],
12+
includeMessageHistory: false,
13+
}
14+
15+
export default definition

.agents/planners/decomposing-planner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Step 3: Synthesis
4848
- Create a unified implementation plan that:
4949
- Combines insights from all subtask plans
5050
- Resolves any conflicts or overlaps
51+
- Simplfies the plans while still accomplishing the task correctly -- most likely each subtask plan will do too much and add too much complexity
5152
- Presents a coherent, step-by-step implementation
5253
- Includes all necessary code changes in markdown code blocks
5354
- Follows the guidelines below
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { type SecretAgentDefinition } from '../types/secret-agent-definition'
2+
import implementationPlanner from './implementation-planner'
3+
4+
const definition: SecretAgentDefinition = {
5+
...implementationPlanner,
6+
id: 'implementation-planner-lite',
7+
displayName: 'Implementation Planner Lite',
8+
model: 'x-ai/grok-4-fast',
9+
}
10+
11+
export default definition

.agents/read-only-commander-lite.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { publisher } from './constants'
2-
import {
3-
PLACEHOLDER,
4-
type SecretAgentDefinition,
5-
} from './types/secret-agent-definition'
2+
import { type SecretAgentDefinition } from './types/secret-agent-definition'
63
import readOnlyCommander from './read-only-commander'
74

85
const readOnlyCommanderLite: SecretAgentDefinition = {
96
...readOnlyCommander,
107
id: 'read-only-commander-lite',
118
displayName: 'ReadOnly Commander Lite',
129
publisher,
13-
model: 'x-ai/grok-code-fast-1',
10+
model: 'x-ai/grok-4-fast',
1411
spawnerPrompt:
1512
'Can run quick read-only terminal commands and report back on the results. Has a basic understanding of the codebase. Is speedy and low-cost,',
1613
}

.agents/reviewer/reviewer-lite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { SecretAgentDefinition } from '../types/secret-agent-definition'
66
const definition: SecretAgentDefinition = {
77
id: 'reviewer-lite',
88
publisher,
9-
...reviewer('x-ai/grok-4-fast:free'),
9+
...reviewer('x-ai/grok-4-fast'),
1010
}
1111

1212
export default definition

0 commit comments

Comments
 (0)