Keep json schema $defs on transform

This commit is contained in:
William Easton 2025-07-06 21:13:50 -05:00
commit 8cdce8d848
No known key found for this signature in database
2 changed files with 21 additions and 0 deletions

View file

@ -553,6 +553,7 @@ class TransformedTool(Tool):
"""
# Build transformed schema and mapping
parent_defs = parent_tool.parameters.get("$defs", {})
parent_props = parent_tool.parameters.get("properties", {}).copy()
parent_required = set(parent_tool.parameters.get("required", []))
@ -608,6 +609,9 @@ class TransformedTool(Tool):
"required": list(new_required),
}
if parent_defs:
schema["$defs"] = parent_defs
# Create forwarding function that closes over everything it needs
async def _forward(**kwargs):
# Validate arguments

View file

@ -383,6 +383,23 @@ async def test_forward_raw_outside_context_raises_error():
):
await forward_raw(new_x=1, old_y=2)
def test_transform_args_with_parent_defaults():
"""Test that transform_args with parent defaults works."""
class CoolModel(BaseModel):
x: int = 10
def parent_tool(cool_model: CoolModel) -> int:
return cool_model.x
tool = Tool.from_function(parent_tool)
new_tool = Tool.from_tool(
tool
)
assert new_tool.parameters["$defs"] == tool.parameters["$defs"]
def test_transform_args_validation_unknown_arg(add_tool):
"""Test that transform_args with unknown arguments raises ValueError."""