Platform Engineering3 January 20278 min read

Build Lab: From Chain to Governed Agent — Part 7 of 8

Tracing, evaluations and failure reconstruction

When an agent gives a wrong answer, the team must be able to say what it was asked, what it knew, what it decided, what it did and under which versions, then prove the fix. Part 7 of Build Lab: From Chain to Governed Agent joins traces, evaluations and checkpoint history into a seven-question failure reconstruction ledger that ends with a new regression case.

#AI Observability#AI Evaluation#LangSmith#AI Agents#Incident Response

Consider an illustrative complaint at a public service counter. A person says the service told them, in their own language, that a certified copy of a document would do, and an official later told them an original was required. The team has the complaint, a rough time and the person's language. To respond honestly, it needs to know what the person actually asked, how the request was interpreted, which service information was retrieved, what the model concluded, whether a human approved anything, and which prompt, model and index versions were live at the time. Then it needs to fix the cause and show that the fix holds.

If any of those pieces is missing, the investigation becomes a guess, and the fix becomes a prompt edit that nobody can test. Part 6 made approvals survive a restart. This part makes the whole run explainable afterwards.

A trace records what happened and an evaluation judges whether it was good enough; failure reconstruction needs both, joined by a correlation identifier and version metadata, and it is only finished when the failure has become a regression case that blocks the next release.

What a trace must hold

LangSmith's observability concepts (accessed 25 November 2026) give a usable vocabulary. A run is a single unit of work, such as a model call, a prompt format or a retrieval. A trace is the collection of runs for one operation, bound by a trace identifier. A thread is a sequence of traces for one multi-turn session, grouped by a thread_id metadata key. Metadata are key-value pairs attached to runs, tags are strings for filtering, and feedback scores an individual run.

Those are containers. What you put in them decides whether a failure can be reconstructed. For each run in the exception path, record:

  • a correlation identifier that joins the trace to the case record, the checkpoint thread and any approval;
  • the model identifier and provider route, the prompt version and the graph version;
  • the retrieval index version and the source identifiers returned;
  • tool names, arguments in redacted form, results and errors;
  • approval decisions with the reviewer's role and time;
  • latency and token counts per run, and the outcome of the whole trace.

The metadata and tags page shows both set on the @traceable decorator or per call. Tracing for LangChain and LangGraph is switched on through environment variables such as LANGSMITH_TRACING, per the LangGraph tracing page. LangSmith is one option. Its OpenTelemetry page states that it accepts traces from any OpenTelemetry-compatible agent, and that traces can be sent to a different provider by configuring the exporter. That matters if your organisation already has an observability platform and does not want a second home for evidence.

Keep content and metadata apart. A trace of the opening example contains a person's words and possibly personal information. Decide what is stored in full, what is redacted, who may read it and how long it lives, before the first production trace is written. A trace is not an evaluation and Observability for AI cover sampling, retention and the minimum action event in depth.

Evaluations before and after release

A trace cannot tell you whether "a certified copy will do" was wrong. An evaluation can, if someone has written down what right looks like. LangSmith's evaluation concepts (accessed 25 November 2026) separate the parts:

  • a dataset is a collection of examples, each an input with an optional reference output;
  • an experiment is the result of evaluating one application version on a dataset;
  • evaluators can be code (deterministic rules), a language model acting as judge, human review, or a pairwise comparison of two versions;
  • offline evaluation runs before deployment against reference outputs, for benchmarking and regression testing; online evaluation runs on production traffic without references, for monitoring and feedback.

For a service answer, start with code evaluators. They are cheap, repeatable and hard to argue with: did the answer cite only approved sources, did it choose the right next step, did it ask for confirmation, did it escalate when it should have? Add a model judge for qualities a rule cannot check, and specialist human review for meaning in each language, because a judge model can share the blind spots of the model it grades.

# Illustrative; check against the current documentation.
from langsmith import Client

def cites_approved_sources(inputs: dict, outputs: dict, reference_outputs: dict) -> bool:
    return set(outputs["source_ids"]) <= set(reference_outputs["approved_source_ids"])

def correct_next_step(inputs: dict, outputs: dict, reference_outputs: dict) -> bool:
    return outputs["next_step"] == reference_outputs["next_step"]

results = Client().evaluate(
    run_service,                       # your target function
    data="counter-exceptions-synthetic",
    evaluators=[cites_approved_sources, correct_next_step],
    experiment_prefix="prompt-v14-candidate",
)

The evaluation guide gives evaluate and Python evaluators a minimum of langsmith 0.3.13; at the time of writing, 25 November 2026, PyPI listed 0.16.2. The dataset name and prompt label above are synthetic. Build the evaluation system before the agent explains how to design the scorecard behind these evaluators.

The failure reconstruction ledger

The decision tool for this part is a ledger of seven questions. Work through it for every serious complaint or failed evaluation. If a question cannot be answered from stored evidence, that gap is a finding in its own right.

Failure reconstruction. Three kinds of evidence are joined by one correlation identifier: the trace, covering the request and language, retrieval and sources, the model and prompt, tools and outcome, with versions on every run; the checkpoint history, showing the state at each step on the same thread, replayed only against test doubles; and the approval records, with reviewer role, decision and time, edited arguments and reason. Together they feed the failure reconstruction ledger: what was asked, known, decided and done, under which versions, whether it was wrong, and whether it will be caught next time. The fix path writes a reference answer with the service owner, turns the failure into a synthetic regression example, runs an experiment on the full dataset, and adds it to a release gate that blocks failures. Online evaluation of sampled production traces and feedback supplies the next candidate examples.EVIDENCE JOINED BY ONE CORRELATION IDENTIFIERTRACERequest and languageRetrieval and sourcesModel and promptTools and outcomeVersions on every runCHECKPOINT HISTORYState at each stepSame thread identifierReplay only againsttest doublesAPPROVAL RECORDSReviewer roleDecision and timeEdited argumentsReasonFAILURE RECONSTRUCTION LEDGERWhat was asked, known, decided and done?Under which versions? Wrong? Caught next time?Write referencewith service ownerSyntheticregression exampleExperiment onfull datasetRelease gateblocks failuresOnline: sampled production traces and feedback become the next candidate examples
A failure is closed only when it has become a test that blocks the next bad release. CloudNala analysis.
QuestionEvidence that answers itIf it is missing
1. What was asked?Trace input, language detection run, interpreted requestAdd input capture with redaction rules
2. What did it know?Retrieval run, source identifiers, index versionRecord source identifiers per answer
3. What did it decide?Model run, prompt version, structured outputVersion prompts and validate outputs (Parts 1 and 2)
4. What did it do?Tool runs, approval records, checkpoint historyJoin traces to the checkpoint thread and approvals
5. Under which versions?Run metadata: model, prompt, graph, index, policy, package setStamp versions at start-up and on every trace
6. Was it wrong, and why?Evaluator result against a reference, specialist reviewWrite the reference answer with the service owner
7. Will we catch it next time?A new dataset example and a regression gate that fails without the fixThe failure is not closed

Question 4 is where the series joins up. LangGraph's get_state_history returns a thread's checkpoints, newest first, so the state at each step can be compared with the trace. The checkpointers documentation explains that replaying from an earlier checkpoint re-executes everything after it, including model calls and interrupts. That makes replay powerful for diagnosis and dangerous near production. Replay only against a copy of the graph whose tools point at test doubles, never at systems that send, write or pay.

From reconstruction to regression

In the opening example, suppose the ledger shows that retrieval returned an outdated service page alongside the current one, and the model chose the outdated rule. The fix may be in the index, the source boundary or the prompt. Whichever it is, the case becomes a synthetic dataset example: the same kind of request, in the same language, with the reference answer "an original is required" and the approved source identifier. The candidate fix runs as an experiment against the full dataset, not just the new example, so a repair in one place does not break another. The release gate in Part 8 then refuses any version that fails it.

The example must be synthetic or properly redacted. The point is to keep the failure's shape, not the person's words. Every incident becomes a test case sets out ownership and privacy rules for this step.

Online evaluation closes the loop from the other side. Sampled production traces, scored by code evaluators and reviewed by specialists, show drift before complaints do. Feedback recorded on individual runs, such as a person's confirmation or an official's correction, becomes the next set of candidate examples.

What this means for NalaTolika

NalaTolika is a CloudNala concept and reference architecture for governed language interpretation. It has no customers, deployments, pilots, data or results. Its design treats every interpreted answer as something that may need to be explained later: each one carries a correlation identifier, the source references used, the prompt, model, glossary and index versions, and the approval record where an official was involved. Its evaluation set is organised by language and by critical error, so a failure in one language cannot hide inside a good average.

How CloudNala can help

CloudNala sets up the evidence path for agent workflows. We define the trace fields and redaction rules with your owners, connect traces to checkpoints and approvals through one correlation identifier, build a first synthetic evaluation dataset with code evaluators, and run a failure reconstruction drill using the seven-question ledger.

Next in the series: Production packaging, version pinning and rollback. Previous: Part 6, Human approval and durable checkpoints. All parts are on the series page.

Sources and limits: this article is CloudNala analysis. LangSmith and LangGraph concepts and APIs are described from docs.langchain.com pages accessed on 25 November 2026, and the langsmith version from PyPI on the same date; features and names change between releases. LangSmith is named as a dated example, not a recommendation. The code is illustrative and uses synthetic data. The complaint scenario is illustrative and describes no real service. NalaTolika is a concept with no deployments.


Work with CloudNala

CloudNala helps organisations move from technology ambition to practical execution across cloud, AI, data, platform engineering and digital services.

Whether you are exploring AI, modernising your cloud environment, building a public-sector digital service, or turning an idea into a working MVP, we can help you shape the roadmap and deliver the next step.

Book an AI Production Readiness Review or write to us at consult@cloudnala.co.za

Found this useful?

Share