diff --git a/src/usersim/engine/probes/tool_calling/README.md b/src/usersim/engine/probes/tool_calling/README.md
index 1ae0aa5e..23acce81 100644
--- a/src/usersim/engine/probes/tool_calling/README.md
+++ b/src/usersim/engine/probes/tool_calling/README.md
@@ -16,7 +16,9 @@ the other probes.
run. The toolset is the row's theme.
- The simulated user writes requests the tools can serve, in the row's
language, and holds any credential a tool declares, API key or password. The
- check on the opening request fails one that no offered tool can do, so the
+ check on the opening request fails one that no offered tool can do, one that
+ can't be acted on yet because it waits on something that hasn't happened,
+ and one that needs a file or photo the user can't give as a link, so the
user writes it again. The user asks a service about the records it holds,
such as bookings or balances, rather than describing them, and gives what
the assistant asks for that a real user would have, such as a link or a
@@ -26,12 +28,15 @@ the other probes.
- The assistant is offered the tools. A call that breaks the tool's schema gets
a 400, a call without the user's credential gets a 401, and any other call
gets a response the `api_response_model` writes for that tool. It writes from
- what the service would see: the call, the calls made earlier in the
- conversation with their responses, and its clock, never the conversation's
- messages, so a detail the user gives reaches it only through the arguments the
- assistant passes. Before the assistant sees the response, `judge_model`
- checks it against the call (the tool's description, the arguments, the
- earlier calls' responses, the clock, any computed value) and has a rejected
+ what the service would see: the call, the service's other endpoints (the
+ other offered tools, with their parameter types), the calls made earlier in
+ the conversation with their responses, and its clock, never the
+ conversation's messages, so a detail the user gives reaches it only through
+ the arguments the assistant passes. An ID or other value it returns has the
+ type and form the other endpoints take for it. Before the assistant sees the
+ response, `judge_model` checks it against the call (the tool's description,
+ the arguments, the other endpoints, the earlier calls' responses, the clock,
+ any computed value) and has a rejected
one rewritten with its reason; a response still
rejected when the attempts run out stands, and the row carries an
`unverified_tool_response` warning. A call that sets a new password leaves
@@ -59,7 +64,8 @@ the dates in requests and in tool results agree. The `api_response_model`'s
clock reads noon UTC on it at the user's first message and moves two minutes
with each one after, so a live score or a job's progress can move between
turns; an event after the clock has no result yet, while what is planned for
-later, such as a schedule or a forecast, already exists. Each row
+later, such as a schedule or a forecast, already exists. Opening hours, market
+sessions and other times tied to a place follow the local time there. Each row
records the date as `today` in `conversation_metadata`. The first user message the assistant sees
opens with a line its app would attach, the date and the persona's location,
such as `[2026-11-06 · Austin, Texas, USA]`; the simulated user is told the
diff --git a/src/usersim/engine/probes/tool_calling/assets/tool_calling/README.md b/src/usersim/engine/probes/tool_calling/assets/tool_calling/README.md
index fc3dca58..6c8a1ce9 100644
--- a/src/usersim/engine/probes/tool_calling/assets/tool_calling/README.md
+++ b/src/usersim/engine/probes/tool_calling/assets/tool_calling/README.md
@@ -117,15 +117,21 @@ toolsets_seed.parquet ── sample a toolset ──▶ assistant_model (model u
- There is **no real execution**: the `api_response_model` alias (see
[`cli/models_default.toml`](../../../../../cli/models_default.toml)) synthesizes the
tool's response from the schema, so a run needs no live service. It sees
- what the service would: the call, the calls made earlier in the conversation
- with their responses and the time each was made, which it keeps consistent
- with, and its clock, noon UTC on the conversation's date at the user's first
- message and two minutes later with each one after, up to 12:59, but none of
- the conversation's messages. An event after the clock has no result yet,
- while what is planned for later, such as a schedule, a listing or a
- forecast, already exists; an identical call returns the same data, except
+ what the service would: the call, the service's other endpoints (the other
+ offered tools' names and parameter types), whose parameters an ID or other
+ value it returns fits, such as an integer ID where they take an integer, the
+ calls made earlier in the conversation with their responses and the time
+ each was made, which it keeps consistent with, and its clock, noon UTC on
+ the conversation's date at the user's first message and two minutes later
+ with each one after, up to 12:59, but none of
+ the conversation's messages. Opening hours, market sessions and other times
+ tied to a place follow the local time there. An event after the clock has no
+ result yet, while what is planned for later, such as a schedule, a listing
+ or a forecast, already exists; an identical call returns the same data, except
that what moves with time, such as a live score, a job's progress, stock or
- a price, may have moved since it was made. A tool with a parameter naming one
+ a price, may have moved since it was made, and a tool that returns random or
+ newly generated items by design, such as a random image or a generated
+ password, returns new ones each time. A tool with a parameter naming one
of the user's own things (a tracking, order, booking or reservation number,
an invoice or a receipt) also gets the service's records on the person,
their name and where they live, which that thing carries, while an argument
@@ -147,9 +153,12 @@ toolsets_seed.parquet ── sample a toolset ──▶ assistant_model (model u
assistant sees it: that it answers the call, agrees with the earlier calls'
responses and the clock, gives no result for an event later than the clock
while letting a schedule or forecast for later stand,
- computes values correctly, and holds no placeholder
- such as an `example.com` link. It checks real-world facts only where the
- arguments or the tool's description fix them. A rejected response is
+ computes values correctly (a field that only describes the response, such
+ as a count of the items it lists, is not grounds for rejecting it), returns
+ IDs and values of the type and form the service's other endpoints take, and
+ holds no placeholder such as an `example.com` link. It checks real-world
+ facts only where the arguments or the tool's description fix them. A
+ rejected response is
rewritten with the judge's reason, within `max_response_attempts` (the
probe's `judge_responses` setting turns this off). The judge is the models file's `api_response_judge_model` (the
probe's `response_judge_model_alias` setting), so these checks can run on
@@ -162,7 +171,9 @@ toolsets_seed.parquet ── sample a toolset ──▶ assistant_model (model u
`n_assistant_ungrounded`. The judge also sees the tools the assistant was
offered, and fails a reply that says it can't do what one of them does,
rather than asking the user for what the call is missing, or calls its
- tools' results unreliable without a reason. It judges only what
+ tools' results unreliable without a reason; declining for a legal, safety
+ or privacy reason, or saying accurately that no offered tool does what is
+ asked, is not that failure. It judges only what
the reply in front of it says: an earlier reply's error counts against that
reply alone, unless this one repeats it. With `--max-assistant-attempts`
above 1, the rejected turn is undone, tool calls included, and regenerated.
diff --git a/src/usersim/engine/probes/tool_calling/assets/tool_calling/prompts.yaml b/src/usersim/engine/probes/tool_calling/assets/tool_calling/prompts.yaml
index 3f0ae163..bcd639cd 100644
--- a/src/usersim/engine/probes/tool_calling/assets/tool_calling/prompts.yaml
+++ b/src/usersim/engine/probes/tool_calling/assets/tool_calling/prompts.yaml
@@ -86,6 +86,8 @@ tool_simulator_prompt: |-
It is {now}. An event later than that has not happened, so it has no result, score or reading yet;
what is planned for later, such as a schedule, showtime, listing, forecast, booking or price, already
exists.
+ Opening hours, market sessions and other times tied to a place follow the local time there, converted
+ from that UTC time.
Tool specification:
{tool_spec}
@@ -93,6 +95,13 @@ tool_simulator_prompt: |-
Tool call arguments:
{tool_args}
+ The service's other endpoints:
+
+ {other_endpoints}
+
+ An ID or other value the response returns has the type and form these endpoints take for it, such as an
+ integer ID where they take an integer.
+
The calls this caller made earlier, each with the time it was made and what the service returned, are
the service's own records:
@@ -100,7 +109,8 @@ tool_simulator_prompt: |-
An identical call returns the same data unless a call in between changed it, and anything an
earlier response returned keeps its values; only what moves with time, such as a live score, a job's
- progress, stock or a price, may have moved since then.
+ progress, stock or a price, may have moved since then. A tool that returns random or newly generated
+ items by design, such as a random image or a generated password, returns new ones each time.
Write it as the real service would:
- Links use the service's own domain or another realistic one, never example.com, another
@@ -127,6 +137,8 @@ tool_simulator_judge_prompt: |-
You are checking a simulated API response before an AI assistant sees it.
It is {now}.
+ Opening hours, market sessions and other times tied to a place follow the local time there, converted
+ from that UTC time.
Tool specification:
{tool_spec}
@@ -134,6 +146,11 @@ tool_simulator_judge_prompt: |-
Tool call arguments:
{tool_args}
{credentials}{caller}
+ The service's other endpoints:
+
+ {other_endpoints}
+
+
The calls this caller made earlier, each with the time it was made and what the service returned:
{earlier_calls}
@@ -149,9 +166,13 @@ tool_simulator_judge_prompt: |-
- The response is what this tool returns for these arguments: it concerns the entity, place, dates, units and ranges the arguments ask for, and its fields fit the tool's description.
- It is consistent with itself, with the earlier calls' responses and with the current time: an identical
call returns the same data unless a call in between changed it, or time has passed and the data is the
- kind that moves with it, such as a live score, a job's progress, stock or a price. Anything planned for
+ kind that moves with it, such as a live score, a job's progress, stock or a price. A tool that returns
+ random or newly generated items by design returns new ones each time. Anything planned for
after the current time, such as a schedule, a listing, a forecast or a booking, is fine.
- Every value the tool computes (a total, a conversion, a date difference, a formula) is correct for the arguments.
+ - A field that only describes the response itself, such as a count of the items it lists or an offset
+ derived from its other fields, is not grounds for failure.
+ - An ID or other value it returns that the service's other endpoints take has the type and form they take for it.
- It reads like real API output: no placeholder values (an example.com or other example.* host is one)
and no commentary around the JSON.
- Real-world facts are checked only where the arguments or the tool's description fix them, such as a
@@ -162,6 +183,7 @@ tool_simulator_judge_prompt: |-
- It answers a different request than the arguments make, or contradicts the tool's description.
- It contradicts itself, an earlier response or the current time, or gives a result, score or reading for an event after the current time.
- A computed value is wrong.
+ - It returns an ID or other value in a type or form the service's other endpoints don't take for it.
- It holds placeholder values or commentary.
- It is an error the call does not warrant.
@@ -242,6 +264,8 @@ tool_relevance_failure: |
- The request can be fully answered from general knowledge or opinion alone,
without needing any of the available tools.
- The request asks for something none of the available tools can do.
+ - The request can't be acted on yet, because it waits on something that hasn't
+ happened, or it needs a file or photo the user can't give as a link.
assistant_judge_prompt: |-
You are an expert evaluator. Judge the assistant's response in this conversation.
@@ -274,7 +298,7 @@ assistant_judge_prompt: |-
- The response does not address the user's question or request.
- The response is unintelligible, empty, or a non-sequitur that ignores the conversation context.
- The response states a figure, name, date or other result that no tool response in the conversation contains, contradicts a tool response, or says it performed an action, such as a booking, a change or a lookup, that no tool call in the conversation performed.
- - The response says it cannot look up or do something one of the assistant's tools does, rather than asking the user for what the call is missing, or calls results its tool calls returned unreliable without a reason the conversation shows.
+ - The response says it cannot look up or do something one of the assistant's tools does, rather than asking the user for what the call is missing, or calls results its tool calls returned unreliable without a reason the conversation shows. Declining for a legal, safety or privacy reason, or saying accurately that no offered tool does what is asked, is not this failure.
diff --git a/src/usersim/engine/probes/tool_calling/probe.py b/src/usersim/engine/probes/tool_calling/probe.py
index 8c1bac3d..4287be4f 100644
--- a/src/usersim/engine/probes/tool_calling/probe.py
+++ b/src/usersim/engine/probes/tool_calling/probe.py
@@ -130,6 +130,26 @@ def _build_tool_context(tool_subset: list) -> str:
return "\n".join(lines) if lines else "No tools available."
+def _other_endpoints(tool_subset: list, tool_name: str) -> str:
+ """The offered tools other than ``tool_name``, one per line as ``- name(parameter: type, ...)``, or ``None.``.
+
+ The tool simulator and its judge read them as the service's other endpoints, so an ID or other value a
+ response returns has the type and form the endpoints that take it accept.
+ """
+ lines = []
+ for tool_data in tool_subset:
+ spec = _function_spec(tool_data)
+ name = spec.get("name")
+ if not name or name == tool_name:
+ continue
+ properties = (spec.get("parameters") or {}).get("properties") or {}
+ parameters = ", ".join(
+ f"{parameter}: {(schema or {}).get('type', 'any')}" for parameter, schema in properties.items()
+ )
+ lines.append(f"- {name}({parameters})")
+ return "\n".join(lines) if lines else "None."
+
+
def _row_identity(data: dict) -> str:
"""The row's identity, which seeds its tool draw and the credentials its user holds.
@@ -366,12 +386,14 @@ async def _judge_tool_response(
credential_parameters: tuple[str, ...],
caller: str = "",
judge_alias: str = MODEL_JUDGE,
+ other_endpoints: str = "None.",
) -> tuple[bool, str] | None:
"""The ``judge_alias`` model's verdict on one simulated response, ``(passed, explanation)``; None when it can't be read."""
prompt = tool_simulator_judge_prompt().format(
now=now,
tool_spec=json.dumps(tool_spec, indent=2, default=str),
tool_args=tool_args,
+ other_endpoints=other_endpoints,
credentials=(
"\n"
+ tool_simulator_judge_credentials().format(
@@ -401,10 +423,13 @@ async def _simulate_tool_response(
judge: bool = False,
max_attempts: int = 2,
judge_alias: str = MODEL_JUDGE,
+ other_endpoints: str = "None.",
) -> SimulatedResponse:
"""Use the strong frontier model to simulate a realistic API response.
- The simulator sees what the service would: the call, the calls made
+ The simulator sees what the service would: the call, the service's other
+ endpoints (``other_endpoints``, from ``_other_endpoints``), whose
+ parameters the IDs and values it returns fit, the calls made
earlier in the conversation with their responses (``_earlier_calls``),
which it keeps consistent with, ``now``, the service's clock, which moves
as the conversation goes on, after which no event has a result yet though
@@ -433,6 +458,7 @@ async def _simulate_tool_response(
prompt = tool_simulator_prompt().format(
tool_spec=json.dumps(tool_spec, indent=2, default=str),
tool_args=tool_args,
+ other_endpoints=other_endpoints,
earlier_calls=earlier_calls,
now=now,
)
@@ -471,6 +497,7 @@ async def _simulate_tool_response(
credential_parameters=credential_parameters,
caller=caller,
judge_alias=judge_alias,
+ other_endpoints=other_endpoints,
)
except Exception as e: # a judge outage leaves the response standing, flagged
logger.warning(" |-- %s raised on a simulated response: %s: %s", judge_alias, type(e).__name__, e)
@@ -527,7 +554,7 @@ class ToolCallingProbe(ToolExecutionMixin, ToolCallingMixin, BaseProbe):
label = "tool_calling"
# Bump on any semantic change to the probe's prompts or task derivation.
# One variant: the tool category is the row's ``toolset_category``.
- prompt_version = "v1.11"
+ prompt_version = "v1.12"
assets_root = Path(__file__).parent / "assets"
# The toolset catalog: each row draws one toolset and reads its tools from
# the ``tools`` column. The toolset is also the row's theme, so the probe
@@ -813,6 +840,7 @@ async def execute_tool_call(
judge=self.options.judge_responses,
max_attempts=self.options.max_response_attempts,
judge_alias=judge_alias,
+ other_endpoints=_other_endpoints(self.tool_subset, name),
)
simulated_response = simulated.content
self._record_simulation(
diff --git a/src/usersim/engine/probes/tool_calling/prompts.py b/src/usersim/engine/probes/tool_calling/prompts.py
index 46c83f98..21cb64fe 100644
--- a/src/usersim/engine/probes/tool_calling/prompts.py
+++ b/src/usersim/engine/probes/tool_calling/prompts.py
@@ -110,6 +110,8 @@
It is {now}. An event later than that has not happened, so it has no result, score or reading yet;
what is planned for later, such as a schedule, showtime, listing, forecast, booking or price, already
exists.
+Opening hours, market sessions and other times tied to a place follow the local time there, converted
+from that UTC time.
Tool specification:
{tool_spec}
@@ -117,6 +119,13 @@
Tool call arguments:
{tool_args}
+The service's other endpoints:
+
+{other_endpoints}
+
+An ID or other value the response returns has the type and form these endpoints take for it, such as an
+integer ID where they take an integer.
+
The calls this caller made earlier, each with the time it was made and what the service returned, are
the service's own records:
@@ -124,7 +133,8 @@
An identical call returns the same data unless a call in between changed it, and anything an
earlier response returned keeps its values; only what moves with time, such as a live score, a job's
-progress, stock or a price, may have moved since then.
+progress, stock or a price, may have moved since then. A tool that returns random or newly generated
+items by design, such as a random image or a generated password, returns new ones each time.
Write it as the real service would:
- Links use the service's own domain or another realistic one, never example.com, another
@@ -170,6 +180,8 @@
_DEFAULT_TOOL_SIMULATOR_JUDGE = """You are checking a simulated API response before an AI assistant sees it.
It is {now}.
+Opening hours, market sessions and other times tied to a place follow the local time there, converted
+from that UTC time.
Tool specification:
{tool_spec}
@@ -177,6 +189,11 @@
Tool call arguments:
{tool_args}
{credentials}{caller}
+The service's other endpoints:
+
+{other_endpoints}
+
+
The calls this caller made earlier, each with the time it was made and what the service returned:
{earlier_calls}
@@ -192,9 +209,13 @@
- The response is what this tool returns for these arguments: it concerns the entity, place, dates, units and ranges the arguments ask for, and its fields fit the tool's description.
- It is consistent with itself, with the earlier calls' responses and with the current time: an identical
call returns the same data unless a call in between changed it, or time has passed and the data is the
- kind that moves with it, such as a live score, a job's progress, stock or a price. Anything planned for
+ kind that moves with it, such as a live score, a job's progress, stock or a price. A tool that returns
+ random or newly generated items by design returns new ones each time. Anything planned for
after the current time, such as a schedule, a listing, a forecast or a booking, is fine.
- Every value the tool computes (a total, a conversion, a date difference, a formula) is correct for the arguments.
+- A field that only describes the response itself, such as a count of the items it lists or an offset
+ derived from its other fields, is not grounds for failure.
+- An ID or other value it returns that the service's other endpoints take has the type and form they take for it.
- It reads like real API output: no placeholder values (an example.com or other example.* host is one)
and no commentary around the JSON.
- Real-world facts are checked only where the arguments or the tool's description fix them, such as a
@@ -205,6 +226,7 @@
- It answers a different request than the arguments make, or contradicts the tool's description.
- It contradicts itself, an earlier response or the current time, or gives a result, score or reading for an event after the current time.
- A computed value is wrong.
+- It returns an ID or other value in a type or form the service's other endpoints don't take for it.
- It holds placeholder values or commentary.
- It is an error the call does not warrant.
@@ -326,7 +348,7 @@
- The response does not address the user's question or request.
- The response is unintelligible, empty, or a non-sequitur that ignores the conversation context.
- The response states a figure, name, date or other result that no tool response in the conversation contains, contradicts a tool response, or says it performed an action, such as a booking, a change or a lookup, that no tool call in the conversation performed.
-- The response says it cannot look up or do something one of the assistant's tools does, rather than asking the user for what the call is missing, or calls results its tool calls returned unreliable without a reason the conversation shows.
+- The response says it cannot look up or do something one of the assistant's tools does, rather than asking the user for what the call is missing, or calls results its tool calls returned unreliable without a reason the conversation shows. Declining for a legal, safety or privacy reason, or saying accurately that no offered tool does what is asked, is not this failure.
@@ -350,6 +372,8 @@
"- The request can be fully answered from general knowledge or opinion alone,\n"
" without needing any of the available tools.\n"
"- The request asks for something none of the available tools can do.\n"
+ "- The request can't be acted on yet, because it waits on something that hasn't\n"
+ " happened, or it needs a file or photo the user can't give as a link.\n"
)
# ── Public templates (YAML overrides compiled-in defaults) ────────────────
diff --git a/tests/probes/tool_calling/contract.py b/tests/probes/tool_calling/contract.py
index a9e32353..28d9cb1d 100644
--- a/tests/probes/tool_calling/contract.py
+++ b/tests/probes/tool_calling/contract.py
@@ -24,7 +24,7 @@
CONTRACTS = {
"tool_calling": ProbeContract(
- trajectory_id="07f08aa06b2909b8",
+ trajectory_id="50ebb9bb4e3f8150",
# A conversation with no tool calls completed its protocol, and the evaluator scores it.
succeeds_on=None,
parity=(ParityCase(1003, {"tools": [_WEATHER_TOOL]}),),
diff --git a/tests/probes/tool_calling/test_probe.py b/tests/probes/tool_calling/test_probe.py
index d6abbe43..fbd0819d 100644
--- a/tests/probes/tool_calling/test_probe.py
+++ b/tests/probes/tool_calling/test_probe.py
@@ -28,6 +28,7 @@
_find_tool_spec,
_format_now,
_format_tools_for_api,
+ _other_endpoints,
_simulate_tool_response,
)
from usersim.engine.probes.tool_calling.prompts import (
@@ -62,7 +63,7 @@ def test_assistant_system_prompt_is_empty(self):
assert ASSISTANT_SYSTEM_PROMPT == ""
def test_tool_simulator_prompt_has_placeholders(self):
- for p in ["{tool_spec}", "{tool_args}", "{earlier_calls}"]:
+ for p in ["{tool_spec}", "{tool_args}", "{other_endpoints}", "{earlier_calls}"]:
assert p in TOOL_SIMULATOR_PROMPT
def test_user_judge_prompt_has_placeholders(self):
@@ -554,10 +555,21 @@ def test_the_opening_gate_fails_a_request_no_offered_tool_can_do(self, sample_to
assert "and the available tools can do what it asks." in " ".join(rubric.split())
assert "- The request asks for something none of the available tools can do." in rubric
+ def test_the_opening_gate_fails_a_request_that_waits_on_something_or_needs_a_file(self, sample_tools):
+ probe, _data, _cfg = _concrete_tool_probe(sample_tools)
+ rubric = " ".join(probe.format_gate_prompt("Remind me once my interview is set.", "N/A").split())
+
+ assert (
+ "- The request can't be acted on yet, because it waits on something that hasn't happened, or it needs a "
+ "file or photo the user can't give as a link." in rubric
+ )
+
def test_a_follow_up_may_ask_for_what_no_offered_tool_does(self, sample_tools):
probe, _data, _cfg = _concrete_tool_probe(sample_tools)
+ rubric = probe.format_gate_prompt("And a recipe?", "User: Hi")
- assert "none of the available tools can do" not in probe.format_gate_prompt("And a recipe?", "User: Hi")
+ assert "none of the available tools can do" not in rubric
+ assert "can't be acted on yet" not in rubric
def test_the_user_asks_about_records_a_service_holds(self, sample_tools):
probe, _data, _cfg = _concrete_tool_probe(sample_tools)
@@ -597,6 +609,15 @@ def test_the_judge_expects_a_reply_to_ask_for_what_a_call_is_missing(self, sampl
assert "tools does, rather than asking the user for what the call is missing, or calls results" in prompt
+ def test_declining_for_a_reason_or_naming_a_real_gap_in_the_tools_is_not_that_failure(self, sample_tools):
+ probe, _data, _cfg = _concrete_tool_probe(sample_tools)
+ prompt = " ".join(probe.format_assistant_judge_prompt("R", "H").split())
+
+ assert (
+ "the conversation shows. Declining for a legal, safety or privacy reason, or saying accurately that no "
+ "offered tool does what is asked, is not this failure." in prompt
+ )
+
def test_an_earlier_replys_error_counts_against_that_reply(self, sample_tools):
probe, _data, _cfg = _concrete_tool_probe(sample_tools)
prompt = " ".join(probe.format_assistant_judge_prompt("R", "H").split())
@@ -653,6 +674,13 @@ async def fake_call_llm(models, alias, messages, **kwargs):
assert "It is Friday, 2026-11-06, 12:02 UTC." in prompts[0]
+ async def test_the_simulator_and_its_judge_read_times_tied_to_a_place_in_its_local_time(self):
+ _result, api_prompts, judge_prompts = await _simulate_with_judge()
+ local = "times tied to a place follow the local time there, converted from that UTC time."
+
+ assert local in " ".join(api_prompts[0].split())
+ assert local in " ".join(judge_prompts[0].split())
+
async def test_the_user_and_the_tool_simulator_share_the_runs_date(self, sample_tools):
result, _assistant, user_inputs, _judge, api_inputs = await _run_concrete_tool_probe(sample_tools)
@@ -749,6 +777,98 @@ async def test_the_simulator_reads_no_records_for_a_lookup(self, sample_tools):
assert "A User" not in prompt
+async def _simulate_with_judge(spec: dict | None = None, arguments: str = '{"location": "Tokyo"}'):
+ """One judged simulated response; returns it with the prompts the simulator and its judge read."""
+ api_prompts: list[str] = []
+ judge_prompts: list[str] = []
+
+ async def fake_call_llm(models, alias, messages, **kwargs):
+ api_prompts.append(messages[0]["content"])
+ return {"content": '{"temp": 22}'}
+
+ async def fake_judge(models, alias, prompt):
+ judge_prompts.append(prompt)
+ return "Fine.", "success", True, True
+
+ tool_call = {"function": {"name": "get_weather", "arguments": arguments}}
+ with (
+ patch("usersim.engine.probes.tool_calling.probe.acall_llm", side_effect=fake_call_llm),
+ patch("usersim.engine.probes.tool_calling.probe.run_inline_judge_ex", side_effect=fake_judge),
+ ):
+ result = await _simulate_tool_response(
+ {},
+ spec or {"name": "get_weather", "parameters": {"type": "object"}},
+ tool_call,
+ [],
+ now="Friday, 2026-11-06, 12:00 UTC",
+ judge=True,
+ )
+ return result, api_prompts, judge_prompts
+
+
+def _tool(tool_name: str, **parameter_types: str) -> dict:
+ properties = {parameter: {"type": kind} for parameter, kind in parameter_types.items()}
+ return {"tool": {"type": "function", "function": {"name": tool_name, "parameters": {"properties": properties}}}}
+
+
+async def test_a_tool_that_returns_random_or_generated_items_returns_new_ones_each_time():
+ _result, api_prompts, judge_prompts = await _simulate_with_judge()
+
+ assert "A tool that returns random or newly generated items by design" in " ".join(api_prompts[0].split())
+ assert "random or newly generated items by design returns new ones each time" in " ".join(judge_prompts[0].split())
+
+
+async def test_the_response_judge_checks_computed_values_but_not_fields_describing_the_response():
+ _result, _api_prompts, judge_prompts = await _simulate_with_judge()
+ rubric = " ".join(judge_prompts[0].split())
+
+ assert "Every value the tool computes (a total, a conversion, a date difference, a formula) is correct" in rubric
+ assert (
+ "A field that only describes the response itself, such as a count of the items it lists or an offset derived "
+ "from its other fields, is not grounds for failure." in rubric
+ )
+
+
+class TestOtherEndpoints:
+ """The simulated service and its judge see the service's other endpoints, so an ID a response returns has the
+ type the endpoints that take it accept."""
+
+ def test_each_other_offered_tool_is_listed_with_its_parameter_types(self):
+ tools = [_tool("add_pet", name="string"), _tool("get_pet", pet_id="integer"), _tool("list_pets")]
+
+ assert _other_endpoints(tools, "add_pet") == "- get_pet(pet_id: integer)\n- list_pets()"
+
+ def test_a_tool_offered_alone_has_no_other_endpoints(self):
+ assert _other_endpoints([_tool("add_pet", name="string")], "add_pet") == "None."
+
+ async def test_the_simulator_and_its_judge_read_the_probes_other_tools(self, sample_tools):
+ probe, _data, _cfg = _concrete_tool_probe(sample_tools)
+ prompts = []
+
+ async def fake_call_llm(models, alias, messages, **kwargs):
+ prompts.append(messages[0]["content"])
+ return {"content": '{"temp": 22}'}
+
+ async def fake_judge(models, alias, prompt):
+ prompts.append(prompt)
+ return "Fine.", "success", True, True
+
+ tool_call = {"id": "c", "function": {"name": "get_weather", "arguments": '{"location": "Tokyo"}'}}
+ with (
+ patch("usersim.engine.probes.tool_calling.probe.acall_llm", side_effect=fake_call_llm),
+ patch("usersim.engine.probes.tool_calling.probe.run_inline_judge_ex", side_effect=fake_judge),
+ ):
+ await probe.execute_tool_call(
+ "get_weather", {"location": "Tokyo"}, tool_call, ConversationState(), {}, turn_idx=0, call_idx=0
+ )
+
+ expected = _other_endpoints(probe.tool_subset, "get_weather")
+ assert "- search_recipes(ingredient: string, cuisine: string)" in expected
+ assert len(prompts) == 2
+ assert all(f"\n{expected}\n" in prompt for prompt in prompts)
+ assert all("- get_weather(" not in prompt for prompt in prompts)
+
+
class TestCredentials:
"""The user holds the key a tool declares, and only a call carrying it reaches the simulated service."""