{"record":{"id":"b8725c91c027ecd8","repo":"ruvnet/ruflo","slug":"agent-execute-failed","errorCode":null,"errorMessage":"agent_execute failed","messagePattern":"agent_execute failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts","lineNumber":365,"sourceCode":"\n        let stepEntry: typeof stepResults[number] = { stepId: step.stepId, type: step.type, status: 'running' };\n\n        try {\n          if (step.type === 'task') {\n            const cfg = step.config as Record<string, unknown>;\n            const agentId = (cfg.agentId as string) || (workflow.variables.defaultAgentId as string);\n            const promptTpl = (cfg.prompt as string) || step.name;\n            if (!agentId) throw new Error(`task step ${step.stepId} requires config.agentId or workflow.variables.defaultAgentId`);\n            const prompt = interp(promptTpl);\n            const result = await executeAgentTask({\n              agentId,\n              prompt,\n              systemPrompt: cfg.systemPrompt ? interp(String(cfg.systemPrompt)) : undefined,\n              maxTokens: cfg.maxTokens as number | undefined,\n              temperature: cfg.temperature as number | undefined,\n              timeoutMs: cfg.timeoutMs as number | undefined,\n            });\n            if (!result.success) throw new Error(result.error || 'agent_execute failed');\n            step.result = result;\n            workflow.variables[`${step.stepId}.output`] = result.output;\n            workflow.variables.lastStepOutput = result.output;\n            stepEntry = { stepId: step.stepId, type: 'task', status: 'completed', durationMs: result.durationMs, output: result.output };\n          } else if (step.type === 'wait') {\n            const cfg = step.config as Record<string, unknown>;\n            const ms = Math.min(Math.max(0, (cfg.ms as number) || 0), 60000);\n            await new Promise(r => setTimeout(r, ms));\n            step.result = { waitedMs: ms };\n            stepEntry = { stepId: step.stepId, type: 'wait', status: 'completed', durationMs: ms };\n          } else if (step.type === 'condition') {\n            // Simple condition: config.when is a JS expression evaluated against workflow.variables.\n            // For safety, we only support `var === 'value'` or `var === number`.\n            const cfg = step.config as Record<string, unknown>;\n            const expr = String(cfg.when || 'true').trim();\n            const m = expr.match(/^([a-zA-Z_][\\w]*)\\s*===?\\s*(['\\\"])?([^'\\\"]*)\\2?$/);\n            let truthy = false;\n            if (m) {","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts#L347-L383","documentation":"In a workflow 'task' step, executeAgentTask() (from agent-execute-core) returned { success: false } and this throw fires. 'agent_execute failed' is only the FALLBACK text used when result.error is empty — normally the real cause is propagated (e.g. 'Agent not found', 'Agent has been terminated', 'Anthropic API error 401: ...', 'Ollama API error ...', provider timeouts). Seeing the generic string means the failure path produced no message, so you must reproduce the agent call directly to learn why.","triggerScenarios":"A task step whose agentId refers to a deleted or never-spawned agent; an agent whose status is 'terminated'; provider errors (bad/missing API key, 4xx/5xx from Anthropic/Ollama/custom provider); a provider failure mode that returns success:false without an error string, making the workflow surface the fallback message.","commonSituations":"Workflow templates referencing agent ids from a previous session (agent store is gone); API key rotated or expired between workflow runs; Ollama not running locally; agents terminated by a lifecycle cleanup while the workflow was still executing.","solutions":["Verify the agent exists and is not terminated: call agent_list / agent_status with the same agentId the step uses.","Reproduce outside the workflow: call agent_execute with the same agentId and prompt — it returns the detailed error string.","Check provider configuration (API keys env vars, Ollama reachable, providerLabel endpoints) for the agent's configured model/provider.","If the direct call also yields an empty error, capture it as a bug — success:false with no message is a lost-error defect in the execute path."],"exampleFix":"// before\n{ type: 'task', config: { agentId: 'coder-42', prompt: '...' } } // coder-42 from an old session\n// workflow run -> step failed: 'agent_execute failed'\n\n// after\nawait mcp.call('agent_spawn', { agentType: 'coder', agentId: 'coder-42' }); // ensure it exists\nawait mcp.call('agent_execute', { agentId: 'coder-42', prompt: 'ping' });   // verify, see real error if any\n// then run the workflow","handlingStrategy":"validation","validationCode":"// Before workflow_run, confirm every referenced agent exists and is alive:\nasync function assertAgentsReady(agentIds: string[], mcp: McpClient): Promise<void> {\n  const { agents } = await mcp.call('agent_list', {});\n  const alive = new Map(agents.map((a: any) => [a.agentId, a.status]));\n  for (const id of agentIds) {\n    const status = alive.get(id);\n    if (!status) throw new Error(`agent ${id} not found — spawn it before the run`);\n    if (status === 'terminated') throw new Error(`agent ${id} is terminated — respawn before the run`);\n  }\n}","typeGuard":"interface AgentTaskResult { success: boolean; error?: string; output?: string }\nfunction isFailedAgentResult(r: AgentTaskResult): r is AgentTaskResult & { success: false } {\n  return r.success === false;\n}","tryCatchPattern":"try {\n  return await callTool('workflow_run', { workflowId });\n} catch (e) {\n  if ((e as Error).message === 'agent_execute failed') {\n    // Generic fallback text: real cause was empty — reproduce directly for the detailed error\n    const probe = await callTool('agent_execute', { agentId, prompt: 'ping' });\n    return stepError(`agent_execute failed (no message); direct probe says: ${probe.error ?? 'ok now — transient provider issue'}`);\n  }\n  throw e;\n}","preventionTips":["Pre-check agent existence/status with agent_list before starting a workflow that references them.","Keep provider config (API keys, Ollama URL) verified — provider errors propagate as result.error, so a healthy provider avoids the step failing at all.","When a step fails with the generic message, always run the same agent via agent_execute to recover the real error string."],"tags":["workflow","agent","execution","provider","agent-execute"],"backgroundTag":"agent-execution-failed","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}