Skip to content

Commit 059f44a

Browse files
committed
Generate plan max
1 parent 27abd17 commit 059f44a

File tree

3 files changed

+150
-29
lines changed

3 files changed

+150
-29
lines changed

.agents/agent-builder.ts

Lines changed: 2 additions & 2 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, 'planners', 'implementation-planner.ts'),
26+
join(__dirname, 'planners', 'generate-plan.ts'),
2727
'utf8',
2828
)
2929
const planSelectorExampleContent = readFileSync(
3030
join(__dirname, 'planners', 'plan-selector.ts'),
3131
'utf8',
3232
)
3333
const implementationPlannerMaxExampleContent = readFileSync(
34-
join(__dirname, 'planners', 'implementation-planner-max.ts'),
34+
join(__dirname, 'planners', 'generate-plan-max.ts'),
3535
'utf8',
3636
)
3737
const examplesAgentsContent = [
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { publisher } from '../constants'
2+
import { type SecretAgentDefinition } from '../types/secret-agent-definition'
3+
4+
const definition: SecretAgentDefinition = {
5+
id: 'generate-plan-max',
6+
publisher,
7+
model: 'anthropic/claude-sonnet-4.5',
8+
displayName: 'Maximum Plan Generator',
9+
spawnerPrompt:
10+
'Generates 5 independent planning iterations, then selects the absolute best plan from all variations.',
11+
inputSchema: {},
12+
outputMode: 'structured_output',
13+
outputSchema: {
14+
type: 'object',
15+
properties: {
16+
plan: {
17+
type: 'string',
18+
description: 'The best plan selected from all variations',
19+
},
20+
},
21+
required: ['plan'],
22+
},
23+
toolNames: ['spawn_agents', 'set_output'],
24+
spawnableAgents: ['generate-plan', 'plan-selector'],
25+
26+
includeMessageHistory: true,
27+
inheritParentSystemPrompt: true,
28+
29+
handleSteps: function* ({ logger }) {
30+
// Step 1: Spawn 5 generate-plan agents in parallel
31+
const { toolResult: planResults } = yield {
32+
toolName: 'spawn_agents',
33+
input: {
34+
agents: Array.from({ length: 5 }, () => ({
35+
agent_type: 'generate-plan',
36+
})),
37+
},
38+
}
39+
40+
if (!Array.isArray(planResults)) {
41+
yield {
42+
toolName: 'set_output',
43+
input: { plan: 'Failed to generate plans.' },
44+
}
45+
return
46+
}
47+
48+
const plannerResult = planResults[0]
49+
const plans =
50+
plannerResult.type === 'json'
51+
? (plannerResult.value as { plan?: string }[])
52+
: []
53+
54+
logger.info({ plans }, 'plans')
55+
56+
// Extract all the plans from the structured outputs
57+
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
58+
const plansWithIds = plans.map((plan, idx) => {
59+
return {
60+
id: letters[idx],
61+
plan: JSON.stringify(plan),
62+
}
63+
})
64+
65+
logger.info({ plansWithIds }, 'plansWithIds')
66+
67+
if (plansWithIds.length === 0) {
68+
yield {
69+
toolName: 'set_output',
70+
input: { plan: 'No valid plans were generated.' },
71+
}
72+
return
73+
}
74+
75+
// Step 2: Spawn plan-selector to choose the best plan
76+
const { toolResult: selectedPlanResult } = yield {
77+
toolName: 'spawn_agents',
78+
input: {
79+
agents: [
80+
{
81+
agent_type: 'plan-selector',
82+
prompt: 'Choose the best plan from these options',
83+
params: {
84+
plans: plansWithIds,
85+
},
86+
},
87+
],
88+
},
89+
}
90+
91+
logger.info({ selectedPlanResult }, 'selectedPlanResult')
92+
93+
if (!Array.isArray(selectedPlanResult) || selectedPlanResult.length < 1) {
94+
yield {
95+
toolName: 'set_output',
96+
input: { plan: 'Failed to select a plan.' },
97+
}
98+
return
99+
}
100+
101+
const selectedPlan = selectedPlanResult[0]
102+
const selectedPlanId =
103+
selectedPlan.type === 'json' && selectedPlan.value
104+
? (selectedPlan.value as { selectedPlanId: string }).selectedPlanId
105+
: null
106+
107+
const selectedPlanWithId = plansWithIds.find(
108+
(plan) => plan.id === selectedPlanId,
109+
)
110+
111+
// Step 3: Set the selected plan as output
112+
yield {
113+
toolName: 'set_output',
114+
input: {
115+
plan: selectedPlanWithId?.plan ?? plansWithIds[0].plan,
116+
},
117+
}
118+
},
119+
}
120+
121+
export default definition

.agents/planners/plan-selector.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const definition: SecretAgentDefinition = {
1010
model: 'anthropic/claude-sonnet-4.5',
1111
displayName: 'Plan Selector',
1212
spawnerPrompt:
13-
'Expert at evaluating and selecting the best plan from multiple options based on quality, feasibility, and simplicity.',
14-
toolNames: ['read_files', 'set_output'],
13+
'Expert at evaluating and selecting the best high-level plan from multiple generate-plan outputs based on simplicity and correctness.',
14+
toolNames: ['set_output'],
1515
spawnableAgents: [],
1616
inputSchema: {
1717
prompt: {
@@ -42,44 +42,44 @@ const definition: SecretAgentDefinition = {
4242
reasoning: {
4343
type: 'string',
4444
description:
45-
"Thoughts on each plan and what's better or worse about each plan, leading up to which plan is the best choice.",
45+
'Analysis of each plan and reasoning for which is the best choice',
4646
},
4747
selectedPlanId: {
4848
type: 'string',
49-
description: 'The ID of the chosen plan.',
49+
description: 'The ID of the chosen plan',
5050
},
5151
},
5252
required: ['reasoning', 'selectedPlanId'],
5353
},
54+
inheritParentSystemPrompt: true,
5455
includeMessageHistory: true,
55-
systemPrompt: `You are an expert plan evaluator with deep experience in software engineering, architecture, and project management.
56+
instructionsPrompt: `For reference, here is the original user request:
57+
<user_message>
58+
${PLACEHOLDER.USER_INPUT_PROMPT}
59+
</user_message>
5660
57-
We're interested in the simplest solution that will accomplish the task correctly! You got this!
61+
You are evaluating multiple high-level plans generated by the generate-plan agent. Each plan has already been carefully crafted (generate-plan creates 5 alternatives internally and picks the best), so your job is to select the absolute best among these already-good plans.
5862
59-
${PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS}`,
63+
Analyze each plan based on:
6064
61-
instructionsPrompt: `Analyze all the provided implementations and select the best one based on:
65+
1. **Simplicity** - Which plan is the cleanest and most straightforward? Avoid over-engineering.
66+
2. **Correctness** - Which plan most accurately addresses all user requirements without adding unnecessary features?
67+
3. **Minimal scope** - Which plan touches the fewest files and has the least complexity?
68+
4. **Clarity** - Which plan is easiest to understand and follow?
69+
5. **Maintainability** - Which approach will be easiest to maintain and extend?
70+
6. **Best practices** - Which plan best follows existing codebase patterns?
71+
7. **User intent** - Which plan best addresses the user's intent and would surprise them the least?
6272
63-
1. **Simplicity** - How clean and easy to understand is the implementation? Is the code overcomplicated or over-engineered?
64-
2. **Correctness** - Does the implementation correctly address the requirements?
65-
3. **Quality** - How well does it work? How clear is the implementation?
66-
4. **Efficiency** - How minimal and focused are the changes? Were more files changed than necessary? Is the code verbose?
67-
5. **Maintainability** - How well will this approach work long-term?
68-
6. **Does what the user expects** - Make sure the implementation addresses all the requirements in the user's request, and does not do other stuff that the user did not ask for.
73+
Key principles:
74+
- Satisfying the user expectations is important
75+
- Simpler is better - we want the most straightforward solution that works
76+
- Fewer file changes is better
77+
- Reusing existing code is better than writing new code
78+
- Matching existing patterns and conventions is important
6979
70-
More on **Simplicity**:
71-
- We don't want an over-engineered solution.
72-
- We're not interested in endless safety and correctness checks.
73-
- Modifying fewer files is better.
74-
- Reusing existing code is better than writing new code.
75-
- It's good to match existing patterns and conventions in the codebase, including naming conventions, code style, and architecture.
76-
77-
For each implementation, evaluate:
78-
- Strengths and weaknesses
79-
- Implementation complexity
80-
- Alignment with the original task
81-
82-
Use the set_output tool to return your selection.`,
80+
For each plan, briefly evaluate strengths and weaknesses. Then use set_output to return your selection with:
81+
- reasoning: Your analysis and why you chose the winner
82+
- selectedPlanId: The ID of the best plan`,
8383
}
8484

8585
export default definition

0 commit comments

Comments
 (0)