Implement runtime tool ID and display name mapping in DuplexPipeline. Enhance Assistants and ToolLibrary components to utilize new mappings for improved tool identification and display. Update DebugDrawer to reflect changes in tool display names during interactions.
This commit is contained in:
@@ -94,6 +94,17 @@ def _normalize_runtime_tool_schema(tool_id: str, raw_schema: Any) -> Dict[str, A
|
||||
return schema
|
||||
|
||||
|
||||
def _compose_runtime_system_prompt(base_prompt: Optional[str]) -> str:
|
||||
raw = str(base_prompt or "").strip()
|
||||
tool_policy = (
|
||||
"Tool usage policy:\n"
|
||||
"- Tool function names/IDs are internal and must never be shown to users.\n"
|
||||
"- When users ask which tools are available, describe capabilities in natural language.\n"
|
||||
"- Do not expose raw tool call payloads, IDs, or executor details."
|
||||
)
|
||||
return f"{raw}\n\n{tool_policy}" if raw else tool_policy
|
||||
|
||||
|
||||
def _resolve_runtime_tools(db: Session, selected_tool_ids: List[str], warnings: List[str]) -> List[Dict[str, Any]]:
|
||||
_ensure_tool_resource_schema(db)
|
||||
ids = [str(tool_id).strip() for tool_id in selected_tool_ids if str(tool_id).strip()]
|
||||
@@ -115,6 +126,11 @@ def _resolve_runtime_tools(db: Session, selected_tool_ids: List[str], warnings:
|
||||
continue
|
||||
|
||||
category = str(resource.category if resource else TOOL_CATEGORY_MAP.get(tool_id, "query"))
|
||||
display_name = (
|
||||
str(resource.name or tool_id).strip()
|
||||
if resource
|
||||
else str(TOOL_REGISTRY.get(tool_id, {}).get("name") or tool_id).strip()
|
||||
)
|
||||
description = (
|
||||
str(resource.description or resource.name or "").strip()
|
||||
if resource
|
||||
@@ -135,9 +151,15 @@ def _resolve_runtime_tools(db: Session, selected_tool_ids: List[str], warnings:
|
||||
"executor": "client" if category == "system" else "server",
|
||||
"function": {
|
||||
"name": tool_id,
|
||||
"description": description or tool_id,
|
||||
"description": (
|
||||
f"Display name: {display_name}. {description}".strip()
|
||||
if display_name
|
||||
else (description or tool_id)
|
||||
),
|
||||
"parameters": schema,
|
||||
},
|
||||
"displayName": display_name or tool_id,
|
||||
"toolId": tool_id,
|
||||
}
|
||||
if defaults:
|
||||
runtime_tool["defaultArgs"] = defaults
|
||||
@@ -149,7 +171,7 @@ def _resolve_runtime_tools(db: Session, selected_tool_ids: List[str], warnings:
|
||||
def _resolve_runtime_metadata(db: Session, assistant: Assistant) -> tuple[Dict[str, Any], List[str]]:
|
||||
warnings: List[str] = []
|
||||
metadata: Dict[str, Any] = {
|
||||
"systemPrompt": assistant.prompt or "",
|
||||
"systemPrompt": _compose_runtime_system_prompt(assistant.prompt),
|
||||
"firstTurnMode": assistant.first_turn_mode or "bot_first",
|
||||
"greeting": assistant.opener or "",
|
||||
"generatedOpenerEnabled": bool(assistant.generated_opener_enabled),
|
||||
|
||||
Reference in New Issue
Block a user