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:
tool_response_issue: agent behaved correctly on bad input. The fix is the integration or a support ticket, never prompting around broken data.tool_unavailable: a tool the instructions require was missing from the request's tool list (harness pruning/assembly bug). The fix is a code_ticket against tool selection — never an instruction edit.tool_not_enabled: the needed capability exists on the agent's attached integrations but is filtered out of its tool list (e.g.tool_access). The fix is agent_config: enable the tool, usually plus a small instruction addition describing when to use it.context_bloat: duplicated tool results or runaway payload size degraded the turn. The fix is a code_ticket against payload assembly.ambiguous_instructions: the fix is an instructions Document edit — wording validated first with replay_llm (n=5), applied on the appropriate branch, then live-validated with mock conversations.data_presentation: tool data is correct but shaped so the model must infer the answer (absence-by-omission, needle-in-huge-payload, unit ambiguity). The proposed reshaped tool block is validated first via replay_llm with replace_content_strings (substituting a simulated version of the new shape); the fix is the tool's response model in code, or a support ticket carrying the validated shape. Never papered over with instructions.model_slip: flakiness measured with replay_llm (n=5);payload_overrides/modelsare candidate mitigations. Persistent slips (>=80% failure on replay) are not slips — they are re-diagnosed as ambiguous_instructions or data_presentation and both are A/B tested in replay.needs_human: the fix is routing (transfer rules / task assignment in the Document), not tuning.user_error/working_as_intended: the evidence answers the complaint; current behavior can optionally be pinned as a test.state_carryover_error/context_dilution: trajectory causes. The frozen payload already contains the conversation history the model saw, so these are always in scope;context_turnsadds Message-entity metadata (ids, timestamps) for prior turns.
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
complaint: str. REQUIRED ground-truth assertion of what went wrong.message_id: optional str. Assistant message id (or pass llm_request_id).llm_request_id: optional str. Direct cached request id.model: optional str. Analyzer model (pinned default).context_turns: optional int. Include the N prior assistant turns' Message entities (ids, metadata) as extra trajectory evidence.validate: optional bool. Run the replay measurement described above before returning (adds 5-10 real completions plus judge calls).
Returns
DiagnoseResponse
message_id: optional str or null. Assistant message analyzed, when given.llm_request_id: str. Frozen request analyzed.classification: "tool_response_issue" or "tool_unavailable" or "tool_not_enabled" or "context_bloat" or "ambiguous_instructions" or 8 more. ROOT CAUSE. Determines the fix path.frozen_turn_classification: optional "tool_response_issue" or "tool_unavailable" or "tool_not_enabled" or "context_bloat" or "ambiguous_instructions" or 8 more or null. What the analyzed turn itself did, when it differs from the root cause — typically state_carryover_error when the turn inherited a decision made earlier in the trajectory.root_cause: optional DiagnoseRootCause or null. Where the wrong decision was first made.propagation_chain: optional List[int]. Message indices from the root-cause turn to the frozen turn through which the wrong decision propagated.operative_term: optional str or null. The caller's phrase whose handling is under complaint (e.g. "blood work"). Used to test whether the instructions were clear.cited_instruction_quote: optional str or null. Exact instruction text the analyzer says decides the behavior. For model_slip it must literally appear in the frozen instructions and contain the operative term, else the verdict is downgraded to ambiguous_instructions.complaint_verdict: "confirmed" or "contradicted" or "undeterminable". Whether the payload actually supports the complaint.evidence_of_engagement: optional bool or null. Whether the response quoted, paraphrased, or acted on the tool data relevant to the complaint. A data_presentation verdict requires True; False with that label is downgraded to ambiguous_instructions (the data was never read, so its shape cannot be the cause). None when the analyzer did not say.summary: optional str or null. The verdict in a few sentences.evidence: optional List[DiagnoseEvidence]. Pinpointed artifacts behind the verdict.other_deviations: optional List[DiagnoseOtherDeviation]. Secondary instruction deviations seen in the trajectory that were not needed to explain the complaint.suggested_fix: DiagnoseSuggestedFix. The proposed fix and ready-to-run replay arguments.validation: optional DiagnoseValidation. Replay measurement of the verdict; only run with validate=True.suggested_checks: optional List[str]. Checks to pin this as an AgentTest.follow_up_questions: optional List[str]. Set when evidence was insufficient.analyzer_model: str. Model that produced the analysis.diagnosis_cost_usd: optional float or null. What the analysis cost, in US dollars, when known.parse_degraded: optional bool. The analyzer's JSON needed repair, so fields may be partial. Treat the verdict as lower-confidence.
Example request
curl -X POST "https://api.hilus.ai/Platform/lab/diagnose" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'