Add parameter schema and defaults to ToolResource model and schemas. Implement runtime tool resolution in assistants and tools routers, ensuring proper handling of tool parameters. Update tests to validate new functionality and ensure correct integration of parameter handling in the API.

This commit is contained in:
Xin Wang
2026-02-27 14:44:28 +08:00
parent d942c85eff
commit 5f768edf68
13 changed files with 397 additions and 9 deletions

View File

@@ -187,6 +187,17 @@ async def execute_server_tool(
tool_name = _extract_tool_name(tool_call)
args = _extract_tool_args(tool_call)
resource_fetcher = tool_resource_fetcher or fetch_tool_resource
resource: Optional[Dict[str, Any]] = None
if tool_name and tool_name not in {"calculator", "code_interpreter", "current_time"}:
try:
resource = await resource_fetcher(tool_name)
except Exception:
resource = None
defaults = resource.get("parameter_defaults") if isinstance(resource, dict) else None
if isinstance(defaults, dict) and defaults:
merged_args = dict(defaults)
merged_args.update(args)
args = merged_args
if tool_name == "calculator":
expression = str(args.get("expression") or "").strip()
@@ -269,7 +280,6 @@ async def execute_server_tool(
}
if tool_name and tool_name not in {"calculator", "code_interpreter", "current_time"}:
resource = await resource_fetcher(tool_name)
if resource and str(resource.get("category") or "") == "query":
method = str(resource.get("http_method") or "GET").strip().upper()
if method not in {"GET", "POST", "PUT", "PATCH", "DELETE"}: