Skip to content

Commit 9bb9901

Browse files
committed
Improvements for iterative orchestrator
1 parent 288c9be commit 9bb9901

File tree

3 files changed

+90
-25
lines changed

3 files changed

+90
-25
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { SecretAgentDefinition } from 'types/secret-agent-definition'
2+
import { createBase2 } from './base2'
3+
4+
const definition: SecretAgentDefinition = {
5+
...createBase2('fast'),
6+
id: 'base2-with-files-input',
7+
displayName: 'Buffy the Fast Orchestrator',
8+
9+
inputSchema: {
10+
prompt: {
11+
type: 'string',
12+
description: 'A coding task to complete',
13+
},
14+
params: {
15+
type: 'object',
16+
properties: {
17+
maxContextLength: {
18+
type: 'number',
19+
},
20+
filesToRead: {
21+
type: 'array',
22+
items: {
23+
type: 'string',
24+
},
25+
},
26+
},
27+
required: ['filesToRead'],
28+
},
29+
},
30+
31+
handleSteps: function* ({ params }) {
32+
yield {
33+
toolName: 'read_files',
34+
input: { paths: params?.filesToRead || [] },
35+
}
36+
37+
let steps = 0
38+
while (true) {
39+
steps++
40+
// Run context-pruner before each step
41+
yield {
42+
toolName: 'spawn_agent_inline',
43+
input: {
44+
agent_type: 'context-pruner',
45+
params: params ?? {},
46+
},
47+
includeToolCall: false,
48+
} as any
49+
50+
const { stepsComplete } = yield 'STEP'
51+
if (stepsComplete) break
52+
}
53+
},
54+
}
55+
export default definition

.agents/orchestrator/iterative-orchestrator/iterative-orchestrator-step.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,27 @@ const definition: SecretAgentDefinition = {
3737
type: 'object',
3838
properties: {
3939
title: { type: 'string' },
40-
prompt: { type: 'string' },
40+
prompt: {
41+
type: 'string',
42+
description:
43+
'The exact prompt that will be sent to the agent that will implement or decide the step',
44+
},
4145
type: { type: 'string', enum: ['implementation', 'decision'] },
42-
successCriteria: { type: 'array', items: { type: 'string' } },
43-
filesToReadHints: { type: 'array', items: { type: 'string' } },
46+
filesToReadHints: {
47+
type: 'array',
48+
items: { type: 'string' },
49+
description:
50+
'Include paths to files that will help the agent implement or decide the step',
51+
},
4452
},
4553
required: ['title', 'prompt', 'type'],
4654
},
4755
},
48-
notes: { type: 'string' },
56+
notes: {
57+
type: 'string',
58+
description:
59+
'Any notes for the future orchestator agent. What you want to accomplish with these steps, why you chose them, and what you want to accomplish next. Also, estimate the remaining number of steps needed to complete the task.',
60+
},
4961
},
5062
required: ['isDone', 'nextSteps', 'notes'],
5163
},
@@ -61,20 +73,12 @@ Important: you *must* make at least one tool call, via <codebuff_tool_call> synt
6173
- If only one step is needed next, return a single-item array.
6274
- Mark isDone=true only when the overall task is truly complete.
6375
64-
Return JSON via set_output with:
65-
{
66-
isDone: boolean,
67-
nextSteps: [
68-
{
69-
title: string,
70-
prompt: string, // exact prompt to give to the implementor or decision maker
71-
type: 'implementation' | 'decision', // whether this is a coding task or decision
72-
successCriteria?: string[] // 3-6 bullet checks that show this step is done
73-
filesToReadHints?: string[] // optional globs/paths hints
74-
}
75-
],
76-
notes: string // short rationale for these steps
77-
}
76+
## Guidelines
77+
- It's better to make small changes at a time and validate them as you go. Writing a lot of code without testing it or typechecking it or validating it in some way is not good!
78+
- Keep the scope of your changes as small as possible.
79+
- Try to complete your task in as few steps as possible.
80+
- There is a time limit on the number of steps you can take. If you reach the limit, you will be cut off prematurely before the task is complete.
81+
- Prefer not to parallelize steps if they are at all related, because you can get a better result by doing them sequentially.
7882
`,
7983
stepPrompt: `Important: you *must* make at least one tool call, via <codebuff_tool_call> syntax, in every response message!`,
8084
}

.agents/orchestrator/iterative-orchestrator/iterative-orchestrator.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type StepInfo = {
99
title: string
1010
prompt: string
1111
type: 'implementation' | 'decision'
12-
successCriteria?: string[]
1312
filesToReadHints?: string[]
1413
}
1514

@@ -22,7 +21,7 @@ const definition: SecretAgentDefinition = {
2221
'Orchestrates the completion of a large task through batches of independent steps.',
2322
outputMode: 'structured_output',
2423
toolNames: ['spawn_agents', 'set_output'],
25-
spawnableAgents: ['iterative-orchestrator-step', 'base2-fast'],
24+
spawnableAgents: ['iterative-orchestrator-step', 'base2-with-files-input'],
2625

2726
inputSchema: {
2827
prompt: { type: 'string', description: 'Overall task to complete' },
@@ -38,8 +37,10 @@ const definition: SecretAgentDefinition = {
3837
}[] = []
3938
let completed = false
4039
let iteration = 0
40+
const maxIterations = 15
4141

42-
while (!completed) {
42+
while (!completed && iteration < maxIterations) {
43+
const remainingIterations = maxIterations - iteration
4344
iteration++
4445
// 1) Plan next step
4546
const planningBundle = [
@@ -93,18 +94,23 @@ const definition: SecretAgentDefinition = {
9394
break
9495
}
9596

97+
const reminder =
98+
remainingIterations <= 5
99+
? `<reminder>You are approaching the MAXIMUM NUMBER OF ITERATIONS! You have ${remainingIterations} iterations left to complete the task, or at least get it into a working state. You must try to wrap up the task in the remaining iterations or be cut off!</system_remender>`
100+
: `<reminder>You have ${remainingIterations} steps left to complete the task.</reminder>`
101+
96102
// 3) Execute all steps in parallel
97103
const executionAgents = steps.map((step) => {
98104
if (step.type === 'decision') {
99105
return {
100-
agent_type: 'base2-fast',
101-
prompt: `DECISION TASK: ${step.prompt}\n\nThis is a decision-making step, not an implementation step. Your job is to research options, analyze trade-offs, and make a clear recommendation with rationale. Write out your decision in the last message. Do not create a file with your decision.`,
106+
agent_type: 'base2-with-files-input',
107+
prompt: `DECISION TASK: ${step.prompt}\n\nThis is a decision-making step, not an implementation step. Your job is to research options, analyze trade-offs, and make a clear recommendation with rationale. Write out your decision in the last message. Do not create a file with your decision. ${reminder}`,
102108
params: { filesToRead: step.filesToReadHints || [] },
103109
}
104110
} else {
105111
return {
106-
agent_type: 'base2-fast',
107-
prompt: step.prompt,
112+
agent_type: 'base2-with-files-input',
113+
prompt: `${step.prompt}\n\n${reminder}`,
108114
params: { filesToRead: step.filesToReadHints || [] },
109115
}
110116
}

0 commit comments

Comments
 (0)