{"slug": "how-do-you-make-a-crewai-agent-survive-a-crash", "title": "How Do You Make a CrewAI Agent Survive a Crash?", "summary": "A developer demonstrated a durable-execution wrapper for CrewAI agents that converts each tool call into a Dapr workflow activity, so a crashed or redeployed process resumes from the last completed call instead of restarting the task. The DaprWorkflowAgentRunner class replaces crew.kickoff() and persists tool inputs and outputs in the workflow history, with a fixed run ID preventing duplicate runs on restart. The approach still re-executes any activity that was mid-flight at crash time, so the developer recommends idempotency keys for tools that send email or write records.", "body_md": "Run it under a durable workflow, so every tool call is saved as it completes. For CrewAI durable execution, that's one wrapper class around the agent you already have: DaprWorkflowAgentRunner turns each tool call into a Dapr workflow activity, and after a crash the run continues from the last completed one instead of starting over.\n\nWhat happens without it\n\n`crew.kickoff()` runs the whole task inside your Python process. The tool results the agent has gathered and its place in the reasoning loop live in that process's memory. If a deploy or an OOM kill takes the process out halfway, the task starts again from the top, and every tool it already called gets called again.\n\nThe change\n\n```\npip install \"diagrid[crewai]\"\ndapr init\npython\nfrom crewai import Agent, Task\nfrom crewai.tools import tool\nimport dapr.ext.workflow as wf\nfrom diagrid.agent.crewai import DaprWorkflowAgentRunner\n\n@tool(\"Search the web for information\")\ndef search_web(query: str) -> str:\n    return f\"Results for: {query}\"  # swap in your real search tool\n\nagent = Agent(\n    role=\"Research Analyst\",\n    goal=\"Analyse market trends\",\n    backstory=\"A careful analyst who cites sources\",\n    tools=[search_web],\n    llm=\"openai/gpt-4o-mini\",\n)\n\ntask = Task(\n    description=\"Research Q4 trends in durable execution for AI agents\",\n    expected_output=\"Five bullet points with sources\",\n    agent=agent,\n)\n\nrunner = DaprWorkflowAgentRunner(agent=agent, name=\"market-research\", max_iterations=10)\nrunner.start()\n\nrun_id = \"q4-trends\"\nclient = wf.DaprWorkflowClient()\nif client.get_workflow_state(run_id) is None:\n    out = runner.run_sync(task=task, session_id=run_id, workflow_id=run_id, timeout=600)\n    print(out.final_response)\nelse:\n    state = client.wait_for_workflow_completion(run_id, timeout_in_seconds=600)\n    print(state.serialized_output)\n\nrunner.shutdown()\ndapr run --app-id market-research -- python crew_app.py\n```\n\nThe Agent and Task are the same objects you'd hand to a Crew. The runner takes the place of `kickoff()`.\n\nWhat gets saved\n\nEach tool call runs as a workflow activity. When it finishes, its input and output go into the workflow history in your state store. If the process dies, the Dapr runtime reactivates the workflow and replays it. Completed activities return their saved results, and execution continues from the first one that hadn't finished, with the agent's local state restored.\n\nThe fixed `run_id` is there so a restarted script finds the unfinished run and waits on it, rather than starting a second copy of the same task.\n\nWhere it stops\n\nAn activity that was mid-flight when the process died runs again from its start, because nothing recorded its result. For a search tool that costs you one extra search. For a tool that sends an email or writes a record, pass an idempotency key made from the run ID and the step, and let the receiving system drop the repeat.\n\nTakeaway\n\nIf a CrewAI agent runs longer than the gap between your deploys, wrap it, give each run a stable ID, and make a list of which of its tools write to something. The CrewAI page has the rest: [https://www.diagrid.io/learn/crewai-durable-execution](https://www.diagrid.io/learn/crewai-durable-execution)\n\nGive it a spin and lmk what breaks 👀", "url": "https://wpnews.pro/news/how-do-you-make-a-crewai-agent-survive-a-crash", "canonical_source": "https://dev.to/casper_nielsen_47eb2e6023/how-do-you-make-a-crewai-agent-survive-a-crash-2cc3", "published_at": "2026-10-29 09:34:51+00:00", "updated_at": "2026-10-29 09:47:13.538006+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "mlops", "ai-infrastructure"], "entities": ["CrewAI", "Dapr", "Diagrid", "DaprWorkflowAgentRunner", "OpenAI"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/how-do-you-make-a-crewai-agent-survive-a-crash", "markdown": "https://wpnews.pro/news/how-do-you-make-a-crewai-agent-survive-a-crash.md", "text": "https://wpnews.pro/news/how-do-you-make-a-crewai-agent-survive-a-crash.txt", "jsonld": "https://wpnews.pro/news/how-do-you-make-a-crewai-agent-survive-a-crash.jsonld"}}