Skip to main content

Crate serve_agentcore

Crate serve_agentcore 

Source
Expand description

§serve-agentcore (experimental)

Run a serve app on Amazon Bedrock AgentCore Runtime, part of the Everruns ecosystem.

Experimental. Like serve, this is a proof of concept with no compatibility promise.

AgentCore Runtime runs one container per session in its own microVM and talks to it over HTTP on port 8080. This crate serves that contract on top of serve’s host:

  • GET /ping: {"status":"Healthy"}, or HealthyBusy while a turn runs, so AgentCore keeps the session alive for background work.
  • POST /invocations: an AG-UI 1.0 run of the app’s agent, streamed as server-sent events. The body is AG-UI RunAgentInput (what the AgentCore AG-UI protocol forwards), or {"prompt": "..."} (what InvokeAgentRuntime callers usually send). The AG-UI thread defaults to the AgentCore session id from X-Amzn-Bedrock-AgentCore-Runtime-Session-Id.
  • GET /ws: the same runs over AgentCore’s WebSocket transport. Each text message is one invocation body; the run’s AG-UI events come back as one text message each, so a connection can carry several runs in turn.
  • serve’s own /v1 wire API and /health, unchanged, for local use and eval --against.

Everything else is serve’s: the app, its agents and tools, approvals, ask_user, and the durable SQLite session log, kept on AgentCore session storage (/mnt/workspace) when the runtime mounts it, so sessions survive the microVM stopping.

use serve::prelude::*;

#[agent]
fn assistant() -> Agent {
    Agent::builder()
        .model("anthropic/claude-sonnet-5")
        .instructions("Be brief.")
        .build()
}

#[tokio::main]
async fn main() -> serve::Result {
    // No command (what AgentCore runs) or `agentcore`: the AgentCore
    // contract on :8080. `dev`, `start`, `eval`, `manifest`, `deploy`:
    // serve's own commands.
    serve_agentcore::start(App::builder().discover().build()).await
}

Structs§

Options
How router boots the app.
Storage
Where a booted app keeps its state.

Constants§

PORT
The port the AgentCore HTTP and AG-UI protocol contracts require.
SESSION_HEADER
The header AgentCore Runtime sets on every request, naming the session (and so the microVM) it routed to.
SESSION_STORAGE
Where serve-agentcore looks for AgentCore session storage when SERVE_DATA_DIR is not set: the mount path the AgentCore docs use.

Functions§

router
The AgentCore contract around app: /ping, /invocations, and serve’s /v1 wire API. Returns the router and the agent /invocations runs.
start
Run the app: with no command, or with agentcore, serve the AgentCore Runtime contract; any other command is serve’s (see serve::start).