> ## Documentation Index
> Fetch the complete documentation index at: https://docs.latitude.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Healing Agents

> Close the loop from detected production failure to reviewed pull request by dispatching your coding agent with the evidence attached.

A self-healing agent is one whose production failures reach a coding agent automatically, with the evidence attached, so remediation starts from the detection instead of from a person relaying context. Latitude closes that loop end to end: traffic is observed, recurring patterns become tracked [signals](https://docs.latitude.so/signals/overview.md), escalations dispatch your coding agent, and the fix lands as a pull request that a person reviews, backed by a regression test in your CI.

![The self-healing loop: your agent, telemetry, signals, escalation, coding agent, pull request.](https://mintcdn.com/latitude-monitoring/1Be7ZyGZ0yY1PfcU/images/self-healing-loop-light.png?fit=max\&auto=format\&n=1Be7ZyGZ0yY1PfcU\&q=85\&s=d4a28f540e5b32c0108854e2a1f29c2c)

The self-healing loop, from production failure to reviewed pull request.

## How the loop closes

**1. Detect failures in production**

Connect [telemetry](https://docs.latitude.so/telemetry/start-tracing.md) so every interaction arrives as a trace and multi-turn conversations group into [sessions](https://docs.latitude.so/observability/sessions.md). Find failures with [Search](https://docs.latitude.so/search/overview.md) when you can describe them, or let [Behaviors](https://docs.latitude.so/behaviours/overview.md) surface the topics and trends you would not think to look for. [Annotations](https://docs.latitude.so/annotations/overview.md) and [flaggers](https://docs.latitude.so/annotations/flaggers.md) record what you find, and Latitude groups those into named, tracked [signals](https://docs.latitude.so/signals/overview.md).

**2. Score live traffic continuously**

Give a signal an [evaluation](https://docs.latitude.so/evaluations/overview.md), a script that can combine code rules, semantic similarity, and LLM judgment, and live traffic is scored as it arrives. The evaluation's [trigger](https://docs.latitude.so/evaluations/triggers.md) controls how much: generated evaluations start at a 10 percent sample, so raise the sampling and adjust the filters if the signal needs full coverage. Evaluations generated from your annotations carry an [alignment record](https://docs.latitude.so/evaluations/alignment.md), so how often the script agrees with a human reviewer is a measured number.

**3. Escalate what is growing**

A signal escalates when its recent occurrences clear its own weekly rhythm, and [monitors](https://docs.latitude.so/monitors/overview.md) extend the same mechanism to saved searches and raw traffic metrics such as cost, latency, or cache hit rate. Either one opens an incident.

**4. Dispatch your coding agent**

With [agent dispatch](https://docs.latitude.so/agent-dispatch/overview.md) configured, an escalating signal or an open incident wakes your coding agent with a prompt, a deep link, and sample failing traces. Latitude is the trigger and the context provider, not the agent runtime: the dispatched agent runs in your environment, with your credentials, against your repository. Direct integrations exist for [Claude Code](https://docs.latitude.so/agent-dispatch/claude-code.md), [Cursor](https://docs.latitude.so/agent-dispatch/cursor.md), and [Linear](https://docs.latitude.so/agent-dispatch/linear.md), with [webhooks](https://docs.latitude.so/agent-dispatch/webhooks.md) for everything else.

**5. Verify the fix and lock it in CI**

The dispatched agent investigates through the [MCP server](https://docs.latitude.so/getting-started/mcp.md), reading the signal, slicing occurrences, and reading the failing conversations, then opens a pull request. Turn the failing traces behind the signal into a [dataset](https://docs.latitude.so/datasets/overview.md) and add a [regression test](https://docs.latitude.so/test-and-fix/regression-testing.md) that replays it in CI, so the fix has to pass before it merges and every later prompt change is checked against the same failure. With the [GitHub integration](https://docs.latitude.so/more/github.md) connected, the merge itself resolves the signal: a pull request that references the signal's slug closes it on landing, and a revert reopens it.

## Where humans stay

Two points of the loop are human by design. Annotations are the ground truth that evaluations are aligned against, and a person reviews every pull request before it merges. Everything between those points, finding examples, reconstructing context, and carrying trace ids between tools, is what the loop automates.

## Set it up

1. [Start tracing](https://docs.latitude.so/telemetry/start-tracing.md) one production agent.
2. Annotate a handful of real failures, or let [flaggers](https://docs.latitude.so/annotations/flaggers.md) do it.
3. Generate an [evaluation](https://docs.latitude.so/evaluations/overview.md) for the signal that matters most.
4. Add a [monitor](https://docs.latitude.so/monitors/overview.md) for any metric you cannot afford to miss.
5. Configure [agent dispatch](https://docs.latitude.so/agent-dispatch/overview.md) under **Settings → Integrations**.

Your coding agent can drive the whole workspace through the MCP server:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
claude mcp add --transport http latitude https://api.latitude.so/v1/mcp
```

For other coding agents, see the [MCP server docs](https://docs.latitude.so/getting-started/mcp.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.