Sub topic 14
Monitoring and improving a live application
This chapter assumes you have deployed an agent to a serving endpoint, can read MLflow traces, and have seen the evaluation workflow from the earlier chapters. Here you will learn how to watch the application once real users reach it, and how to turn what you see into improvements.
Why a deployed agent still needs attention
Offline evaluation uses a fixed dataset. Production traffic does not. Users ask questions you did not predict, documents in the index go stale, and a model endpoint can slow down or fail. Monitoring answers three questions:
- Is the endpoint healthy (errors, latency, usage)?
- Is the quality of answers holding up?
- Which real requests should become new test cases?
What to watch
Different signals come from different places. Check each one for your workspace, because the available features depend on your setup.
| Signal | Where it comes from | What it tells you |
|---|---|---|
| Errors and latency | Serving endpoint metrics | Whether the service is up and fast |
| Token usage and request counts | AI Gateway usage tracking | Cost and traffic trends |
| Request and response detail | MLflow traces from the endpoint | What the agent actually did |
| Quality scores | Scorers or judges run on traces | Whether answers stay correct and grounded |
| User feedback | Ratings attached to traces | Where users are unhappy |
The improvement loop
Monitoring only pays off if findings return to development. The loop below is the usual shape.
Inspecting production traces
Because the agent from earlier chapters is instrumented with @mlflow.trace, its calls can be searched like data. This example pulls failed requests from an experiment.
import mlflow
mlflow.set_experiment("/Shared/support-agent-prod")
failed = mlflow.search_traces(
filter_string="attributes.status = 'ERROR'",
max_results=50,
)
print(f"{len(failed)} failed traces")
print(failed[["request", "response"]].head())The result is a pandas DataFrame. Read the failing requests and group them by cause. A retriever that returns nothing, a tool that raises an exception, and a prompt that confuses the model each need a different fix.
Turning findings into fixes
Match the symptom to the layer you change:
- Answers are wrong but retrieval returned the right chunk. Revise the system prompt or message structure.
- Retrieval returned irrelevant chunks. Revisit chunk size, the embedding model, or the number of results
k. - The answer is not in the index at all. Add documents to the source Delta table and let the index sync.
- A tool call failed. Fix the tool, or tighten its description so the model calls it correctly.
After each change, rerun evaluation on your dataset, including the new cases you added from production. Then register and deploy the new version as before. Deploying a version is reversible only if you keep the old one registered, so do not delete earlier versions of the model in Unity Catalog.
Common mistakes
- Watching only latency and error rate. An endpoint can return HTTP 200 for every request while giving poor answers.
- Evaluating once before launch and never again. Quality drifts as data and usage change.
- Adding every production request to the evaluation set. Pick representative and failed cases, or the set stops being a useful benchmark.
- Changing the prompt, the retriever, and the model at once. You cannot tell which change helped.
Exercise
Users report that your RAG agent says "I could not find that" for questions whose answers exist in a document you uploaded to the source table yesterday. Endpoint error rate is normal. Which two things do you check first, and what do you do with one of these failing requests afterward?
Show answer
First check that the Delta Sync index has synced the new rows (a TRIGGERED pipeline only updates when you run a sync), and look at the retriever span in the trace to see which chunks came back. Afterward, add the failing question with its expected answer to the evaluation dataset so future versions are tested against it.