This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-06 08:53:00 +09:00
1 parent d878373728
commit 97f71f6ebb
2 files changed
+7 -12

No files matched your search

+6
View File
@@ -1077,6 +1077,9 @@ async def chat_completion_tools_handler(
if error := prepare_tool_call(prepared, tool.get('spec', {}).get('parameters')):
raise ValueError(error)
tool_function_params = JSONCodec.loads(prepared['arguments'])
if tool_type != 'mcp':
allowed_params = tool.get('spec', {}).get('parameters', {}).get('properties', {})
tool_function_params = {k: v for k, v in tool_function_params.items() if k in allowed_params}
if tool.get('direct', False):
tool_result = await event_caller(
@@ -3069,6 +3072,9 @@ async def execute_tool_call(form_data, metadata, event_caller, tool_call, histor
return params, 'Error: Uploaded file display is not available.', None, None, False
tool_type = tool.get('type', '')
direct_tool = tool.get('direct', False)
if tool_type != 'mcp':
allowed_params = tool.get('spec', {}).get('parameters', {}).get('properties', {})
params = {key: value for key, value in params.items() if key in allowed_params}
try:
if (
not is_saved_chat_id(metadata.get('chat_id'))
+1 -12
View File
@@ -11,10 +11,6 @@ import math
import re
from uuid import uuid4
from jsonschema import Draft202012Validator
from referencing import Registry
from referencing.exceptions import Unresolvable
FINAL_ANSWER_PROMPT = (
'Tool use has stopped for this response. Use the results already available to answer the user. '
'Explain any unfinished work briefly. Do not request or describe additional tool calls.'
@@ -107,15 +103,8 @@ def _coerce(value, schema, depth=0):
def normalize_arguments(raw, schema=None):
params = parse_arguments(raw)
if schema is not None:
# Provider schemas strip nullability; use them for coercion, leaving validation to the tool.
params = _coerce(params, schema)
try:
# Schemas may use local $defs; fetching arbitrary external refs is never part of tool execution.
error = next(Draft202012Validator(schema, registry=Registry()).iter_errors(params), None)
except Unresolvable as exc:
raise ValueError('Tool schema contains an unresolved reference.') from exc
if error:
path = '.'.join(str(part) for part in error.absolute_path) or 'arguments'
raise ValueError(f'Invalid {path}: {error.message}')
_check_json_value(params)
return params