rig-agentcore
Run a Rig agent on AWS Bedrock AgentCore Runtime.
AgentCore runs an agent as an ARM64 container serving its HTTP protocol contract on port
8080. AgentCoreApp serves it for a Rig agent:
| Path | What it does |
|---|---|
POST /invocations |
Takes {"prompt": "..."}. Answers {"response": "...", "status": "success"}, or server-sent events ({"text"} as the model writes, then {"response"}) when the caller accepts text/event-stream. |
GET /ping |
{"status": "Healthy"}, or "HealthyBusy" while work is open, with time_of_last_update. |
use Agent;
use AgentCoreApp;
async
-
Sessions: the
X-Amzn-Bedrock-AgentCore-Runtime-Session-Idheader names the conversation; each session's messages are kept and sent with its next invocation. By default they live in memory (at most 1000 sessions, oldest forgotten first).history_storekeeps them in anyrig-memorystore (DirStoreon disk,rig-sqlite,rig-postgres), so they survive a restart and several apps can share them. Any session id works: one of 1-128 of[A-Za-z0-9_-]names its log as it is, any other is hashed into a safe log name. A save that loses a race with another writer retries up to 10 times; if it still fails, the answer is returned, the failure is logged, and that turn is not persisted. A failed load is an error reported before the agent runs. Each invocation sends the newest messages that fithistory_window(32k tokens by default,rig_memory::recent::TokenBudget), never splitting a tool call from its result. An empty window sends no history. In memory, messages beyond the window are forgotten when a run is saved. Withhistory_store, the store keeps the whole conversation and the window only limits what is sent.use Agent; use AgentCoreApp;DirStoreneeds rig-memory'sfsfeature: enable it in your ownCargo.toml(rig-memory = { version = "0.47", features = ["fs"] }). -
Summaries:
summarize_history(summarizer, keep_recent, trigger_messages)makes a long session shorter. Once a session holds more thantrigger_messagesmessages, an agent without tools (summarizer) summarizes all but the newestkeep_recent, and that one summary becomes the session's first message. The cut never separates a tool call from its result. If the summary fails, a warning is logged, the session keeps its full history, and the invocation answers as usual. Withhistory_store, the summary is written to the store in place of the messages it replaces. Rig-memory has no summarizing window (its compaction is a planning API the caller drives), so this option is built on its compaction helpers.Each summary attempt is traced as an
agentcore.summarizespan under the invocation span. It records the messages summarized and kept, the outcome (summarized,skipped_changed,skipped_nothing_olderorfailed), and the summarizer's token usage. The prompt and the summary text are recorded only withrecord_content. Success is also an info event, and a failure keeps its warning.use Agent; use AgentCoreApp; -
Traces: each invocation runs in an
agentcore.invocationspan that continues the caller's trace (traceparent) and gives every span under itsession.id, throughrig-otel. With rig-otel'sawsfeature exporting to CloudWatch, that is what AgentCore Observability and AgentCore Evaluations read. To see the spans of theserveexample on your machine, setOTEL_EXPORTER_OTLP_ENDPOINT(for examplehttp://127.0.0.1:4318) and run it against a collector. -
Limits: all opt-in.
max_concurrent_taskscaps invocations running at once (past the cap, 429 before the agent runs; no cap by default, since AgentCore Runtime gives each session its own microVM).max_run_durationstops an invocation, summarizing included, after a time (504, or an{"error"}event when streaming, and its turn is not kept; no limit by default).max_request_bytessets the body limit (default 2 MiB, answered with 413). Outside AgentCore Runtime, a cap around 32 and a ten-minute run limit suit most agents.use Duration; use Agent; use AgentCoreApp; -
Background work:
/pinganswersHealthyBusywhile an invocation is running, and while work fromspawn_taskor atrack_taskguard is open. AgentCore Runtime keeps a session running while it reportsHealthyBusy, so a background task outlives the invocation that started it. The status returns toHealthywhen the work ends.use AgentCoreApp; -
Content:
record_content(true)records prompts and replies on the GenAI spans. AgentCore Evaluations needs them to judge a session. They are off by default, as in Rig. The setting applies to every invocation and always overridesAgentBuilder::record_content_telemetryon the agent. The agent's setting is ignored when it is served throughAgentCoreApp, so to record content, call.record_content(true)on the app. This is planned to change in 0.48 (PR #42), so that an app setting left unset keeps the agent's.
Verified on AWS
On 2026-11-26, an agent built with this crate ran on Amazon Bedrock AgentCore Runtime in us-east-1:
- It was deployed as an ARM64 container image from Amazon ECR, with an execution role.
- A two-turn session kept its conversation across invocations.
- Its traces reached CloudWatch (
aws/spans), with the session id on every span. The agent usedrecord_content(true)and rig-otel'sawsexport. - AgentCore Evaluations' built-in evaluators scored the sessions from those spans: GoalSuccessRate 1.0, Helpfulness 0.83 and Correctness 1.0 per turn.
That agent was a private application that used a calculator tool and a Bedrock model. The
steps below use the public serve example instead. They reproduce the deployment and
invocation. The example does not export traces, so step 6 adds that to your own agent.
Set these once. Replace the placeholders with your values:
-
Build the ARM64 image from the repository root. Docker needs buildx. On an x86 host the build runs under emulation and is slow.
-
Create an ECR repository and push the image:
| \ -
Create an execution role for the runtime. AWS documents the required permissions in IAM permissions for AgentCore Runtime. Save the trust policy as
trust.json:Save this permissions policy as
execution.json. It covers pulling the image, writing logs, and sending traces and metrics (the statements AWS lists for the runtime execution role). Addbedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamfor your model only if your agent calls Bedrock: -
Create the runtime with the AWS CLI. Its
helpoutput lists every option:aws bedrock-agentcore-control create-agent-runtime help. Or use the console, under Amazon Bedrock AgentCore. The developer guide is at https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/.The runtime starts in
CREATING. Wait untilstatusisREADY, then note its ARN:The example serves
/pingand/invocationson port 8080, as the HTTP protocol contract requires. -
Invoke the runtime. The session id must be at least 33 characters, and
uuidgengives 36. The output goes toout.json:Save the request body as
payload.json:Send a second call with the same
--runtime-session-idand a prompt such asWhat is my name?. The runtime's logs show that the second request carries the first turn's messages. WithoutOPENROUTER_MODELandOPENROUTER_API_KEYin the runtime's environment, the example answers with a scripted model. Keep API keys out of plain environment variables: use AWS Secrets Manager. -
Enable observability. Turn on CloudWatch Transaction Search once per account. AWS documents the steps in Enable transaction search. Create the resource policy from that page (
aws logs put-resource-policy), then run:Then add traces to your agent. Serve it through
AgentCoreApp::new(agent).record_content(true), since the app's setting overrides the agent'srecord_content_telemetry. Callrig_otel::Telemetry::builder().aws_cloudwatch().await, and setOTEL_RESOURCE_ATTRIBUTES=service.name=<name>,aws.log.group.names=/aws/bedrock-agentcore/runtimes/<runtime-id>-DEFAULTon the runtime, asrig-oteldocuments. AgentCore Observability and Evaluations then read the spans. -
Clean up when you are done:
Testing
cargo test serves the contract over real HTTP for agents on scripted models: ping (with
busy status while work is open), a
session keeping its conversation, sessions kept apart, streamed replies, a bad body,
the run and body limits, and an invocation continuing the caller's trace with the session on every span.