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:
+39
-1
@@ -69,6 +69,7 @@ class PhebyAdapter(BasePlatformAdapter):
|
||||
self._server: Any = None
|
||||
self._loop: Optional[asyncio.AbstractEventLoop] = None
|
||||
self._drafts: Dict[str, Dict[str, Any]] = {} # conv → draft state
|
||||
self._tool_desc_cache: Optional[Dict[str, str]] = None
|
||||
|
||||
@property
|
||||
def authorization_is_upstream(self) -> bool:
|
||||
@@ -271,6 +272,36 @@ class PhebyAdapter(BasePlatformAdapter):
|
||||
logger.debug("[pheby] tool session lookup failed", exc_info=True)
|
||||
return None
|
||||
|
||||
def _tool_description(self, tool_name: str) -> Optional[str]:
|
||||
"""First line of the tool's catalog description, for the tool-call UI.
|
||||
|
||||
Sourced from the same schema catalog the gateway sends to the model
|
||||
(``model_tools.get_tool_definitions``) — cheap lookup, memoized per
|
||||
toolset config. The UI clamps this to 2 lines; unknown tools send
|
||||
no field at all (clients hide undefined data rather than showing a
|
||||
placeholder).
|
||||
"""
|
||||
if not tool_name:
|
||||
return None
|
||||
try:
|
||||
from model_tools import get_tool_definitions
|
||||
if self._tool_desc_cache is None:
|
||||
self._tool_desc_cache = {
|
||||
str(td.get("function", {}).get("name") or ""):
|
||||
str(td.get("function", {}).get("description") or "").strip()
|
||||
for td in get_tool_definitions(quiet_mode=True)
|
||||
}
|
||||
desc = self._tool_desc_cache.get(tool_name) or None
|
||||
except Exception:
|
||||
logger.debug("[pheby] tool description lookup failed", exc_info=True)
|
||||
self._tool_desc_cache = {}
|
||||
return None
|
||||
if not desc:
|
||||
return None
|
||||
# Keep the first descriptive line; UI shows max 2 lines.
|
||||
first_line = desc.splitlines()[0].strip()
|
||||
return proto.safe_str(first_line, 300)
|
||||
|
||||
def on_pre_tool_call(self, **kwargs: Any) -> None:
|
||||
conversation_id = self._conversation_for_session_id(
|
||||
str(kwargs.get("session_id") or ""))
|
||||
@@ -278,16 +309,20 @@ class PhebyAdapter(BasePlatformAdapter):
|
||||
return
|
||||
tool_id = str(kwargs.get("tool_call_id") or
|
||||
f"t-{proto.new_id()[:12]}")
|
||||
tool_name = str(kwargs.get("tool_name") or "tool")
|
||||
event = {
|
||||
"type": proto.S_TOOL_EVENT,
|
||||
"conversation_id": conversation_id,
|
||||
"run_id": hermes_bridge.active_run_id(conversation_id),
|
||||
"tool_call_id": tool_id,
|
||||
"tool_name": str(kwargs.get("tool_name") or "tool"),
|
||||
"tool_name": tool_name,
|
||||
"status": "running",
|
||||
"args_redacted": _redact_args(kwargs.get("args")),
|
||||
"ts": proto.now_iso(),
|
||||
}
|
||||
description = self._tool_description(tool_name)
|
||||
if description:
|
||||
event["description"] = description
|
||||
hermes_bridge.record_tool_event(conversation_id, event)
|
||||
self.schedule_broadcast(event)
|
||||
|
||||
@@ -324,6 +359,9 @@ class PhebyAdapter(BasePlatformAdapter):
|
||||
# gets outcome status; verbose content stays in Hermes.
|
||||
"ts": proto.now_iso(),
|
||||
}
|
||||
description = self._tool_description(tool_name)
|
||||
if description:
|
||||
event["description"] = description
|
||||
error_message = kwargs.get("error_message")
|
||||
if error_message and event["status"] == "failed":
|
||||
event["error"] = proto.safe_str(error_message, 200)
|
||||
|
||||
Reference in New Issue
Block a user