AWS Builder Center
How to Build a Production-Ready AI Agent on AWS

How to Build a Production-Ready AI Agent on AWS

Deploy-time defaults, runtime overrides, and a credential-capture pattern that knows when to ask

Cloud Architect
A small configuration layer — deploy-time defaults, runtime overrides, on-demand tool integration, and a credential-capture pattern that knows when to ask — is what turns a hardcoded agent script into a governable, reusable agent platform.

Introduction

Most teams that ship an AI agent start the same way: a system prompt, a model client, and a handful of tool functions, all wired directly into application code. It's maybe fifty lines, and it works well enough to demo. Prompt engineering gets that first response into good shape. Context engineering keeps it grounded once the conversation gets longer. Neither one answers a much more mundane question: how does a different team change what this agent does — which model backs it, which tools it can reach, which behavior it defaults to — without touching the code and shipping a new build?
That gap is what harness engineering fills. If prompt engineering shapes what you say to the model, and context engineering shapes what you put in its window, harness engineering shapes the scaffolding around the model itself: the layer that decides which model answers, which tools and agents are reachable, which memory persists, and — critically — which of those choices the deploying team locks down as a default versus leaves open for the end user to override on a given turn.
Organizations wiring agent behavior directly into application code run into a specific, recurring set of problems:
  • New agent behavior requires a code change and a redeploy, even when nothing changed except which tools are attached or which model answers.
  • AI-generated or third-party agent code can't be trusted to run inline with everything else, so every new agent variant needs its own review path, its own isolation, or both.
  • Users increasingly expect to pick their own model or turn on a connector mid-conversation, and neither of those is possible until someone builds the plumbing for it.
  • Every external tool or agent-to-agent call needs a credential, and asking for it at the wrong moment either creates consent fatigue or leaves a long-running task stalled on a permission prompt nobody's there to answer.
  • Building all of this by hand is a genuine, ongoing engineering investment — one that increasingly duplicates a layer AWS has now turned into a managed primitive.

What makes a harness different

A bare model call is a function: prompt in, completion out. Nothing about which tools are available, which memory persists, or which model responds is decided outside that one call — it's all baked into the code that made it.
A harness adds a configuration boundary around that call. The system prompt, model ID, tool list, and memory bindings are lifted out of code and into data — injected as defaults at deploy time, and optionally overridden at invocation time by whoever is actually running the agent on a given turn. The agent code itself becomes generic: read the config, assemble the tools, hand off to the model, apply the hooks. It stops needing to change every time the agent's behavior does, which is also what makes it safe to code-scan once and reuse for every agent variant that follows.
The shorthand for this is agent = model + harness, and the harness is the part actually doing the engineering. A well-built one does two things: it raises the odds the agent gets a task right on the first pass, and it gives you a place to put the guardrails — token ceilings, iteration limits, credential scoping — that stop it from going wrong quietly.
Deploy-time inputs feed a generic harness, which assembles a runtime the same way for every agent variant.


Key layers of an agent harness on AWS

Two configuration layers, not one

“Configure the agent” sounds like one step. In practice it's two layers with different owners and different lifetimes, and collapsing them produces the two failure modes above: either every change requires a redeploy, or every user can silently override behavior nobody intended to expose.
  • Deploy-time configuration (the defaults). Persona, instructions, and guidelines combined into one system prompt; the default model ID and token ceiling; the MCP servers and agent-to-agent (A2A) endpoints enabled for this agent; the memory resource it's bound to. Set once, at deployment, injected as config rather than hardcoded, and identical for every session until the agent is redeployed.
  • Runtime configuration (the overrides). A session ID to resume or create; a model ID swap, constrained to an allow-list the deploying team set; a list of connector IDs to attach for this invocation only; a bearer token or credential reference for auth. Set per request, scoped to that one session, gone the moment the session ends
// deploy-time defaults (injected once, at deployment)
{
"system_prompt": "persona, instructions, guidelines",
"model_id": "default-model",
"max_tokens": 16384,
"allowed_model_ids": ["default-model", "alt-model-a", "alt-model-b"],
"integrations": {
"mcp_servers": [{ "name": "utilities", "enabled": true }],
"memory": { "enabled": true, "resource": "employee-assistant" }
}
}
// runtime override (sent with a single invocation)
{
"prompt": "What is the weather in New York?",
"session_id": "existing-session-id-or-null",
"model_id": "alt-model-a",
"connector_ids": [3, 7]
}
The runtime payload never replaces the deploy-time config wholesale — it merges into it, and only along the axes the deploying team chose to expose. A model override that isn't in allowed_model_ids gets rejected, not silently applied. That's the whole point of having two layers instead of one: the defaults are a governance boundary, not just a starting value.
Deploy-time defaults and runtime overrides merge into one effective configuration for each invocation

Tools and agents are attached the same way
MCP servers and A2A endpoints look like two different integration types, but the harness treats them identically: each is named, gated behind an enabled flag, optionally authenticated, and appended to the tool list the model sees. An MCP server gives the agent a tool — a weather API, an internal database, a search index. An A2A endpoint gives it something closer to a colleague — another agent, addressable in its own right, that this agent can delegate a sub-task to. Both are just entries in the same conditional list-building step, gated by the same flag, at deploy time or at runtime.
if config.integrations.mcp_servers:
for server in enabled(config.integrations.mcp_servers):
tools.extend(build_mcp_client(server))
if config.integrations.a2a_agents:
for agent in enabled(config.integrations.a2a_agents):
tools.extend(build_a2a_client(agent))

The credential-capture gate — the highest-risk moment in the system

Deciding when to ask a user for a credential is a security decision disguised as a UX detail, and getting it wrong fails in one of two predictable directions. Capture credentials too early — at deploy time, set once by an administrator — and a single shared credential ends up serving every user of that connector, which is fine for a public search API and wrong for anything personal. Capture them too late — only when the tool is actually about to be invoked — and a long-running task can stall mid-execution waiting on a permission prompt, minutes or hours after the user who could answer it has walked away. The workable middle is to capture the credential at the moment the user explicitly toggles a connector on. That's the point of highest intent and lowest consent fatigue — the user just asked for this integration, so asking them to authorize it right then reads as expected, not as an interruption. It's also the natural point to decide scope: a personal API key stored per-user, versus a shared credential managed once at the admin level for the whole deployment. Waiting any longer just moves the same question to a worse moment.
Credentials are captured when the user toggles a connector on — not at deploy time, and not at first tool call


Bounded runtime — ceilings on the loop, not just the prompt

An agent that can call tools can also loop — reasoning, calling a tool, reasoning again — for longer than anyone intended, and every extra iteration is both latency and cost. A harness puts hard ceilings on that loop the same way a memory system puts a ceiling on prompt size: a maximum token budget per response, and a maximum number of iterations per invocation. Neither is a creative constraint on the model — they're the harness-level equivalent of a circuit breaker, tripped before a stuck agent turns into a runaway bill.

Common use cases for an agent harness

  • Per-user model choice without a redeploy. One agent, one deployed harness, and each user picks from an allow-list the deploying team controls. Changing who's allowed to pick what is a config change, not a code change.
  • On-demand tool enablement mid-conversation. A user turns on a connector partway through a session — a search tool, an internal system — and the harness attaches it for that invocation without restarting the conversation or redeploying the agent.
  • Multi-agent delegation via A2A. An agent hands part of a task to another agent addressed as an A2A endpoint, configured and authenticated exactly like any other tool, so the calling agent doesn't need special-cased logic for “this one's actually a colleague.”
  • Config-driven memory attachment. Binding an agent to a durable memory resource is a deploy-time integration flag, not a code path — the same pattern used for tools, applied to state.
  • Swapping a custom harness for a managed one. Because the agent code only ever reads config and assembles tools, the harness underneath it — hand-built today, a managed service tomorrow — can change without rewriting the agent.

An example journey: getting there from a hardcoded agent

You don't need all of this on day one.
Externalize the system prompt and model ID first. Pull them out of code and into a config object the agent reads at startup. This alone makes an agent redeployable without a code change for the most common tweak anyone asks for.
Split deploy-time defaults from runtime overrides. Define an allow-list for anything you're willing to let a user override — model choice is the easiest first candidate — and reject anything outside it rather than silently accepting it.
Add conditional tool loading, gated by an enabled flag. Build the tool list from config instead of a hardcoded import list, so adding an MCP server or an A2A agent is a config entry, not a deploy.
Add credential capture at toggle-time, not at first tool call. Wire the consent prompt to the moment a user turns a connector on, and decide per-connector whether the credential is personal or shared at the admin level.
Add hard ceilings on iterations and tokens. Put a circuit breaker on the agent loop before you need one, not after a runaway session shows up in a cost report.
Evaluate a managed harness once the custom one works. At that point you've proven out what your agents actually need — the remaining question is whether to keep maintaining that scaffolding yourself or hand the deploy-time/runtime split, the tool wiring, and the iteration ceilings to a managed service built for exactly this layer.
Each step is independently useful, which is what makes this a migration rather than a rewrite.

Is a managed harness right for you?

A few signals are worth checking before you invest further in a hand-built one.
Start with how often “add a tool” or “change the model” turns into a pull request. If every new agent variant needs a code review and a redeploy just to change a connector list, that's not a testing rigor problem — it's a harness problem, and no amount of careful code review fixes a layer that was never meant to hold configuration in the first place. Then check who's running the code. If you're already running AI-generated or third-party agent logic and asking whether it's safe to execute inline with everything else, a pre-written, config-driven agent shape is what lets you code-scan once and trust every variant that follows, instead of isolating each one individually.
Per-user choice is another tell. If letting users pick their own model or toggle their own tools is a real, requested feature rather than a hypothetical, that's runtime configuration you need to build regardless of whether the harness underneath is custom or managed.
And weigh the maintenance line item honestly. A hand-built harness teaches you a lot about what your agents actually need — telemetry, cost estimation, exactly where the credential prompt should sit — but every one of those is also now something your team owns and has to keep working as the underlying model APIs change. A managed harness that already does the deploy-time/runtime split, tool wiring, and credential handling is a smaller, steadier surface to maintain than the equivalent hand-built one, once you've confirmed you actually need the layer at all

Conclusion

Harness engineering sits between prompt engineering and infrastructure: not what you say to the model, but what you let it reach, whose defaults apply, and what a user is allowed to override on a given turn. None of it requires exotic infrastructure — a config object instead of hardcoded values, an allow-list for runtime overrides, a credential prompt tied to the moment of intent, and hard ceilings on the agent loop. What's changed is that this layer, built by hand for the last two years, is now something AWS ships as a managed primitive — turning a few weeks of scaffolding into a single deployable resource.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article