# Maintenance and the closed loop

> In a closed loop, the agent starts with no one asking for it: on an alert or on a schedule. What the agent finds goes back into the lifecycle as a new intent, and people triage it.

Detection stays deterministic. A script watches a stable metric: CI test failures, server errors after a deploy, PR duration. It computes a control band over a rolling window. When the first threshold is crossed, it logs the event. At the second, it asks the agent for a diagnosis, in read-only mode. At the third, the agent may open a PR or run an approved procedure, such as a rollback.

The agent writes its diagnosis up as an intent. The team that owns the service triages it: fix, schedule or close. Items closed without action help tune the thresholds. After each fix, a new case joins the evaluation suite.

Security works the same way. A one-off scan goes stale quickly, because code changes and each model generation finds new flaws. So scheduled scans run on top of the pipeline checks on every change. Their fixes go through PR review.

The loop also closes on each change. The agent can read production logs, traces and metrics, so it follows its own PR all the way to production. It compares metrics before and after. If it spots a regression caused by its change, it reacts through an approved path: a fix, switching off the feature flag or a rollback through the pipeline. The ticket only closes once the change runs without degradation. This follow-through extends a software factory that runs from ticket to production, though few organizations do it yet.

Three workflows are good places to start: fixing bugs from tickets, supporting on-call and updating vulnerable dependencies. On call, the agent links a latency spike to a deploy and proposes a fix for approval. In each case, the agent starts outside any developer’s session: it is an ambient agent, with its own identity and permissions scoped to its task, and the platform supplies its context and keeps a record of its work.

**When**: Once the factory already runs with reliable checkpoints and an up-to-date evaluation suite.

**Trade-offs**: Agents handle maintenance without waiting to be asked. The cost: badly tuned thresholds create noise, and every automatic action has to be approved and tested in advance.

## Where to start

- Pick a metric with a stable baseline
- Write a tested detection script
- Define what the agent may do at each level
- Give agents read-only access to production logs and metrics
- Test the rollback ahead of time
- Turn every fixed incident into an evaluation

## Common mistakes

- Handing detection itself to the model
- Letting the agent act in production outside approved paths
- Never adjusting thresholds and drowning in noise

## Metrics

- Time from breach to the intent reaching the triage queue
- Share of findings that become merged fixes
- Repeat incidents of the same kind

## Sources

- [Anthropic, The AI-native SDLC playbook](https://claude.com/fr/resources/articles/the-ai-native-sdlc-playbook)
- [Atlassian, The AI SDLC transformation playbook](https://www.atlassian.com/blog/ai-at-work/ai-sdlc-transformation-playbook)
- [Port, AI SDLC: a practical guide to SDLC AI agents](https://www.port.io/blog/ai-sdlc)
