|
| 1 | +import { publisher } from '../constants' |
| 2 | +import { type SecretAgentDefinition } from '../types/secret-agent-definition' |
| 3 | + |
| 4 | +const definition: SecretAgentDefinition = { |
| 5 | + id: 'implementation-planner-max', |
| 6 | + publisher, |
| 7 | + model: 'openai/gpt-5', |
| 8 | + displayName: 'Implementation Planner Max', |
| 9 | + spawnerPrompt: |
| 10 | + 'Creates the best possible implementation plan by generating 3 different plans in parallel and selecting the optimal one. Includes full code changes.', |
| 11 | + inputSchema: { |
| 12 | + prompt: { |
| 13 | + type: 'string', |
| 14 | + description: |
| 15 | + 'The task to plan for. Include the requirements and expected behavior after implementing the plan. Include quotes from the user of what they expect the plan to accomplish.', |
| 16 | + }, |
| 17 | + }, |
| 18 | + outputMode: 'structured_output', |
| 19 | + includeMessageHistory: true, |
| 20 | + toolNames: ['spawn_agents', 'set_output'], |
| 21 | + spawnableAgents: ['implementation-planner', 'plan-selector'], |
| 22 | + handleSteps: function* ({ prompt }) { |
| 23 | + // Step 1: Spawn 3 planners in parallel. |
| 24 | + const agents = Array.from({ length: 3 }, () => ({ |
| 25 | + agent_type: 'implementation-planner', |
| 26 | + prompt, |
| 27 | + })) |
| 28 | + const { toolResult: plannerResults } = yield { |
| 29 | + toolName: 'spawn_agents', |
| 30 | + input: { |
| 31 | + agents, |
| 32 | + }, |
| 33 | + } |
| 34 | + |
| 35 | + if (!Array.isArray(plannerResults)) { |
| 36 | + yield { |
| 37 | + toolName: 'set_output', |
| 38 | + input: { error: 'Failed to generate plans.' }, |
| 39 | + } |
| 40 | + return |
| 41 | + } |
| 42 | + const plannerResult = plannerResults[0] |
| 43 | + const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 44 | + const plans = |
| 45 | + plannerResult.type === 'json' ? (plannerResult.value as any[]) : [] |
| 46 | + const plansWithIds = plans.map((plan, index) => ({ |
| 47 | + id: letters[index], |
| 48 | + plan: JSON.stringify(plan), |
| 49 | + })) |
| 50 | + |
| 51 | + // Step 2: Spawn plan selector to choose the best plan |
| 52 | + const { toolResult: selectedPlanResult } = yield { |
| 53 | + toolName: 'spawn_agents', |
| 54 | + input: { |
| 55 | + agents: [ |
| 56 | + { |
| 57 | + agent_type: 'plan-selector', |
| 58 | + prompt: `Choose the best plan from these options for the task: ${prompt}`, |
| 59 | + params: { |
| 60 | + plans: plansWithIds, |
| 61 | + }, |
| 62 | + }, |
| 63 | + ], |
| 64 | + }, |
| 65 | + } |
| 66 | + |
| 67 | + if (!Array.isArray(selectedPlanResult) || selectedPlanResult.length < 1) { |
| 68 | + yield { |
| 69 | + toolName: 'set_output', |
| 70 | + input: { error: 'Failed to select a plan.' }, |
| 71 | + } |
| 72 | + return |
| 73 | + } |
| 74 | + const selectedPlan = selectedPlanResult[0] |
| 75 | + const selectedPlanId = |
| 76 | + selectedPlan.type === 'json' && selectedPlan.value |
| 77 | + ? (selectedPlan.value as { selectedPlanId: string }).selectedPlanId |
| 78 | + : null |
| 79 | + const selectedPlanWithId = plansWithIds.find( |
| 80 | + (plan) => plan.id === selectedPlanId, |
| 81 | + ) |
| 82 | + |
| 83 | + // Step 3: Set the selected plan as output |
| 84 | + yield { |
| 85 | + toolName: 'set_output', |
| 86 | + input: { |
| 87 | + plan: selectedPlanWithId?.plan ?? plans[0], |
| 88 | + }, |
| 89 | + } |
| 90 | + }, |
| 91 | +} |
| 92 | + |
| 93 | +export default definition |
0 commit comments