Quickstart: run a durable AgentCore agent locally
In this quickstart, you create a budget analyst agent with Strands and the Diagrid package, and serve it with the HTTP contract that Amazon Bedrock AgentCore Runtime uses. You run it on your machine, connected to a Diagrid project, before you deploy it to AWS.
This quickstart shows you how to:
- Run a Strands agent as a durable workflow with the Diagrid package.
- Serve the agent on the AgentCore contract:
POST /invocationsandGET /pingon port 8080. - Invoke the agent and continue a conversation across invocations.
- Inspect the run in Diagrid: its ID, status, steps and timing, and the session's stored conversation.
An agent hosted on AgentCore must serve the POST /invocations endpoint, which AgentCore calls with each request, and the GET /ping endpoint, which AgentCore uses to check its health. The Diagrid AgentcoreRunner class serves both for you, so your code only defines the agent.
The commands on this page have a macOS/Linux and a Windows (PowerShell) variant. The guide uses Strands. See the reference for the other supported frameworks.
Prerequisites
- A Diagrid account and the Diagrid CLI, version 1.146.0 or later. Update it the way you installed it:
brew upgrade diagrid,npm install -g @diagrid/cli@latest, ordiagrid updateafter the install script. - Python 3.11 to 3.13 and uv
- An AWS account and the AWS CLI v2. The agent calls its model through Amazon Bedrock with your AWS CLI login, so that identity needs
bedrock:InvokeModelWithResponseStreamon the model. - Access to the Bedrock model you pick, in your region. The model must support tool use.
- jq, on macOS and Linux
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 the agent's ID
Create a Diagrid project with a managed key-value store, and set it as the default project for the Diagrid CLI. The managed workflow store that holds the state of every agent run is included by default.
diagrid project create agentcore-quickstart --deploy-managed-kv --wait --use
Create the agent's ID, the agent's workload identity. The agent connects to Diagrid with the ID's Diagrid credentials.
diagrid agent create budget-planner --wait
3. Create the agent project
Create the project folder and add the Diagrid package with its AgentCore extra, awsbedrock, and its Strands extra. The botocore[crt] package lets the AWS SDK for Python use the credentials of aws login:
uv init --bare --python 3.13 budget-planner
cd budget-planner
uv add "diagrid[awsbedrock,strands]==0.5.5" "strands-agents==1.69.0" "botocore[crt]" "opentelemetry-sdk<1.46"
opentelemetry-sdk is pinnedopentelemetry-sdk 1.46.0 removed LoggingHandler, and dapr-agents 1.1.1, which the Diagrid package installs, still imports it. Without the pin, uv add installs 1.46.0 and importing AgentcoreRunner fails with ImportError: cannot import name 'LoggingHandler'. Remove the pin once a dapr-agents release supports opentelemetry-sdk 1.46.
4. Create the agent
Create main.py. It holds what is specific to this agent: its tool, its model and its prompt. It builds the Strands agent, hands it to the Diagrid runner DaprWorkflowAgentRunner, and serves the runner with AgentcoreRunner from the Diagrid package:
import logging
import os
import textwrap
import time
# Imported first: on AgentCore it loads the agent's secrets before the Dapr SDK reads them.
from diagrid.agent.awsbedrock import AgentcoreRunner
from strands import Agent, tool
from strands.models.bedrock import BedrockModel
from diagrid.agent.core.state import DaprStateStore
from diagrid.agent.strands import DaprWorkflowAgentRunner
logging.basicConfig(level=logging.INFO)
PRICES = {
"venue": 3500,
"catering": 2250,
"entertainment": 1500,
"decorations": 800,
"miscellaneous": 500,
}
ITEMS = ", ".join(PRICES)
@tool
def calculate_budget(items: str) -> str:
"""Calculate total budget from a comma-separated list of cost items."""
lines = ["Budget breakdown:"]
total = 0
for item in (i.strip() for i in items.split(",")):
if not item:
continue
price = PRICES.get(item.lower())
if price is None:
lines.append(f"- {item}: no price available")
continue
lines.append(f"- {item}: ${price:,}")
total += price
buffer = round(total * 0.15)
lines.append(f"Total: ${total:,}")
lines.append(f"Recommended buffer (15%): ${buffer:,}")
lines.append(f"Grand Total: ${total + buffer:,}")
return "\n".join(lines)
# LONG_RUN_SECONDS > 0 adds a slow tool, so a run lasts long enough to interrupt.
# Unset or 0: the agent is the quickstart's budget planner, unchanged.
LONG_RUN_SECONDS = int(os.environ.get("LONG_RUN_SECONDS") or 0)
@tool
def check_vendor_availability(item: str) -> str:
"""Check whether a vendor for one cost item is available on the event date."""
logging.info("check_vendor_availability(%s): started, takes %ss", item, LONG_RUN_SECONDS)
time.sleep(LONG_RUN_SECONDS)
logging.info("check_vendor_availability(%s): done", item)
return f"{item}: vendor available on the event date."
# AWS_REGION is the region to call Bedrock in; unset or empty uses the AWS profile's.
# BEDROCK_MODEL_ID is any model or inference profile that supports tool use, available in that region.
# BEDROCK_MAX_TOKENS is sent as maxTokens; unset or empty uses the model's limit.
# temperature=0 makes Amazon Nova call the tool reliably.
max_tokens = os.environ.get("BEDROCK_MAX_TOKENS")
model = BedrockModel(
region_name=os.environ.get("AWS_REGION") or None,
model_id=os.environ.get("BEDROCK_MODEL_ID") or "us.amazon.nova-lite-v1:0",
temperature=0.0,
**({"max_tokens": int(max_tokens)} if max_tokens else {}),
)
system_prompt = textwrap.dedent(f"""\
You are a budget analyst specializing in event planning.
When asked to estimate costs, use the calculate_budget tool with a comma-separated list of cost items.
Allowed items are {ITEMS}.
Correct spelling of items in user request if needed.
Return the full budget breakdown with line items, totals, and recommended buffer.
Always call the tool when you need to calculate the price for item.
""")
tools = [calculate_budget]
if LONG_RUN_SECONDS > 0:
tools.append(check_vendor_availability)
system_prompt += (
"After calculating the budget, call check_vendor_availability once for each item, "
"one call at a time, and include each item's availability in your answer.\n"
)
agent = Agent(model=model, tools=tools, system_prompt=system_prompt)
# Diagrid: run the agent as a durable workflow.
runner = DaprWorkflowAgentRunner(
name="budget-planner",
agent=agent,
state_store=DaprStateStore(store_name="kvstore"),
)
if __name__ == "__main__":
# AgentCore: serve POST /invocations and GET /ping on port 8080.
AgentcoreRunner(runner).serve()
check_vendor_availability is off unless LONG_RUN_SECONDS is set. It makes a run take about two minutes, long enough to interrupt a run and watch it recover. Leave it unset in this quickstart.
5. Configure the AWS account
The agent calls Bedrock with the AWS SDK's default credentials, which are your AWS CLI login. There is no model API key to set.
Log in to AWS
Log in with your AWS Management Console credentials. The command opens a browser to sign in:
aws login
If your organization uses IAM Identity Center, run aws sso login instead. Check which identity the agent will use:
aws sts get-caller-identity
Set the region and the model
The agent reads its model settings from the environment. Set the region to call Bedrock in and the model ID:
- macOS/Linux
- Windows
export AWS_REGION="us-east-1"
export BEDROCK_MODEL_ID="us.amazon.nova-lite-v1:0"
$env:AWS_REGION = "us-east-1"
$env:BEDROCK_MODEL_ID = "us.amazon.nova-lite-v1:0"
BEDROCK_MODEL_ID takes a model ID or an inference profile ID. For example:
| Model | BEDROCK_MODEL_ID |
|---|---|
| Amazon Nova Lite | us.amazon.nova-lite-v1:0 |
| Amazon Nova Pro | us.amazon.nova-pro-v1:0 |
| Anthropic Claude Sonnet 4.6 | global.anthropic.claude-sonnet-4-6 |
An ID that starts with us., eu., apac. or global. is a cross-region inference profile. Pick the prefix that matches AWS_REGION: a us. profile works only from a US region. Anthropic models need a one-time use case form before an account's first call.
To cap the length of each model response, also set BEDROCK_MAX_TOKENS, for example to 1024. A response that reaches the limit is cut off.
6. Configure the Diagrid connection
The agent connects to Diagrid with the project's endpoints and the agent's Diagrid credentials. Read them into the environment, in the same terminal:
- macOS/Linux
- Windows
export DAPR_GRPC_ENDPOINT="$(diagrid project get agentcore-quickstart -o json | jq -r .status.endpoints.grpc.url)"
export DAPR_HTTP_ENDPOINT="$(diagrid project get agentcore-quickstart -o json | jq -r .status.endpoints.http.url)"
export DAPR_API_TOKEN="$(diagrid agent get budget-planner -o json | jq -r '.status.appIds[0].status.apiToken')"
$project = diagrid project get agentcore-quickstart -o json | Out-String | ConvertFrom-Json
$env:DAPR_GRPC_ENDPOINT = $project.status.endpoints.grpc.url
$env:DAPR_HTTP_ENDPOINT = $project.status.endpoints.http.url
$env:DAPR_API_TOKEN = (diagrid agent get budget-planner -o json | Out-String | ConvertFrom-Json).status.appIds[0].status.apiToken
7. Run the agent
uv run python main.py
Wait for the log line Uvicorn running on http://0.0.0.0:8080.
8. Invoke the agent
Open a new terminal and send the request AgentCore would send, with a session ID in the header:
- macOS/Linux
- Windows
curl -X POST http://localhost:8080/invocations \
-H "Content-Type: text/plain" \
-H "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id: local-session-0123456789abcdef0123" \
-d 'Calculate the budget for a corporate event with venue, catering, and entertainment'
Invoke-RestMethod -Method Post -Uri 'http://localhost:8080/invocations' -ContentType 'text/plain' -Headers @{ 'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id' = 'local-session-0123456789abcdef0123' } -Body 'Calculate the budget for a corporate event with venue, catering, and entertainment'
The request waits until the run ends. The response holds the workflow ID, which is the session ID, the run's status and the agent's answer:
{
"instance_id": "local-session-0123456789abcdef0123",
"status": "COMPLETED",
"result": "Here's the budget breakdown for your corporate event:\n\n- **Venue**: $3,500\n- **Catering**: $2,250\n- **Entertainment**: $1,500\n\n**Total**: $7,250 …"
}
The exact wording of result depends on the model. For example, Amazon Nova models start it with their reasoning in a <thinking> block.
The agent takes the whole request body as the task, so the request is plain text. See the reference for the details of the protocol.
9. Continue the conversation
Send a follow-up with the same session ID:
- macOS/Linux
- Windows
curl -X POST http://localhost:8080/invocations \
-H "Content-Type: text/plain" \
-H "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id: local-session-0123456789abcdef0123" \
-d 'Recalculate without entertainment'
Invoke-RestMethod -Method Post -Uri 'http://localhost:8080/invocations' -ContentType 'text/plain' -Headers @{ 'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id' = 'local-session-0123456789abcdef0123' } -Body 'Recalculate without entertainment'
The answer drops the entertainment line and recalculates the totals. The Strands runner keeps the session's messages, tool calls and tool results included, in the kvstore state store under strands-budget-planner-<session ID>-messages. Each run loads them before its first model call and saves them when it ends, keeping the newest 40 messages. Because they are in Diagrid, the conversation survives a crash or a new container.
10. Inspect the execution
Every invocation ran as a workflow under the budget-planner ID. List the executions:
diagrid workflow list --project agentcore-quickstart --id budget-planner
The workflow ID is the session ID, and the workflow name is dapr.strands.BudgetPlanner.workflow. A new task in a session replaces the session's finished run, so the list shows only the latest run of each session: the follow-up from step 9.
Print that run and its steps:
diagrid workflow get local-session-0123456789abcdef0123 --id budget-planner --project agentcore-quickstart
This is part of the output for the follow-up from step 9. Long values are cut short and some events are left out. The history lists the newest event first:
execution:
appId: budget-planner
createdAt: 2026-12-01T16:32:12.168372827Z
endAt: 2026-12-01T16:32:14.388402939Z
executionTimeMs: 2216
input: "{\"task\": \"Recalculate without entertainment\", \"session_id\": \"local-session-0123456789abcdef0123\"}"
name: dapr.strands.BudgetPlanner.workflow
output: "{\"result\": \"… Here is the updated budget breakdown for your corporate event: …\", \"tool_calls\": [{\"tool_name\": \"calculate_budget\", \"tool_use_id\": \"tooluse_SXFeuByIlyscjNyUQ1RR0v\", \"input\": {\"items\": \"venue,catering\"}}]}"
startAt: 2026-12-01T16:32:12.17240578Z
status: completed
workflowId: local-session-0123456789abcdef0123
history:
- date: 2026-12-01T16:32:14.388402939Z
eventType: ExecutionCompleted
metadata:
name: dapr.strands.BudgetPlanner.workflow
workflow_status: completed
- date: 2026-12-01T16:32:14.312208953Z
eventType: TaskCompleted
metadata:
name: strands_save_history
task_scheduled_id: "5"
- date: 2026-12-01T16:32:14.173379832Z
eventType: TaskCompleted
metadata:
name: strands_call_model
task_scheduled_id: "4"
output: "{\"tool_uses\": [], \"text\": \"… Here is the updated budget breakdown for your corporate event: …\", \"stop_reason\": \"end_turn\", …"
- date: 2026-12-01T16:32:13.142650522Z
eventType: TaskCompleted
metadata:
name: strands_execute_tool
task_scheduled_id: "3"
output: "{\"toolUseId\": \"tooluse_SXFeuByIlyscjNyUQ1RR0v\", \"status\": \"success\", \"content\": [{\"text\": \"… Budget breakdown:\\\\n- venue: $3,500\\\\n- catering: $2,250\\\\nTotal: $5,750 …"
- date: 2026-12-01T16:32:13.094235529Z
eventId: "3"
eventType: TaskScheduled
metadata:
name: strands_execute_tool
task_scheduled_id: "3"
input: "{\"tool_name\": \"calculate_budget\", \"tool_use_id\": \"tooluse_SXFeuByIlyscjNyUQ1RR0v\", \"tool_input\": {\"items\": \"venue,catering\"}}"
- date: 2026-12-01T16:32:12.217260715Z
eventId: "1"
eventType: TaskScheduled
metadata:
name: strands_load_history
task_scheduled_id: "1"
input: "{\"session_id\": \"local-session-0123456789abcdef0123\"}"
- date: 2026-12-01T16:32:12.168372827Z
eventType: ExecutionStarted
metadata:
name: dapr.strands.BudgetPlanner.workflow
workflow_instance_id: local-session-0123456789abcdef0123
In the output, look at:
- Status and timing:
status,startAt,endAtandexecutionTimeMsunderexecution. - Input and output:
execution.inputholds this run's task and the session ID, andexecution.outputholds the answer underresultand the run's tool calls undertool_calls. - Steps:
strands_load_historyreads the session's earlier messages, astrands_call_modelstep runs for each model call, astrands_execute_toolstep runs for eachcalculate_budgetcall, with the items in itsinput, andstrands_save_historystores the updated messages.
The workflow holds only this run. The conversation is in the kvstore state store, under the key from step 9. Print it:
diagrid call state get strands-budget-planner-local-session-0123456789abcdef0123-messages --component kvstore --id budget-planner --project agentcore-quickstart
The value is the list of messages the next run in this session sends to the model: both tasks, the model's answers, and the tool calls and their results.
The Diagrid Console lists the same executions on its Workflows page. See Operate workflow instances.
Use another framework
AgentcoreRunner serves the Diagrid runner of any supported framework, so the rest of this quickstart, and the hosted agents and Diagrid-managed sessions guides, work the same with another framework. Three things change:
- The package extra. Add the framework's extra instead of
strands, for exampleuv add "diagrid[awsbedrock,langgraph]" "opentelemetry-sdk<1.46", plus the framework's packages, such asuv add langchain langchain-awsfor LangGraph with Amazon Bedrock. - The runner. Build the framework's agent and hand it to its Diagrid runner, then serve that runner with
AgentcoreRunner, as before. - The system prompt. Add
TRANSCRIPT_INSTRUCTIONto it. The Strands runner keeps the conversation in the state store. The other runners get it in the task text, and the instruction tells the model to answer only the last request. See Conversation history.
For example, here is the budget planner as a LangGraph agent. The tool and its prices are the same as in step 4:
import os
import textwrap
# Imported first: on AgentCore it loads the agent's secrets before the Dapr SDK reads them.
from diagrid.agent.awsbedrock import TRANSCRIPT_INSTRUCTION, AgentcoreRunner
from langchain_aws import ChatBedrockConverse
from langchain_core.tools import tool
from langchain.agents import create_agent
from diagrid.agent.langgraph import DaprWorkflowGraphRunner
PRICES = {
"venue": 3500,
"catering": 2250,
"entertainment": 1500,
"decorations": 800,
"miscellaneous": 500,
}
ITEMS = ", ".join(PRICES)
@tool
def calculate_budget(items: str) -> str:
"""Calculate total budget from a comma-separated list of cost items."""
lines = ["Budget breakdown:"]
total = 0
for item in (i.strip() for i in items.split(",")):
if not item:
continue
price = PRICES.get(item.lower())
if price is None:
lines.append(f"- {item}: no price available")
continue
lines.append(f"- {item}: ${price:,}")
total += price
buffer = round(total * 0.15)
lines.append(f"Total: ${total:,}")
lines.append(f"Recommended buffer (15%): ${buffer:,}")
lines.append(f"Grand Total: ${total + buffer:,}")
return "\n".join(lines)
model = ChatBedrockConverse(
region_name=os.environ.get("AWS_REGION") or None,
model=os.environ.get("BEDROCK_MODEL_ID") or "us.amazon.nova-lite-v1:0",
temperature=0.0,
)
system_prompt = textwrap.dedent(f"""\
You are a budget analyst specializing in event planning.
When asked to estimate costs, use the calculate_budget tool with a comma-separated list of cost items.
Allowed items are {ITEMS}.
Correct spelling of items in user request if needed.
Return the full budget breakdown with line items, totals, and recommended buffer.
Always call the tool when you need to calculate the price for item.
""") + TRANSCRIPT_INSTRUCTION
graph = create_agent(model, tools=[calculate_budget], system_prompt=system_prompt)
# Diagrid: run the graph as a durable workflow.
runner = DaprWorkflowGraphRunner(graph=graph, name="budget-planner")
if __name__ == "__main__":
# AgentCore: serve POST /invocations and GET /ping on port 8080.
AgentcoreRunner(runner).serve()
Each run is a dapr.langgraph.BudgetPlanner.workflow execution, with a step for each node the graph runs: model and tools. The Dockerfile and the AWS setup in the other guides don't change.
For each framework's own options, see the tutorials in Agent frameworks.
Clean up
Press Ctrl+C in the terminal that runs the agent.
If you continue with AgentCore hosted agents, keep the budget-planner folder and the agentcore-quickstart project. Otherwise, delete the project and everything in it:
diagrid project delete agentcore-quickstart
Summary
In this quickstart, you:
- Ran a Strands agent as a durable workflow with the Diagrid package.
- Served it on the AgentCore HTTP contract with
AgentcoreRunner. - Invoked it twice in one session, and got an answer that used the first.
- Inspected the latest run, its steps and its timing, and the session's stored conversation, with the Diagrid CLI.
Next steps
- Deploy the agent to AgentCore hosted agents.
- Let Diagrid start and stop AgentCore sessions with Diagrid-managed sessions.
- Learn how history and replay work in Durable execution.
- Find tutorials and access policies for Strands in Agent frameworks.
Was this page helpful?