Filter the $schema field in tool parameters of kosong genai provide…#713
Filter the $schema field in tool parameters of kosong genai provide…#713pvzheroes125 wants to merge 2 commits intomainfrom
$schema field in tool parameters of kosong genai provide…#713Conversation
…r so that kimi-cli can work properly when using gemini models with third-party mcp. (Tool parameters is a `BaseModel` with `extra=forbid` in genai sdk while `TypedDict` in anthropic and openai sdk)
| if '$schema' in tool.parameters: | ||
| del tool.parameters['$schema'] |
There was a problem hiding this comment.
🔴 Mutation of shared tool.parameters dict removes $schema field permanently
The tool_to_google_genai function directly mutates the tool.parameters dictionary by deleting the $schema key, which permanently modifies the original Tool object.
Click to expand
How the bug is triggered
The Tool object is a Pydantic BaseModel that is typically reused across multiple API calls. When tool_to_google_genai is called:
if '$schema' in tool.parameters:
del tool.parameters['$schema']This directly modifies the original tool.parameters dict. Since the same Tool instance is returned by toolset.tools (see kosong/tooling/simple.py:89-90), subsequent uses of this tool will have the $schema field missing.
Actual vs Expected behavior
Actual: The $schema field is permanently removed from the original tool object after the first call to tool_to_google_genai.
Expected: The function should create a copy of the parameters dict before modifying it, leaving the original tool object unchanged.
Impact
- If the same tool is used with multiple providers (e.g., OpenAI and Google GenAI), the
$schemafield will be missing for subsequent provider calls. - If the tool's
parametersdict is used elsewhere in the application (e.g., for validation, logging, or serialization), it will be missing the$schemafield. - This violates the principle of least surprise - a conversion function should not have side effects on its input.
Recommendation: Create a shallow copy of the parameters dict before modifying it:
parameters = tool.parameters.copy()
if '$schema' in parameters:
del parameters['$schema']
return Tool(
function_declarations=[
FunctionDeclaration(
name=tool.name,
description=tool.description,
parameters=parameters,
)
]
)Was this helpful? React with 👍 or 👎 to provide feedback.
2c7074a to
08500b2
Compare
Filter the
$schemafield in tool parameters of kosong genai provider so that kimi-cli can work properly when using gemini models with third-party mcp. (Tool parameters is aBaseModelwithextra=forbidin genai sdk whileTypedDictin anthropic and openai sdk)Related Issue
Resolve #(issue_number)
Description
Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.