Diagnose why an agent reply went wrong

POST /Platform/lab/diagnose

Diagnose why an agent reply went wrong.

Applies when the reported defect is in what the model decided, said, or omitted and can therefore be explained by the frozen LLM request/response — not merely because an agent or conversation was involved.

Runtime and lifecycle defects are categorically out of scope: voice latency or audio quality, TTS/STT timing, missing recordings or after-call summaries, delayed/incomplete conversation notifications, telephony events, webhooks, networking, worker performance, and post-response tool execution. A frozen LLM payload contains no evidence about those failures, so diagnosing them here wastes an analyzer completion and returns insufficient evidence; they are investigated with runtime logs, traces, metrics, and persisted call/session state.

The turn is judged against the complaint (the ground-truth assertion of what went wrong, e.g. "said the office is open until 8pm on Saturdays; it closes at 1pm"). The complaint is required because most bad turns look superficially coherent — only the assertion makes the missing evidence the smoking gun.

By default exactly one analyzer completion; no tool loop, no live tool execution, no writes. The frozen cached payload is the ground truth for what the model saw — current live entity state is deliberately excluded (it may have changed since the incident and is inspected separately). If evidence is insufficient the result is insufficient_evidence plus focused follow-up questions rather than autonomous data fetching.

The verdict is judged twice. The analyzer reports the ROOT CAUSE (classification, which drives the fix path) and, when the analyzed turn merely inherited an earlier wrong decision, a separate frozen_turn_classification (typically state_carryover_error) with root_cause / propagation_chain locating where the decision was first made. Then the route enforces the rules the analyzer can talk itself out of: a model_slip must cite an instruction that literally appears in the frozen instructions AND contains the caller's operative_term, else it is downgraded to ambiguous_instructions; data_presentation without evidence_of_engagement becomes ambiguous_instructions; replay_arguments are filtered to replay_llm's real parameters and every replace/insert target is checked against the payload (replay_arguments_runnable); evidence refs are verified (ref_verified).

Classifications and their fix paths:

By default any proposed fix comes back unvalidated (validation_status: "not_run") with ready-to-run replay arguments; validation happens through replay_llm before anything is applied. With validate=True the route runs that measurement itself when the verdict is replayable (model_slip, ambiguous_instructions, data_presentation): a baseline arm (frozen payload unchanged, n=5, judged against the analyzer's success_criterion) and, if the suggested fix is a runnable payload edit, an edited arm with it applied. Both arms replay the ROOT-CAUSE turn when it was located and matched to a frozen request (root_cause.llm_request_id) — replaying a turn that merely confirmed an earlier decision cannot measure anything — and replay_arguments are pinned to that same turn. A model_slip whose baseline fails >=80% of the time is relabelled ambiguous_instructions (or data_presentation when the evidence shows engagement with a reshaped tool block) — a reproducible slip is not a slip. Results are in validation. Create a persistent AgentTest when the incident is recurring, high impact, fragile, or represents behavior shared across agents or clinics.

Costs money: one large high-reasoning analyzer completion over the whole frozen payload, plus 5-10 replays and judge calls with validate; the cost is reported in diagnosis_cost_usd. Asynchronous by default: requests finishing within ~45s return inline; longer ones return HTTP 202 with a pollable async id (GET /Platform/jobs/async/{async_id}), so a dropped client connection does not discard completed LLM work.

Body parameters

Returns

DiagnoseResponse

Example request

curl -X POST "https://api.hilus.ai/Platform/lab/diagnose" \
  -H "Authorization: Bearer $HILUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'