Simulated users
A turn producer plays the user in multi-turn conversations, scripted or backed by an existing simulator, in code and in the case runner.
Fixed turns work when you know every user message up front. When the next message depends on what the agent said,
a turn producer plays the user: a function from the conversation so far to the next message, or None / null
to stop. Produced messages are recorded as message events with attributes.simulated: true.
The producer receives a Conversation: messages (oldest first, the agent's replies as assistant),
last_reply / lastReply, turn (0-based), case_id / caseId, the run's worlds (so a simulated customer can
react to what the agent actually did), and session for its own memory.
# A scripted customer: opens with the problem, answers the question, stops once the refund is confirmed.
# For an LLM persona, adapt an openevals simulated user with openevals_user(...), or ask any simulator in here.
def customer(c: Conversation) -> str | None:
if c.turn == 0:
return "My kettle arrived damaged."
if c.last_reply and "order number" in c.last_reply:
return "It's A-1001."
return None
// A scripted customer: opens with the problem, answers the question, stops once the refund is confirmed.
// For an LLM persona, adapt an openevals simulated user with openevalsUser(...), or ask any simulator in here.
const customer: UserTurn = ({ turn, lastReply }) => {
if (turn === 0) return "My kettle arrived damaged.";
if (lastReply?.includes("order number")) return "It's A-1001.";
return null;
};In code
converse(agent, user) alternates the producer and your agent inside trace() until the producer stops or
max_turns / maxTurns (default 10) user turns ran, and returns the conversation.
async def main() -> None:
async with trace() as t:
await converse(support_agent(), customer)
assert t.tool_names == ["lookup_order", "issue_refund"]
said = [e.content for e in t.events if e.type == "message"] # recorded with attributes.simulated: true
assert said == ["My kettle arrived damaged.", "It's A-1001."]
asyncio.run(main())const t = await trace(() => converse(supportAgent(), customer));
assert.deepEqual(t.toolNames, ["lookup_order", "issue_refund"]);
const said = t.events.filter((e) => e.type === "message").map((e) => (e as { content?: string }).content);
assert.deepEqual(said, ["My kettle arrived damaged.", "It's A-1001."]); // recorded with attributes.simulated: trueIn the case runner
Pass the producer as user= to run_cases (Python) or user in runCases and describeCases options
(TypeScript). After the case's own prompt or turns, it writes each next turn until it stops or the turn limit is
reached. It is not used for input.script cases.
# In a case, the producer writes the turns after the case's own prompt (here it skips turn 0, which the case has).
def follow_up(c: Conversation) -> str | None:
return "It's A-1001." if c.last_reply and "order number" in c.last_reply else None
cases = parse_case_file(
"""
id: refund-after-a-question
input: "My kettle arrived damaged."
expect:
tools: { exactly: [lookup_order, issue_refund] }
output: { contains: R-1001 }
""",
"evals/refund-after-a-question.yaml",
)
async def agent(case_input: CaseInput) -> str:
# One agent per run, kept in `session` across the turns.
answer = case_input.session.setdefault("agent", support_agent())
return await answer(case_input.prompt)
report = run_cases(cases, config=resolve_config(agent=agent), store=MemoryFixtureStore(), mode="live", user=follow_up)
assert report["verdicts"][0]["status"] == "pass", report["verdicts"][0]// In a case, the producer writes the turns after the case's own prompt (here it skips turn 0, which the case has).
const followUp: UserTurn = (c) => (c.lastReply?.includes("order number") ? "It's A-1001." : null);
const cases = parseCaseFile(
`
id: refund-after-a-question
input: "My kettle arrived damaged."
expect:
tools: { exactly: [lookup_order, issue_refund] }
output: { contains: R-1001 }
`,
"evals/refund-after-a-question.yaml",
);
const config = resolveConfig({
// One agent per run, kept in `session` across the turns.
agent: (input: CaseInput) => {
input.session.agent ??= supportAgent();
return (input.session.agent as ReturnType<typeof supportAgent>)(input.prompt);
},
});
const report = await runCases(cases, { config, store: memoryFixtureStore(), mode: "live", user: followUp });
assert.equal(report.verdicts[0]?.status, "pass");LLM personas
Viewport Evals does not ship its own persona engine. openevals_user(...) / openevalsUser(...) adapts an openevals
simulated user (create_llm_simulated_user / createLLMSimulatedUser, or a custom function of the same shape) into
a producer. For other simulators, such as Scenario or ADK, write a producer that asks them for the next message.
A producer's own model calls run inside the case's record and replay scope but outside the agent's capture: they are recorded and replayed with the fixture, and never count toward the agent's model calls or budget.
Next: model matrix and flakes.
Simulated time
Run reminders, waits, scheduled jobs and multi-day conversations in milliseconds on a simulated clock, in code and as multi-episode YAML cases.
Production replay
Turn a Langfuse, LangSmith or Braintrust trace into a regression test with one command, replay a new agent version against the trace's real tool responses, and assert the behavior diff.