This commit is contained in:
Sydney Runkle
2025-08-29 17:04:25 -04:00
parent fcfb9dd3a7
commit 8086a20865
2 changed files with 34 additions and 1 deletions
@@ -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.
+33
View File
@@ -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")
]
}