From 4771434033b08429050150939adcc0de7505429c Mon Sep 17 00:00:00 2001 From: yaron2 Date: Wed, 10 Dec 2025 11:18:21 -0800 Subject: [PATCH 1/4] Add crewAI and workflow documentation Signed-off-by: yaron2 --- .../developing-applications/crewai/_index.md | 12 ++ .../crewai/crewai-workflows.md | 204 ++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 daprdocs/content/en/developing-applications/crewai/_index.md create mode 100644 daprdocs/content/en/developing-applications/crewai/crewai-workflows.md diff --git a/daprdocs/content/en/developing-applications/crewai/_index.md b/daprdocs/content/en/developing-applications/crewai/_index.md new file mode 100644 index 00000000000..d56d3a8b254 --- /dev/null +++ b/daprdocs/content/en/developing-applications/crewai/_index.md @@ -0,0 +1,12 @@ +--- +type: docs +title: "CrewAI" +linkTitle: "CrewAI" +weight: 25 +description: "Dapr first-class integrations with CrewAI Agents" +--- + +### What is the Dapr CrewAI integration? + +Dapr provides powerful APIs for developers looking to build OpenAI agents that scale and operate reliably in producton. Dapr provides first class integratons that range from agent session management to connecting agents via pub/sub and orchestrating agentic workflows. + \ No newline at end of file diff --git a/daprdocs/content/en/developing-applications/crewai/crewai-workflows.md b/daprdocs/content/en/developing-applications/crewai/crewai-workflows.md new file mode 100644 index 00000000000..b1009c14ed7 --- /dev/null +++ b/daprdocs/content/en/developing-applications/crewai/crewai-workflows.md @@ -0,0 +1,204 @@ +--- +type: docs +title: "CrewAI Workflows" +linkTitle: "CrewAI Workflows" +weight: 25 +description: "How to run CrewAI agents with durable, fault-tolerant execution using Dapr Workflows" +--- + +## Overview + +Dapr Workflows make it possible to run CrewAI agents **reliably**, **durably**, and **with built-in resiliency**. +By orchestrating CrewAI tasks with the Dapr Workflow engine, developers can: + +- Ensure long-running CrewAI work survives crashes and restarts +- Get automatic checkpoints, retries, and state recovery +- Run each CrewAI task as a durable activity +- Observe execution through tracing, metrics, and structured logs + +This guide walks through orchestrating multiple CrewAI tasks using Dapr Workflows, ensuring each step is run *exactly once* even if the process restarts. + +## Getting Started + +Initialize Dapr locally to set up a self-hosted environment for development. This process installs the Dapr sidecar binaries, provisions the workflow engine, and prepares a default components directory. For full details, see the official [guide on initializing Dapr locally]({{% ref install-dapr-selfhost.md %}}). + +Initialize Dapr: + +```bash +dapr init +``` + +Verify that daprio/dapr, openzipkin/zipkin, and redis are running: + +```bash +docker ps +``` + +### Install Python + +{{% alert title="Note" color="info" %}} +Make sure you have Python already installed. `Python >=3.10`. For installation instructions, visit the official [Python installation guide](https://www.python.org/downloads/). +{{% /alert %}} + +### Install Dependencies + +```bash +pip install dapr dapr-ext-workflow crewai +``` + +### Create a Python Virtual Environment (recommended) + +```bash +python -m venv .venv +source .venv/bin/activate # Windows: .venv\Scripts\activate +``` + +### Create a Workflow to Run CrewAI Tasks + +Create a file named crewai_workflow.py and paste the following: + +```python +from dapr.ext.workflow import ( + WorkflowRuntime, + DaprWorkflowContext, + WorkflowActivityContext, + DaprWorkflowClient, +) +from crewai import Agent, Task, Crew +import time + +wfr = WorkflowRuntime() + +# ------------------------------------------------------------ +# 1. Define Agent, Tasks, and Task Dictionary +# ------------------------------------------------------------ +agent = Agent( + role="Research Analyst", + goal="Research and summarize impactful technology updates.", + backstory="A skilled analyst who specializes in researching and summarizing technology topics.", +) + +tasks = { + "latest_ai_news": Task( + description="Find the latest news about artificial intelligence.", + expected_output="A 3-paragraph summary of the top 3 stories.", + agent=agent, + ), + "ai_startup_launches": Task( + description="Summarize the most impactful AI startup launches in the last 6 months.", + expected_output="A list summarizing 2 AI startups with links.", + agent=agent, + ), + "ai_policy_updates": Task( + description="Summarize the newest AI government policy and regulation updates.", + expected_output="A bullet-point list summarizing the latest policy changes.", + agent=agent, + ), +} + +# ------------------------------------------------------------ +# 2. Activity — runs ONE task by name +# ------------------------------------------------------------ +@wfr.activity(name="run_task") +def run_task_activity(ctx: WorkflowActivityContext, task_name: str): + print(f"Running CrewAI task: {task_name}", flush=True) + + task = tasks[task_name] + + # Create a Crew for just this one task + temp_crew = Crew(agents=[agent], tasks=[task]) + + # kickoff() works across CrewAI versions + result = temp_crew.kickoff() + + return str(result) + +# ------------------------------------------------------------ +# 3. Workflow — orchestrates tasks durably +# ------------------------------------------------------------ +@wfr.workflow(name="crewai_multi_task_workflow") +def crewai_workflow(ctx: DaprWorkflowContext): + print("Starting multi-task CrewAI workflow", flush=True) + + latest_news = yield ctx.call_activity(run_task_activity, input="latest_ai_news") + startup_summary = yield ctx.call_activity(run_task_activity, input="ai_startup_launches") + policy_updates = yield ctx.call_activity(run_task_activity, input="ai_policy_updates") + + return { + "latest_news": latest_news, + "startup_summary": startup_summary, + "policy_updates": policy_updates, + } + +# ------------------------------------------------------------ +# 4. Runtime + Client (entry point) +# ------------------------------------------------------------ +if __name__ == "__main__": + wfr.start() + + client = DaprWorkflowClient() + instance_id = "crewai-multi-01" + + client.schedule_new_workflow( + workflow=crewai_workflow, + input=None, + instance_id=instance_id + ) + + state = client.wait_for_workflow_completion(instance_id, timeout_in_seconds=60) + print(state.serialized_output) +``` + +### Create the Workflow Database Component + +Dapr Workflows persist durable state using any [Dapr state store]({{% ref supported-state-stores %}}) that supports workflows. +Create a components directory, then create the file workflowstore.yaml: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" + - name: actorStateStore + value: "true" +``` + +This component stores: + +* Checkpoints +* Execution history +* Deterministic resumption state +* Final output data + +### Set a CrewAI LLM Provider + +CrewAI needs an LLM configuration or token to run. See instructions [here](https://docs.crewai.com/en/concepts/llms#setting-up-your-llm). + +### Run the Workflow + +Launch the CrewAI workflow using the Dapr CLI: + +```bash +dapr run \ + --app-id crewaiwf \ + --dapr-grpc-port 50001 \ + --resources-path ./components \ + -- python3 ./crewai_workflow.py +``` + +As the workflow runs, each CrewAI task is executed as a durable activity. +If the process crashes, the workflow resumes exactly where it left off. + +Open Zipkin to view workflow traces: + +``` +http://localhost:9411 +``` From 4d446a2de4bb4887255e8f027dceb237399b018a Mon Sep 17 00:00:00 2001 From: yaron2 Date: Thu, 11 Dec 2025 12:41:12 -0800 Subject: [PATCH 2/4] typos Signed-off-by: yaron2 --- daprdocs/content/en/developing-applications/crewai/_index.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/daprdocs/content/en/developing-applications/crewai/_index.md b/daprdocs/content/en/developing-applications/crewai/_index.md index d56d3a8b254..95ce99ca83f 100644 --- a/daprdocs/content/en/developing-applications/crewai/_index.md +++ b/daprdocs/content/en/developing-applications/crewai/_index.md @@ -8,5 +8,4 @@ description: "Dapr first-class integrations with CrewAI Agents" ### What is the Dapr CrewAI integration? -Dapr provides powerful APIs for developers looking to build OpenAI agents that scale and operate reliably in producton. Dapr provides first class integratons that range from agent session management to connecting agents via pub/sub and orchestrating agentic workflows. - \ No newline at end of file +Dapr provides APIs for developers looking to build CrewAI agents that scale and operate reliably in production. Dapr provides first class integrations that range from agent session management to connecting agents via pub/sub and orchestrating agentic workflows. From 45c76b4c0d6ff7ffe28253f8b2fa110911ea0dbc Mon Sep 17 00:00:00 2001 From: yaron2 Date: Tue, 16 Dec 2025 18:06:40 -0800 Subject: [PATCH 3/4] review comments Signed-off-by: yaron2 --- .../agent-integrations/crewai/_index.md | 11 +++++++++ .../crewai/crewai-workflows.md | 24 ++++++++++++------- .../developing-applications/crewai/_index.md | 11 --------- 3 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 daprdocs/content/en/developing-ai/agent-integrations/crewai/_index.md rename daprdocs/content/en/{developing-applications => developing-ai/agent-integrations}/crewai/crewai-workflows.md (89%) delete mode 100644 daprdocs/content/en/developing-applications/crewai/_index.md diff --git a/daprdocs/content/en/developing-ai/agent-integrations/crewai/_index.md b/daprdocs/content/en/developing-ai/agent-integrations/crewai/_index.md new file mode 100644 index 00000000000..7b28fd6ae56 --- /dev/null +++ b/daprdocs/content/en/developing-ai/agent-integrations/crewai/_index.md @@ -0,0 +1,11 @@ +--- +type: docs +title: "CrewAI" +linkTitle: "CrewAI" +weight: 25 +description: "Dapr first-class integrations with CrewAI Agents" +--- + +### What is the Dapr CrewAI integration? + +Dapr provides CrewAI agents first class integrations that range from agent session management to connecting agents via pub/sub and orchestrating agentic workflows. diff --git a/daprdocs/content/en/developing-applications/crewai/crewai-workflows.md b/daprdocs/content/en/developing-ai/agent-integrations/crewai/crewai-workflows.md similarity index 89% rename from daprdocs/content/en/developing-applications/crewai/crewai-workflows.md rename to daprdocs/content/en/developing-ai/agent-integrations/crewai/crewai-workflows.md index b1009c14ed7..484be8151fc 100644 --- a/daprdocs/content/en/developing-applications/crewai/crewai-workflows.md +++ b/daprdocs/content/en/developing-ai/agent-integrations/crewai/crewai-workflows.md @@ -11,16 +11,16 @@ description: "How to run CrewAI agents with durable, fault-tolerant execution us Dapr Workflows make it possible to run CrewAI agents **reliably**, **durably**, and **with built-in resiliency**. By orchestrating CrewAI tasks with the Dapr Workflow engine, developers can: -- Ensure long-running CrewAI work survives crashes and restarts -- Get automatic checkpoints, retries, and state recovery -- Run each CrewAI task as a durable activity -- Observe execution through tracing, metrics, and structured logs +- Ensure long-running CrewAI work survives crashes and restarts. +- Get automatic checkpoints, retries, and state recovery. +- Run each CrewAI task as a durable activity. +- Observe execution through tracing, metrics, and structured logs. This guide walks through orchestrating multiple CrewAI tasks using Dapr Workflows, ensuring each step is run *exactly once* even if the process restarts. ## Getting Started -Initialize Dapr locally to set up a self-hosted environment for development. This process installs the Dapr sidecar binaries, provisions the workflow engine, and prepares a default components directory. For full details, see the official [guide on initializing Dapr locally]({{% ref install-dapr-selfhost.md %}}). +Initialize Dapr locally to set up a self-hosted environment for development. This process installs the Dapr sidecar binaries, provisions the workflow engine, and prepares a default components directory. For full details, see [guide on initializing Dapr locally]({{% ref install-dapr-selfhost.md %}}). Initialize Dapr: @@ -149,6 +149,8 @@ if __name__ == "__main__": print(state.serialized_output) ``` +This CrewAI agent starts a workflow that does news gathering and summary for the subjects of AI and startups. + ### Create the Workflow Database Component Dapr Workflows persist durable state using any [Dapr state store]({{% ref supported-state-stores %}}) that supports workflows. @@ -158,7 +160,7 @@ Create a components directory, then create the file workflowstore.yaml: apiVersion: dapr.io/v1alpha1 kind: Component metadata: - name: statestore + name: workflowstore spec: type: state.redis version: v1 @@ -173,7 +175,7 @@ spec: This component stores: -* Checkpoints +* Code execution checkpoints * Execution history * Deterministic resumption state * Final output data @@ -182,6 +184,12 @@ This component stores: CrewAI needs an LLM configuration or token to run. See instructions [here](https://docs.crewai.com/en/concepts/llms#setting-up-your-llm). +For example, to set up OpenAI: + +``` +export OPENAI_API_KEY=sk-... +``` + ### Run the Workflow Launch the CrewAI workflow using the Dapr CLI: @@ -195,7 +203,7 @@ dapr run \ ``` As the workflow runs, each CrewAI task is executed as a durable activity. -If the process crashes, the workflow resumes exactly where it left off. +If the process crashes, the workflow resumes exactly where it left off. You can try this by killing the process after the first activity and then rerunning that command line above with the same app ID. Open Zipkin to view workflow traces: diff --git a/daprdocs/content/en/developing-applications/crewai/_index.md b/daprdocs/content/en/developing-applications/crewai/_index.md deleted file mode 100644 index 95ce99ca83f..00000000000 --- a/daprdocs/content/en/developing-applications/crewai/_index.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -type: docs -title: "CrewAI" -linkTitle: "CrewAI" -weight: 25 -description: "Dapr first-class integrations with CrewAI Agents" ---- - -### What is the Dapr CrewAI integration? - -Dapr provides APIs for developers looking to build CrewAI agents that scale and operate reliably in production. Dapr provides first class integrations that range from agent session management to connecting agents via pub/sub and orchestrating agentic workflows. From 7de512c854980d35019636d0d395ea4d4724b4ee Mon Sep 17 00:00:00 2001 From: yaron2 Date: Tue, 16 Dec 2025 18:15:39 -0800 Subject: [PATCH 4/4] switch order of .env and deps Signed-off-by: yaron2 --- .../agent-integrations/crewai/crewai-workflows.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/daprdocs/content/en/developing-ai/agent-integrations/crewai/crewai-workflows.md b/daprdocs/content/en/developing-ai/agent-integrations/crewai/crewai-workflows.md index 484be8151fc..e6ea8a79f9a 100644 --- a/daprdocs/content/en/developing-ai/agent-integrations/crewai/crewai-workflows.md +++ b/daprdocs/content/en/developing-ai/agent-integrations/crewai/crewai-workflows.md @@ -40,17 +40,17 @@ docker ps Make sure you have Python already installed. `Python >=3.10`. For installation instructions, visit the official [Python installation guide](https://www.python.org/downloads/). {{% /alert %}} -### Install Dependencies +### Create a Python Virtual Environment (recommended) ```bash -pip install dapr dapr-ext-workflow crewai +python -m venv .venv +source .venv/bin/activate # Windows: .venv\Scripts\activate ``` -### Create a Python Virtual Environment (recommended) +### Install Dependencies ```bash -python -m venv .venv -source .venv/bin/activate # Windows: .venv\Scripts\activate +pip install dapr dapr-ext-workflow crewai ``` ### Create a Workflow to Run CrewAI Tasks @@ -154,7 +154,7 @@ This CrewAI agent starts a workflow that does news gathering and summary for the ### Create the Workflow Database Component Dapr Workflows persist durable state using any [Dapr state store]({{% ref supported-state-stores %}}) that supports workflows. -Create a components directory, then create the file workflowstore.yaml: +Create a directory named `components`, then create the file workflowstore.yaml: ```yaml apiVersion: dapr.io/v1alpha1