adapter: include tool catalog description in S_TOOL_EVENT

Pre/post tool call events now carry the tool's first-line catalog
description (from model_tools.get_tool_definitions, memoized) so the
Pheby app can show it under the tool name in the tool-call UI.
Unknown tools omit the field entirely (hide-undefined-data).
This commit is contained in:
2026-10-11 01:58:04 +00:00
parent 7ad8bf1155
commit 7b94342eb8
3 changed files with 165 additions and 1 deletions
+77
View File
@@ -609,6 +609,83 @@ class TestBridge:
assert ev["status"] == "completed"
assert ev["duration_ms"] == 1234
@pytest.mark.asyncio
async def test_tool_events_carry_description(self, tmp_path, monkeypatch):
"""pre/post tool events include the catalog description (first line)."""
server = make_server(tmp_path)
client = FakeClientConnection()
client.authenticated = True
server._clients["t"] = client
from pheby.adapter import PhebyAdapter
from gateway.config import PlatformConfig
real = PhebyAdapter(PlatformConfig(
enabled=True, extra={"secret": "test-secret-abc123"}))
real._server = server
real._loop = asyncio.get_running_loop()
monkeypatch.setattr(real, "_conversation_for_session_id",
lambda _sid: "conv1")
import model_tools
monkeypatch.setattr(
model_tools, "get_tool_definitions", lambda **kw: [
{"function": {"name": "web_search",
"description": "Search the web for "
"information.\nSecond line."}},
])
from pheby import hermes_bridge
real.on_pre_tool_call(
session_id="s1", tool_name="web_search",
tool_call_id="call-d", args={})
real.on_post_tool_call(
session_id="s1", tool_name="web_search",
tool_call_id="call-d", status="ok", duration_ms=5)
await asyncio.sleep(0)
tool_events = [e for e in client.ws.events()
if e["type"] == proto.S_TOOL_EVENT]
assert len(tool_events) == 2
assert all(ev.get("description") == "Search the web for information."
for ev in tool_events)
# Runtime snapshot (reconnect replay) carries it too. The bridge's
# tool bucket is module-global across tests — look up by call id.
snap = hermes_bridge.runtime_snapshot("conv1")
snap_ev = next(t for t in snap["tools"]
if t["tool_call_id"] == "call-d")
assert snap_ev["description"] == "Search the web for information."
@pytest.mark.asyncio
async def test_unknown_tool_event_has_no_description(self, tmp_path,
monkeypatch):
server = make_server(tmp_path)
client = FakeClientConnection()
client.authenticated = True
server._clients["t"] = client
from pheby.adapter import PhebyAdapter
from gateway.config import PlatformConfig
real = PhebyAdapter(PlatformConfig(
enabled=True, extra={"secret": "test-secret-abc123"}))
real._server = server
real._loop = asyncio.get_running_loop()
monkeypatch.setattr(real, "_conversation_for_session_id",
lambda _sid: "conv1")
import model_tools
monkeypatch.setattr(
model_tools, "get_tool_definitions", lambda **kw: [
{"function": {"name": "web_search",
"description": "Search the web."}},
])
real.on_pre_tool_call(
session_id="s1", tool_name="mystery_tool",
tool_call_id="call-x", args={})
await asyncio.sleep(0)
ev = [e for e in client.ws.events()
if e["type"] == proto.S_TOOL_EVENT][-1]
# Hide-undefined-data: no description key at all, no placeholder.
assert "description" not in ev
assert ev["tool_name"] == "mystery_tool"
@pytest.mark.asyncio
async def test_approval_push_and_resolve_roundtrip(self, tmp_path,
monkeypatch):