|
| 1 | +import type { AgentDefinition, ToolCall } from '../types/agent-definition' |
| 2 | + |
| 3 | +/** |
| 4 | + * ETL Manager Agent |
| 5 | + * |
| 6 | + * Coordinates the ETL pipeline using handleSteps for sequential execution. |
| 7 | + * A lightweight shim that spawns extract → transform → load in sequence. |
| 8 | + */ |
| 9 | + |
| 10 | +const agent: AgentDefinition = { |
| 11 | + id: 'etl-manager', |
| 12 | + displayName: 'ETL Pipeline Manager', |
| 13 | + model: 'openai/gpt-5', |
| 14 | + version: '1.0.0', |
| 15 | + publisher: 'web-demo', |
| 16 | + |
| 17 | + toolNames: ['spawn_agents', 'think_deeply', 'add_message'], |
| 18 | + |
| 19 | + outputMode: 'last_message', |
| 20 | + stepPrompt: '', |
| 21 | + includeMessageHistory: true, |
| 22 | + |
| 23 | + spawnableAgents: ['extract-agent', 'transform-agent', 'load-agent'], |
| 24 | + |
| 25 | + handleSteps: function* ({ prompt, params }) { |
| 26 | + // Step 1: Generate context-aware prompt for extract agent |
| 27 | + const extractPrompt = `Analyzing user request "${prompt}" to generate optimal extraction strategy. Consider: data domain (${params?.domain || 'unknown'}), specific search terms needed, target sources, and query refinement for maximum relevance.` |
| 28 | + |
| 29 | + const { toolResult: extractResults } = yield { |
| 30 | + toolName: 'spawn_agents', |
| 31 | + input: { |
| 32 | + agents: [ |
| 33 | + { |
| 34 | + agent_type: 'extract-agent', |
| 35 | + prompt: extractPrompt, |
| 36 | + params: params?.extractParams || {}, |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + } satisfies ToolCall |
| 41 | + if (!extractResults || extractResults.length === 0) { |
| 42 | + yield { |
| 43 | + toolName: 'add_message', |
| 44 | + input: { |
| 45 | + role: 'user', |
| 46 | + content: 'Extract step failed.', |
| 47 | + }, |
| 48 | + } satisfies ToolCall |
| 49 | + return |
| 50 | + } |
| 51 | + const extractResult = |
| 52 | + extractResults[0]?.type === 'json' |
| 53 | + ? extractResults[0].value |
| 54 | + : extractResults[0] |
| 55 | + |
| 56 | + // Step 2: Generate context-aware prompt for transform agent |
| 57 | + const transformPrompt = `Processing extracted data from previous step. Need to transform raw data into canonical schema. Consider: data quality, normalization needs, deduplication strategy, and enrichment opportunities based on extracted content.` |
| 58 | + |
| 59 | + const { toolResult: transformResults } = yield { |
| 60 | + toolName: 'spawn_agents', |
| 61 | + input: { |
| 62 | + agents: [ |
| 63 | + { |
| 64 | + agent_type: 'transform-agent', |
| 65 | + prompt: transformPrompt, |
| 66 | + params: { |
| 67 | + ...params?.transformParams, |
| 68 | + extractResult: extractResult, |
| 69 | + }, |
| 70 | + }, |
| 71 | + ], |
| 72 | + }, |
| 73 | + } satisfies ToolCall |
| 74 | + if (!transformResults || transformResults.length === 0) { |
| 75 | + yield { |
| 76 | + toolName: 'add_message', |
| 77 | + input: { |
| 78 | + role: 'user', |
| 79 | + content: 'Transform step failed.', |
| 80 | + }, |
| 81 | + } satisfies ToolCall |
| 82 | + return |
| 83 | + } |
| 84 | + const transformResult = |
| 85 | + transformResults[0]?.type === 'json' |
| 86 | + ? transformResults[0].value |
| 87 | + : transformResults[0] |
| 88 | + |
| 89 | + // Step 3: Generate context-aware prompt for load agent |
| 90 | + const loadPrompt = `Final filtering and ranking phase for user request "${prompt}". Need to apply user constraints, score relevance, and rank results. Consider: user preferences, contextual relevance, quality metrics, and practical constraints.` |
| 91 | + |
| 92 | + const { toolResult: loadResults } = yield { |
| 93 | + toolName: 'spawn_agents', |
| 94 | + input: { |
| 95 | + agents: [ |
| 96 | + { |
| 97 | + agent_type: 'load-agent', |
| 98 | + prompt: loadPrompt, |
| 99 | + params: { |
| 100 | + ...params?.loadParams, |
| 101 | + transformResult: transformResult, |
| 102 | + }, |
| 103 | + }, |
| 104 | + ], |
| 105 | + }, |
| 106 | + } satisfies ToolCall |
| 107 | + if (!loadResults || loadResults.length === 0) { |
| 108 | + yield { |
| 109 | + toolName: 'add_message', |
| 110 | + input: { |
| 111 | + role: 'user', |
| 112 | + content: 'Load step failed.', |
| 113 | + }, |
| 114 | + } satisfies ToolCall |
| 115 | + return |
| 116 | + } |
| 117 | + const loadResult = |
| 118 | + loadResults[0]?.type === 'json' ? loadResults[0].value : loadResults[0] |
| 119 | + |
| 120 | + // Return final ETL results |
| 121 | + yield { |
| 122 | + toolName: 'add_message', |
| 123 | + input: { |
| 124 | + role: 'user', |
| 125 | + content: |
| 126 | + typeof loadResult === 'string' |
| 127 | + ? loadResult |
| 128 | + : JSON.stringify(loadResult), |
| 129 | + }, |
| 130 | + } satisfies ToolCall |
| 131 | + }, |
| 132 | + |
| 133 | + inputSchema: { |
| 134 | + prompt: { |
| 135 | + type: 'string', |
| 136 | + description: |
| 137 | + 'The data processing request to execute through ETL pipeline', |
| 138 | + }, |
| 139 | + params: { |
| 140 | + type: 'object', |
| 141 | + properties: { |
| 142 | + domain: { |
| 143 | + type: 'string', |
| 144 | + description: |
| 145 | + 'Data domain for ETL processing, e.g. places, events, projects', |
| 146 | + }, |
| 147 | + extractParams: { |
| 148 | + type: 'object', |
| 149 | + description: 'Any special parameters for extract agent', |
| 150 | + }, |
| 151 | + transformParams: { |
| 152 | + type: 'object', |
| 153 | + description: 'Any special parameters for transform agent', |
| 154 | + }, |
| 155 | + loadParams: { |
| 156 | + type: 'object', |
| 157 | + description: 'Any special parameters for load agent', |
| 158 | + }, |
| 159 | + }, |
| 160 | + }, |
| 161 | + }, |
| 162 | + |
| 163 | + systemPrompt: |
| 164 | + 'You are an ETL pipeline manager that coordinates sequential data processing through extract, transform, and load stages.', |
| 165 | + |
| 166 | + spawnerPrompt: |
| 167 | + 'Use this agent to execute a complete ETL pipeline for data processing requests', |
| 168 | + |
| 169 | + instructionsPrompt: '', |
| 170 | +} |
| 171 | + |
| 172 | +export default agent |
0 commit comments