mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-26 22:05:29 +00:00
core[major]: Remove "Schema" suffix from tool name (#26389)
Remove the automatically appended "Schema" suffix to tool names.
This commit is contained in:
@@ -307,7 +307,7 @@ def create_schema_from_function(
|
|||||||
valid_properties.append(field)
|
valid_properties.append(field)
|
||||||
|
|
||||||
return _create_subset_model(
|
return _create_subset_model(
|
||||||
f"{model_name}Schema",
|
model_name,
|
||||||
inferred_model,
|
inferred_model,
|
||||||
list(valid_properties),
|
list(valid_properties),
|
||||||
descriptions=arg_descriptions,
|
descriptions=arg_descriptions,
|
||||||
|
@@ -87,7 +87,7 @@ def tool(
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
{
|
{
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"description": "The foo.",
|
"description": "The foo.",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@@ -419,7 +419,7 @@ def test_structured_tool_from_function_docstring() -> None:
|
|||||||
"baz": {"title": "Baz", "type": "string"},
|
"baz": {"title": "Baz", "type": "string"},
|
||||||
},
|
},
|
||||||
"description": inspect.getdoc(foo),
|
"description": inspect.getdoc(foo),
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["bar", "baz"],
|
"required": ["bar", "baz"],
|
||||||
}
|
}
|
||||||
@@ -461,7 +461,7 @@ def test_structured_tool_from_function_docstring_complex_args() -> None:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"description": inspect.getdoc(foo),
|
"description": inspect.getdoc(foo),
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["bar", "baz"],
|
"required": ["bar", "baz"],
|
||||||
}
|
}
|
||||||
@@ -562,7 +562,7 @@ def test_structured_tool_from_function_with_run_manager() -> None:
|
|||||||
"baz": {"title": "Baz", "type": "string"},
|
"baz": {"title": "Baz", "type": "string"},
|
||||||
},
|
},
|
||||||
"description": inspect.getdoc(foo),
|
"description": inspect.getdoc(foo),
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["bar", "baz"],
|
"required": ["bar", "baz"],
|
||||||
}
|
}
|
||||||
@@ -794,7 +794,7 @@ def test_structured_tool_from_function() -> None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert _schema(structured_tool.args_schema) == {
|
assert _schema(structured_tool.args_schema) == {
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": inspect.getdoc(foo),
|
"description": inspect.getdoc(foo),
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -1123,7 +1123,7 @@ def test_tool_arg_descriptions() -> None:
|
|||||||
foo1 = tool(foo)
|
foo1 = tool(foo)
|
||||||
args_schema = _schema(foo1.args_schema) # type: ignore
|
args_schema = _schema(foo1.args_schema) # type: ignore
|
||||||
assert args_schema == {
|
assert args_schema == {
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": inspect.getdoc(foo),
|
"description": inspect.getdoc(foo),
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -1137,7 +1137,7 @@ def test_tool_arg_descriptions() -> None:
|
|||||||
foo2 = tool(foo, parse_docstring=True)
|
foo2 = tool(foo, parse_docstring=True)
|
||||||
args_schema = _schema(foo2.args_schema) # type: ignore
|
args_schema = _schema(foo2.args_schema) # type: ignore
|
||||||
expected = {
|
expected = {
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"description": "The foo.",
|
"description": "The foo.",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -1226,7 +1226,7 @@ def test_tool_annotated_descriptions() -> None:
|
|||||||
foo1 = tool(foo)
|
foo1 = tool(foo)
|
||||||
args_schema = _schema(foo1.args_schema) # type: ignore
|
args_schema = _schema(foo1.args_schema) # type: ignore
|
||||||
assert args_schema == {
|
assert args_schema == {
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": inspect.getdoc(foo),
|
"description": inspect.getdoc(foo),
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -1449,7 +1449,7 @@ def injected_tool_with_schema(x: int, y: str) -> str:
|
|||||||
@pytest.mark.parametrize("tool_", [InjectedTool()])
|
@pytest.mark.parametrize("tool_", [InjectedTool()])
|
||||||
def test_tool_injected_arg_without_schema(tool_: BaseTool) -> None:
|
def test_tool_injected_arg_without_schema(tool_: BaseTool) -> None:
|
||||||
assert _schema(tool_.get_input_schema()) == {
|
assert _schema(tool_.get_input_schema()) == {
|
||||||
"title": "fooSchema",
|
"title": "foo",
|
||||||
"description": "foo.\n\nArgs:\n x: abc\n y: 123",
|
"description": "foo.\n\nArgs:\n x: abc\n y: 123",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -1488,7 +1488,7 @@ def test_tool_injected_arg_without_schema(tool_: BaseTool) -> None:
|
|||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"tool_",
|
"tool_",
|
||||||
[injected_tool, injected_tool_with_schema, InjectedToolWithSchema()],
|
[injected_tool_with_schema, InjectedToolWithSchema()],
|
||||||
)
|
)
|
||||||
def test_tool_injected_arg_with_schema(tool_: BaseTool) -> None:
|
def test_tool_injected_arg_with_schema(tool_: BaseTool) -> None:
|
||||||
assert _schema(tool_.get_input_schema()) == {
|
assert _schema(tool_.get_input_schema()) == {
|
||||||
@@ -1529,6 +1529,46 @@ def test_tool_injected_arg_with_schema(tool_: BaseTool) -> None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_tool_injected_arg() -> None:
|
||||||
|
tool_ = injected_tool
|
||||||
|
assert _schema(tool_.get_input_schema()) == {
|
||||||
|
"title": "foo",
|
||||||
|
"description": "foo.",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {"description": "abc", "title": "X", "type": "integer"},
|
||||||
|
"y": {"description": "123", "title": "Y", "type": "string"},
|
||||||
|
},
|
||||||
|
"required": ["x", "y"],
|
||||||
|
}
|
||||||
|
assert _schema(tool_.tool_call_schema) == {
|
||||||
|
"title": "foo",
|
||||||
|
"description": "foo.",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {"x": {"description": "abc", "title": "X", "type": "integer"}},
|
||||||
|
"required": ["x"],
|
||||||
|
}
|
||||||
|
assert tool_.invoke({"x": 5, "y": "bar"}) == "bar"
|
||||||
|
assert tool_.invoke(
|
||||||
|
{"name": "foo", "args": {"x": 5, "y": "bar"}, "id": "123", "type": "tool_call"}
|
||||||
|
) == ToolMessage("bar", tool_call_id="123", name="foo")
|
||||||
|
expected_error = (
|
||||||
|
ValidationError if not isinstance(tool_, InjectedTool) else TypeError
|
||||||
|
)
|
||||||
|
with pytest.raises(expected_error):
|
||||||
|
tool_.invoke({"x": 5})
|
||||||
|
|
||||||
|
assert convert_to_openai_function(tool_) == {
|
||||||
|
"name": "foo",
|
||||||
|
"description": "foo.",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {"x": {"type": "integer", "description": "abc"}},
|
||||||
|
"required": ["x"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_tool_inherited_injected_arg() -> None:
|
def test_tool_inherited_injected_arg() -> None:
|
||||||
class barSchema(BaseModel):
|
class barSchema(BaseModel):
|
||||||
"""bar."""
|
"""bar."""
|
||||||
@@ -1552,7 +1592,7 @@ def test_tool_inherited_injected_arg() -> None:
|
|||||||
|
|
||||||
tool_ = InheritedInjectedArgTool()
|
tool_ = InheritedInjectedArgTool()
|
||||||
assert tool_.get_input_schema().model_json_schema() == {
|
assert tool_.get_input_schema().model_json_schema() == {
|
||||||
"title": "fooSchema",
|
"title": "fooSchema", # Matches the title from the provided schema
|
||||||
"description": "foo.",
|
"description": "foo.",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -1561,6 +1601,7 @@ def test_tool_inherited_injected_arg() -> None:
|
|||||||
},
|
},
|
||||||
"required": ["y", "x"],
|
"required": ["y", "x"],
|
||||||
}
|
}
|
||||||
|
# Should not include `y` since it's annotated as an injected tool arg
|
||||||
assert tool_.tool_call_schema.model_json_schema() == {
|
assert tool_.tool_call_schema.model_json_schema() == {
|
||||||
"title": "foo",
|
"title": "foo",
|
||||||
"description": "foo.",
|
"description": "foo.",
|
||||||
|
Reference in New Issue
Block a user