Skip to content
Generative AI

Six Layers Around the Model: Engineering Idempotent, Observable AI Agents for Cloud Operations

An AI operations agent fixed the same incident three times in one night. Every root cause sat outside the model. Here are the six layers of engineering around it, and how to…

PCPraveen ChandrasekharanDecember 2, 2026 · 11 min read

The incident that was fixed three times

Between 2 a.m. and 5 a.m., an artificial intelligence (AI) operations agent fixed the same incident three times.

That evening’s release of the checkout service had started leaking database connections. By 2:05 a.m. the connection pool was full, new requests had none left to use, and checkout began returning errors. The alarm started the agent. It saw the full pool, restarted the service, watched the errors stop and closed the ticket as resolved. It never asked why the pool had filled up.

The restart had freed the leaked connections, but it hadn’t stopped the leak. At 3:05 a.m. the pool was full again. The alarm fired, and the agent started a fresh run with no memory of the first. It opened a new ticket, restarted the service and closed the ticket. At 4:05 a.m. it happened a third time. Each outage lasted about 20 minutes, from the moment the pool filled until the restarted service was taking payments again. Each time, the agent reported success, so nobody was paged.

At 4:50 a.m., the customer’s payments team called to ask why overnight orders had dropped three times. The on-call engineer saw three resolved P1 (priority 1, highest-severity) tickets for the same service, an hour apart, and found the cause in five minutes: the release that had gone out that evening. They rolled it back, and checkout was stable by 5:10 a.m. The next morning, the developers traced the leak to an error path that never returned its connection to the pool. Had a human been paged at the first alarm, it would have been one outage of under 30 minutes instead of three.

The model behind the agent was not the problem. The team had benchmarked five frontier models and deployed the one that scored highest. When the postmortem was complete, every root cause sat outside the model, in the engineering around it.

The incident is a composite, drawn from failure patterns that recur across the industry. The engineering around the model can be described as six layers. Below is how each layer failed, what fixes it, and how to build it on Amazon Web Services (AWS).

Layer 1. Trigger and experience: know when to hand over to a human

What failed: Starting from the alarm was right; the agent was at work within a minute each time. But nothing ever came out the other end. Every run ended in “Resolved,” so the agent never escalated, and each ticket said only, “Service restarted, errors cleared.” Nobody reading the third ticket could tell it was the third.

The fix: Decide in advance when the agent must hand over to a human, and make one of those rules about repetition: the same fix on the same service twice in one night means the fix isn’t working, however well each run went. Escalate then, and whenever the agent can’t resolve something. The escalation is a one-paragraph summary: the evidence, the action it proposes and the decision it needs. A person should be able to decide in under a minute without opening a log. And every ticket should say what a person needs to spot a pattern: what the agent saw, what it did, and whether it has seen this before.

On AWS: CloudWatch alarms reach Amazon EventBridge natively, and EventBridge starts the investigation. Escalations go to an on-call paging tool, such as AWS Systems Manager Incident Manager or PagerDuty, not to a chat thread or a ticket nobody reads at night.

Layer 2. Orchestration and state: remember what was done, and make every action idempotent

What failed: Each alarm started a new run with no record of the runs before it. The third run had no idea that the first two had restarted the same service, for the same reason, an hour apart. To the agent, it was three unrelated incidents.

The fix: Give the agent a memory that outlives a single run. Keep state per service: open and recent incidents, what was tried and what happened. When an alarm fires, link it to any recent incident on the same service before doing anything: the same symptom and the same fix within a few hours is one incident, not three. Within a run, save progress after every step, so a retry resumes where it stopped instead of starting over. Give every action that changes something an idempotency key, built from the incident identifier (ID) and the step and never generated by the model. Here, the second alarm would have joined the first incident, its restart would have carried the same key as the first restart, and instead of running again it would have returned the earlier result. The agent would have had to try something else, or ask a human.

On AWS: Keep each service’s incidents and each run’s checkpoints in DynamoDB or Aurora PostgreSQL. AWS Step Functions keeps state within a run and retries only the step that failed. For tool calls, the idempotency utility in Powertools for AWS Lambda stores each key and returns the saved result when the same key arrives again.

Where double payments come from, and why Layer 2 stops them

A double payment is the same missing memory. A run charges the card, then times out before it can record that it did. The retry starts fresh, doesn’t know the charge went through, and charges again. Replace “charge the card” with “pay the supplier invoice” and the story is the same.

Layer 2 stops it. The retry resumes from the last completed step, and the payment carries an idempotency key built from the order or invoice number. Layer 3 backs this up, because the payment tool itself refuses a key it has already processed. Layer 5 adds human approval for high-value or irreversible payments.

Layer 3. Tools and deterministic logic: the agent proposes, code decides

What failed: The closure rule existed only in the prompt: close a ticket once the error rate has stayed below 1% for 15 minutes. Each time, the rule passed, because the restart really had cleared the errors. But it only looked at errors, never at whether the cause was gone. Connections in use were already climbing again at the same rate.

A restart frees the leaked connections, then the pool fills again within the hour

Illustrative pattern, not data from a real incident

The fix: Move rules that must hold into code. The closure check becomes a unit-tested function that queries the signals itself and returns pass or fail. It watches the trend, not a single reading: connections in use falling after a restart is not a pass if they are climbing again at the same rate. The model can recommend closing a ticket; only the function can close it. Give the agent its tools through one connector service, and keep every tool read-only unless you deliberately switch on an action that changes something. Each of those actions comes with its own check in code.

On AWS: The closure check is a Lambda function that the ticket tool calls before it closes anything. It reads CloudWatch metrics directly: the load balancer’s 5xx (server error) count and the database’s connection count over the last 30 minutes, failing if connections are still climbing. The restart tool is another Lambda function that records each restart per service in DynamoDB and refuses a second one within 12 hours unless an engineer approves it. Both sit behind one gateway, such as Amazon Bedrock AgentCore Gateway, and the agent’s own AWS Identity and Access Management (IAM) role has no direct access to Amazon Elastic Container Service (ECS), so it can’t go around the checks.

Layer 4. Trusted context: give the agent what is current, including what just changed

What failed: The prompt included the customer’s runbook for the checkout service, last updated a few weeks earlier. Since then, checkout had started storing orders in a new relational database. The runbook knew nothing about it. Its only step for slow responses was “restart the service,” written when checkout held no database connections and a restart cleared everything. The agent did see that the connection pool was full, but the runbook had nothing to say about pools: nothing about finding what was holding the connections, checking whether a release had just gone out, or rolling it back. So each time, the agent fell back on the one step it had.

The fix: Don’t paste a runbook into the prompt and hope it is current. Let the agent look things up as it works: that customer’s runbooks, architecture notes and past incidents, and what has changed recently, such as releases and configuration changes. A full pool a few hours after a release points straight at the release. Check each runbook’s date against the systems it covers. If a database was added after the runbook was last updated, tell the agent the runbook is out of date, so it treats the advice with suspicion and escalates instead of following it blindly. Past incidents come back as evidence to check, not answers to copy: a restart that held for only 41 minutes is evidence that restarting isn’t the fix.

On AWS: An Amazon Bedrock knowledge base holds the customer’s runbooks and past incidents, filtered to that customer’s accounts. Recent changes come from the ECS service’s deployment history and AWS CloudTrail. A small custom check compares each runbook’s last update with the change history of the resources it covers in AWS Config, such as a database added after the runbook was written, and marks the runbook as stale.

Layer 5. Evaluation and human control: test before you trust

What failed: The agent had been demonstrated on three incidents and properly tested on none. Every test incident ended the moment the errors cleared. Nobody had tried it on a fault that comes back after it has been fixed.

The fix: Build a golden set from your own past incidents, each with a root cause agreed by senior engineers, and run every change to a prompt, tool or model against it before it ships. Include the cases that fool people too: a leak that comes back an hour after a restart, and the same alarm three times in one night. Use deterministic checks where the answer is a fact: did the agent check whether connections were still climbing before it closed the ticket, did it look at what had changed recently, did it escalate the second time? Use a large language model (LLM) judge for what needs judgment, such as the quality of the reasoning. Decide which actions need a human’s approval. Here, a first restart can run on its own, but a second restart of the same service, or closing a P1 that has already come back, waits for an engineer. Engineers stop digging through logs at 3 a.m. and start reviewing the agent’s conclusions.

On AWS: Amazon Bedrock evaluations for LLM-as-a-judge scoring, run in the deployment pipeline so a change that lowers the score doesn’t ship. Step Functions task tokens pause a workflow until an engineer approves, for example before a second restart. Agents running elsewhere use the same pattern: a pending action that waits for an approval event.

Layer 6. Runtime and control plane: one gateway for every model call

What failed: When the postmortem asked why the agent restarted the service three times, nobody could answer. It called the model provider directly, with an application programming interface (API) key kept in an environment file, and nothing recorded what it had read, what it concluded, or why it chose a restart each time. Nothing limited it either: had the leak continued, it would have kept restarting all night.

The fix: Route all model traffic through one LLM gateway inside your own cloud account. Trace every prompt, tool result and response, so any decision can be replayed. Here, the three runs would have sat side by side, each reading the same full pool and the same runbook and choosing the same restart. Give each agent its own identity and budget, and have the gateway stop calls when the budget is spent, not leave you to find out from the bill.

On AWS: Model invocation logging and traces in Amazon CloudWatch, so every run’s prompts and responses are kept. Amazon Bedrock, with an IAM role and an application inference profile per agent to track its cost. The gateway enforces the hard limit; AWS Budgets actions can back it up by blocking access, but billing data arrives too late to be the only control. Amazon Bedrock Guardrails, using the ApplyGuardrail API on logs and tool output before they reach the model.

The Comprinno view: an agent is a production service

Fix the six layers and the same model that fixed the incident three times would have fixed it once, by paging a human after the first restart. Nothing about the model has to change.

An operations agent is a production service, not a feature. It needs what every production service needs: a service level objective (SLO), a runbook, an on-call owner, change management and a cost budget, the same as the checkout service it looks after. If you wouldn’t let an unversioned script with a shared API key restart your production checkout three times in a night without telling anyone, don’t let an agent do it either.

Models will keep getting better and cheaper, and the leaderboard will change every quarter. What lasts is what you build around them: your golden incident sets, your deterministic checks, your context boundaries, and the engineers who own the system at 3 a.m.

Building that takes more than choosing a model. It takes cloud architecture, AI engineering, security and operations working as one team. That is where Comprinno, an AWS Premier Tier Services Partner and managed service provider, comes in. We run cloud operations for our customers, and we build and govern the agents that help run them.

Want to put agents into production without waking up to three resolved P1s? Talk to Comprinno about your cloud, AI and security roadmap.

The six-layer framework is adapted from a post by Mark Ajzenstadt (@mardehaym) on X.

PC

Written by Praveen Chandrasekharan, Chief Product Officer (CPO), Comprinno

CloudScape newsletter

Cloud insights, proven patterns and success stories.

Simplified for your next step. Delivered to your inbox.