Skip to content
binaryheap
Go back

Building a Serverless Rust Agent with Strands and AgentCore

At Homeschool Ace, I’ve built agents to evaluate student work against answer keys, review essays and research papers for grading, and parse and import curriculum syllabi. I’ve hosted agent workloads on Lambda and ECS, so where to run the agent is a question I’ve had to answer a few times now. Homeschool Ace

Take syllabus import. A parent uploads a PDF, we store it in S3, and the import goes onto a queue. A Go worker on ECS Fargate extracts the text, with Textract available for OCR, and calls Bedrock to help turn that text into a course draft. The parent reviews the draft before applying it to the course. That’s an example of an AI feature I already had to find a home for.

If you’d asked me a month ago to build another one, I might have reached for the TypeScript Strands SDK and run it on AgentCore. What I like about AgentCore is that I get a runtime built for the agent and a way to manage what it can reach as it grows beyond the first couple of tools.

Rust is my first choice for serverless code. The new Strands SDK preview lets me use it for the whole agent on a serverless platform designed to run agents. I wanted to see what that looked like with a small app I could run locally and package the same way for AWS. Strands Rust announcement

The question I picked for the sample is one I’d ask about the importer. Why did this syllabus import fail? I’d want to know how far it got and what the logs say happened next. The sample uses fictional jobs and logs. Job IMP-1042 finished extracting text from the PDF, then the Bedrock call timed out while generating the course draft.

Where the agent runs

AgentCore Runtime is where I configure the compute for the agent. For this sample I bring a container and an HTTP handler. AWS runs it on demand, scales it, and gives each runtime session an isolated environment. A session can serve multiple invocations. The troubleshooter creates a fresh Strands agent per request because each question can be answered on its own. How AgentCore Runtime works

Compute is one of the decisions I’d make for a larger build. I’d also want a way to manage which shared tools an agent can call, and a place for teams to find the agent definitions, tools, and skills they’ve approved. AgentCore Gateway can expose shared tools and enforce policies on the calls it handles. AWS Agent Registry gives teams a catalog with approval and discovery. For this first build, the two tools are ordinary Rust functions running inside the agent’s container. Gateway tool access · AWS Agent Registry

What Strands does for us

Inside the Axum server, Strands handles the back and forth with Nova Lite on Amazon Bedrock. It sends the question and tool definitions to the model. When the model requests get_import_status, Strands calls the Rust function and passes the job state and last completed stage back. The model can then request get_import_logs to see what happened. Strands runs that tool and sends its result back for the model to explain. Strands Rust quickstart

That’s the loop I’d otherwise have to write. My job is to supply the model, the tools, and a system prompt that describes how to use them. The sample uses strands version 0.1.0 so I can choose the pieces myself. The strands-harness crate gives you a preconfigured agent with built-in tools. Strands Rust API reference

let mut agent = Agent::builder()
    .model(model)
    .system_prompt(SYSTEM_PROMPT)
    .tools(tool_list![GetImportStatus, GetImportLogs])
    .printer(false)
    .build()?;

Write a tool in Rust

The logs tool is a Rust function that looks up a job ID and returns the recorded events in order. The job ID travels with the result so the model can tie the evidence back to the job it asked about.

#[tool(description = "Retrieve the stage events for a syllabus import job in execution order.")]
pub(super) async fn get_import_logs(
    /// Import job ID returned by get_import_status.
    job_id: String,
) -> Result<Option<ImportLogs>, ToolError> {
    Ok(find_job(&job_id).map(|job| ImportLogs {
        job_id: job.status.job_id,
        events: job.events,
    }))
}

#[tool] uses the argument types and doc comments to produce the tool schema and gives me the GetImportLogs type I registered above. The Rust code owns the lookup and gives the model an explicit missing result when the fixture has no matching job. Strands Rust tool example

Follow the tool calls in the logs

The import events tell me what happened to the syllabus. I also want to see what the agent did to get that answer. Strands fires hooks after the model and tool calls, so I log the outcome of each call with a request ID. A tool’s Success status means the lookup returned successfully. The job status inside that result can still be failed. Strands Rust hooks

The handler asks Strands for structured output using a schema derived from the Rust Answer type. The SDK adds a strands_structured_output tool that checks the final answer before the server returns it as JSON. How Strands validates structured output

I deployed the sample with CDK in us-east-1. Once CloudFormation reached CREATE_COMPLETE and AgentCore reported the default endpoint ready, I sent the example request. It returned HTTP 200. Here’s the response.

{
  "answer": "The last completed stage was 'text_extraction'. The next stage 'course_draft' failed due to a timeout in the bedrock request."
}

These are the corresponding CloudWatch lines for the same request, with timestamps and IDs omitted. You can see both of my lookup tools and the SDK’s final output validation.

INFO Tool call finished tool=get_import_status status=Success
INFO Tool call finished tool=get_import_logs status=Success
INFO Tool call finished tool=strands_structured_output status=Success
INFO Agent invocation finished elapsed_ms=2336 model_latency_ms=2193 tool_time_ms=0

The summary is for that one request. It records elapsed wall-clock time, the SDK’s reported model latency, and the time spent executing the tools. The in-memory tool calls registered 0 ms at the SDK’s millisecond precision.

Run the agent on your machine

You’ll need Rust 1.96 or newer. From the sample repository, run the scripted test to follow the same tool sequence locally. It runs without AWS credentials. Sample repository

cargo test --locked diagnoses_failed_import -- --nocapture

To try it with Nova Lite, start the server using a profile with permission to invoke the model in us-east-1.

AWS_PROFILE=your-sandbox-profile AWS_REGION=us-east-1 cargo run --locked

From another terminal in the repository root, send the example prompt.

curl --fail-with-body http://127.0.0.1:8080/invocations \
  -H 'Content-Type: application/json' \
  --data-binary @examples/import.json

The server terminal shows the model and tool events for the live request. Try IMP-1043 for an import that’s ready for review, or IMP-9999 to see how the model handles an unknown job.

Put the same server on AgentCore

AgentCore’s HTTP contract is a familiar shape if you’ve built an API with Axum. The container serves GET /ping for health checks and POST /invocations for requests, both on port 8080. The CDK app packages the server as a Linux ARM64 image, publishes it to ECR, and points an AgentCore runtime at the image. AgentCore HTTP contract

Your CLI identity needs permission to call the runtime. The runtime gets its own execution role with access to the image and the one Bedrock model the sample uses. My runtime used platform V2, which took a few minutes to prepare its initial snapshot. The README walks through deploying with CDK, invoking with the same examples/import.json file, and cleaning up. The same log lines go to the runtime’s standard logs in CloudWatch. Sample deployment instructions · View AgentCore runtime logs

Why Rust for a serverless agent?

A lot of an agent’s wall-clock time can go into waiting on the model or a tool call. I still have an artifact to ship, a process to start, and memory in use while the agent waits. Those are some of the same things I’ve cared about when running Rust on Lambda. Rust and Lambda Performance

For this sample, the Linux ARM64 release executable was 31.4 MB. I measured the executable inside the finished container image, and docker image inspect reported 42.5 MB for the image. That includes the Debian base and CA certificates as well as the app.

The Strands team measured the same preconfigured harness on ARM64 Lambda and reported median cold starts of 50 ms for Rust and 635 ms for TypeScript, with peak memory of 48 MB and 195 MB, respectively. Those are Lambda measurements across 100 runs. They give me a reason to pay attention to the footprint of the code hosting the agent, even when the model call is the longest stretch of the request. Strands Lambda benchmark

Wrapping Up

What I like about this setup is how little changes between writing the first tool and giving someone an endpoint they can call. The tools are regular Rust functions, Strands takes care of calling them and getting the results back to the model, and AgentCore runs the same server I used locally. If you give the preview a spin, pick a question from your own work that takes a couple of lookups to answer. Follow one request through the logs and see what the agent actually called.

Thanks for reading and happy building!


Share this post on:

Next Post
John Henry at the Keyboard