Compare commits

..
Author SHA1 Message Date
Sydney Runkle 8086a20865 add test 2025-08-29 17:04:25 -04:00
Sydney Runkle fcfb9dd3a7 asyncio escape hatch 2025-08-29 17:02:03 -04:00
Sydney RunkleandGitHub 120ae38c12 chore(docs): fix runtime context link (#6043) 2025-08-29 13:45:39 -04:00
4 changed files with 40 additions and 47 deletions
@@ -1550,29 +1550,6 @@
},
"name": "Last-Event-ID",
"in": "header"
},
{
"required": false,
"schema": {
"anyOf": [
{
"type": "string",
"enum": ["lifecycle", "run_modes", "state_update"]
},
{
"type": "array",
"items": {
"type": "string",
"enum": ["lifecycle", "run_modes", "state_update"]
}
}
],
"default": ["run_modes"],
"title": "Stream Modes",
"description": "Stream modes to control which events are returned. 'lifecycle' returns only run start/end events, 'run_modes' returns all run events (default behavior), 'state_update' returns only state update events."
},
"name": "stream_modes",
"in": "query"
}
],
"responses": {
@@ -4436,17 +4413,6 @@
"title": "Checkpoint During",
"description": "Whether to checkpoint during the run.",
"default": false
},
"durability": {
"type": "string",
"enum": [
"sync",
"async",
"exit"
],
"title": "Durability",
"description": "Durability level for the run. Must be one of 'sync', 'async', or 'exit'.",
"default": "async"
}
},
"type": "object",
@@ -4683,17 +4649,6 @@
"title": "Checkpoint During",
"description": "Whether to checkpoint during the run.",
"default": false
},
"durability": {
"type": "string",
"enum": [
"sync",
"async",
"exit"
],
"title": "Durability",
"description": "Durability level for the run. Must be one of 'sync', 'async', or 'exit'.",
"default": "async"
}
},
"type": "object",
+1 -1
View File
@@ -1040,7 +1040,7 @@ def node_a(state: State, runtime: Runtime[ContextSchema]):
...
```
See [this guide](../how-tos/graph-api.ipynb#add-runtime-configuration) for a full breakdown on configuration.
See [this guide](../how-tos/graph-api.md#add-runtime-configuration) for a full breakdown on configuration.
:::
:::js
@@ -443,7 +443,12 @@ class ToolNode(RunnableCallable):
return invalid_tool_message
try:
call_args = {**call, **{"type": "tool_call"}}
response = self.tools_by_name[call["name"]].invoke(call_args, config)
tool = self.tools_by_name[call["name"]]
try:
response = tool.invoke(call_args, config)
except NotImplementedError:
response = asyncio.run(tool.ainvoke(call_args, config))
# GraphInterrupt is a special exception that will always be raised.
# It can be triggered in the following scenarios,
+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")
]
}