Testing and debugging agents
This guide shows how to check what an agent will do before real contacts see it, and how to find out why it did the wrong thing after they have. You will preview an agent's assembled context, read the exact request behind a reply, diagnose a bad reply against a complaint, validate a fix on the frozen request, simulate whole conversations on a branch, and keep the behaviour covered with saved tests. Everything here lives in the lab.
How the lab works
An agent's behaviour comes from its configuration (the agent, its
workflows, documents and integrations), which is stored as
entities on branches. main is what real contacts
get. The lab looks at that behaviour in two ways:
- Frozen turns. A reply an agent sends keeps the exact request its
model received and the response it gave, for as long as that request is
kept (an expired one is refused), named by the reply's
metadata.llm_request_id. Reading, diagnosing and replaying a turn work on this frozen payload. They answer "what did the model see then?", and take no branch, because a frozen request cannot be rebuilt from today's configuration. - Live configuration. Rendering a context, simulating a conversation and running saved tests build the agent from a branch as it stands now. They answer "what will the agent do with this configuration?", so you run them on the branch you changed.
| Operation | What it answers | Model calls |
|---|---|---|
| Render context | What the agent's model would receive now | None |
| Read a turn | What the model saw and said in one reply | None |
| Diagnose | Why one reply went wrong, and where the fix belongs | One analysis, more with validation |
| Replay | Would this edit have changed that reply? | One per completion |
| Simulate | How does a whole conversation go on this branch? | Every turn, every tool answer, every verdict |
| Run tests | Do the saved tests for this behaviour still pass? | Every test, every sample |
[!WARNING] Everything except rendering a context and reading a turn runs the real model, so it costs money. A test run is capped at 10 tests. Run only what your change touches, on the branch you changed.
Preview what an agent sees
Render context assembles an agent's view
exactly as a turn does, without a turn and without a model call. It returns
every view block with the [EntityType:id] header it is placed under, the
tools the agent would be handed, and what is still missing before the agent
can run its workflows. Because it is free and repeatable, it is the
instrument for configuration work: run it after every step (attach a
workflow, answer a decision, edit a document) and compare the output.
curl -X GET "https://api.hilus.ai/Platform/lab/render-context?agent_id=agt_123&branch=feature%2Ffix-hours&include_text=false" \
-H "Authorization: Bearer $HILUS_API_KEY"
Response:
{
"agent_id": "agt_123",
"agent_name": "Front desk",
"branch": "feature/fix-hours",
"blocks": [
{
"entity_name": "Agent",
"entity_id": "agt_123",
"header": "[Agent:agt_123]",
"chars": 4210
},
{
"entity_name": "Document",
"entity_id": "doc_321",
"header": "[Document:doc_321]",
"chars": 9876
}
],
"total_chars": 14086,
"collected_tools": [
"Conversation.escalate_to",
"Scheduler.find_open_slots"
],
"filter_patterns_matching_nothing": [
"Scheduler.book_slot"
],
"session_only_patterns": []
}
Three fields catch what reading the configuration cannot:
collected_toolsis what the agent's entity graph actually yields after its tool access is applied. An integration that is not attached, or a tool name that no longer exists, silently drops tools; here you see the result.filter_patterns_matching_nothingnames tools the configuration allows explicitly that match no real tool: a typo, a renamed tool or a missing integration. In the response above,Scheduler.book_slotis allowed but does not exist.readinesslists what is still missing before the agent can run its workflows, such as an unanswered decision.
Set include_text to false
for a quick size-and-header comparison, and
render to true to get the whole
context as one string. The context is the same for every conversation:
nothing a customer says changes it, so one render shows what every
conversation starts from.
[!NOTE] A live conversation adds channel-specific blocks and the current time on top of the rendered context. To see those, read a real turn.
Read the turn behind a reply
Read a turn returns the frozen request and response behind one reply: the system prompt, every view block, the tool list with full schemas, the conversation so far, tool results, and the model's response, exactly as sent and received. Pass the reply's message id and the route resolves its request id, or pass the request id directly.
curl -X GET "https://api.hilus.ai/Platform/lab/llm-data?message_id=msg_456" \
-H "Authorization: Bearer $HILUS_API_KEY"
Set render to "html" for a readable
page. Reading a turn is the manual counterpart of diagnosing it: use it
when you want to check a detail yourself, or to confirm what a diagnosis
cites.
Diagnosing a wrong agent reply
Read this when someone reports that an agent said or did the wrong thing: gave a wrong fact, skipped a step, called the wrong tool, or promised something it should not. The workflow is: find the turn, diagnose it against the complaint, validate a fix on the frozen turn, make the change on a branch, simulate it, and promote it through a changeset with the evidence attached. The example follows one report: "the agent told a customer the office is open until 5pm on Saturdays; it closes at 1pm."
[!WARNING] The lab explains what the model decided. Latency, audio quality, speech timing, dropped calls, late notifications and failed deliveries leave no trace in a frozen request, so a diagnosis cannot find them. Investigate those from the call or conversation record and the logs for its request id, and report them if they are platform defects.
1. Find the turn
You need the message id of the assistant reply that went wrong. If you know the conversation, its messages carry their ids. Otherwise search reply text with an HQL query:
curl -X POST "https://api.hilus.ai/Platform/query/hql" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"hql": "Message | role = '\''assistant'\'' AND content ~* '\''open until 5'\'' AND created_at >= NOW() - INTERVAL '\''7 days'\'' | select id, conversation.id, created_at | limit 10"
}'
Pick the reply the complaint is about. When the wrong decision was made several turns earlier, still start from the reply that shows the problem: the diagnosis locates the earlier turn for you.
2. Diagnose it against the complaint
Diagnose reads the frozen request and judges the reply against your complaint: a factual statement of what went wrong. The complaint is required because most bad replies look coherent on their own; only the assertion makes the missing evidence stand out. State the fact, not a guess at the cause.
curl -X POST "https://api.hilus.ai/Platform/lab/diagnose" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"message_id": "msg_456",
"complaint": "Told the customer the office is open until 5pm on Saturdays; it closes at 1pm on Saturdays."
}'
Diagnose is asynchronous by default: a slow analysis answers
202 Accepted with an async id, and you poll
the execution until it completes (the
Long-running calls section below has the details). The result:
Response:
{
"message_id": "msg_456",
"llm_request_id": "llmreq_789",
"classification": "ambiguous_instructions",
"complaint_verdict": "confirmed",
"operative_term": "Saturday",
"summary": "The instructions list weekday hours only; nothing covers Saturday, and the model extended the weekday closing time.",
"evidence": [
{
"kind": "view_block",
"ref": "messages[1], block 3",
"quote": "Hours: Monday to Friday 8am to 5pm",
"why_relevant": "The only hours in the context; Saturday is absent.",
"message_index": 1,
"ref_verified": true
}
],
"suggested_fix": {
"type": "document_edit",
"target": "Document doc_321",
"proposed_change": "Add Saturday hours (9am to 1pm) and state that the office is closed on Sunday.",
"validation_status": "not_run",
"replay_arguments": {
"replace_content_strings": [
[
"Hours: Monday to Friday 8am to 5pm",
"Hours: Monday to Friday 8am to 5pm; Saturday 9am to 1pm; closed Sunday"
]
],
"n": 5,
"judge": "states that the office closes at 1pm on Saturdays"
},
"replay_arguments_runnable": true
},
"analyzer_model": "hilus/high"
}
Check complaint_verdict first: contradicted means the frozen request
does not support the complaint (the agent may have been right), and
undeterminable comes with follow_up_questions to answer. Set
validate to true to have diagnose
run the replay measurement of step 4 itself before it returns; that adds
five to ten completions.
3. Read the classification
The classification is the root cause, and
it decides where the fix belongs. Fix at the cause: an instruction edit
that papers over broken tool data hides the defect and breaks again.
| Classification | What happened | Where the fix goes |
|---|---|---|
ambiguous_instructions |
The instructions are silent or ambiguous about this case | Edit the instructions, validated by replay first |
tool_not_enabled |
The tool exists on an attached integration but the agent's tool access filters it out | Agent configuration: allow the tool, usually with a line on when to use it |
tool_response_issue |
The agent was right given what a tool returned; the data was wrong or broken | The integration or the upstream data, never the instructions |
data_presentation |
The data was correct but shaped so the model had to infer the answer | Reshape the tool response; file a ticket with the replay-validated shape |
tool_unavailable |
A tool the instructions need was missing from the request | A platform defect: file a ticket |
context_bloat |
Duplicated or oversized tool results degraded the turn | A platform defect: file a ticket |
model_slip |
A well-formed request the model got wrong anyway | Measure it with replays first; a reproducible "slip" is not a slip |
needs_human |
The request is beyond the agent's policy | Routing: transfer or task rules, not wording |
state_carryover_error, context_dilution |
The wrong decision was made earlier, or the instruction was crowded out | Fix and replay at root_cause, not at the reply you started from |
user_error, working_as_intended |
The evidence answers the complaint | Nothing to fix; optionally pin the behaviour as a test |
insufficient_evidence |
The request cannot decide it | Answer follow_up_questions |
When root_cause is set, the reply you analyzed only carried out a
decision made at an earlier turn. Replay root_cause.llm_request_id:
replaying the later turn cannot undo a decision it inherited.
When the behaviour should differ per organization, the fix is a Workflow decision (a keyed answer that blocks and tools select on), not a sentence such as "if this office...".
4. Replay a fix on the frozen turn
Replay runs the frozen request again with your
edit applied, before anything live changes. Caching and tool execution are
off, so a replay never reaches an integration. The diagnosis's
replay_arguments are ready to pass as they are:
curl -X POST "https://api.hilus.ai/Platform/lab/replay-llm" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"llm_request_id": "llmreq_789",
"replace_content_strings": [
[
"Hours: Monday to Friday 8am to 5pm",
"Hours: Monday to Friday 8am to 5pm; Saturday 9am to 1pm; closed Sunday"
]
],
"n": 5,
"judge": "states that the office closes at 1pm on Saturdays"
}'
replace_content_strings
takes [old, new] pairs, where old must match text in the frozen request
exactly, or [index, new_text] to overwrite one text block. A string
judge grades every completion against
that requirement and keeps the failing ones so you can read their wording:
Response:
{
"summary": {
"total": 5,
"errored": 0,
"original": "__spoke_only__",
"outcomes": {
"__spoke_only__": 5
},
"changed": false,
"verdicts": {
"criteria_pass": 5
}
},
"results": [
{
"llm_request_id": "llmreq_789",
"message_id": "msg_456",
"replays": [],
"summary": {
"total": 5,
"errored": 0,
"original": "__spoke_only__",
"outcomes": {
"__spoke_only__": 5
},
"changed": false,
"verdicts": {
"criteria_pass": 5
}
}
}
],
"diffs": []
}
How many replays to run:
- One replay is enough for a deterministic, low-risk correction such as a missing fact.
- Run five or more for a suspected model slip, when the first replay is
ambiguous, or when the behaviour is high impact. If the unedited request
fails four times in five or more, it was never a slip: treat it as
ambiguous_instructionsordata_presentation. - Pass a list of message or request ids to run the same edit across several real turns and check it fixes the target without disturbing others.
Other probes use upsert_tools (reword a tool description), remove_tools and models.
5. Make the change on a branch
Once the replay passes, make the same edit to the live configuration on a feature branch. Edit text within a document with an exact replacement:
curl -X POST "https://api.hilus.ai/Platform/entities/Document/edit" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"ids": [
"doc_321"
],
"branch": "feature/fix-hours",
"anchor": "lines",
"old": "Hours: Monday to Friday 8am to 5pm",
"new": "Hours: Monday to Friday 8am to 5pm; Saturday 9am to 1pm; closed Sunday",
"commit_message": "Add Saturday and Sunday hours (replay-validated, 5/5)"
}'
Agent settings and tool access are whole values: change them with a patch instead. Then render the context on the branch to confirm the change landed where the model will see it.
6. Simulate the change
A replay proves one turn; a simulation proves the conversation. Run the scenario from the complaint on your branch, with requirements a judge grades every run against:
curl -X POST "https://api.hilus.ai/Platform/lab/simulate" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "agt_123",
"branch": "feature/fix-hours",
"scenario": "A customer asks whether the office is open this Saturday afternoon. They believe it is open until 5pm. Stop once they have a definite answer.",
"requirements": [
"The agent says the office closes at 1pm on Saturdays",
"The agent never says the office is open after 1pm on a Saturday"
],
"n": 3,
"moment_now": "2026-09-14T09:30:00-07:00"
}'
Response:
{
"agent_id": "agt_123",
"branch": "feature/fix-hours",
"store": false,
"moment_now": "2026-09-14T16:30:00+00:00",
"n": 3,
"goal_met_count": 3,
"requirements": [
"The agent says the office closes at 1pm on Saturdays",
"The agent never says the office is open after 1pm on a Saturday"
],
"requirements_passed_count": 6,
"requirements_total_count": 6,
"all_requirements_passed": true,
"runs": [
{
"stop_reason": "goal_met",
"num_turns": 2,
"turns": [
{
"user": "Hi, are you open this Saturday afternoon? I think you're open until 5.",
"assistant": "On Saturdays we're open from 9am to 1pm, so we close at 1pm.",
"llm_request_id": "llmreq_901",
"tool_calls": []
}
],
"requirement_results": [
{
"requirement": "The agent says the office closes at 1pm on Saturdays",
"passed": true,
"explanation": "The agent states the 1pm closing time."
}
]
}
]
}
Simulations are mocked and in memory by default: tools that write or cannot
be undone never reach a live integration and nothing is written, so running
one against main is safe. Reads answer from the live system unless you
pin their answers or mock every tool.
Every turn carries its llm_request_id, so a failing run can be diagnosed
and replayed exactly like a real reply. The Simulating conversations
section below covers fixtures, seeding from the real conversation and
reproducible reruns.
7. Pin it with a saved test, when warranted
Save a test when the behaviour is recurring, high impact, fragile or shared by many agents; a one-off correction for one organization usually needs only the replay and the simulation. To pin the incident turn itself with checks, save it as a test:
curl -X POST "https://api.hilus.ai/Platform/lab/create-test" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"message_id": "msg_456",
"name": "Saturday hours end at 1pm",
"checks": [
{
"type": "content",
"excludes": [
"until 5"
]
},
{
"type": "semantic",
"question": "Does the agent say the office closes at 1pm on Saturdays?"
}
],
"live_entity_keys": [
"Document:doc_321"
],
"branch": "feature/fix-hours"
}'
Entities in live_entity_keys are rebuilt from the current branch on every run; everything else stays frozen as it was at the incident. Put the document you are fixing there, so the test checks your edit rather than the old text. The test is saved even when its first run fails.
8. Open a changeset with the evidence
Promote the branch through a changeset and attach the runs that prove it, so the reviewer sees real artifacts rather than your summary:
curl -X POST "https://api.hilus.ai/Platform/entities/changesets" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from_branch": "feature/fix-hours",
"to_branch": "main",
"description": "Add Saturday and Sunday hours; the agent extended weekday hours to Saturday.",
"origin_ref": "conv_987",
"test_evidence": [
{
"tool": "lab replay",
"ref_id": "llmreq_789",
"outcome": "passed",
"summary": "5/5 replays state the 1pm Saturday closing"
},
{
"tool": "lab simulate",
"ref_id": "async_2f9c",
"branch": "feature/fix-hours",
"outcome": "passed",
"scenario": "Customer asks about Saturday afternoon hours"
}
]
}'
For a simulation, the ref_id is the async id of its run; for a saved
simulation test or workflow scenario it is the run id, which is permanent.
After the merge, rerun the saved tests that cover the change on main.
[!NOTE] Forensics (reading, diagnosing and replaying turns) always work on the frozen request, whatever branch you are on. Edits, simulations of the change and test runs happen on the feature branch. Never test by holding unmocked conversations against production integrations, and never edit a document to mask broken tool data.
Simulating conversations
A simulation drives a model-simulated contact against the agent for up to 20 agent turns and returns the transcript. It catches what a single turn cannot: a wrong sequence of tools, a decision carried into a later turn, or an agent that recovers and then relapses.
Write the scenario as the contact. Say who they are, what they know,
what they want and when to stop. Everything else that happens goes in the
prose too: "once the agent sends the payment link, the payment lands",
"two turns in, the same person texts a photo", "no one writes; the agent's
follow-up job fires". The scenario is read into a typed plan of events,
returned on each run as plan, with any events_not_fired.
Answer tools with fixtures. By default every tool the agent calls gets
a generated, schema-valid answer consistent with the scenario. Pin the
answers that matter with tool_responses,
keyed by tool names the agent really has (see collected_tools in the
rendered context):
curl -X POST "https://api.hilus.ai/Platform/lab/simulate" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "agt_123",
"scenario": "An existing customer calls to move next Tuesday'\''s appointment to later the same week. Stop once a new time is confirmed or they give up.",
"from_number": "+15555550123",
"tool_responses": {
"Scheduler.find_open_slots": "Thursday 10am and Friday 3pm are open; nothing else this week"
},
"requirements": [
"The agent offers only Thursday 10am or Friday 3pm"
],
"moment_now": "2026-09-14T09:30:00-07:00"
}'
Each run's tool_fixture_report says which calls were answered by a
fixture, generated, reused from an earlier run, or real, and which
fixtures went unused (usually because the agent chose a sibling tool).
from_number opens the run like an
inbound phone call, with the agent's caller lookup and greeting first.
Reproduce and rerun. The whole run is evaluated at moment_now. Rerunning with the same moment and byte-identical scenario text replays from cache, so a rerun is fast and comparable; change the moment to force fresh runs. Set n (up to 5) to measure how often a trajectory goes wrong, and give up to 15 requirements per call.
Start from a real conversation. To reproduce an incident that built up over several turns, copy its history with seed_conversation_id and up_to_message_id; the simulated contact continues from there.
[!NOTE] mock_all_tools set to
falselets tools without a fixture read live data once per scenario; writes and irreversible tools are always mocked. store set totruepersists the conversations so you can browse them by id; stored simulations are refused onmainand land on the agent's own simulation branch unless you name a feature branch.
Saved tests
Three kinds of saved test run through run tests:
- An AgentTest pins one turn with content, tool-call and semantic checks. Create one from a reply as in step 7.
- A SimulationTest saves a scenario, its requirements, a run count and a pass threshold. Create it as an entity when a multi-turn behaviour has no other coverage.
- A Workflow's acceptance scenarios are the agent's multi-turn tests for that workflow: one simulated conversation per scenario that applies to the agent's answers. Run them by the workflow's id with the agent under test.
curl -X POST "https://api.hilus.ai/Platform/entities/SimulationTest" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"branch": "feature/fix-hours",
"commit_message": "Regression test for Saturday hours",
"yaml_content": "name: Saturday hours\nagent: agt_123\nscenario: A customer asks whether the office is open Saturday afternoon. Stop once answered.\nrequirements:\n - The agent says the office closes at 1pm on Saturdays\nn: 3\npass_threshold: 1.0"
}'
Select tests by id, or by an HQL query that returns test rows, and name the branch whose configuration they should test:
curl -X POST "https://api.hilus.ai/Platform/lab/run-tests" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"hql": "AgentTest | name ilike '\''%hours%'\'' | limit 5",
"branch": "feature/fix-hours"
}'
curl -X POST "https://api.hilus.ai/Platform/lab/run-tests" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"test_ids": [
"wf_654"
],
"agent_id": "agt_123",
"branch": "feature/fix-hours"
}'
Response:
{
"branch": "feature/fix-hours",
"response_samples": 1,
"judge_runs": 1,
"estimated_agent_generations": 1,
"elapsed_ms": 48210.5,
"total": 2,
"passed": 1,
"failed": 0,
"flaky": 1,
"errored": 0,
"results": [
{
"test_id": "wf_654#after_hours",
"test_name": "Opening hours - after-hours caller",
"kind": "workflow_scenario",
"outcome": "passed",
"pass_fraction": "100%",
"run_id": "simrun_111",
"conversation_ids": []
},
{
"test_id": "wf_654#weekend",
"test_name": "Opening hours - weekend caller",
"kind": "workflow_scenario",
"outcome": "flaky",
"pass_fraction": "67%",
"failed_checks": [
{
"feedback": "The agent offered a Sunday slot: it said the office is open Sunday morning."
}
],
"run_id": "simrun_112",
"conversation_ids": []
}
]
}
There is no run-everything selector: a run is capped at 10
tests, and the request is refused when a selection is larger. For
AgentTests, response_samples
generates several fresh replies and passes only when all of them pass;
mixed results are flaky. One sample is the normal check; use five for
high-impact or previously flaky behaviour. Flaky means the behaviour is
sensitive, and the remedy is clearer instructions, not rerunning until it
passes. Every execution is recorded, so results stay queryable even if
your client disconnects.
Long-running calls
Diagnose, replay, simulate and test runs are asynchronous by default. A
call that does not finish quickly answers 202 Accepted with an async id
(also in the X-Hilus-Async-Id header); poll
the execution until its status is completed
or failed. The protocol is the same for every Hilus service and is
described under Async operations in the API reference introduction.
curl -X GET "https://api.hilus.ai/Platform/jobs/async/async_2f9c" \
-H "Authorization: Bearer $HILUS_API_KEY"
A completed record's result holds the route's documented response. The
record is kept for a limited time after it finishes, and a dropped
connection never discards finished work: poll again with the same id.
Next steps
- Tests cost money: the rules for running tests and attaching evidence.
- Changing what is live: how a branch becomes
mainthrough a reviewed changeset. - Support tickets: report a platform defect a diagnosis points to.
- The lab reference, including every field of a diagnosis and a simulation.
See also: testing, changesets