mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-14 14:05:37 +00:00
standard-tests: Fix ToolsIntegrationTests to correctly handle "content_and_artifact" tools (#29391)
**Description:**
The response from `tool.invoke()` is always a ToolMessage, with content
and artifact fields, not a tuple.
The tuple is converted to a ToolMessage here
b6ae7ca91d/libs/core/langchain_core/tools/base.py (L726)
**Issue:**
Currently `ToolsIntegrationTests` requires `invoke()` to return a tuple
and so standard tests fail for "content_and_artifact" tools. This fixes
that to check the returned ToolMessage.
This PR also adds a test that now passes.
This commit is contained in:
@@ -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 content
|
||||
assert 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 content
|
||||
assert isinstance(tool_message.content, (str, list))
|
||||
|
Reference in New Issue
Block a user