langgraph[patch]: fix create_react_agent inspectability (#2948)

Co-authored-by: vbarda <vadym@langchain.dev>
This commit is contained in:
Bagatur
2025-01-07 18:47:31 +00:00
committed by GitHub
co-authored by vbarda
parent 3dbe37041a
commit 8ab206043c
2 changed files with 11 additions and 4 deletions
@@ -554,6 +554,10 @@ def create_react_agent(
)
model_runnable = preprocessor | model
# If any of the tools are configured to return_directly after running,
# our graph needs to check if these were called
should_return_direct = {t.name for t in tool_classes if t.return_direct}
# Define the function that calls the model
def call_model(state: AgentState, config: RunnableConfig) -> AgentState:
_validate_chat_history(state["messages"])
@@ -673,10 +677,6 @@ def create_react_agent(
should_continue,
)
# If any of the tools are configured to return_directly after running,
# our graph needs to check if these were called
should_return_direct = {t.name for t in tool_classes if t.return_direct}
def route_tool_responses(state: AgentState) -> Literal["agent", "__end__"]:
for m in reversed(state["messages"]):
if not isinstance(m, ToolMessage):
+7
View File
@@ -1,4 +1,5 @@
import dataclasses
import inspect
import json
from functools import partial
from typing import (
@@ -2040,3 +2041,9 @@ def test__get_state_args() -> None:
return 0.0
assert _get_state_args(foo) == {"a": None, "b": "bar"}
def test_inspect_react() -> None:
model = FakeToolCallingModel(tool_calls=[])
agent = create_react_agent(model, [])
inspect.getclosurevars(agent.nodes["agent"].bound.func)