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.
Select your framework. Every code block on this page follows the tab you pick.
- LangGraph
- Microsoft Agent Framework (.NET)
- OpenAI Agents
- Deep Agents
- CrewAI
- Google ADK
- Pydantic AI
- Strands
- Mastra
- Dapr Agents
The diagrid[langgraph] package runs your compiled graph as a workflow, with each graph node as its own activity.
The Diagrid.AI.Microsoft.AgentFramework package runs each agent invocation as a workflow, with every model call and tool call as its own activity.
The diagrid[openai_agents] package runs the agent loop as a workflow, with every model call and tool call as its own activity.
The diagrid[deepagents] package runs your deep agent's graph as a workflow, with each graph node as its own activity.
The diagrid[crewai] package runs the agent loop as a workflow, with every model call and tool call as its own activity.
The diagrid[adk] package runs the agent loop as a workflow, with every model call and tool call as its own activity.
The diagrid[pydantic_ai] package runs the agent loop as a workflow, with every model call and tool call as its own activity.
The diagrid[strands] package runs the agent loop as a workflow, with every model call and tool call as its own activity.
The @diagrid/agent-mastra package runs the agent loop as a workflow, with every model call and tool call as its own activity.
Dapr Agents is durable by design, so there is no package to add. A DurableAgent runs as a workflow, and reaches your Foundry model through a conversation component in your Diagrid project.
Prerequisites
- A Diagrid account and the Diagrid CLI
- A Microsoft Foundry project with a chat model deployment that supports tool calling. This quickstart was tested with a
gpt-5.4-minideployment. - The Azure CLI, signed in with
az login
- LangGraph
- Microsoft Agent Framework (.NET)
- OpenAI Agents
- Deep Agents
- CrewAI
- Google ADK
- Pydantic AI
- Strands
- Mastra
- Dapr Agents
- Python 3.11 to 3.13 and uv
- A role on the Foundry project that allows model inference, such as Foundry User
- .NET 10 SDK
- A role on the Foundry project that allows model inference, such as Foundry User
- Python 3.11 to 3.13 and uv
- Access to the API keys of your Foundry resource
- Python 3.11 to 3.13 and uv
- A role on the Foundry project that allows model inference, such as Foundry User
- Python 3.11 to 3.13 and uv
- Access to the API keys of your Foundry resource
- Python 3.11 to 3.13 and uv
- Access to the API keys of your Foundry resource
- Python 3.11 to 3.13 and uv
- Access to the API keys of your Foundry resource
- Python 3.11 to 3.13 and uv
- Access to the API keys of your Foundry resource
- Node.js 22.13 or later
- Access to the API keys of your Foundry resource
- Python 3.11 to 3.13 and uv
- Access to the API keys of your Foundry resource
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
- LangGraph
- Microsoft Agent Framework (.NET)
- OpenAI Agents
- Deep Agents
- CrewAI
- Google ADK
- Pydantic AI
- Strands
- Mastra
- Dapr Agents
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"
dotnet new web -n travel-planner
cd travel-planner
dotnet add package Diagrid.AI.Microsoft.AgentFramework --version 1.2.1
dotnet add package Microsoft.Agents.AI.Foundry --version 1.5.0
dotnet add package Azure.Identity --version 1.21.0
uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "diagrid[openai_agents]==0.5.3"
uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "diagrid[deepagents]==0.5.3" "azure-identity==1.27.0"
uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "diagrid[crewai]==0.5.3"
uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "diagrid[adk]==0.5.3" "google-adk==1.39.1"
The install pins google-adk to its 1.x line. With google-adk 2.x, diagrid 0.5.3 doesn't pass the tools' parameters to the model.
uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "diagrid[pydantic_ai]==0.5.3"
uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "diagrid[strands]==0.5.3"
mkdir travel-planner
cd travel-planner
npm init -y
npm pkg set type=module
npm install @diagrid/agent-mastra@0.2.0 @mastra/core@1.83.0 zod@4.6.7 tsx@4.23.15
uv init --bare --python 3.13 travel-planner
cd travel-planner
uv add "dapr-agents==1.1.1"
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.
- LangGraph
- Microsoft Agent Framework (.NET)
- OpenAI Agents
- Deep Agents
- CrewAI
- Google ADK
- Pydantic AI
- Strands
- Mastra
- Dapr Agents
The agent signs in to Foundry with Microsoft Entra ID, using your az login session, and calls the model through the project endpoint.
- macOS/Linux
- Windows
export FOUNDRY_PROJECT_ENDPOINT="https://<foundry-resource>.services.ai.azure.com/api/projects/<foundry-project>"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:FOUNDRY_PROJECT_ENDPOINT = "https://<foundry-resource>.services.ai.azure.com/api/projects/<foundry-project>"
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<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.
- macOS/Linux
- Windows
export FOUNDRY_PROJECT_ENDPOINT="https://<foundry-resource>.services.ai.azure.com/api/projects/<foundry-project>"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:FOUNDRY_PROJECT_ENDPOINT = "https://<foundry-resource>.services.ai.azure.com/api/projects/<foundry-project>"
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<model-deployment>"
The Diagrid runner calls the model with the default OpenAI client, which reads its endpoint and key from the environment. Point it at the OpenAI-compatible endpoint of your Foundry resource.
- macOS/Linux
- Windows
export OPENAI_BASE_URL="https://<foundry-resource>.openai.azure.com/openai/v1/"
export OPENAI_API_KEY="$(az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv)"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:OPENAI_BASE_URL = "https://<foundry-resource>.openai.azure.com/openai/v1/"
$env:OPENAI_API_KEY = az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<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.
- macOS/Linux
- Windows
export FOUNDRY_PROJECT_ENDPOINT="https://<foundry-resource>.services.ai.azure.com/api/projects/<foundry-project>"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:FOUNDRY_PROJECT_ENDPOINT = "https://<foundry-resource>.services.ai.azure.com/api/projects/<foundry-project>"
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<model-deployment>"
The Diagrid runner calls the model through LiteLLM, which reads its endpoint and key from the environment. Point it at the OpenAI-compatible endpoint of your Foundry resource.
- macOS/Linux
- Windows
export OPENAI_BASE_URL="https://<foundry-resource>.openai.azure.com/openai/v1/"
export OPENAI_API_KEY="$(az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv)"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:OPENAI_BASE_URL = "https://<foundry-resource>.openai.azure.com/openai/v1/"
$env:OPENAI_API_KEY = az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<model-deployment>"
The agent calls the model through LiteLLM, which reads its endpoint and key from the environment. Point it at the OpenAI-compatible endpoint of your Foundry resource.
- macOS/Linux
- Windows
export OPENAI_BASE_URL="https://<foundry-resource>.openai.azure.com/openai/v1/"
export OPENAI_API_KEY="$(az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv)"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:OPENAI_BASE_URL = "https://<foundry-resource>.openai.azure.com/openai/v1/"
$env:OPENAI_API_KEY = az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<model-deployment>"
The Diagrid runner calls the model with the default OpenAI client, which reads its endpoint and key from the environment. Point it at the OpenAI-compatible endpoint of your Foundry resource.
- macOS/Linux
- Windows
export OPENAI_BASE_URL="https://<foundry-resource>.openai.azure.com/openai/v1/"
export OPENAI_API_KEY="$(az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv)"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:OPENAI_BASE_URL = "https://<foundry-resource>.openai.azure.com/openai/v1/"
$env:OPENAI_API_KEY = az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<model-deployment>"
The agent calls the model with the OpenAI client, which reads its endpoint and key from the environment. Point it at the OpenAI-compatible endpoint of your Foundry resource.
- macOS/Linux
- Windows
export OPENAI_BASE_URL="https://<foundry-resource>.openai.azure.com/openai/v1/"
export OPENAI_API_KEY="$(az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv)"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:OPENAI_BASE_URL = "https://<foundry-resource>.openai.azure.com/openai/v1/"
$env:OPENAI_API_KEY = az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<model-deployment>"
The agent calls the model through the OpenAI-compatible endpoint of your Foundry resource, with the endpoint and key taken from the environment.
- macOS/Linux
- Windows
export OPENAI_BASE_URL="https://<foundry-resource>.openai.azure.com/openai/v1/"
export OPENAI_API_KEY="$(az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv)"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="<model-deployment>"
$env:OPENAI_BASE_URL = "https://<foundry-resource>.openai.azure.com/openai/v1/"
$env:OPENAI_API_KEY = az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<model-deployment>"
Dapr Agents calls the model through a conversation component in your Diagrid project, so the Foundry endpoint and key live in Diagrid and not in the agent. Create the component and scope it to the agent:
diagrid component create llm-provider \
--type conversation.openai \
--metadata apiType=azure \
--metadata endpoint="https://<foundry-resource>.openai.azure.com/" \
--metadata apiVersion=2025-04-01-preview \
--metadata model="<model-deployment>" \
--metadata key="$(az cognitiveservices account keys list --name <foundry-resource> --resource-group <resource-group> --query key1 --output tsv)" \
--scopes travel-planner \
--wait
5. Add the Diagrid package to the agent
- LangGraph
- Microsoft Agent Framework (.NET)
- OpenAI Agents
- Deep Agents
- CrewAI
- Google ADK
- Pydantic AI
- Strands
- Mastra
- Dapr Agents
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:
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)
In an existing agent, register the agent with AddDaprAgents() and run it through IDaprAgentInvoker:
using Azure.Identity;
+using Diagrid.AI.Microsoft.AgentFramework.Abstractions;
+using Diagrid.AI.Microsoft.AgentFramework.Hosting;
using Microsoft.Agents.AI;
...
-var agent = CreateAgent();
+// Diagrid: register the agent so every run is a durable workflow.
+builder.Services.AddDaprAgents().WithAgent(_ => CreateAgent());
...
-app.MapPost("/agent/run", async (RunRequest request, CancellationToken ct) =>
+app.MapPost("/agent/run", async (IDaprAgentInvoker invoker, RunRequest request, CancellationToken ct) =>
{
- var result = await agent.RunAsync(request.Task, cancellationToken: ct);
+ var agent = invoker.GetAgent("travel-planner");
+ var result = await invoker.RunAgentAsync(agent, request.Task, cancellationToken: ct);
return Results.Ok(new { response = result.Text });
Replace the contents of Program.cs with the complete agent:
using System.ComponentModel;
using Azure.AI.Projects;
using Azure.Identity;
using Diagrid.AI.Microsoft.AgentFramework.Abstractions;
using Diagrid.AI.Microsoft.AgentFramework.Hosting;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
[Description("Get the weather forecast for a city.")]
static string GetWeather(string city) => $"The forecast for {city} is sunny, 22°C.";
[Description("Search for flights between two cities.")]
static string SearchFlights(string origin, string destination) =>
$"Found 3 flights from {origin} to {destination}, from $420 round trip.";
// Microsoft Foundry model, authenticated with Microsoft Entra ID.
var projectEndpoint = new Uri(Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT")!);
var deployment = Environment.GetEnvironmentVariable("AZURE_AI_MODEL_DEPLOYMENT_NAME")!;
AIAgent CreateAgent() => new AIProjectClient(projectEndpoint, new DefaultAzureCredential())
.AsAIAgent(
model: deployment,
instructions: "You are a travel planner. Use the tools to check the weather "
+ "and find flights, then reply with a short plan.",
name: "travel-planner",
tools:
[
AIFunctionFactory.Create(GetWeather, name: "get_weather"),
AIFunctionFactory.Create(SearchFlights, name: "search_flights"),
]);
var builder = WebApplication.CreateBuilder(args);
// Diagrid: register the agent so every run is a durable workflow.
builder.Services.AddDaprAgents().WithAgent(_ => CreateAgent());
var app = builder.Build();
app.MapPost("/agent/run", async (IDaprAgentInvoker invoker, RunRequest request, CancellationToken ct) =>
{
var agent = invoker.GetAgent("travel-planner");
var result = await invoker.RunAgentAsync(agent, request.Task, cancellationToken: ct);
return Results.Ok(new { response = result.Text });
});
app.Run("http://localhost:8001");
record RunRequest(string Task);
In an existing agent, hand the agent to DaprWorkflowAgentRunner and let the runner serve it:
-from agents import Agent, Runner, function_tool
+from agents import Agent, function_tool
+from diagrid.agent.openai_agents import DaprWorkflowAgentRunner
...
-result = Runner.run_sync(agent, "Plan a weekend trip from Seattle to Lisbon.")
-print(result.final_output)
+# Diagrid: run the agent as a durable workflow.
+runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
+runner.serve(port=8001)
Create agent.py with the complete agent:
import os
from agents import Agent, function_tool
from diagrid.agent.openai_agents import DaprWorkflowAgentRunner
@function_tool
def get_weather(city: str) -> str:
"""Get the weather forecast for a city."""
return f"The forecast for {city} is sunny, 22°C."
@function_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."
# The model is a Microsoft Foundry deployment. The OpenAI client reads
# OPENAI_BASE_URL and OPENAI_API_KEY, which point at your Foundry resource.
agent = Agent(
name="travel-planner",
instructions="You are a travel planner. Use the tools to check the weather "
"and find flights, then reply with a short plan.",
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
tools=[get_weather, search_flights],
)
# Diagrid: run the agent as a durable workflow.
runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
runner.serve(port=8001)
In an existing agent, hand the deep agent to DaprWorkflowDeepAgentRunner and let the runner serve it:
from deepagents import create_deep_agent
+from diagrid.agent.deepagents import DaprWorkflowDeepAgentRunner
from langchain_core.tools import tool
...
-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 = DaprWorkflowDeepAgentRunner(agent=agent, name="travel-planner")
+runner.serve(port=8001)
Create agent.py with the complete agent:
import os
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from deepagents import create_deep_agent
from diagrid.agent.deepagents import DaprWorkflowDeepAgentRunner
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_deep_agent(
model=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 = DaprWorkflowDeepAgentRunner(agent=agent, name="travel-planner")
runner.serve(port=8001)
In an existing agent, hand the agent to DaprWorkflowAgentRunner and let the runner serve it. The task comes from the request, so the Task and Crew objects go away:
-from crewai import Agent, Crew, Task
+from crewai import Agent
from crewai.tools import tool
+from diagrid.agent.crewai import DaprWorkflowAgentRunner
...
-task = Task(
- description="Plan a weekend trip from Seattle to Lisbon.",
- expected_output="A short travel plan with the weather and a flight option.",
- agent=agent,
-)
-
-result = Crew(agents=[agent], tasks=[task]).kickoff()
-print(result.raw)
+# Diagrid: run the agent as a durable workflow.
+runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
+runner.serve(port=8001)
Create agent.py with the complete agent:
import os
from crewai import Agent
from crewai.tools import tool
from diagrid.agent.crewai import DaprWorkflowAgentRunner
@tool("Get the weather forecast")
def get_weather(city: str) -> str:
"""Get the weather forecast for a city."""
return f"The forecast for {city} is sunny, 22°C."
@tool("Search for flights")
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."
# The model is a Microsoft Foundry deployment. The OpenAI client reads
# OPENAI_BASE_URL and OPENAI_API_KEY, which point at your Foundry resource.
agent = Agent(
role="Travel planner",
goal="Plan short trips using the weather and flight tools.",
backstory="You are a travel planner. Use the tools to check the weather "
"and find flights, then reply with a short plan.",
tools=[get_weather, search_flights],
llm=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
)
# Diagrid: run the agent as a durable workflow.
runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
runner.serve(port=8001)
In an existing agent, hand the agent to DaprWorkflowAgentRunner and let the runner serve it. The runner needs each tool wrapped in FunctionTool:
-import asyncio
import os
+from diagrid.agent.adk import DaprWorkflowAgentRunner
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
-from google.adk.runners import InMemoryRunner
from google.adk.tools import FunctionTool
-from google.genai import types
...
-
-async def main() -> None:
- runner = InMemoryRunner(agent=agent, app_name="travel-planner")
- session = await runner.session_service.create_session(
- app_name="travel-planner", user_id="user"
- )
- message = types.Content(
- role="user",
- parts=[types.Part(text="Plan a weekend trip from Seattle to Lisbon.")],
- )
- async for event in runner.run_async(
- user_id="user", session_id=session.id, new_message=message
- ):
- if event.is_final_response() and event.content:
- print(event.content.parts[0].text)
-
-
-asyncio.run(main())
+# Diagrid: run the agent as a durable workflow.
+runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
+runner.serve(port=8001)
Create agent.py with the complete agent:
import os
from diagrid.agent.adk import DaprWorkflowAgentRunner
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
from google.adk.tools import FunctionTool
def get_weather(city: str) -> str:
"""Get the weather forecast for a city."""
return f"The forecast for {city} is sunny, 22°C."
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."
# The model is a Microsoft Foundry deployment. LiteLLM reads
# OPENAI_BASE_URL and OPENAI_API_KEY, which point at your Foundry resource.
agent = LlmAgent(
name="travel_planner",
model=LiteLlm(model=f"openai/{os.environ['AZURE_AI_MODEL_DEPLOYMENT_NAME']}"),
instruction="You are a travel planner. Use the tools to check the weather "
"and find flights, then reply with a short plan.",
tools=[FunctionTool(get_weather), FunctionTool(search_flights)],
)
# Diagrid: run the agent as a durable workflow.
runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
runner.serve(port=8001)
In an existing agent, hand the agent to DaprWorkflowAgentRunner and let the runner serve it:
+from diagrid.agent.pydantic_ai import DaprWorkflowAgentRunner
from pydantic_ai import Agent
...
-result = agent.run_sync("Plan a weekend trip from Seattle to Lisbon.")
-print(result.output)
+# Diagrid: run the agent as a durable workflow.
+runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
+runner.serve(port=8001)
Create agent.py with the complete agent:
import os
from diagrid.agent.pydantic_ai import DaprWorkflowAgentRunner
from pydantic_ai import Agent
def get_weather(city: str) -> str:
"""Get the weather forecast for a city."""
return f"The forecast for {city} is sunny, 22°C."
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."
# The model is a Microsoft Foundry deployment. The OpenAI client reads
# OPENAI_BASE_URL and OPENAI_API_KEY, which point at your Foundry resource.
agent = Agent(
f"openai:{os.environ['AZURE_AI_MODEL_DEPLOYMENT_NAME']}",
system_prompt="You are a travel planner. Use the tools to check the weather "
"and find flights, then reply with a short plan.",
tools=[get_weather, search_flights],
)
# Diagrid: run the agent as a durable workflow.
runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
runner.serve(port=8001)
In an existing agent, hand the agent to DaprWorkflowAgentRunner and let the runner serve it:
+from diagrid.agent.strands import DaprWorkflowAgentRunner
from strands import Agent, tool
...
-result = agent("Plan a weekend trip from Seattle to Lisbon.")
-print(result)
+# Diagrid: run the agent as a durable workflow.
+runner = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
+runner.serve(port=8001)
Create agent.py with the complete agent:
import os
from diagrid.agent.strands import DaprWorkflowAgentRunner
from strands import Agent, tool
from strands.models.openai import OpenAIModel
@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."
# The model is a Microsoft Foundry deployment. The OpenAI client reads
# OPENAI_BASE_URL and OPENAI_API_KEY, which point at your Foundry resource.
agent = Agent(
model=OpenAIModel(model_id=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"]),
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 = DaprWorkflowAgentRunner(agent=agent, name="travel-planner")
runner.serve(port=8001)
In an existing agent, hand the agent to DaprWorkflowAgentRunner and invoke it through the runner. The adapter has no built-in server, so the example adds a small HTTP endpoint:
+import { createServer } from 'node:http';
+import { randomUUID } from 'node:crypto';
import { Agent } from '@mastra/core/agent';
import { createTool } from '@mastra/core/tools';
+import { DaprWorkflowAgentRunner } from '@diagrid/agent-mastra';
import { z } from 'zod';
...
-const result = await agent.generate('Plan a weekend trip from Seattle to Lisbon.');
-console.log(result.text);
+// Diagrid: run the agent as a durable workflow.
+const runner = new DaprWorkflowAgentRunner({ agent, name: 'travel-planner' });
+runner.registerShutdownHandlers();
+await runner.start();
+
+createServer(async (req, res) => {
+ if (req.method !== 'POST' || req.url !== '/agent/run') {
+ res.writeHead(404).end();
+ return;
+ }
+ let body = '';
+ for await (const chunk of req) body += chunk;
+ const result = await runner.invoke({
+ prompt: JSON.parse(body).task,
+ threadId: randomUUID(),
+ messages: [],
+ });
+ res.writeHead(200, { 'Content-Type': 'application/json' });
+ res.end(JSON.stringify(result));
+}).listen(8001, () => console.log('Listening on http://localhost:8001'));
Create agent.ts with the complete agent:
import { createServer } from 'node:http';
import { randomUUID } from 'node:crypto';
import { Agent } from '@mastra/core/agent';
import { createTool } from '@mastra/core/tools';
import { DaprWorkflowAgentRunner } from '@diagrid/agent-mastra';
import { z } from 'zod';
const getWeather = createTool({
id: 'getWeather',
description: 'Get the weather forecast for a city.',
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => `The forecast for ${city} is sunny, 22°C.`,
});
const searchFlights = createTool({
id: 'searchFlights',
description: 'Search for flights between two cities.',
inputSchema: z.object({ origin: z.string(), destination: z.string() }),
execute: async ({ origin, destination }) =>
`Found 3 flights from ${origin} to ${destination}, from $420 round trip.`,
});
// The model is a Microsoft Foundry deployment, reached through the
// OpenAI-compatible endpoint of your Foundry resource.
const agent = new Agent({
id: 'travel-planner',
name: 'travel-planner',
instructions:
'You are a travel planner. Use the tools to check the weather ' +
'and find flights, then reply with a short plan.',
model: {
id: `openai/${process.env.AZURE_AI_MODEL_DEPLOYMENT_NAME}`,
url: process.env.OPENAI_BASE_URL,
apiKey: process.env.OPENAI_API_KEY,
},
tools: { getWeather, searchFlights },
});
// Diagrid: run the agent as a durable workflow.
const runner = new DaprWorkflowAgentRunner({ agent, name: 'travel-planner' });
runner.registerShutdownHandlers();
await runner.start();
createServer(async (req, res) => {
if (req.method !== 'POST' || req.url !== '/agent/run') {
res.writeHead(404).end();
return;
}
let body = '';
for await (const chunk of req) body += chunk;
const result = await runner.invoke({
prompt: JSON.parse(body).task,
threadId: randomUUID(),
messages: [],
});
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(result));
}).listen(8001, () => console.log('Listening on http://localhost:8001'));
There is nothing to wrap. Create agent.py with a DurableAgent that uses the llm-provider component you created:
import logging
from dapr_agents import DurableAgent, tool
from dapr_agents.llm import DaprChatClient
from dapr_agents.workflow.runners import AgentRunner
logging.basicConfig(level=logging.INFO)
@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."
# The model is a Microsoft Foundry deployment, reached through the
# llm-provider conversation component in your Diagrid project.
agent = DurableAgent(
name="travel-planner",
role="Travel planner",
goal="Plan short trips using the weather and flight tools.",
instructions=[
"Use the tools to check the weather and find flights, "
"then reply with a short plan."
],
tools=[get_weather, search_flights],
llm=DaprChatClient(component_name="llm-provider"),
)
runner = AgentRunner()
try:
runner.serve(agent, port=8001)
finally:
runner.shutdown()
agent.stop()
6. Run the agent
- LangGraph
- Microsoft Agent Framework (.NET)
- OpenAI Agents
- Deep Agents
- CrewAI
- Google ADK
- Pydantic AI
- Strands
- Mastra
- Dapr Agents
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 --project foundry-quickstart --id travel-planner -- dotnet run
Wait for the log line Established gRPC bidirectional stream with Dapr sidecar.
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 --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 --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 --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 --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 --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 --project foundry-quickstart --id travel-planner -- npx tsx agent.ts
Wait for the log line Listening on http://localhost:8001.
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:
- macOS/Linux
- Windows
curl -X POST http://localhost:8001/agent/run \
-H "Content-Type: application/json" \
-d '{"task": "Plan a weekend trip from Seattle to Lisbon."}'
Invoke-RestMethod -Method Post -Uri 'http://localhost:8001/agent/run' -ContentType 'application/json' -Body '{"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.
- LangGraph
- Microsoft Agent Framework (.NET)
- OpenAI Agents
- Deep Agents
- CrewAI
- Google ADK
- Pydantic AI
- Strands
- Mastra
- Dapr Agents
{
"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.
{
"response": "Here’s a simple weekend plan for Lisbon:\n\n- **Flights:** 3 options from Seattle to Lisbon, starting at **$420 round trip** …"
}
The agent's log shows the ID of the workflow that ran the request:
Scheduled workflow 'AgentRunWorkflow' with instance ID '6e3ac31b-9332-4f1a-afc0-5cfba145e791'
{
"instance_id": "openai-agents-80a69285-c10b9406",
"type": "workflow_completed",
"workflow_id": "openai-agents-80a69285-c10b9406",
"final_response": "Here’s a simple weekend plan for Seattle → Lisbon:\n\n- **Flights:** 3 options found, starting at **$420 round trip** …",
"iterations": 2,
"status": "completed"
}
{
"instance_id": "graph-0aef579e-3a5d9d16",
"type": "workflow_completed",
"workflow_id": "graph-0aef579e-3a5d9d16",
"output": {
"messages": ["…"]
},
"steps": 5,
"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.
{
"instance_id": "crewai-66517192-97e1f2e4",
"type": "workflow_completed",
"workflow_id": "crewai-66517192-97e1f2e4",
"final_response": "Here’s a simple weekend trip plan from Seattle to Lisbon:\n\n- **Flights:** I found **3 round-trip options** …",
"iterations": 2,
"status": "completed"
}
{
"instance_id": "agent-45773fd7-17080be4",
"type": "workflow_completed",
"workflow_id": "agent-45773fd7-17080be4",
"final_response": "Here’s a quick weekend trip plan from Seattle to Lisbon:\n\n- **Flight:** 3 options found from Seattle to Lisbon, starting at **$420 round trip** …",
"iterations": 2,
"status": "completed"
}
{
"instance_id": "pydantic-ai-b18c2d09-e78f5603",
"type": "workflow_completed",
"workflow_id": "pydantic-ai-b18c2d09-e78f5603",
"final_response": "Weekend trip plan from Seattle to Lisbon:\n\n- Weather: Sunny and warm, around 22°C …",
"iterations": 2,
"status": "completed"
}
{
"instance_id": "strands-daf4f044-9c27c2f7",
"type": "workflow_completed",
"workflow_id": "strands-daf4f044-9c27c2f7",
"result": "Here’s a simple weekend plan for Lisbon:\n\n- **Weather:** Sunny and about **22°C**, great for walking and sightseeing …",
"tool_calls": [
{ "tool_name": "get_weather", "tool_use_id": "call_KkQvtXlCBSxuVWQcmBhNHWvD", "input": { "city": "Lisbon" } },
{ "tool_name": "search_flights", "tool_use_id": "call_HYf9JxKhnLFRQSKfgLJaRyQ7", "input": { "origin": "Seattle", "destination": "Lisbon" } }
]
}
{
"text": "Weekend trip plan from Seattle to Lisbon:\n\n- **Flights:** 3 options found, starting at **$420 round trip** …",
"messages": ["…"],
"iterations": 2,
"status": "completed"
}
messages holds the whole conversation, including both tool calls and their results.
Dapr Agents starts the run and answers at once with the ID of the workflow:
{
"instance_id": "0df60c1cf34b4002a4daae17fe8a08c0",
"status_url": "/agent/instances/0df60c1cf34b4002a4daae17fe8a08c0"
}
Read the result from the status URL, with your own instance ID:
curl http://localhost:8001/agent/instances/<instance-id>
When runtime_status is COMPLETED, the answer is in serialized_output:
{
"instance_id": "0df60c1cf34b4002a4daae17fe8a08c0",
"name": "dapr.agents.travel-planner.workflow",
"runtime_status": "COMPLETED",
"created_at": "2026-11-16T05:41:13.134188",
"last_updated_at": "2026-11-16T05:41:34.730836",
"serialized_input": "{\"task\": \"Plan a weekend trip from Seattle to Lisbon.\"}",
"serialized_output": "{\"content\": \"Here’s a simple weekend plan for Lisbon from Seattle: …\", \"role\": \"assistant\", …}",
"serialized_custom_status": null,
"pending_inputs": []
}
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,endAtandexecutionTimeMsunderexecution. - Input and output:
execution.inputis what the run received, andexecution.outputis what it returned. - Steps and tool calls: each step has a
TaskScheduledevent with itsinputand aTaskCompletedevent with itsoutput. In the example, theget_weathercall is scheduled with the argumentLisbonand completes with the forecast. - History and timing of each step: the
dateof every event, to the nanosecond.
The names of the workflow and of its steps depend on the framework:
| Framework | Workflow name | Model step | Tool step |
|---|---|---|---|
| Microsoft Agent Framework | AgentRunWorkflow | CallLlmActivity | ExecuteToolActivity |
| LangGraph | dapr.langgraph.TravelPlanner.workflow | execute_node_activity, node model | execute_node_activity, node tools |
| Deep Agents | dapr.deepagents.TravelPlanner.workflow | execute_node_activity, node model | execute_node_activity, node tools |
| OpenAI Agents | dapr.openai.TravelPlanner.workflow | call_llm_activity | execute_tool_activity |
| CrewAI | dapr.crewai.TravelPlanner.workflow | call_llm_activity | execute_tool_activity |
| Google ADK | dapr.adk.TravelPlanner.workflow | call_llm_activity | execute_tool_activity |
| Pydantic AI | dapr.pydanticai.TravelPlanner.workflow | call_llm_activity | execute_tool_activity |
| Strands | dapr.strands.TravelPlanner.workflow | strands_call_model | strands_execute_tool |
| Mastra | dapr.mastra.TravelPlanner.workflow | diagrid.mastra.invokeModel.travel-planner | diagrid.mastra.invokeTool.travel-planner |
| Dapr Agents | dapr.agents.travel-planner.workflow | dapr.agents.travel-planner.call_llm | dapr.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
- Deploy the agent to Foundry hosted agents.
- Check Troubleshooting when a step doesn't behave as shown.
- See a run recover from a crash in the agent durability quickstart.
- Learn how history and replay work in Durable execution.
- Find tutorials and access policies for your framework in Agent frameworks.