Skip to main content

Quickstart: run a durable agent with the Diagrid CLI

Agent frameworks like CrewAI, LangGraph, and others give you tools, LLM orchestration, and prompt management — but none of them handle what happens when things go wrong in production. Some offer basic checkpointing, but you still need to detect failures at scale, build your own recovery mechanisms, and coordinate resumption across instances to avoid duplicate runs.

Diagrid adds the missing infrastructure: automatic failure detection, automatic recovery at scale, and multi-instance agent coordination. Your agent code stays the same — Diagrid handles the rest.

Diagrid works with the following agent frameworks, select one and continue following the quickstart.

tip

Using Claude Code, Codex or the Copilot CLI? Try the AI coding agent version of this quickstart.

note

Diagrid Cloud is free and the fastest way to get started — no infrastructure to set up. For production or on-premises requirements, Diagrid also offers other hosting options, including BYOC and Enterprise Server.

Prerequisites​

1. Log in to Diagrid​

Authenticate to Diagrid using the following command:

diagrid login

This command opens a new browser window where you'll be shown a confirmation code that should match the code in your terminal. Confirm the code, and if you're not logged into Diagrid, you'll be redirected to login.

Confirm your user details are correct using the following command:

diagrid whoami

The expected output contains the name of the organization, your user name, and the Diagrid API endpoint.

2. Clone and Navigate​

git clone https://github.com/diagridio/catalyst-quickstarts.git

Navigate to the quickstart directory for your framework:

cd catalyst-quickstarts/agents/dapr-agents/durable-agent

3. Explore the Code​

Invitations Manager — a durable agent that sends event invitations to guests via email and physical mail. Dapr Agents is the native AI agent framework built on Dapr — durability, state, and pub/sub are built into the agent itself.

Open main.py. The agent uses Pydantic models for structured tool input and output:

from typing import List
from pydantic import BaseModel, Field
from dapr_agents import tool, DurableAgent
from dapr_agents.llm import DaprChatClient

class InvitationResult(BaseModel):
sent: int = Field(description="Number of invitations sent")
method: str = Field(description="Delivery method")

class InvitationSchema(BaseModel):
guest_count: int = Field(description="Number of guests to invite")
event_type: str = Field(description="Type of event")

@tool(args_model=InvitationSchema)
def send_invitations(guest_count: int, event_type: str) -> List[InvitationResult]:
"""Send event invitations to guests."""
return [
InvitationResult(sent=int(guest_count * 0.7), method="email"),
InvitationResult(sent=int(guest_count * 0.3), method="physical mail"),
]

The DurableAgent class brings everything together — memory, state, registry, and pub/sub are all configured at the agent level:

agent = DurableAgent(
name="invitations-manager",
role="Invitations Manager",
goal="Send event invitations to guests using the send_invitations tool. Report how many were sent by email and physical mail.",
instructions=[
"When asked to send invitations, use the send_invitations tool with the guest count and event type.",
"Always report back the exact number of invitations sent and via which delivery method.",
],
tools=[send_invitations],
llm=DaprChatClient(component_name="llm-provider"),
memory=AgentMemoryConfig(
store=ConversationDaprStateMemory(store_name="kvstore")
),
state=AgentStateConfig(
store=StateStoreService(store_name="kvstore", key_prefix="invitations-manager:"),
),
registry=AgentRegistryConfig(
store=StateStoreService(store_name="agent-registry"),
),
pubsub=AgentPubSubConfig(
pubsub_name="pubsub",
agent_topic="events.invitations.requests",
broadcast_topic="agents.broadcast",
),
)

runner = AgentRunner()
runner.serve(agent, port=int(os.environ.get("APP_PORT", "8006")))
tip

Unlike other frameworks, Dapr Agents has durability, state, pub/sub, and failure recovery built in natively. Automatic failure detection, crash recovery, and multi-instance coordination are all handled out of the box — no wrapper needed.

4. Configure API Key​

This quickstart uses OpenAI as the LLM provider for every framework except the Claude Agents tab, which uses Anthropic. Diagrid is LLM-agnostic — you're free to use any provider supported by your chosen framework. The LangGraph, Microsoft Agent Framework and Spring AI tabs need no key at all: LangGraph's crash-test app makes no model call, and the other two ship a deterministic offline model you can swap for a real provider with DIAGRID_QUICKSTART_MODEL=openai.

The LLM is configured via DaprChatClient(component_name="llm-provider") — a Dapr component in resources/llm-provider.yaml that references your OpenAI API key:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: llm-provider
spec:
type: conversation.openai
version: v1
metadata:
- name: key
value: "{{OPENAI_API_KEY}}"
- name: model
value: gpt-4.1-2025-04-14

Update the key value with your OpenAI API key.

5. Install Dependencies​

uv sync

6. Create Diagrid Project and Agent​

Set up the Diagrid project, then register the agent.

Create a Diagrid project with managed key-value and pub/sub enabled, and set it as the default for this session. The managed workflow store that agents run on is included by default.

diagrid project create durable-agent-quickstart --deploy-managed-kv --deploy-managed-pubsub --wait --use

Register the agent with the project.

diagrid agent create invitations-manager --wait

7. Run with Diagrid Cloud​

uv run diagrid dev run -f dev-python-durable-agent.yaml --approve
tip

diagrid dev run runs your code locally and connects it to the Diagrid Cloud workflow engine. Your agent code never leaves your machine — only workflow state is stored in Diagrid.

Wait for the readiness log before proceeding — Uvicorn running on <localhost:port> for the Python frameworks, or Established gRPC bidirectional stream with Dapr sidecar for the Microsoft Agent Framework (.NET) tab.

You can open the Diagrid Cloud web console, navigate to the Agents section, and select your agent from the list to inspect its configuration and executions.

8. Trigger the Agent​

Open a new terminal and trigger the agent:

curl -X POST http://localhost:8006/agent/run \
-H "Content-Type: application/json" \
-d '{"task": "Send invitations to 100 guests for a corporate networking event"}'

Expected output:

== APP - invitations-manager == Invitations sent: 70 via email, 30 via physical mail

9. Crash Recovery​

Your code runs locally throughout this test. The Diagrid Cloud workflow engine — not your machine — tracks which steps completed and stores their results. That's what makes recovery possible even after a full process crash.

Stop the running application with Ctrl+C.

Crash recovery is built into Dapr Agents natively — the DurableAgent class automatically persists each tool execution as a workflow activity. If the process crashes, it resumes from the last saved state. See the Durable Agent Quickstart for a detailed walkthrough.

tip

Because workflow state is stored remotely in Diagrid (not in your process), the engine replays saved results instead of re-executing completed steps. This works even after a full process crash.

10. View in the Diagrid Web Console​

Open the Diagrid Cloud web console and navigate to the Workflows section. Select the workflow instance to inspect the full execution trace, including the input/output of every tool and LLM call and state persistence.

11. Clean Up​

Stop the running application with Ctrl+C, then delete the Diagrid project:

diagrid project delete durable-agent-quickstart

Summary​

In this quickstart, you:

  • Built a Dapr Agents durable agent with structured tool schemas and Dapr-native LLM configuration
  • Ran it locally connected to Diagrid Cloud for state persistence and crash recovery
  • Triggered the agent via REST API and inspected execution in the Diagrid Web Console

Next steps​