Drug-Safety Agent on Databricks · Tools · The tool facade
The thin Python view of a tool
The model is given tools that take a drug and an event, because that is how a scientist talks. The tool servers we test against key every row, so a call also needs the row's key. A small class sits between the two and is the only place that difference lives.
What it does. It exposes three tool descriptions with the (drug, event) shape; it builds the row key such as lisinopril:ANGIOEDEMA; it calls the server; it maps the row back to the shape the rest of the agent expects; and for statistics it calls the same Python function the local tool uses. It adds no business rules.
The shape of a good tool client. The agent holds only a thin typed view of a tool. The data, the permissions and the audit trail belong to the system that owns the data.
The real code
Cut from the repository each time this site is built, so it always matches what runs. Each header names the file and the line it was cut from.
src/drugsafety/world_tools.py:76PairTools: a tool client wrapping another tool clientclass PairTools:
"""A `ToolClient` over another one: the model's view (drug, event), the server's view (row keys)."""
def __init__(self, inner, seen: list[dict] | None = None, source: str = "agent") -> None:
self.inner = inner
self.source = source
self.seen = seen if seen is not None else []
async def list_tools(self, identity: Identity) -> ToolRegistry:
reads = tuple(
ToolSpec(
name=n,
description=d,
input_schema=_SCHEMA,
output_schema={"type": "object"},
side_effect=SideEffectClass.READ,
entity="drug_event" if n != "get_label_mentions" else "label",
)src/drugsafety/world_tools.py:184_read(): compose the key, call, map the row back async def _read(self, name: str, drug: str, event: str, identity, key) -> dict:
if name not in DESCRIPTIONS:
return {"error": f"no such tool: {name}"}
if event.upper() not in T.SYNONYMS:
return _unknown()
row_id = drug.lower() if name == "get_label_mentions" else pair_id(drug, event)
got = await self.inner.call(name, {"id": row_id, "drug": drug.lower(), "event": event.upper()}, identity, key)
row = got.structured or {}
if not row.get("found", False) and "id" not in row:
return _unknown()
if name == "get_report_counts":
return _counts(row)
if name == "get_signal_stats":
c = _counts(row)
return T.stats_from_counts(c["drug"], c["event"], c["a"], c["b"], c["c"], c["d"])
return T.label_mentions_from(
{"drug": row["drug"], "effective_time": row.get("effective_time"), "warnings": row.get("text", "")}, event
)