AWS Builder Center

Introducing the AWS Guidance for Agentic AI Operational Foundations

Agent prototypes often stall before production because the platform pieces around them are missing. This post introduces the Guidance for Agentic AI Operational Foundations on AWS, a Terraform sample that deploys a LangGraph customer service agent on Amazon Bedrock AgentCore Runtime. It shows how to connect a central model gateway, Amazon Bedrock Guardrails, tracing with Amazon Bedrock AgentCore Observability and Langfuse, and offline evaluation, so teams can ship agents with governance built in.

Building a working agent demo has become fast. A developer can wire an LLM to a few tools and a knowledge base in an afternoon. Getting that same agent approved for production usually takes much longer, and the agent code is rarely the reason.
The delays come from questions that sit around the agent. Which teams can use which models, and who pays for the tokens? What happens when a user tries to get the agent to give advice it shouldn't, or pastes a Social Security number into the chat? When the agent gives a wrong answer, how do you find out which step went wrong? And when someone changes the prompt, how do you know the agent didn't get worse?
To help answer these questions, AWS offers the  Guidance for Agentic AI Operational Foundations on AWS , part of the  AWS Solutions Library . This post is for platform engineers, ML engineers, and architects who want a working example of the shared capabilities that agentic AI projects need before they scale from one agent to many.

The Challenge: The Platform Layer Gets Skipped

Agent prototypes tend to focus on the agent itself. The shared platform capabilities that production teams expect get left for later, and then they block the launch:
  • Model access and cost control: When each project calls model providers directly, nobody has a central view of usage or spend. Limiting which teams can use expensive models, or setting budgets per team, means changing every application.
  • Safety and responsible AI: Agents take free-form input from users and generate free-form output. Without screening on both sides, harmful content, off-limits topics, and personal data can pass straight through.
  • Visibility into agent behavior: A single answer can involve several LLM calls, a knowledge base lookup, and an external API call. Without step-by-step traces, debugging a bad answer is guesswork.
  • Quality measurement: Prompts, models, and tools change often. Without a repeatable evaluation, teams can't tell whether a change made the agent better or worse.
Each project can solve these problems on its own, but that repeats the same work and produces inconsistent results. A shared platform layer solves them once.

AWS Guidance for Agentic AI Operational Foundations

This Guidance gives you a  deployable code sample  that uses a customer service (CX) agent to demonstrate three platform capabilities working together:
  1. A centralized AI model gateway for cross-project governance such as cost tracking, usage limits, and model access control.
  1. Guardrails that screen user input and agent output for harmful content, denied topics, and sensitive information.
  1. Observability that records each step of the agent's reasoning as a trace, plus an offline evaluation harness built on those traces.
The agent itself is built with LangGraph and runs on Amazon Bedrock AgentCore Runtime. Infrastructure is defined in Terraform (OpenTofu also works). The Guidance deliberately uses tools that are popular with AWS customers and keeps the code free of extra abstraction layers. If you prefer different tools for some of these capabilities, switching takes some effort but should be straightforward.

Architecture Overview

The sample agent answers customer questions for a fictional broadband provider. It can search a knowledge base of help articles, search the web, and create or look up support tickets. Every request passes through the platform capabilities described above.


Request Flow

A typical request goes through the architecture like this:
  1. Sign-in: The user signs in to a Streamlit chat application, which runs locally on the builder's machine. Amazon Cognito authenticates the user and issues a JWT.
  1. Invocation: The app sends the user's message with the JWT to the agent's  /invocations  endpoint on Amazon Bedrock AgentCore Runtime. The runtime's JWT authorizer validates the token against the Amazon Cognito user pool before the request reaches the agent.
  1. Trace start: The agent opens a trace in Langfuse so every later step is recorded.
  1. Input screening: The agent sends the user's message to Amazon Bedrock Guardrails. If the guardrail blocks it, the agent returns a configured message instead of calling the model.
  1. Model call: The agent calls the LLM through the model gateway using the OpenAI-compatible API. By default the gateway routes the request to an Anthropic Claude model on Amazon Bedrock.
  1. Tool calls: If the model asks for tools, the agent runs them:
  •  retrieve_context  searches an Amazon Bedrock Knowledge Base backed by Amazon OpenSearch Serverless, with documents loaded from Amazon S3.
  •  web_search  uses Tavily (optional).
  •  create_support_ticket  and  get_support_tickets  call the Zendesk API (optional).
  •  get_conversation_history  reads earlier turns from Amazon Bedrock AgentCore Memory.
  1. Final answer: The agent makes another model call through the gateway to write the response.
  1. Output screening: The response goes back through Amazon Bedrock Guardrails before it's returned.
  1. Trace end and response: The agent closes the Langfuse trace with metadata and metrics, then returns the answer to the Streamlit app. Users can rate the answer in the app, and that feedback is recorded with the trace.
Supporting services handle configuration and secrets. AWS Secrets Manager stores the gateway API key and the Langfuse, Tavily, and Zendesk credentials. AWS Systems Manager Parameter Store holds resource IDs such as the guardrail ID. The agent container image is built during deployment and stored in Amazon ECR, and runtime telemetry goes to Amazon CloudWatch through Amazon Bedrock AgentCore Observability.

Key Features and Benefits

Centralized Model Gateway

Benefit: Every model call from every project goes through one place, so platform teams can control access, track usage, and set limits without changing application code.
How: The agent doesn't call model providers directly. It calls a gateway with an OpenAI-compatible API, using an API key issued by the gateway. The Guidance recommends the LiteLLM-based  Guidance for Multi-Provider Generative AI Gateway on AWS , which provides:
  • Access to many models from Amazon Bedrock and other providers through one API
  • Load balancing across model deployments
  • Usage and cost tracking by key, team, and user
  • Budgets and rate limits at the model, key, team, and user level
Because the agent only knows the gateway URL and a model name, you can change the model behind it in the gateway's configuration.

Amazon Bedrock Guardrails on Input and Output

Benefit: Harmful content, off-limits topics, and sensitive personal data are caught before they reach the model or the user.
How: The agent calls Amazon Bedrock Guardrails twice per request: once on the user's message and once on the agent's response. The guardrail deployed by Terraform includes:
  • A content filter for hate speech, applied to input and output
  • Sensitive information filters that anonymize US Social Security numbers and bank routing numbers
  • A denied topic for investment advice, as an example of a topic a regulated business might need to avoid
  • A managed profanity word list
These are starting points. You can add more content filter categories, prompt attack detection, more PII types, or your own denied topics in the guardrail module to match your policies. Guardrails can be turned off for local development with a setting.

Tracing with Amazon Bedrock AgentCore Observability and Langfuse

Benefit: You can see each step the agent took to produce an answer, including which tools it called and how long each step took.
How: The Guidance combines  Amazon Bedrock AgentCore Observability , which uses OpenTelemetry and sends data to Amazon CloudWatch, with  Langfuse , an open-source LLM observability platform. Langfuse traces show:
  • Every LLM call and non-LLM step, such as knowledge base retrieval and API calls, in a nested timeline
  • Response times, token usage, and estimated cost per request
  • The agent's reasoning and tool choices
  • User feedback attached to each conversation
You can self-host Langfuse on AWS using a  separate AWS sample  or use Langfuse's cloud service.

Offline Evaluation

Benefit: You can measure agent quality with a repeatable test, and run it again after every change to prompts, models, or tools.
How: The Guidance includes two scripts:
  •  offline_evaluation.py  sends a set of test queries to the agent, waits for the traces to appear in Langfuse, and pulls metrics from them.
  •  response_quality_evaluator.py  uses a model on Amazon Bedrock as a judge to score each response.
You define test cases in a  groundtruth.json  file, listing each query and the tools you expect the agent to use. The evaluation reports:
  • Success rate: the share of queries that returned a response without error
  • Tool accuracy: how often the agent picked the expected tools
  • Retrieval quality: relevance scores from knowledge base retrieval
  • Response quality: faithfulness, correctness, and helpfulness, each scored from 0.0 to 1.0 by the judge model
  • Latency: total time and time per tool
Results are saved to CSV files, so you can compare runs over time.

Conversation Memory

Benefit: The agent can refer back to earlier turns in a conversation.
How: Terraform deploys an Amazon Bedrock AgentCore Memory resource with a 30-day event expiry. The agent gets a  get_conversation_history  tool that reads earlier events for the current user and session.

Infrastructure as Code

Benefit: You can deploy, change, and tear down the whole sample in a repeatable way.
How: Terraform modules define the Amazon Bedrock AgentCore Runtime and Amazon Bedrock AgentCore Memory, the AWS Identity and Access Management (IAM) execution role, the guardrail, the knowledge base with its Amazon OpenSearch Serverless collection and Amazon S3 bucket, the Amazon Cognito user pool, AWS Secrets Manager secrets, and AWS Systems Manager Parameter Store parameters. Terraform also builds the agent container with Docker or Finch and pushes it to Amazon ECR.
The table below summarizes the main capabilities and the components that provide them:
Capability Area
Specific Capability
How It's Enabled
Agent
Customer service agent with tools
LangGraph on Amazon Bedrock AgentCore Runtime
Identity
User sign-in and token validation
Amazon Cognito + Amazon Bedrock AgentCore Runtime JWT authorizer
Model access
One API for many models, usage tracking, budgets, rate limits
Model gateway (Multi-Provider Generative AI Gateway Guidance)
Safety
Input and output screening
Amazon Bedrock Guardrails
Knowledge
Search over your documents
Amazon Bedrock Knowledge Bases + Amazon OpenSearch Serverless + Amazon S3
Memory
Conversation history
Amazon Bedrock AgentCore Memory
Tools
Web search and ticketing (optional)
Tavily, Zendesk
Observability
Step-by-step traces, metrics, user feedback
Langfuse + Amazon Bedrock AgentCore Observability + Amazon CloudWatch
Evaluation
Tool accuracy and response quality scoring
Offline evaluation scripts + Amazon Bedrock judge model
Secrets and config
Credentials and resource IDs
AWS Secrets Manager + AWS Systems Manager Parameter Store
Deployment
Infrastructure as code
Terraform or OpenTofu

Getting Started: Deploying the Foundations

This section gives a high-level overview of deploying the Guidance.
Disclaimer: This walkthrough is based on the  GitHub repository  documentation available at the time of writing. Always check the repository for current instructions. Deploying this solution incurs costs for the AWS resources used, and optional third-party services have their own pricing. As an AWS Guidance sample, support is best effort through the repository's GitHub Issues.

Prerequisites

  • An AWS account with permissions to create AWS Identity and Access Management (IAM) roles and policies and to deploy the Amazon Bedrock AgentCore, Amazon Bedrock, Amazon OpenSearch Serverless, Amazon Cognito, and other resources in the architecture.
  • AWS Command Line Interface (AWS CLI) installed and configured, Terraform or OpenTofu, uv (or another Python environment), and Docker or Finch.
  • A macOS or Linux shell. Windows Subsystem for Linux may work but hasn't been fully tested.
  • Optional: a Langfuse project and API keys, a Tavily API key, and a Zendesk API token.

Step 1: Configure the Deployment

Clone the repository and create your configuration file from the example:
git clone https://github.com/aws-solutions-library-samples/guidance-for-agentic-ai-operational-foundations-on-aws.git
cd guidance-for-agentic-ai-operational-foundations-on-aws
cp infra/terraform.tfvars.example infra/terraform.tfvars
The defaults for the core settings work for most cases. Terraform stores its state in an Amazon S3 bucket you provide when you initialize. If you'd rather use local state, remove the  backend "s3"  block from  infra/terraform.tf .

Step 2: Connect the External Components

Add the values for the components that this Guidance connects to in  infra/terraform.tfvars :
  • Model gateway (required):  gateway_url  and  gateway_api_key 
  • Langfuse (optional):  langfuse_host ,  langfuse_public_key , and  langfuse_secret_key 
  • Tavily (optional):  tavily_api_key 
  • Zendesk (optional):  zendesk_domain ,  zendesk_email , and  zendesk_api_token 
Terraform stores these values in AWS Secrets Manager for the agent to read at runtime. Keep  terraform.tfvars  out of source control because it contains credentials.

Step 3: Deploy

cd infra
terraform init
terraform apply
When the apply finishes, Terraform prints outputs such as the Amazon Cognito user pool ID, the guardrail ID, and the knowledge base ID.

Step 4: Load Your Documents and Create a User

Copy the documents you want the agent to search into the knowledge base bucket, then start an ingestion job:
aws s3 cp your-documents/ s3://$(terraform output -raw s3_bucket_name)/ --recursive

aws bedrock-agent start-ingestion-job \
--knowledge-base-id $(terraform output -raw knowledge_base_id) \
--data-source-id $(terraform output -raw data_source_id)
Ingestion runs in the background. You can check its progress in the Amazon Bedrock console.
Next, create a user for yourself in the Amazon Cognito user pool, either in the Amazon Cognito console or with the AWS Command Line Interface (AWS CLI). The repository README includes example CLI commands. For more than one user, let Amazon Cognito generate temporary passwords and send them to users by email, as described in the  Amazon Cognito developer guide .

Step 5: Chat with the Agent

Run the Streamlit app on your machine:
cd cx-agent-frontend
uv venv
uv sync --frozen
uv run streamlit run src/app.py --server.port 8501 --server.address 127.0.0.1
Open  http://localhost:8501 , sign in, and ask a question about your documents. To see a guardrail in action, ask the agent where you should invest your money. The denied topic blocks the request, and the agent declines.
If you configured Langfuse, open your project to see the trace for each request. You can also talk to the agent from the  chat_to_agentcore.ipynb  notebook in the repository.

Step 6: Run an Evaluation

Create a  groundtruth.json  file with your test queries and the tools you expect the agent to use:
[
{
"query": "How do I reset my router hub?",
"expected_tools": ["retrieve_context"]
}
]
Set the Langfuse environment variables ( LANGFUSE_SECRET_KEY ,  LANGFUSE_PUBLIC_KEY ,  LANGFUSE_HOST ) and  AGENT_ARN , make sure your AWS credentials are available, and run the evaluation:
python offline_evaluation.py
The script prints a summary of success rate, tool accuracy, retrieval quality, latency, and response quality scores, and saves detailed results to CSV files.

Step 7: Iterate

The Streamlit app works with both a local agent and the deployed one, so you can develop locally and test against the same UI. See  cx-agent-backend/README.md  in the repository for the local setup.
When you change the agent code,  terraform apply  builds and pushes a new container image. It doesn't redeploy the Amazon Bedrock AgentCore Runtime automatically. To roll out the new image, choose Update hosting on the runtime in the Amazon Bedrock AgentCore console.

Cleanup

To remove the resources when you're done, run  terraform destroy  from the  infra  folder. If it reports that the Amazon ECR repository or Amazon S3 buckets aren't empty, empty them and run the command again. Then delete the Terraform state bucket if you created one, and clean up the model gateway, Langfuse, and any Tavily or Zendesk resources by following their own documentation.

Why This Guidance Matters for AWS Builders

  • A pattern for the platform layer: The Guidance shows how a model gateway, guardrails, tracing, and evaluation fit around one agent, so platform teams can offer them as shared services to many agent teams.
  • Central governance without app changes: Routing model calls through a gateway lets platform teams manage model access, budgets, and rate limits in one place.
  • Safety checks on both sides of the model: Amazon Bedrock Guardrails screens what users send and what the agent returns, using policies you define.
  • Debugging you can act on: Traces show each LLM call and tool call with timing and token counts, so you can find where an answer went wrong.
  • Quality you can measure: An evaluation set and an LLM judge give you scores to compare before and after each change.
  • Swappable parts: Each capability uses a common tool with little abstraction, so you can replace one when your organization has a different standard.

Conclusion: Build the Foundations Once, Use Them for Every Agent

Most of the work of putting an agent into production is the platform around it: model access, safety, visibility, and quality checks. The Guidance for Agentic AI Operational Foundations on AWS shows these capabilities working together around a real agent on Amazon Bedrock AgentCore, deployed with Terraform, so you can adapt the pattern to your own agents.
Explore the  code on GitHub , deploy it in a development account, and try the guardrails, traces, and evaluation with your own documents and test cases. For the model gateway it builds on, see the  Guidance for Multi-Provider Generative AI Gateway on AWS 
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