| 176 | } |
| 177 | |
| 178 | function resolveWorkflowAgents( |
| 179 | inputAgents: WorkflowAgentInput[], |
| 180 | context: ToolUseContext, |
| 181 | ): ResolvedWorkflowAgent[] { |
| 182 | const activeAgents = context.options.agentDefinitions.activeAgents |
| 183 | const defaultAgent = |
| 184 | activeAgents.find(agent => agent.agentType === 'general-purpose') ?? |
| 185 | activeAgents[0] |
| 186 | |
| 187 | if (!defaultAgent) { |
| 188 | throw new Error('No agents are available for workflow execution.') |
| 189 | } |
| 190 | |
| 191 | return inputAgents.map(agentInput => { |
| 192 | const selectedAgent = agentInput.agent_type |
| 193 | ? activeAgents.find(agent => agent.agentType === agentInput.agent_type) |
| 194 | : defaultAgent |
| 195 | |
| 196 | if (!selectedAgent) { |
| 197 | throw new Error( |
| 198 | `Workflow agent type not found: ${agentInput.agent_type}`, |
| 199 | ) |
| 200 | } |
| 201 | |
| 202 | return { |
| 203 | id: createAgentId(), |
| 204 | name: agentInput.name, |
| 205 | description: agentInput.description ?? agentInput.name, |
| 206 | prompt: agentInput.prompt, |
| 207 | agentType: selectedAgent.agentType, |
| 208 | model: agentInput.model, |
| 209 | maxTurns: agentInput.max_turns, |
| 210 | selectedAgent, |
| 211 | } |
| 212 | }) |
| 213 | } |
| 214 | |
| 215 | async function runWorkflowAgentTask({ |
| 216 | taskId, |