mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-07 02:07:52 +02:00
add test
This commit is contained in:
@@ -447,7 +447,7 @@ class ToolNode(RunnableCallable):
|
||||
|
||||
try:
|
||||
response = tool.invoke(call_args, config)
|
||||
except NotImplementedError as e:
|
||||
except NotImplementedError:
|
||||
response = asyncio.run(tool.ainvoke(call_args, config))
|
||||
|
||||
# GraphInterrupt is a special exception that will always be raised.
|
||||
|
||||
@@ -1156,3 +1156,36 @@ async def test_tool_node_command_remove_all_messages():
|
||||
command = result[0]
|
||||
assert isinstance(command, Command)
|
||||
assert command.update == {"messages": [RemoveMessage(id=REMOVE_ALL_MESSAGES)]}
|
||||
|
||||
|
||||
async def test_async_tool_called_syncly() -> None:
|
||||
"""Confirm that async tools can be called synchronously."""
|
||||
|
||||
@dec_tool
|
||||
async def async_tool():
|
||||
"""An async tool."""
|
||||
return "async tool"
|
||||
|
||||
tool_node = ToolNode([async_tool])
|
||||
result = tool_node.invoke(
|
||||
{
|
||||
"messages": [
|
||||
AIMessage(
|
||||
content="",
|
||||
tool_calls=[
|
||||
{
|
||||
"name": "async_tool",
|
||||
"args": {},
|
||||
"id": "1",
|
||||
"type": "tool_call",
|
||||
}
|
||||
],
|
||||
)
|
||||
]
|
||||
}
|
||||
)
|
||||
assert result == {
|
||||
"messages": [
|
||||
ToolMessage(content="async tool", name="async_tool", tool_call_id="1")
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user