Skip to content

Commit 3ece798

Browse files
refactor: remove tool alias resolution (no longer needed)
With a single canonical name (acme_get_order) used in both scenario controls and OTLP traces, the alias map was dead complexity. Revert tool_selection to simple exact string matching. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 31a1c1d commit 3ece798

3 files changed

Lines changed: 4 additions & 82 deletions

File tree

‎audits/agentic/checks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def evaluate_checks(trajectory, expectations, snapshot):
323323
results = trace_integrity(trajectory)
324324
tools = (expectations.tools if expectations else {})
325325
retrieval = (expectations.retrieval if expectations else {})
326-
results += tool_selection(trajectory, tools, snapshot)
326+
results += tool_selection(trajectory, tools)
327327
results += tool_permissions(trajectory, snapshot)
328328
results += retrieval_checks(trajectory, retrieval, snapshot)
329329
return results

‎audits/agentic/checks/tools.py‎

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,7 @@ def _arguments_match(observed: Any, expected: Any) -> bool:
3636
return observed == expected
3737

3838

39-
def _build_alias_map(snapshot: dict | None) -> dict[str, set[str]]:
40-
"""Build a map from logical tool name → all known invocation aliases.
41-
42-
Given the frozen agent config snapshot, every tool's name, external_id,
43-
and invocation_names are treated as interchangeable identifiers for the
44-
same underlying capability. This lets scenario controls reference a
45-
logical alias (e.g. ``acme_get_order``) while the trace carries the
46-
real OpenWebUI function name (e.g. ``acme_get_order``).
47-
"""
48-
alias_map: dict[str, set[str]] = {}
49-
if not snapshot:
50-
return alias_map
51-
for tool in snapshot.get("tools", []):
52-
if not isinstance(tool, dict):
53-
continue
54-
ids = {
55-
str(v)
56-
for v in [tool.get("name"), tool.get("external_id"), *(tool.get("invocation_names") or [])]
57-
if v
58-
}
59-
for ident in ids:
60-
alias_map.setdefault(ident, set()).update(ids)
61-
return alias_map
62-
63-
64-
def tool_selection(trajectory: AgentTrajectory, expected: dict, snapshot: dict | None = None) -> list[CheckResult]:
39+
def tool_selection(trajectory: AgentTrajectory, expected: dict) -> list[CheckResult]:
6540
"""Check tool calls against expected requirements."""
6641
calls = [s for s in trajectory.primary_steps if s.kind == "tool"]
6742
# Runtime builtins (search_chats, get_current_timestamp, ...) are granted
@@ -72,18 +47,9 @@ def tool_selection(trajectory: AgentTrajectory, expected: dict, snapshot: dict |
7247
required = expected.get("expected", [])
7348
out = []
7449

75-
alias_map = _build_alias_map(snapshot)
76-
77-
def _resolve(name: str) -> set[str]:
78-
"""Return the set of span names that satisfy *name* (including itself)."""
79-
if name in alias_map:
80-
return alias_map[name]
81-
return {name}
82-
8350
for item in required:
8451
name = item.get("name")
85-
acceptable_names = _resolve(name) if name else set()
86-
matching = [step for step in calls if step.name in acceptable_names]
52+
matching = [step for step in calls if step.name == name]
8753
count = len(matching)
8854
# min_calls may be present as null — treat it as 1.
8955
lo, hi = item.get("min_calls"), item.get("max_calls")
@@ -137,12 +103,7 @@ def _resolve(name: str) -> set[str]:
137103

138104
forbidden = set(expected.get("forbidden", []))
139105
if forbidden:
140-
# Expand forbidden names through the alias map so that forbidding a
141-
# logical alias also catches all real invocation names.
142-
expanded_forbidden: set[str] = set()
143-
for fname in forbidden:
144-
expanded_forbidden.update(_resolve(fname))
145-
bad = expanded_forbidden.intersection({s.name for s in calls})
106+
bad = forbidden.intersection({s.name for s in calls})
146107
out.append(
147108
result(
148109
"tool.forbidden",

‎audits/agentic/tests/test_evaluate.py‎

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -263,42 +263,3 @@ def test_known_tool_matches_its_frozen_openwebui_invocation_name():
263263
assert result[0].evidence_span_ids == ["s1"]
264264

265265

266-
def test_tool_selection_resolves_alias_to_real_openwebui_function_name():
267-
"""Scenario control says acme_get_order but trace has acme_get_order.
268-
269-
The frozen snapshot maps both names to the same tool, so the check
270-
must PASS even though the span name differs from the control name.
271-
"""
272-
from audits.agentic.checks import tool_selection
273-
274-
trajectory = AgentTrajectory([
275-
TrajectoryStep("s1", "tool", "acme_get_order", arguments={"order_id": "ACME-9999"}),
276-
])
277-
expected = {
278-
"expected": [{
279-
"name": "acme_get_order",
280-
"min_calls": 1,
281-
"max_calls": 1,
282-
"arguments": {"order_id": "ACME-9999"},
283-
}],
284-
}
285-
snapshot = {
286-
"tools": [{
287-
"name": "Acme Order Lookup",
288-
"external_id": "acme_order_lookup",
289-
"invocation_names": ["acme_get_order", "acme_get_order"],
290-
"enabled": True,
291-
"read_only": True,
292-
"has_side_effects": False,
293-
}]
294-
}
295-
296-
results = tool_selection(trajectory, expected, snapshot)
297-
298-
required = next(r for r in results if r.id == "tool.required")
299-
assert required.status == "PASS"
300-
assert required.observed == 1
301-
assert required.evidence_span_ids == ["s1"]
302-
303-
args_check = next(r for r in results if r.id == "tool.arguments")
304-
assert args_check.status == "PASS"

0 commit comments

Comments
 (0)