aws-agentic-ai-reference-architecture
AWS agentic AI blueprint built to survive production: Bedrock, MCP, guardrails, telemetry.
git clone https://github.com/fernando-moretes/app-aws-agentic-ai-reference-architecture.gitListen to guide
generated on playGenerated only on first play
Powered by Amazon Polly + OmniVoice
A bilingual reference architecture for agentic AI workloads on AWS — Amazon Bedrock, tools over MCP, guardrails, an identity boundary, observability and a DevSecOps pipeline — documented with ADRs, a threat model and a Well-Architected review, plus a static site published on Vercel.
Why this repository exists
Most AI demos stop at the chat UI. It works in the video, it works in the meeting, and the question nobody asks is the one that matters: who operates this agent at 2 AM when it loops calling the same tool for the fortieth time?
This repository grew out of that question. After years operating platforms in regulated environments, I learned that an agent in production is not a model with access to functions — it's a distributed system with a non-deterministic component in the middle. It needs what every other distributed system needs: bounded retries, a circuit breaker, a fallback path, an audit trail, a cost ceiling and a human with veto power.
The goal here is not an installable product. It's a blueprint: the design, the decisions recorded as ADRs, the threat model, the review against the Well-Architected pillars and the pipeline that validates all of it on every commit. Someone arriving to design an agent platform on AWS finds the skeleton ready to adapt — and, more importantly, finds the reasoning behind each choice, which is what actually gets lost when a project changes hands.
The published version at agentic-ai.moretes.com is the reading surface; the repository is the source, with the diagram in docs/diagrams/architecture.mmd and the documentation in docs/architecture.md.
What makes up the reference stack
How a request flows through the architecture
Every call crosses the identity boundary, passes the guardrail, reaches the agent runtime and only then touches tools or data — with telemetry and audit events emitted in parallel.
- Identity broker · IAM · inbound/outbound authz
- Bedrock Guardrails · política de entrada e saída
- Agent runtime · Lambda / ECS / AgentCore-style
- Amazon Bedrock · modelo primário + fallback
- MCP Tool Gateway · allow-list de ferramentas
- Knowledge Bases / · OpenSearch Serverless
- Sistemas internos · APIs de negócio
- CloudWatch · X-Ray · OTel · traces de raciocínio e tool calls
- EventBridge · HITL + eventos de auditoria
How the pieces fit together
Identity boundary: nothing reaches the agent without passing the identity broker, and nothing leaves the agent toward an internal system without a credential scoped to that call. This separates two questions that usually get conflated — "may this user talk to the agent?" and "may this agent call this API on behalf of this user?". A single execution role for all traffic answers both with "yes" and eliminates the isolation.
Guardrails ahead of the runtime: Bedrock Guardrails evaluates the inbound prompt and the outbound response. Keeping that step outside the agent's code means the responsible-AI policy is auditable as configuration, not as emergent behavior hidden in a system prompt.
MCP Tool Gateway with an allow-list: the agent doesn't discover tools; it receives a list. Every tool invocation emits its own telemetry, which answers the most common incident question — "what exactly did the agent do?" — without reconstructing the reasoning from the model's log.
EventBridge for what is asynchronous: human approval and audit trails don't fit the synchronous cycle of a request. Emitting an event and letting the agent wait for the verdict is what allows a human to decide without holding a connection open.
Resilience and cost are design decisions, not on-call decisions
What separates this design from a demo is the part that only shows up when something fails. Bounded retries and a circuit breaker on every model and tool call: an agent with no iteration ceiling consumes tokens indefinitely, and the breaker is what keeps one degraded tool from taking the rest down. A fallback model strategy: when the primary model answers with throttling or unavailability, routing drops to a second model instead of returning an error to the user. Human escalation as a first-class path, not a caught exception.
On cost, the rule is the same as on any platform I spent years operating: what hurts is not the first month's bill — it's the cost of maintaining, auditing and fixing over years. That's why the design carries a token budget per request and per period, model routing by task complexity and caching of responses and retrieved context. None of the three is new; the difference is treating them as part of the architecture, with a metric and an alarm, rather than as an optimization for later.
All of it is recorded in ADRs, a threat model and a review against the Well-Architected pillars, and the CI pipeline runs the checks on every commit. GitFlow, Vercel secrets and the security pipeline details live in OPERATIONS.md.
How to run it locally
- 1
Clone the repository
git clone https://github.com/fernando-moretes/app-aws-agentic-ai-reference-architecture.gitand enter the directory. Readdocs/architecture.mdbefore anything else — it's the map for the rest. - 2
Install the Python package and run the suite
python -m pip install -e . pytestfollowed bypytest -q. The suite is what CI runs; if it passes on your machine, the pipeline will pass too. No AWS credentials are needed for this step. - 3
Build the frontend
cd frontend && npm ci && npm run lint && npm run build. It's a dependency-light static site ready for Vercel — the same one served at agentic-ai.moretes.com. - 4
Open the diagram and the documents
docs/diagrams/architecture.mmdrenders in any Mermaid viewer. The ADRs and the threat model are the parts most worth copying into your own project — adapt the decisions, not just the drawing. - 5
To publish, follow OPERATIONS.md
The flow is GitFlow; secrets live in Vercel, never in the repository; the security pipeline runs before deploy. Skipping this step is the fastest way to leak a token in a commit.
git clone https://github.com/fernando-moretes/app-aws-agentic-ai-reference-architecture.git
cd app-aws-agentic-ai-reference-architecture
# Python package + test suite (same checks CI runs)
python -m pip install -e . pytest
pytest -q
# Static frontend (Vercel-ready)
cd frontend
npm ci
npm run lint
npm run buildWhat this repository is not
It is not a terraform apply that stands up the whole platform. It's a reference architecture: design, decisions, threat model, Well-Architected checklist and a site that presents them. The Python code validates what is documented; provisioning Bedrock, Guardrails, OpenSearch and EventBridge in your account remains your job — and should be, because account limits, region and regulatory regime change the answer.
Frequently asked questions
Why MCP instead of direct function calling on Bedrock?
Because the allow-list needs to live outside the prompt. With an MCP gateway, the tool set is versioned, auditable configuration; every invocation goes through a single point where authorization and telemetry can be applied. Direct function calling works for a prototype — it stops working when three teams publish tools for the same agent.
OpenSearch Serverless or Bedrock Knowledge Bases?
Use Knowledge Bases when the standard ingestion pipeline is enough and you want zero operations. Use OpenSearch Serverless when you need control over chunking, a tenantId filter in the query, or an index shared with another workload. The design accepts both; the choice is your ADR.
Do I need an AWS account to get value from the repository?
Not to read it, run the tests and build the site. You need one when you implement the design — and at that point start with the threat model and the Well-Architected review, which is what saves the most rework.
References
Who it's for
Use this repository when: you're designing an agent platform on AWS for an environment with real regulatory requirements — BACEN, LGPD, PCI-DSS — and need to justify every decision to an architecture board or an audit; when the team already knows how to call Bedrock and what's missing is the operational part — identity, guardrails, breakers, audit, cost; or when you want a starting point for your own ADRs instead of a blank page. Don't use it when the goal is a two-week prototype to validate an idea: there the weight of the architecture slows you down more than it helps, and a chat with direct function calling does the job. The difference between the two scenarios is not the model — it's who answers when the agent does the wrong thing in production.
Architecture, AWS, AI and market deep dives — straight to your inbox. Free.
No spam · unsubscribe anytime