BISWAS Bengali reliability markBISWASAGENTIC RELIABILITY & TRUST
← All stories

AI OBSERVABILITY

Your AI App Is Slow. Can an Agent Find the Cause?

One request, one hidden fault, and a modelled investigation: trace the delay, contain a degraded replica, and examine what the agent’s context costs.

Deepak BiswasDeepak Biswas
21 October 2026

The request that got slow

Someone types “Find and summarize the deployment guide” into your internal AI assistant. Yesterday the answer came back in under two seconds. Today it takes eight. The dashboard is green. Nothing is down. Where did six seconds go?

Tracing the request answers that question. Containing it, and proving that the mitigation helped, is the harder part. This post walks through a small system we drew to make that whole loop visible: a gateway that records every hop, an agent that investigates, and a worked answer to what that investigation costs.

Follow one request

Step through with the arrows or the ← → keys. The diagram, the trace, and the terminal stay in sync. Hit Play to let it run. On a phone, swipe the diagram sideways.

What the trace shows

A trace is the record of one request. Each step in it is a span, and spans nest: the application span wraps everything the app waits on, and each gateway span wraps the model call it forwards. The proxy creates the trace ID, and every hop passes it along.

Switch between the healthy request and the slow one. Each bar shows when a span started and how long it lasted.

Compare the two traces and two things stand out:

  • The model calls didn’t change. llm.call #1 takes 700 ms and llm.call #2 takes 820 ms in both. The model isn’t the problem.
  • The tool span grew by six seconds, from 180 ms to 6,185 ms, and its child span names the replica that served it: search-svc B.

That’s the whole diagnosis, and it’s only possible because the MCP server records which replica it called as a span attribute. Without that attribute the trace would point at the tool, and nothing more specific.

How the agent finds it

The agent works in a loop: look at something, decide what to check next, act, and look again. (The pattern comes from ReAct; see go deeper.) Here is its run on this incident, written out step by step so you don’t need a widget to follow it.

  1. Read the alert. /ask p95 latency is above SLO. The alert names a service, not a cause.
  2. Pull slow traces. It fetches traces from the alert window that ran over 5 s, and healthy traces from the hour before, to compare.
  3. Rule out the model. Before touching anything else, it compares the model-call spans. They’re the same in fast and slow traces, so it sets the model aside. No runbook told it to check this first, and neither did the system prompt, which describes the tools and the output format and names no component and no order of checks. It chose that check from what the trace showed, and that choice is what makes this different from a scripted recovery.
  4. Find the span that grew. Only mcp.search_docs changed. Grouped by replica, the slow calls all went to B, while A still answers in about 180 ms.
  5. Check what the load balancer sees. B’s health check passes in milliseconds. That’s why nothing removed it, and it confirms this is a gray failure: the service is broken but its health check still passes.
  6. Retrieve a runbook. It searches the runbooks for “one replica slow, health check passing” and gets back Drain a degraded replica (RB-017). That runbook lists two tools, drain_replica and replay_probe, and the agent loads only those.
  7. Check the preconditions. The runbook says to drain only if the remaining replicas have room for the extra traffic. Replica A’s load metrics show it does.
  8. Act. It drains replica B. B is still running, so this can be undone with one call.
  9. Verify. It replays the original request as a probe 20 times. All 20 go to A and finish in under 2 s, and /ask p95 drops back under the SLO.
  10. Hand off. It opens a ticket containing the evidence, the action it took, and the open question: why is B’s search endpoint slow?

What the gateway does, and what it doesn’t

AI gateway

  • Routes requests to models and MCP tools
  • Applies policy: who may call what, with which limits
  • Records every hop as a trace span

Troubleshooting agent

  • Reads telemetry the gateway and app emit
  • Retrieves the runbook that matches the symptom
  • Calls a small set of restricted remediation tools

An AI gateway such as the open-source agentgateway gives you connectivity, security, observability, and governance for agent traffic. It does not ship with a troubleshooter. The agent in this demo is a separate component we built and plugged in behind the telemetry. Keeping that seam visible is what makes the demo honest.

Building the agent is a topic in itself: which telemetry queries it may run, how runbooks are ranked, which tools it may hold and with what preconditions, and how it is stopped when it is wrong. This post treats it as a box with three inputs and one output. The next post opens the box.

Isn’t this just a health check?

Automated recovery is older than large language models. Health checks, failover, autoscaling, and scripted runbooks all restore service without a human. Every one of them follows a rule somebody wrote in advance.

The new part is in the walkthrough at the step called Rule out the model. The agent looks at the model-call spans, sees they are unchanged, and only then turns to the MCP dependency. Nobody wrote that branch. It chose an investigation path across telemetry, documentation, and tools. That is the capability worth demonstrating, and the only claim we make.

The walkthrough above is simplified on purpose: one alert, one fault, and we own the replica pool. Real systems raise a dozen alerts for one fault, all of them true, and the agent’s first job becomes telling the symptoms from the cause. The closing scenes show that version, and how the agent still finds the leaf.

What the agent’s context costs

The agent’s context is everything it’s given to read: the system prompt, the alert, the runbooks, and the tool definitions. Every model call sends the whole context again. So the cost of an investigation is roughly context size × number of model calls.

There are two ways to equip the agent. Broad context loads every runbook and tool up front, so nothing is ever missing, but every call pays for all of it. Selected context starts with only the alert and a telemetry summary, retrieves the one matching runbook, and loads only the tools that runbook names, two in this run. Its read-only telemetry tools are part of the system prompt in both strategies. Every call pays for a fraction of the context, plus two small extra calls to fetch the runbook and the tools.

To keep the comparison fair, both start with the same number of model calls (this example uses 9). This is a worked example, not a measurement.

At the default settings, selected context uses about 76% fewer tokens. Two caveats keep this honest:

  • Fewer tokens doesn’t mean a better agent. If retrieval returns the wrong runbook, the selected strategy needs more calls, and the gap shrinks or flips. Use the second slider to see where. Anthropic’s engineering team describes this trade-off in advanced tool use: loading tools only when needed saves context but costs an extra round trip.
  • Prompt caching narrows the cost gap. A large context that doesn’t change between calls can be cached by the provider, so repeat calls cost much less. Broad context still fills the model’s context window and gives it more irrelevant text to sift through. Caching lowers the bill, but it doesn’t remove that.

Three views, one trace ID

ViewWhat you should be able to see
Application healthLatency, error rate, throughput, and a marker where the fault went in
Request traceTime spent in the app, the model calls, the gateway, and the MCP tool
Agent executionRetrieved document IDs, tool calls and results, tokens, the action taken, the verification

Gateway telemetry alone cannot show a retrieval inside the application or the agent’s own tool calls. Both are instrumented with OpenTelemetry and OpenInference and sent to Phoenix, so all three views share one trace ID. These are execution records. They are not a window into the model’s private reasoning, and we do not present them as one.

Mock-up of a trace view showing the agent’s investigation as a waterfall of model calls, tool calls, and a runbook retrieval, with token counts per span
The agent-execution view, drawn in the style of a Phoenix trace waterfall. A mock-up made to show what the record looks like, not a screenshot of a run.

Watch it happen

The companion video also has a bonus section at the end: a very high-level look at what the real world looks like beyond this one incident, and the subtle differences between the gateways in the path, from reverse proxy to AI gateway. The last part of the video is a separate page built for recording: reality.html.

0:00The request that got slow
0:46The system, and who owns what
1:14A little chaos engineering, and the trace that shows it
2:18The agent investigates, mitigates, verifies
3:16Why the replica name matters
4:49What the agent’s context costs
5:21What the simple version leaves out
6:09Bonus: the gateways in the path, and how they differ
6:57One paper, five open problems, the courses, and who builds what comes next

Where this meets what you’re studying

If you are a new graduate, or still in your degree, this section is the map from your courses to this post. Nothing here needed a new idea. Each piece has a chapter in courses most computer science students take in their third or fourth year. What’s new is that they now sit in one system, with a model making the decisions.

NetworksThe application layer, what a Layer 7 proxy can read that a Layer 4 one can’t, and a latency fault you inject on purpose.
Distributed systemsReplicas, partial and gray failure, a health probe that passes while the service is wrong, and draining a node without dropping traffic.
Information retrievalRanking a dozen runbooks against a symptom and returning the one that fits, with a score you can defend.
Control theory (often an EE elective)Sense, decide, act, verify. The agent is a closed loop with a model in the decide box, and loops can oscillate.

The smallest useful version you can build: one gray failure behind a passing health check, an agent with read access to traces and metrics, a few runbooks, and one reversible action. Then measure whether its intervention improved the system, and publish the numbers, including the runs where it failed. A starter repository for this version is coming with the next post. The video names the textbooks and courses where each of these ideas is taught.

Glossary

The terms this post leans on, in the order you meet them.

MCP, the Model Context Protocol
An open protocol a model uses to call tools and read data through one standard interface. Here the MCP server fronts the search_docs tool, and the slow replica sits behind it, which is why MCP is at the centre of the diagnosis.
LLM, large language model
The model behind the assistant. In the diagram it is the “LLM provider” box the gateway calls, twice per request here: once to decide on the tool call and once to write the answer.
L7 proxy
A server that reads requests at Layer 7, the HTTP layer with method, path, headers, and body, and decides where to send them. A Layer 4 proxy sees only addresses and ports.
AI gateway
An L7 proxy with handlers for model traffic: provider translation, token counting and budgets, caching, failover, and guardrails.
Trace and span
A trace is the record of one request across every hop. A span is one step in it, with a start time, a duration, and a parent span. Spans nest.
Trace ID
The identifier minted at the first hop and carried in a header (W3C traceparent) so that every hop’s spans join one trace.
Span attribute
A key-value label on a span, such as replica=B. The attribute, not the timing, is what lets the trace name the replica.
p95
The latency that 95% of requests beat. A p95 of 7.8 s means one request in twenty took longer than that.
SLO, service level objective
The target you promise, such as “p95 under 3 s”. Alerts fire when the objective is at risk, not when a server is down.
Health check
A periodic probe such as GET /health. A load balancer removes a replica only when the probe fails.
Gray failure
The service is broken but its health check still passes: its callers feel the problem and its monitors do not. The paper that named it calls this differential observability (Huang et al., HotOS 2017).
Drain
Take one replica out of the load balancer’s rotation so it receives no new requests while existing ones finish. The replica keeps running, so a drain is reversible. It is not the same as scaling down.
Runbook and precondition
A runbook is a written procedure for a known symptom. A precondition is a check that must pass before its action runs, such as “the remaining replicas have room”. RB-017 here is “drain a degraded replica”.
OpenTelemetry and OpenInference
OpenTelemetry is the open standard for emitting traces, metrics, and logs. OpenInference is a set of span conventions on top of it for model calls, retrievals, and tool calls, used by Phoenix.
Context
Everything the model is given to read on one call: system prompt, alert, runbooks, tool definitions. It is limited in size and paid for in tokens on every call.
Prompt caching
A provider feature that stores an unchanged prefix of the context so repeat calls are cheaper. It lowers the bill; it does not shrink what the model has to read past.
429
The HTTP status for “too many requests”. Providers return it when you are rate limited, and an AI gateway returns it when a team’s budget is exhausted, before the provider is ever called.
Token
The unit models bill by, roughly three quarters of an English word.

Go deeper

  1. ReAct: Synergizing Reasoning and Acting in Language Models, ICLR 2023. The pattern of interleaving a model’s decisions, actions, and observations that this agent runs on.
  2. AIOpsLab, MLSys 2025, Microsoft Research. Cloud environments, injected faults, workloads, telemetry, and an evaluation harness for operations agents. The closest published work to this demo.
  3. Advanced tool use, Anthropic engineering. Deferred tool discovery and the context-versus-latency tradeoff measured above.
  4. agentgateway, Solo.io. The open-source gateway for agent traffic used in the demo.
  5. Phoenix, Arize. Tracing for LLM calls, retrievals, and tools over OpenTelemetry.

Organizations named for the piece they build: Solo.io for gateways, Arize for agent observability, Microsoft Research for reproducible operations-agent evaluation, and ResolveAI as an example of a commercial AI SRE product. Their work covers different parts of this architecture; none of it is an endorsement of this post.

CONTINUE THE CONVERSATION

What does this change for your platform?

Talk reliability with Deepak ↗

NEWSLETTER

AI observability,
in your inbox.

The latest technical news and trends in AI observability, AI infrastructure reliability and AI gateways.