AgentCore runner reference
AgentcoreRunner, in the diagrid.agent.awsbedrock module of the Diagrid package, serves a Diagrid agent runner on the AgentCore Runtime HTTP contract: POST /invocations and GET /ping on port 8080. This page describes what it does for each request and what it reads from the environment.
Install it with the awsbedrock extra beside the extra of your framework:
uv add "diagrid[awsbedrock,strands]==0.5.5" "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.
AgentcoreRunner is in diagrid 0.5.5 and later.
Requests
Each AgentCore session runs one task at a time, as the workflow whose ID is the session ID. The runner takes the whole request body as the task text, without parsing it, so send the task as plain text. A request waits until the session's run ends:
| Request | Answer |
|---|---|
| A task, no run in progress | 200 with the result, once the run ends |
| A task, a run in progress | The task isn't started. 200 with the result of the run in progress, once it ends |
{}, the session has a run | No run is started. 200 with the result of the session's run, once it ends |
{}, the session has no run | No run is started. 200 with {"status": "running"} once the container's worker is connected to Diagrid |
| Any request whose run takes more than 14 minutes | 202 with {"status": "RUNNING"}. The run keeps going in Diagrid |
The two statuses differ: running means the session's worker is connected to Diagrid and the session has no run, and RUNNING means the session's run is still executing after the 14-minute wait.
{}collects the session's result. It resumes a run that a restarted container interrupted, and returns the result of a run that finished after its request failed. An empty body works as{}does, but AgentCore refuses a request with no body.- A request waits at most 14 minutes. AgentCore allows a synchronous request 15 minutes, and the limit can't be raised. A run that takes longer keeps running in Diagrid. Send
{}in the same session to collect its result. - A failed run answers
500. AgentCore returns a container's 4xx or 5xx answer to the caller as a424 RuntimeClientError. - The worker connects on the first request. The runner connects to Diagrid as the agent's workflow worker on the session's first invocation, not when the process starts.
{}in a new session starts the worker without giving it a task. - The session ID must be at least 33 characters long. AgentCore requires it.
Health checks
GET /ping answers Healthy. With AGENT_WORKER_KEEPALIVE set, it answers HealthyBusy once the worker has started, so AgentCore doesn't stop the session at its idle timeout. The session then runs until it is stopped, or until it reaches its maximum lifetime, 8 hours by default. Diagrid-managed sessions set it, so that Diagrid decides when a session stops.
Environment variables
| Variable | What it does |
|---|---|
AGENT_SECRET_ARN | The ARN or name of an AWS Secrets Manager secret that holds a JSON object. Importing diagrid.agent.awsbedrock copies its keys into the environment, before the Dapr SDK reads them. Values already in the environment win. Import the module before anything that imports the Dapr SDK |
AGENT_WORKER | false or 0 makes the process start runs through Diagrid without executing any. Workers in other processes execute them. Unset, the process is also a worker |
AGENT_WORKER_KEEPALIVE | Any value but false or 0 makes GET /ping answer HealthyBusy once the worker has started. Unset, false or 0, it always answers Healthy |
DAPR_GRPC_ENDPOINT, DAPR_HTTP_ENDPOINT | The Diagrid project's endpoints |
DAPR_API_TOKEN | The agent's Diagrid credentials. Keep it in the secret |
DO_NOT_TRACK | 1 turns off the anonymous usage event the Diagrid package sends once per process. The event holds versions, the platform and the agent framework, and no prompts, IDs or hostnames |
The guides' agent also reads AWS_REGION, BEDROCK_MODEL_ID and BEDROCK_MAX_TOKENS. Those are read by the agent's code, not by the runner.
Supported frameworks
AgentcoreRunner serves the Diagrid runners of these frameworks:
- Strands
- OpenAI Agents
- Pydantic AI
- Google ADK
- Claude Agent SDK
- LangChain
- smolagents
- CrewAI
- LangGraph
- Deep Agents
A LangGraph or Deep Agents graph must keep its conversation in a messages state key.
HolmesGPT's runner isn't supported, because its runs can wait for a tool approval that the AgentCore contract has no request for.
Conversation history
Invocations with the same session ID share one conversation, stored in Diagrid.
-
Strands. The Strands runner keeps the session's messages, tool calls and tool results included, in the agent's state store under
strands-<agent name>-<session ID>-messages. Each run loads them before its first model call and saves them when it ends, keeping the newest 40 messages. The task sent to the model is only the new request. -
Other frameworks. Their runners start every run with only its task, so
AgentcoreRunnerpasses the conversation in the task text, as lines starting withUser:andAssistant:, up to its newest 20,000 characters. AddTRANSCRIPT_INSTRUCTIONfromdiagrid.agent.awsbedrockto the agent's system prompt, so the model answers only the last request:from diagrid.agent.awsbedrock import TRANSCRIPT_INSTRUCTION, AgentcoreRunnersystem_prompt = "You are a budget analyst. " + TRANSCRIPT_INSTRUCTION
Was this page helpful?