Skip to main content

Quickstart: make a Microsoft Foundry agent durable

In this quickstart, you take a travel-planner agent that runs on a Microsoft Foundry model and add the Diagrid package for its framework. The framework, the model, the tools and the prompt stay the same.

You will learn how to:

  • Point your agent framework at a Microsoft Foundry model deployment.
  • Add the Diagrid package so each agent run is a durable workflow.
  • Run the agent connected to a Diagrid project and invoke it.
  • Inspect the workflow execution: its ID, status, steps and timing.
One agent run as a durable workflowDiagrid records the result of every stepPOST /agent/runstart workflowrun model stepchat requesttwo tool callsrun each tool stepchat request with tool resultsfinal answeranswerTerminalcurlAgent appyour machineDiagridworkflow engineFoundrymodel deploymentTerminalcurlAgent appyour machineDiagridworkflow engineFoundrymodel deployment
One agent run as a durable workflowThe agent runs on your machine and calls your Foundry model itself. Diagrid drives the run step by step and stores each result.

Select your framework. Every code block on this page follows the tab you pick.

The diagrid[langgraph] package runs your compiled graph as a workflow, with each graph node as its own activity.

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. Create the Diagrid project and agent identity​

Create a Diagrid project with a managed key-value store and pub/sub broker, and set it as the default for this session. The managed workflow store that holds the state of every agent run is included by default.

diagrid project create foundry-quickstart --deploy-managed-kv --deploy-managed-pubsub --wait --use

Create the agent's identity in the project. The agent uses this ID and its API token to authenticate to Diagrid.

diagrid agent create travel-planner --wait

3. Create the agent project​

uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "diagrid[langgraph]==0.5.3" "langchain==1.5.0" "langchain-openai==1.8.0" "azure-identity==1.27.0"

A diagrid extra, such as diagrid[langgraph], installs the agent framework it wraps. Don't name the project folder after a package you install, such as langgraph or crewai: uv then refuses to add that package.

4. Point the agent at your Foundry model​

Replace <foundry-resource>, <foundry-project>, <resource-group> and <model-deployment> with the names of your Foundry resource, your Foundry project, its resource group and your model deployment.

The agent signs in to Foundry with Microsoft Entra ID, using your az login session, and calls the model through the project endpoint.

export FOUNDRY_PROJECT_ENDPOINT="https://<foundry-resource>.services.ai.azure.com/api/projects/<foundry-project>"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"

5. Add the Diagrid package to the agent​

In an existing agent, hand the compiled graph to DaprWorkflowGraphRunner and let the runner serve it:

from azure.identity import DefaultAzureCredential, get_bearer_token_provider
+from diagrid.agent.langgraph import DaprWorkflowGraphRunner
from langchain.agents import create_agent
...
-result = agent.invoke(
- {"messages": [{"role": "user", "content": "Plan a weekend trip from Seattle to Lisbon."}]}
-)
-print(result["messages"][-1].content)
+# Diagrid: run the agent as a durable workflow.
+runner = DaprWorkflowGraphRunner(graph=agent, name="travel-planner")
+runner.serve(port=8001)

Create agent.py with the complete agent:

agent.py
import os

from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from diagrid.agent.langgraph import DaprWorkflowGraphRunner
from langchain.agents import create_agent
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI


@tool
def get_weather(city: str) -> str:
"""Get the weather forecast for a city."""
return f"The forecast for {city} is sunny, 22°C."


@tool
def search_flights(origin: str, destination: str) -> str:
"""Search for flights between two cities."""
return f"Found 3 flights from {origin} to {destination}, from $420 round trip."


# Microsoft Foundry model, authenticated with Microsoft Entra ID.
model = ChatOpenAI(
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
base_url=os.environ["FOUNDRY_PROJECT_ENDPOINT"].rstrip("/") + "/openai/v1",
api_key=get_bearer_token_provider(
DefaultAzureCredential(), "https://ai.azure.com/.default"
),
)

agent = create_agent(
model,
tools=[get_weather, search_flights],
system_prompt="You are a travel planner. Use the tools to check the weather "
"and find flights, then reply with a short plan.",
)

# Diagrid: run the agent as a durable workflow.
runner = DaprWorkflowGraphRunner(graph=agent, name="travel-planner")
runner.serve(port=8001)

6. Run the agent​

diagrid dev run --project foundry-quickstart --id travel-planner -- uv run agent.py

Wait for the log line Uvicorn running on http://0.0.0.0:8001.

diagrid dev run starts the agent on your machine with the project's endpoints and the API token of the travel-planner ID in its environment. Those three variables, DAPR_HTTP_ENDPOINT, DAPR_GRPC_ENDPOINT and DAPR_API_TOKEN, are all the agent needs to authenticate to Diagrid and use the workflow store. The agent only makes outbound connections: Diagrid never calls into your machine.

7. Invoke the agent​

Open a new terminal and send the agent a task:

curl -X POST http://localhost:8001/agent/run \
-H "Content-Type: application/json" \
-d '{"task": "Plan a weekend trip from Seattle to Lisbon."}'

The agent calls both tools and answers with a short plan. The wording of the answer differs from run to run.

{
"instance_id": "graph-0218a40d-3d603745",
"type": "workflow_completed",
"workflow_id": "graph-0218a40d-3d603745",
"output": {
"messages": ["…"]
},
"steps": 3,
"status": "completed"
}

output.messages holds the whole conversation: your task, the model's two tool calls, the two tool results, and the answer as the last message.

8. Inspect the execution​

Every request you sent is a workflow in the project. List the workflow executions:

diagrid workflow list --project foundry-quickstart
APP ID WORKFLOW ID NAME START AT END AT STATUS VERIFICATION STATUS
travel-planner openai-agents-80a69285-c10b9406 dapr.openai.TravelPlanner.workflow 2026-11-16T05:28:37.98484497Z 2026-11-16T05:28:44.940106138Z completed

The list gives you the workflow ID, the name of the workflow, its start and end time, and its status. Print one execution with its history, using a workflow ID from your list:

diagrid workflow get <workflow-id> --id travel-planner --project foundry-quickstart

This is part of the output for an OpenAI Agents run. Long values are cut short and some events are left out. The history lists the newest event first:

execution:
appId: travel-planner
createdAt: 2026-11-16T05:28:37.979220057Z
endAt: 2026-11-16T05:28:44.940106138Z
executionTimeMs: 6956
input: "{\"agent_config\": {\"name\": \"travel-planner\", \"instructions\": \"You are a travel planner. …"
name: dapr.openai.TravelPlanner.workflow
output: "{\"final_response\": \"Here’s a simple weekend plan for Seattle → Lisbon: …"
startAt: 2026-11-16T05:28:37.98484497Z
status: completed
workflowId: openai-agents-80a69285-c10b9406
history:
- date: 2026-11-16T05:28:44.940106138Z
eventType: ExecutionCompleted
metadata:
name: dapr.openai.TravelPlanner.workflow
workflow_status: completed
- date: 2026-11-16T05:28:44.765870699Z
eventType: TaskCompleted
metadata:
name: call_llm_activity
task_scheduled_id: "4"
output: "{\"message\": {\"role\": \"assistant\", \"content\": \"Here’s a simple weekend plan for Seattle → Lisbon: …"
- date: 2026-11-16T05:28:41.5269428Z
eventType: TaskCompleted
metadata:
name: execute_tool_activity
task_scheduled_id: "2"
output: "{\"tool_result\": {\"tool_call_id\": \"call_vaiilRReLMkavXEcN076L3o4\", \"tool_name\": \"get_weather\", \"result\": \"The forecast for Lisbon is sunny, 22°C.\" …"
- date: 2026-11-16T05:28:41.307879952Z
eventId: "2"
eventType: TaskScheduled
metadata:
name: execute_tool_activity
task_scheduled_id: "2"
input: "{\"tool_call\": {\"id\": \"call_vaiilRReLMkavXEcN076L3o4\", \"name\": \"get_weather\", \"args\": {\"city\": \"Lisbon\"}}, …"
- date: 2026-11-16T05:28:37.979220057Z
eventType: ExecutionStarted
metadata:
name: dapr.openai.TravelPlanner.workflow
workflow_instance_id: openai-agents-80a69285-c10b9406

In the output, look at:

  • Status and timing: status, startAt, endAt and executionTimeMs under execution.
  • Input and output: execution.input is what the run received, and execution.output is what it returned.
  • Steps and tool calls: each step has a TaskScheduled event with its input and a TaskCompleted event with its output. In the example, the get_weather call is scheduled with the argument Lisbon and completes with the forecast.
  • History and timing of each step: the date of every event, to the nanosecond.

The names of the workflow and of its steps depend on the framework:

FrameworkWorkflow nameModel stepTool step
Microsoft Agent FrameworkAgentRunWorkflowCallLlmActivityExecuteToolActivity
LangGraphdapr.langgraph.TravelPlanner.workflowexecute_node_activity, node modelexecute_node_activity, node tools
Deep Agentsdapr.deepagents.TravelPlanner.workflowexecute_node_activity, node modelexecute_node_activity, node tools
OpenAI Agentsdapr.openai.TravelPlanner.workflowcall_llm_activityexecute_tool_activity
CrewAIdapr.crewai.TravelPlanner.workflowcall_llm_activityexecute_tool_activity
Google ADKdapr.adk.TravelPlanner.workflowcall_llm_activityexecute_tool_activity
Pydantic AIdapr.pydanticai.TravelPlanner.workflowcall_llm_activityexecute_tool_activity
Strandsdapr.strands.TravelPlanner.workflowstrands_call_modelstrands_execute_tool
Mastradapr.mastra.TravelPlanner.workflowdiagrid.mastra.invokeModel.travel-plannerdiagrid.mastra.invokeTool.travel-planner
Dapr Agentsdapr.agents.travel-planner.workflowdapr.agents.travel-planner.call_llmdapr.agents.travel-planner.run_tool

In LangGraph and Deep Agents, a step is a graph node, so both tool calls run inside the one tools step. In the other frameworks, each tool call is a step of its own.

The Diagrid Console lists the same executions on its Workflows page. See Operate workflow instances.

9. Clean up​

Press CTRL+C in the terminal that runs diagrid dev run to stop the agent and disconnect from Diagrid Cloud.

To delete the entire project and all provisioned resources:

diagrid project delete foundry-quickstart

Summary​

In this quickstart, you:

  • Pointed an agent framework at a Microsoft Foundry model deployment.
  • Added the Diagrid package, or used Dapr Agents, to run the agent as a durable workflow.
  • Ran the agent connected to a Diagrid project and got its answer.
  • Inspected the completed workflow, its steps and its timing with the Diagrid CLI.

Next steps​