The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
standard-tests: Fix ToolsIntegrationTests to correctly handle "content_and_artifact" tools (#29391)
Andrew Wason22aa5e07ed86
diff --git a/libs/standard-tests/langchain_tests/integration_tests/tools.py b/libs/standard-tests/langchain_tests/integration_tests/tools.pyindex 2fcd610ccc..86a26338ed 100644--- a/libs/standard-tests/langchain_tests/integration_tests/tools.py+++ b/libs/standard-tests/langchain_tests/integration_tests/tools.py@@ -29,15 +29,10 @@ class ToolsIntegrationTests(ToolsTests):)result = tool.invoke(tool_call)- if tool.response_format == "content":- tool_message = result- elif tool.response_format == "content_and_artifact":- # should be (content, artifact)- assert isinstance(result, tuple)- assert len(result) == 2- tool_message, artifact = result-- assert artifact # artifact can be anything, but shouldn't be none+ tool_message = result+ if tool.response_format == "content_and_artifact":+ # artifact can be anything, except none+ assert tool_message.artifact is not None# check content is a valid ToolMessage contentassert isinstance(tool_message.content, (str, list))@@ -59,15 +54,10 @@ class ToolsIntegrationTests(ToolsTests):)result = await tool.ainvoke(tool_call)- if tool.response_format == "content":- tool_message = result- elif tool.response_format == "content_and_artifact":- # should be (content, artifact)- assert isinstance(result, tuple)- assert len(result) == 2- tool_message, artifact = result-- assert artifact # artifact can be anything, but shouldn't be none+ tool_message = result+ if tool.response_format == "content_and_artifact":+ # artifact can be anything, except none+ assert tool_message.artifact is not None# check content is a valid ToolMessage contentassert isinstance(tool_message.content, (str, list))diff --git a/libs/standard-tests/tests/unit_tests/test_basic_tool.py b/libs/standard-tests/tests/unit_tests/test_basic_tool.pyindex 046e15d760..d8aa16504e 100644--- a/libs/standard-tests/tests/unit_tests/test_basic_tool.py+++ b/libs/standard-tests/tests/unit_tests/test_basic_tool.py@@ -1,4 +1,4 @@-from typing import Type+from typing import Literal, Typefrom langchain_core.tools import BaseTool@@ -16,6 +16,17 @@ class ParrotMultiplyTool(BaseTool): # type: ignorereturn a * b + 80+class ParrotMultiplyArtifactTool(BaseTool): # type: ignore+ name: str = "ParrotMultiplyArtifactTool"+ description: str = (+ "Multiply two numbers like a parrot. Parrots always add eighty for their matey."+ )+ response_format: Literal["content_and_artifact"] = "content_and_artifact"++ def _run(self, a: int, b: int) -> tuple[int, str]:+ return a * b + 80, "parrot artifact"++class TestParrotMultiplyToolUnit(ToolsUnitTests):@propertydef tool_constructor(self) -> Type[ParrotMultiplyTool]:@@ -60,3 +71,26 @@ class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):have {"name", "id", "args"} keys."""return {"a": 2, "b": 3}+++class TestParrotMultiplyArtifactToolIntegration(ToolsIntegrationTests):+ @property+ def tool_constructor(self) -> Type[ParrotMultiplyArtifactTool]:+ return ParrotMultiplyArtifactTool++ @property+ def tool_constructor_params(self) -> dict:+ # if your tool constructor instead required initialization arguments like+ # `def __init__(self, some_arg: int):`, you would return those here+ # as a dictionary, e.g.: `return {'some_arg': 42}`+ return {}++ @property+ def tool_invoke_params_example(self) -> dict:+ """+ Returns a dictionary representing the "args" of an example tool call.++ This should NOT be a ToolCall dict - i.e. it should not+ have {"name", "id", "args"} keys.+ """+ return {"a": 2, "b": 3}