Skip to content

Commit

Permalink
langgraph[patch]: fix create_react_agent inspectability (#2948)
Browse files Browse the repository at this point in the history
Co-authored-by: vbarda <[email protected]>
  • Loading branch information
baskaryan and vbarda authored Jan 7, 2025
1 parent 3dbe370 commit 8ab2060
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libs/langgraph/langgraph/prebuilt/chat_agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ class Agent,Tools otherClass
)
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"])
Expand Down Expand Up @@ -673,10 +677,6 @@ def should_continue(state: AgentState) -> Literal["tools", "__end__"]:
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):
Expand Down
7 changes: 7 additions & 0 deletions libs/langgraph/tests/test_prebuilt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dataclasses
import inspect
import json
from functools import partial
from typing import (
Expand Down Expand Up @@ -2040,3 +2041,9 @@ def foo(a: str, b: int) -> float:
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)

0 comments on commit 8ab2060

Please sign in to comment.