mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-10-12 03:05:28 +02:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8086a20865 | ||
|
|
fcfb9dd3a7 | ||
|
|
120ae38c12 |
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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