Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ Helm chart, commits and tags straight on `main`, then publishes three wheels.
Eleven framework extras — `langgraph`, `crewai`, `adk`, `strands`,
`openai_agents`, `claude_agents`, `pydantic_ai`, `deepagents`, `langchain`,
`smolagents`, `holmesgpt` — plus `agent-core` (shared runtime), `identity`
(`diagrid.identity`'s pyjwt / httpx2 / starlette) and `all`. Note that PyPI
(`diagrid.identity`'s pyjwt / httpx2 / starlette), `bedrock`
(`diagrid.agent.bedrock`'s boto3) and `all`. Note that PyPI
normalises the underscores, so `diagrid[openai-agents]` and
`diagrid[openai_agents]` are the same extra.

- **`identity` is the one non-framework extra.** `diagrid.identity` itself
imports on a bare install; `asgi`, `verifier` and `http` each need it. Its
`starlette` floor is deliberately the 1.x line the rest of the graph already
resolves — raising it forces a repo-wide starlette upgrade.
- **`identity` and `bedrock` are the two non-framework extras.**
`diagrid.identity` itself imports on a bare install; `asgi`, `verifier` and
`http` each need it. Its `starlette` floor is deliberately the 1.x line the
rest of the graph already resolves — raising it forces a repo-wide starlette
upgrade. `bedrock` serves another extra's runner on AgentCore, so it is
installed beside one: `diagrid[bedrock,strands]`.
- **`all` deliberately omits `holmesgpt`.** HolmesGPT's pins on
fastapi/uvicorn/cachetools/mcp/httpx cannot coexist with the other frameworks,
so `[tool.uv].conflicts` declares it incompatible with every other extra
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pip install "diagrid[langchain]"
# For Smolagents
pip install "diagrid[smolagents]"

# To serve any of the above on Amazon Bedrock AgentCore Runtime
pip install "diagrid[bedrock,strands]"

# For HolmesGPT (install in a dedicated environment — see note below)
pip install "diagrid[holmesgpt]"
```
Expand Down
67 changes: 67 additions & 0 deletions diagrid/agent/bedrock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Diagrid Agent Bedrock Extension

This is the Diagrid Agent extension for serving durable agents on [Amazon Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agents-tools-runtime.html).

`BedrockRunner` takes the workflow runner of a diagrid agent and serves it on the AgentCore Runtime HTTP contract: `POST /invocations` and `GET /ping` on port 8080. AgentCore hosts the container and its sessions. Dapr Workflows keep each run's state, so a run's progress and result are not lost when an AgentCore session ends.

## Community

Have questions, hit a bug, or want to share what you're building? Join the [Diagrid Community Discord](https://diagrid.ws/diagrid-community) to connect with the team and other users.

## Installation

Install the `bedrock` extra together with the extra of your agent framework:

```bash
pip install "diagrid[bedrock,strands]"
```

## Prerequisites

1. A Dapr runtime the container can reach: a [Diagrid Catalyst](https://catalyst.diagrid.io/) project, set with `DAPR_GRPC_ENDPOINT`, `DAPR_HTTP_ENDPOINT` and `DAPR_API_TOKEN`
2. An AgentCore Runtime that runs the container image. AgentCore runs only `linux/arm64` images, pulled from Amazon ECR

## Quick Start

```python
# Imported first: it loads the secrets the Dapr SDK reads when it is imported.
from diagrid.agent.bedrock import BedrockRunner

from strands import Agent, tool
from diagrid.agent.strands import DaprWorkflowAgentRunner

@tool
def search(query: str) -> str:
"""Search the web."""
return f"Results for {query}"

agent = Agent(model=my_model, tools=[search])
runner = DaprWorkflowAgentRunner(agent=agent, name="search-agent")

BedrockRunner(runner).serve()
```

`serve()` listens on port 8080, the only port AgentCore Runtime calls. Pass `serve(port=...)` only to run the agent outside AgentCore, for example in a local test. To add routes of your own, such as a health page or a UI, call `app()` instead and serve the FastAPI app it returns.

## Supported Runners

`BedrockRunner` has an adapter for the runners of these extensions: Strands, OpenAI Agents, Pydantic AI, Google ADK, Claude Agent SDK, LangChain, smolagents, CrewAI, LangGraph and Deep Agents. A LangGraph graph must keep its conversation in a `messages` state key.

HolmesGPT's runner is not supported. Its runs can wait for a tool approval, and the AgentCore HTTP contract has no request to send one.

## How It Works

- **One run per session.** AgentCore sends its session ID in the `x-amzn-bedrock-agentcore-runtime-session-id` header. Each task runs as the workflow instance named after that ID. A request that arrives while the session's run is unfinished does not start a new run: it waits for that run and answers with its result. So a request after a container restart resumes the interrupted run.
- **`/invocations` waits for the run to finish.** AgentCore allows a synchronous request 15 minutes. `/invocations` waits at most 14 minutes (`WAIT_SECONDS`). A run that takes longer keeps running, and the request answers `202` with `{"status": "RUNNING"}`. Send `{}` in the same session to collect the result.
- **A request with no task starts no run.** A payload of `{}`, or an empty one, answers with the result of the session's run. When the session has no run, it starts the worker and answers `{"status": "running"}`.
- **Conversation across invocations.** The Strands runner keeps the session's messages in the state store itself. The other runners start every run with only its task, so `BedrockRunner` passes the conversation in the task text instead, as lines starting with `User:` and `Assistant:`, at most its newest 20,000 characters (`MAX_HISTORY_CHARS`). Add `TRANSCRIPT_INSTRUCTION` to those agents' system prompt, so the model answers only the last request.
- **The worker starts on the first request.** The first `/invocations` request connects the runner to Dapr. With `AGENT_WORKER=false`, the container only starts workflows, and workers in other processes execute them.

## Configuration

| Variable | What it does |
|----------|--------------|
| `AGENT_SECRET_ARN` | The ARN or name of an AWS Secrets Manager secret holding a JSON object. Importing the package copies its keys into the environment. Values already in the environment win |
| `AGENT_WORKER_KEEPALIVE` | Any value but `false` or `0` makes `/ping` answer `HealthyBusy` once the worker has started. That keeps the AgentCore session running, and its worker executing runs, until the session reaches its maximum lifetime. Unset, `/ping` always answers `Healthy`, and the idle timeout ends the session |

Keep the Dapr API token and model provider keys in the secret, and give the runtime's execution role permission to read that one secret. The secret values then never appear in the runtime definition.
47 changes: 47 additions & 0 deletions diagrid/agent/bedrock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2026-Present Diagrid Inc.
# SPDX-License-Identifier: BUSL-1.1

"""Diagrid Agent Bedrock - Serve a durable agent on Amazon Bedrock AgentCore Runtime.

This extension serves a diagrid workflow agent runner on the AgentCore Runtime
HTTP contract: ``POST /invocations`` and ``GET /ping`` on port 8080. Each
AgentCore session runs its tasks as the Dapr Workflow instance named after the
session ID, so a run's progress and result outlive the AgentCore session.

Import this package before anything that imports the Dapr SDK: importing it
loads the keys of the AWS Secrets Manager secret named by ``AGENT_SECRET_ARN``
into the environment, and the SDK reads its variables when it is first imported.

Example:
```python
from diagrid.agent.bedrock import BedrockRunner

from strands import Agent
from diagrid.agent.strands import DaprWorkflowAgentRunner

agent = Agent(model=my_model, tools=[my_tool])
runner = DaprWorkflowAgentRunner(agent=agent, name="my-agent")
BedrockRunner(runner).serve()
```

Install:
pip install diagrid[bedrock,strands]
"""

from diagrid.agent.bedrock.runner import (
TRANSCRIPT_INSTRUCTION,
BedrockRunner,
load_secrets,
)
from diagrid.agent.bedrock.version import __version__

__all__ = [
# Main runner class
"BedrockRunner",
# The system prompt line for runners whose task carries the conversation
"TRANSCRIPT_INSTRUCTION",
# Secrets
"load_secrets",
# Version
"__version__",
]
Empty file.
Loading