Simulate whole conversations with an agent from a scenario
POST /Platform/lab/simulate
Simulate whole conversations with an agent from a scenario.
Single-turn diagnose/replay can't catch trajectory failures (wrong
tool sequence, bad state carryover, context dilution,
recover-then-relapse). Simulation drives an LLM-simulated caller
against the agent for up to max_turns turns and returns the
transcript; every agent turn carries its llm_request_id for
diagnose / replay_llm / create_test.
Safety: mock is forced — irreversible tools never execute (they get
an LLM-generated, schema-valid response). By default an un-fixtured
READ runs against the live read API once, memoized per scenario, so
the agent never acts on invented data it was not told to expect.
mock_all_tools=true instead answers every un-fixtured tool
(reads included) with a generated response consistent with the
scenario and the fixtures — no live integration at all. Nothing is
written by default
(ephemeral: no Conversation/Message rows, no branch); store=true
persists the conversations off main.
Reproducibility: the whole run is evaluated at moment_now
(default: the instant the run starts) — system-prompt clock, tool
utcnow, message timestamps, and the simulated caller (cached
per run index). Pass the SAME moment_now and scenario text again
and the run replays from the LLM response cache and the tool-read
memo (fast, no fresh generation); pass a new one to force a fresh
run. Workflow.run_scenarios stores a moment per scenario for
exactly this.
Costs money: every agent turn, simulated-contact turn, generated tool
response and judge verdict is a real model call. The response reports
what the agent itself cost, per run (cost, with the part spent
writing the prompt cache) and on average, cold (cost_per_run_usd)
and with a warm cache (warm_cache_cost_per_run_usd). Asynchronous by
default (pollable result). With requirements an
LLM judge grades each run's transcript (one judge call per
requirement per run) and the response carries PASS/FAIL with
explanations plus totals. Attach a run to a changeset as
test_evidence=[{"tool": "lab simulate", "ref_id": <async_id>, ...}], where async_id is the id this call answers with (the
response itself carries no id). The changeset records the id as
given; the result stays pollable for a day, while each turn's
llm_request_id stays usable for diagnose / replay_llm. Reproduce a trajectory
incident by seeding from a real conversation
(seed_conversation_id + up_to_message_id) and rerunning with
n=5 to measure relapse.
Many contacts in one call: pass scenario a list of scenarios, one
text per contact with that contact's own facts; each runs once. The
first runs alone and writes the agent's prompt
cache, then the rest run 6 at a time and read it, so a
later run costs about the warm-cache price instead of paying the
cache write again, as separate calls started together each would.
requirements, tool_responses and moment_now apply to every
scenario; each run names its scenario and cost sums the batch.
A text given more than once is sampled again for each occurrence, as
n repeats are. At most 100 scenarios. A batch stops
starting runs once its runs have spent more than $25
(agent, simulated contact and judges; see spend_usd) or after
40 minutes: runs already going finish, and each
scenario not started comes back with stop_reason="skipped" and
the reason in failure. For a large batch pass
detail="summary": each run then carries what the contact got
(final_reply), the verdicts and the cost, and the response stays
readable whole. Add report to have each run, and the batch as a
whole, boiled down to the answer you ask for.
Everything that happens is written in the scenario. Cross-channel
events ("once the agent has sent the deposit link, the Stripe
webhook lands: $75 deposit recorded"; "two turns in, his wife texts
from +1760...: 'add Mochi too'"; "no one writes; the agent's
follow-up job for Pesto fires with: ...") and documents the
counterparty sends ("her email carries a one-page rabies certificate
for Pesto: given 2025-03-02 by Dr. Lee") are read out of the prose
into a typed plan (cached per scenario text) and injected the way
production would deliver them. Write a stored document's hash in the
prose (pdf-53ziH9DvJi8) to attach that real file; a described
document is rendered into a PDF. Each run returns its plan and
any events_not_fired.
Body parameters
agent_id: str. Agent under test (must belong to your org).scenario: str. The natural-language scenario, or a list of them for a batch. A scenario says the counterparty's persona, the facts they know, their goal, a stop condition, and anything else that happens during the conversation (see above). E.g. "anxious owner of a diabetic cat asks whether Dr. Sam is in today; a friend told them Sam works Mondays; stop once given a definitive answer". Byte-identical text is part of the replay/memo identity. A scenario in which nobody talks to the agent (driven purely by events) is allowed. One text runsntimes. A list is a batch, one scenario per contact: each runs once, the first alone, and the runs come back in list order. At most 100; a list of two or more is not combined withnabove 1 (a list of one is the same as its text). Runs not started once the batch passes $25 of spend or 40 minutes come back skipped.branch: optional str. Which version of the Documents/Agent to test. Default: your configured branch (mainis fine). Withstore=trueit is also where the conversations land:mainis then refused and the default becomeslab/sim-<agent_id>.max_turns: optional int. Hard cap on agent turns per run (default 10, max 20).n: optional int. Run the same scenario N times for trajectory-level flakiness (default 1, capped at 5). Each run index gets its own caller salt, so the N trajectories differ and each is reproducible.seed_conversation_id: optional str. Real conversation to copy history from (frozen, not re-executed); the caller continues from there.up_to_message_id: optional str. Copy seed messages up to (exclusive) this id.requirements: optional List[Any]. Natural-language expectations graded per run by an LLM judge, e.g. ["The agent emailed a confirmation to the address the contact gave", "The agent never named a staff member unprompted"]. Max 15.tool_responses: optional str. Canned tool answers. Simplest form is a MAP of tool name -> plain-language description, which answers every call of that tool with an LLM-shaped, schema-valid value:{"lookup_phone_number": "one client, Jon Smith, one cat Pesto"}. The map value may also be a list of ordered entries (a literal value, or{when, response|describe|failure, repeat}). The LIST form[{"tool": ..., "responses": [...]}]is equivalent; there each response is a plain string (= describe, every call) or an object with exactly one ofresponse(literal value, passed through as-is),describe(natural language; an LLM shapes it into the tool's return schema) orerror(the tool fails), optionally gated bywhen:[{"tool": "lookup_phone_number", "responses": ["existing client Jon Smith, one cat Pesto", {"when": {"args_subset": {"limit": 2}, "call": 2}, "error": "PIMS down"}]}]. Entries are consumed in order (first unconsumed match wins); a call no entry matches falls back to LLM generation. Each run gets a fresh copy;tool_fixture_reportper run says which calls were fixture / generated / memoized / real and which fixtures went unused. Malformed fixtures are rejected (400), never silently ignored.mock_all_tools: optional bool. Default false: un-fixtured reads run live (memoized per scenario) and only irreversible tools are generated. True = answer EVERY un-fixtured tool (reads included) with an LLM-generated, schema-valid response derived from the scenario text, the supplied fixtures (also lent as examples to sibling tools on the same integration) and prior generated calls — the agent lives in the scenario's world and never touches a live integration. Use it for fictional scenarios, and fixture every read whose answer the test depends on.from_number: optional str. Open the run like an inbound phone call from this number: the agent'sinitial_tool_invocationstemplated on{Call.from_number}(caller lookup) run first, the agent's configured greeting opens the transcript, and the caller is told this is its number. Without it the conversation opens as anonymous webchat. Ignored when seeding.touchpoint: optional str. Touchpoint TYPE the contact arrives on (a concreteTouchpointsubclass name; see the list below). The simulation opens, delivers caller turns and exposes session tools exactly the way that type does in production. Default: the type routed to this agent that supportsmode.mode: optional str. Event type on that touchpoint (voice,sms,fax,email,webchat,form). Default:voicewhenfrom_numberis given, elsewebchat.source: optional str. The contact's identifier (phone number or email address); defaults tofrom_number.store: optional bool. Persist the simulated conversations (default false). Set true to browse them afterwards or drill by message id; they then land on a non-main branch (seebranch).moment_now: optional moment. The instant the simulation is evaluated at (amoment, e.g.2026-09-14T09:30:00-07:00). Default: run start. Reuse a value to replay; change it to refresh (it is part of the tool-read memo identity).verbose: optional bool. Same asdetail="full", kept for existing callers. Combined withdetail="summary"or"none"it is a 400.memoize_tool_results: optional bool. Default true: the result of every live read is memoized per exact scenario text (andmoment_now), so a rerun of the same scenario answers the same reads from the memo and is reproducible. False runs every un-fixtured read live and records nothing, for when the integration's data changed since the last run.detail: optional "none" or "summary" or "turns" or "full". How much of each run the response carries; the totals (goal_met_count, requirement counts,costand the per-run means) are the same at every level, and every run hasfinal_reply, the agent's last reply."turns"(default): each turn carriesuser,assistant,tool_calls(names),tool_errorsand thellm_request_iddrill-down handle, plus the run'splan,openingandtool_fixture_report. Stored runs (store=true) also include the raw messages, since they are browsable by id anyway."summary": each run keeps onlyscenario,conversation_id,stop_reason,failure,num_turns,final_reply, the requirement verdicts andcost; turns, plan, opening, touchpoint and fixture report are left empty, even withstore=true. Judging still reads the whole transcript."full": as"turns"plus the rawmessages/opening_messageswith full tool arguments and results (large)."none": each run keeps onlyscenario,stop_reason,failure,conversation_idandreport, for when the totals, which runs failed and thereportanswer are all you want. Any other value is a 400.report: optional str. What you want back, in plain language, e.g. "for each client: channel used, the exact message sent, and whether it mentions every due item". A cheap model reads each whole run (every turn with its tool calls and results, the plan and the verdicts, whateverdetailis) and answers it in the run'sreport; for several runs one more call combines the answers into the response'sreport. It answers only from the transcript and says "not in the transcript" rather than guess. Costs a little extra, reported inreport_cost_usd; never part ofcost. Pair it withdetail="summary"for a large batch, ordetail="none"to get only the answers and the totals. At most 2000 characters (longer is a 400); blank means none.
Returns
SimulateResponse
agent_id: str. Agent under test.branch: optional str or null. Branch whose entity state drove the runs. Withstore=trueit is also where the simulated conversations were persisted; null means the caller's configured branch (ephemeral run, nothing written).store: optional bool. Whether the simulated conversations were persisted.moment_now: optional str or null. Frozen clock (ISO instant) the runs were evaluated at; null = wall clock.n: int. Runs executed:nfor one scenario, one per scenario for a list of scenarios.goal_met_count: int. Runs whose simulated caller reached its goal.runs: optional List[SimulateRun]. One entry per run.requirements: optional List[str]. The requirements judged.tool_responses: optional List[ToolFixture]. The tool fixtures this simulation ran with (normalized), echoed back so the async result is self-describing and replayable.requirements_passed_count: optional int or null. Requirement verdicts that passed, across all runs.requirements_total_count: optional int or null. Judged requirements across all runs (n x requirements).all_requirements_passed: optional bool or null. Every requirement passed in every judged run.cost: optional SimulateCost or null. What the agent under test cost across all runs, including the tools, live reads and subagents it triggered, in US dollars at provider prices before any billing margin. Excludes the simulated contact, generated tool responses and judges. Runs replayed from the response cache cost (close to) nothing; pass a newmoment_nowto measure fresh runs.cost_per_run_usd: optional float or null. Mean ofcost.total_usdover the runs that started: what one conversation with this agent costs, in US dollars at provider prices before any billing margin, including writing the prompt cache. Seewarm_cache_cost_per_run_usdfor the cost once the cache is warm.warm_cache_cost_per_run_usd: optional float or null. Mean ofcost.warm_cache_usdover the runs that started: what one conversation costs when the prompt cache is already warm, as for clients who follow each other, in US dollars at provider prices before any billing margin. Conversations started at the same moment each pay the cache write.report: optional str or null. The answer toreportacross all runs: for one run, that run'sreport; for several, one more cheap-model call that combines the per-run answers. Null withoutreport.report_cost_usd: optional float or null. What thereportcalls cost (one per run, plus the combining call for several runs), in US dollars at provider prices before any billing margin. Never part ofcost. Null withoutreport.spend_usd: optional float or null. Everything the runs and reports of this call spent, in US dollars at provider prices before any billing margin: the agent, the simulated contact, the judges andreport_cost_usd. Generated tool responses are not counted. A batch stops starting runs once its runs' part of this passes the batch spend cap.
Example request
curl -X POST "https://api.hilus.ai/Platform/lab/simulate" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'