|
1 | 1 | import type { SecretAgentDefinition } from '../../types/secret-agent-definition' |
2 | 2 | import { plannerFactory } from '../planner-factory' |
| 3 | +import { ToolCall } from 'types/agent-definition' |
3 | 4 |
|
4 | 5 | const definition: SecretAgentDefinition = { |
5 | 6 | id: 'planner-gpt-5-high', |
6 | | - ...plannerFactory('openai/gpt-5', 'thinker-gpt-5-high'), |
| 7 | + |
| 8 | + ...plannerFactory('openai/gpt-5'), |
| 9 | + |
| 10 | + reasoningOptions: { |
| 11 | + enabled: true, |
| 12 | + effort: 'high', |
| 13 | + exclude: true, |
| 14 | + }, |
| 15 | + |
| 16 | + spawnableAgents: ['file-explorer', 'researcher', 'thinker-gpt-5-high'], |
| 17 | + |
| 18 | + handleSteps: function* ({ prompt }) { |
| 19 | + // Step 1: Spawn file-explorer and parse out the file paths |
| 20 | + const { agentState: stateAfterFileExplorer } = yield 'STEP' |
| 21 | + const { messageHistory } = stateAfterFileExplorer |
| 22 | + const lastAssistantMessageIndex = |
| 23 | + stateAfterFileExplorer.messageHistory.findLastIndex( |
| 24 | + (message) => message.role === 'assistant', |
| 25 | + ) |
| 26 | + const toolResultMessage = messageHistory[lastAssistantMessageIndex + 1] ?? { |
| 27 | + content: '', |
| 28 | + } |
| 29 | + const filePaths = parseFilePathsFromToolResult(toolResultMessage.content) |
| 30 | + |
| 31 | + // Step 2: Read the files |
| 32 | + yield { |
| 33 | + toolName: 'read_files', |
| 34 | + input: { |
| 35 | + paths: filePaths, |
| 36 | + }, |
| 37 | + } satisfies ToolCall |
| 38 | + |
| 39 | + // Step 3: Spawn deep-thinker to analyze approach |
| 40 | + const { toolResult: deepThinkerToolResult } = yield { |
| 41 | + toolName: 'spawn_agents', |
| 42 | + input: { |
| 43 | + agents: [ |
| 44 | + { |
| 45 | + agent_type: 'gemini-thinker-high', |
| 46 | + prompt: `Create a clear implementation plan for the following task, with a focus on simplicity and making the minimal changes necessary for an awesome implementation. Prompt: ${prompt}`, |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + yield { |
| 53 | + toolName: 'set_output', |
| 54 | + input: { |
| 55 | + plan: deepThinkerToolResult, |
| 56 | + }, |
| 57 | + } |
| 58 | + |
| 59 | + function parseFilePathsFromToolResult(content: string): string[] { |
| 60 | + const filePaths: string[] = [] |
| 61 | + |
| 62 | + // Match file paths that look like valid paths (containing / and file extensions) |
| 63 | + const filePathRegex = |
| 64 | + /(?:^|\s|\*\s*)((?:[\w-]+\/)*[\w.-]+\.[a-zA-Z]{1,4})(?=\s|$|,|\.|:)/gm |
| 65 | + |
| 66 | + let match |
| 67 | + while ((match = filePathRegex.exec(content)) !== null) { |
| 68 | + const filePath = match[1] |
| 69 | + // Filter out obvious false positives and ensure reasonable path structure |
| 70 | + if ( |
| 71 | + filePath && |
| 72 | + !filePath.startsWith('http') && |
| 73 | + !filePath.includes('@') && |
| 74 | + filePath.length > 3 && |
| 75 | + filePath.split('/').length <= 10 |
| 76 | + ) { |
| 77 | + filePaths.push(filePath) |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + // Also look for backtick-quoted file paths |
| 82 | + const backtickPathRegex = /`([^`]+\.[a-zA-Z]{1,4})`/g |
| 83 | + while ((match = backtickPathRegex.exec(content)) !== null) { |
| 84 | + const filePath = match[1] |
| 85 | + if ( |
| 86 | + filePath && |
| 87 | + !filePath.startsWith('http') && |
| 88 | + !filePath.includes('@') |
| 89 | + ) { |
| 90 | + filePaths.push(filePath) |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + // Remove duplicates and return |
| 95 | + return [...new Set(filePaths)] |
| 96 | + } |
| 97 | + }, |
7 | 98 | } |
8 | 99 |
|
9 | 100 | export default definition |
0 commit comments