({
taskId,
workflowName,
objective,
executionMode,
agents,
workflowAbortController,
toolUseContext,
canUseTool,
parentMessage,
rootSetAppState,
}: WorkflowRuntimeParams)
| 372 | } |
| 373 | |
| 374 | async function runWorkflowLifecycle({ |
| 375 | taskId, |
| 376 | workflowName, |
| 377 | objective, |
| 378 | executionMode, |
| 379 | agents, |
| 380 | workflowAbortController, |
| 381 | toolUseContext, |
| 382 | canUseTool, |
| 383 | parentMessage, |
| 384 | rootSetAppState, |
| 385 | }: WorkflowRuntimeParams): Promise<void> { |
| 386 | appendWorkflowLog( |
| 387 | taskId, |
| 388 | `Workflow ${workflowName} started with ${agents.length} agent${agents.length === 1 ? '' : 's'} (${executionMode}).`, |
| 389 | ) |
| 390 | appendWorkflowLog(taskId, `Objective: ${objective}`) |
| 391 | |
| 392 | try { |
| 393 | const results: Array<'completed' | 'failed' | 'killed'> = [] |
| 394 | |
| 395 | if (executionMode === 'parallel') { |
| 396 | results.push( |
| 397 | ...(await Promise.all( |
| 398 | agents.map(agent => |
| 399 | runWorkflowAgentTask({ |
| 400 | taskId, |
| 401 | executionMode, |
| 402 | agent, |
| 403 | workflowAbortController, |
| 404 | toolUseContext, |
| 405 | canUseTool, |
| 406 | parentMessage, |
| 407 | rootSetAppState, |
| 408 | }), |
| 409 | ), |
| 410 | )), |
| 411 | ) |
| 412 | } else { |
| 413 | for (const agent of agents) { |
| 414 | if (workflowAbortController.signal.aborted) { |
| 415 | results.push('killed') |
| 416 | break |
| 417 | } |
| 418 | |
| 419 | const result = await runWorkflowAgentTask({ |
| 420 | taskId, |
| 421 | executionMode, |
| 422 | agent, |
| 423 | workflowAbortController, |
| 424 | toolUseContext, |
| 425 | canUseTool, |
| 426 | parentMessage, |
| 427 | rootSetAppState, |
| 428 | }) |
| 429 | results.push(result) |
| 430 | |
| 431 | if (result === 'failed') { |
nothing calls this directly
no test coverage detected