mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-24 08:32:24 +02:00
chore(prebuilt): revert back to create_react_agent (#6017)
This commit is contained in:
@@ -21,7 +21,7 @@ from langgraph.checkpoint.memory import InMemorySaver
|
||||
from langgraph.constants import END, START
|
||||
from langgraph.graph import StateGraph
|
||||
from langgraph.graph.message import MessagesState, add_messages
|
||||
from langgraph.prebuilt.chat_agent_executor import create_agent
|
||||
from langgraph.prebuilt.chat_agent_executor import create_react_agent
|
||||
from langgraph.prebuilt.tool_node import ToolNode
|
||||
from langgraph.pregel import NodeBuilder, Pregel
|
||||
from langgraph.types import (
|
||||
@@ -1301,7 +1301,7 @@ def test_prebuilt_tool_chat(snapshot: SnapshotAssertion) -> None:
|
||||
]
|
||||
)
|
||||
|
||||
app = create_agent(model, tools)
|
||||
app = create_react_agent(model, tools)
|
||||
|
||||
assert json.dumps(app.get_input_jsonschema()) == snapshot
|
||||
assert json.dumps(app.get_output_jsonschema()) == snapshot
|
||||
|
||||
@@ -23,7 +23,7 @@ from langgraph.checkpoint.base import BaseCheckpointSaver
|
||||
from langgraph.constants import END, START
|
||||
from langgraph.graph.message import add_messages
|
||||
from langgraph.graph.state import StateGraph
|
||||
from langgraph.prebuilt.chat_agent_executor import create_agent
|
||||
from langgraph.prebuilt.chat_agent_executor import create_react_agent
|
||||
from langgraph.prebuilt.tool_node import ToolNode
|
||||
from langgraph.pregel import NodeBuilder, Pregel
|
||||
from langgraph.types import PregelTask, Send, StateSnapshot, StreamWriter
|
||||
@@ -1059,7 +1059,7 @@ async def test_prebuilt_tool_chat() -> None:
|
||||
|
||||
tools = [search_api]
|
||||
|
||||
app = create_agent(model, tools)
|
||||
app = create_react_agent(model, tools)
|
||||
|
||||
assert await app.ainvoke(
|
||||
{"messages": [HumanMessage(content="what is weather in sf")]}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""langgraph.prebuilt exposes a higher-level API for creating and executing agents and tools."""
|
||||
|
||||
from langgraph.prebuilt.chat_agent_executor import create_agent
|
||||
from langgraph.prebuilt.chat_agent_executor import create_react_agent
|
||||
from langgraph.prebuilt.tool_node import (
|
||||
InjectedState,
|
||||
InjectedStore,
|
||||
@@ -10,7 +10,7 @@ from langgraph.prebuilt.tool_node import (
|
||||
from langgraph.prebuilt.tool_validator import ValidationNode
|
||||
|
||||
__all__ = [
|
||||
"create_agent",
|
||||
"create_react_agent",
|
||||
"ToolNode",
|
||||
"tools_condition",
|
||||
"ValidationNode",
|
||||
|
||||
@@ -899,7 +899,7 @@ def _supports_native_structured_output(
|
||||
)
|
||||
|
||||
|
||||
def create_agent(
|
||||
def create_react_agent(
|
||||
model: Union[
|
||||
str,
|
||||
BaseChatModel,
|
||||
@@ -928,7 +928,7 @@ def create_agent(
|
||||
) -> CompiledStateGraph:
|
||||
"""Creates an agent graph that calls tools in a loop until a stopping condition is met.
|
||||
|
||||
For more details on using `create_agent`, visit [Agents](https://langchain-ai.github.io/langgraph/agents/overview/) documentation.
|
||||
For more details on using `create_react_agent`, visit [Agents](https://langchain-ai.github.io/langgraph/agents/overview/) documentation.
|
||||
|
||||
Args:
|
||||
model: The language model for the agent. Supports static and dynamic
|
||||
@@ -1072,13 +1072,13 @@ def create_agent(
|
||||
|
||||
Example:
|
||||
```python
|
||||
from langgraph.prebuilt import create_agent
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
|
||||
def check_weather(location: str) -> str:
|
||||
'''Return the weather forecast for the specified location.'''
|
||||
return f"It's always sunny in {location}"
|
||||
|
||||
graph = create_agent(
|
||||
graph = create_react_agent(
|
||||
"anthropic:claude-3-7-sonnet-latest",
|
||||
tools=[check_weather],
|
||||
prompt="You are a helpful assistant",
|
||||
@@ -1132,6 +1132,6 @@ def create_agent(
|
||||
|
||||
|
||||
__all__ = [
|
||||
"create_agent",
|
||||
"create_react_agent",
|
||||
"AgentState",
|
||||
]
|
||||
|
||||
@@ -27,7 +27,7 @@ from langgraph.graph import START, MessagesState, StateGraph
|
||||
from langgraph.graph.message import REMOVE_ALL_MESSAGES
|
||||
from langgraph.prebuilt import (
|
||||
ToolNode,
|
||||
create_agent,
|
||||
create_react_agent,
|
||||
)
|
||||
from langgraph.prebuilt.chat_agent_executor import (
|
||||
AgentState,
|
||||
@@ -53,7 +53,7 @@ pytestmark = pytest.mark.anyio
|
||||
def test_no_prompt(sync_checkpointer: BaseCheckpointSaver) -> None:
|
||||
model = FakeToolCallingModel()
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[],
|
||||
checkpointer=sync_checkpointer,
|
||||
@@ -83,7 +83,7 @@ def test_no_prompt(sync_checkpointer: BaseCheckpointSaver) -> None:
|
||||
async def test_no_prompt_async(async_checkpointer: BaseCheckpointSaver) -> None:
|
||||
model = FakeToolCallingModel()
|
||||
|
||||
agent = create_agent(model, [], checkpointer=async_checkpointer)
|
||||
agent = create_react_agent(model, [], checkpointer=async_checkpointer)
|
||||
inputs = [HumanMessage("hi?")]
|
||||
thread = {"configurable": {"thread_id": "123"}}
|
||||
response = await agent.ainvoke({"messages": inputs}, thread, debug=True)
|
||||
@@ -108,7 +108,7 @@ async def test_no_prompt_async(async_checkpointer: BaseCheckpointSaver) -> None:
|
||||
|
||||
def test_system_message_prompt():
|
||||
prompt = SystemMessage(content="Foo")
|
||||
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
agent = create_react_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
inputs = [HumanMessage("hi?")]
|
||||
response = agent.invoke({"messages": inputs})
|
||||
expected_response = {
|
||||
@@ -119,7 +119,7 @@ def test_system_message_prompt():
|
||||
|
||||
def test_string_prompt():
|
||||
prompt = "Foo"
|
||||
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
agent = create_react_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
inputs = [HumanMessage("hi?")]
|
||||
response = agent.invoke({"messages": inputs})
|
||||
expected_response = {
|
||||
@@ -133,7 +133,7 @@ def test_callable_prompt():
|
||||
modified_message = f"Bar {state['messages'][-1].content}"
|
||||
return [HumanMessage(content=modified_message)]
|
||||
|
||||
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
agent = create_react_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
inputs = [HumanMessage("hi?")]
|
||||
response = agent.invoke({"messages": inputs})
|
||||
expected_response = {"messages": inputs + [AIMessage(content="Bar hi?", id="0")]}
|
||||
@@ -145,7 +145,7 @@ async def test_callable_prompt_async():
|
||||
modified_message = f"Bar {state['messages'][-1].content}"
|
||||
return [HumanMessage(content=modified_message)]
|
||||
|
||||
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
agent = create_react_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
inputs = [HumanMessage("hi?")]
|
||||
response = await agent.ainvoke({"messages": inputs})
|
||||
expected_response = {"messages": inputs + [AIMessage(content="Bar hi?", id="0")]}
|
||||
@@ -157,7 +157,7 @@ def test_runnable_prompt():
|
||||
lambda state: [HumanMessage(content=f"Baz {state['messages'][-1].content}")]
|
||||
)
|
||||
|
||||
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
agent = create_react_agent(FakeToolCallingModel(), [], prompt=prompt)
|
||||
inputs = [HumanMessage("hi?")]
|
||||
response = agent.invoke({"messages": inputs})
|
||||
expected_response = {"messages": inputs + [AIMessage(content="Baz hi?", id="0")]}
|
||||
@@ -184,7 +184,7 @@ def test_prompt_with_store():
|
||||
model = FakeToolCallingModel()
|
||||
|
||||
# test state modifier that uses store works
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[add],
|
||||
prompt=prompt,
|
||||
@@ -196,7 +196,7 @@ def test_prompt_with_store():
|
||||
assert response["messages"][-1].content == "User name is Alice-hi"
|
||||
|
||||
# test state modifier that doesn't use store works
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[add],
|
||||
prompt=prompt_no_store,
|
||||
@@ -234,14 +234,14 @@ async def test_prompt_with_store_async():
|
||||
model = FakeToolCallingModel()
|
||||
|
||||
# test state modifier that uses store works
|
||||
agent = create_agent(model, [add], prompt=prompt, store=in_memory_store)
|
||||
agent = create_react_agent(model, [add], prompt=prompt, store=in_memory_store)
|
||||
response = await agent.ainvoke(
|
||||
{"messages": [("user", "hi")]}, {"configurable": {"user_id": "1"}}
|
||||
)
|
||||
assert response["messages"][-1].content == "User name is Alice-hi"
|
||||
|
||||
# test state modifier that doesn't use store works
|
||||
agent = create_agent(model, [add], prompt=prompt_no_store, store=in_memory_store)
|
||||
agent = create_react_agent(model, [add], prompt=prompt_no_store, store=in_memory_store)
|
||||
response = await agent.ainvoke(
|
||||
{"messages": [("user", "hi")]}, {"configurable": {"user_id": "2"}}
|
||||
)
|
||||
@@ -282,7 +282,7 @@ def test_model_with_tools(tool_style: str, include_builtin: bool) -> None:
|
||||
)
|
||||
# check valid agent constructor
|
||||
with pytest.raises(ValueError):
|
||||
create_agent(
|
||||
create_react_agent(
|
||||
model.bind_tools(tools),
|
||||
tools,
|
||||
)
|
||||
@@ -431,7 +431,7 @@ def test_react_agent_with_structured_response() -> None:
|
||||
model = FakeToolCallingModel[WeatherResponse](
|
||||
tool_calls=tool_calls, structured_response=expected_structured_response
|
||||
)
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_weather],
|
||||
response_format=WeatherResponse,
|
||||
@@ -491,7 +491,7 @@ def test_react_agent_update_state(
|
||||
|
||||
tool_calls = [[{"args": {}, "id": "1", "name": "get_user_name"}]]
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_user_name],
|
||||
state_schema=CustomState,
|
||||
@@ -542,7 +542,7 @@ def test_react_agent_parallel_tool_calls(
|
||||
[],
|
||||
]
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[human_assistance, get_weather],
|
||||
checkpointer=sync_checkpointer,
|
||||
@@ -606,7 +606,7 @@ def test_create_react_agent_inject_vars() -> None:
|
||||
"type": "tool_call",
|
||||
}
|
||||
model = FakeToolCallingModel(tool_calls=[[tool_call], []])
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
ToolNode([tool1], handle_tool_errors=False),
|
||||
state_schema=AgentStateExtraKey,
|
||||
@@ -646,7 +646,7 @@ async def test_return_direct() -> None:
|
||||
tool_calls=first_tool_call,
|
||||
)
|
||||
model = FakeToolCallingModel(tool_calls=[first_tool_call, []])
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[tool_return_direct, tool_normal],
|
||||
)
|
||||
@@ -673,7 +673,7 @@ async def test_return_direct() -> None:
|
||||
),
|
||||
]
|
||||
model = FakeToolCallingModel(tool_calls=[second_tool_call, []])
|
||||
agent = create_agent(model, [tool_return_direct, tool_normal])
|
||||
agent = create_react_agent(model, [tool_return_direct, tool_normal])
|
||||
result = agent.invoke(
|
||||
{"messages": [HumanMessage(content="Test normal", id="hum1")]}
|
||||
)
|
||||
@@ -702,7 +702,7 @@ async def test_return_direct() -> None:
|
||||
),
|
||||
]
|
||||
model = FakeToolCallingModel(tool_calls=[both_tool_calls, []])
|
||||
agent = create_agent(model, [tool_return_direct, tool_normal])
|
||||
agent = create_react_agent(model, [tool_return_direct, tool_normal])
|
||||
result = agent.invoke({"messages": [HumanMessage(content="Test both", id="hum2")]})
|
||||
assert result["messages"] == [
|
||||
HumanMessage(content="Test both", id="hum2"),
|
||||
@@ -739,7 +739,7 @@ def test__get_state_args() -> None:
|
||||
|
||||
def test_inspect_react() -> None:
|
||||
model = FakeToolCallingModel(tool_calls=[])
|
||||
agent = create_agent(model, [])
|
||||
agent = create_react_agent(model, [])
|
||||
inspect.getclosurevars(agent.nodes["model"].bound.func)
|
||||
|
||||
|
||||
@@ -796,7 +796,7 @@ def test_react_with_subgraph_tools(
|
||||
]
|
||||
)
|
||||
tool_node = ToolNode([addition, multiplication], handle_tool_errors=False)
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
tool_node,
|
||||
checkpointer=sync_checkpointer,
|
||||
@@ -846,7 +846,7 @@ def test_react_agent_subgraph_streaming_sync() -> None:
|
||||
]
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
tools=[get_weather],
|
||||
prompt="You are a helpful travel assistant.",
|
||||
@@ -935,7 +935,7 @@ async def test_react_agent_subgraph_streaming() -> None:
|
||||
]
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
tools=[get_weather],
|
||||
prompt="You are a helpful travel assistant.",
|
||||
@@ -1033,7 +1033,7 @@ def test_tool_node_node_interrupt(
|
||||
]
|
||||
)
|
||||
config = {"configurable": {"thread_id": "1"}}
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[tool_interrupt, tool_normal],
|
||||
checkpointer=sync_checkpointer,
|
||||
@@ -1085,7 +1085,7 @@ def test_dynamic_model_basic() -> None:
|
||||
else:
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
agent = create_agent(dynamic_model, [])
|
||||
agent = create_react_agent(dynamic_model, [])
|
||||
|
||||
result = agent.invoke({"messages": [HumanMessage("hello")]})
|
||||
assert len(result["messages"]) == 2
|
||||
@@ -1123,7 +1123,7 @@ def test_dynamic_model_with_tools() -> None:
|
||||
tool_calls=[[{"args": {"x": 1}, "id": "1", "name": "basic_tool"}], []]
|
||||
)
|
||||
|
||||
agent = create_agent(dynamic_model, [basic_tool, advanced_tool])
|
||||
agent = create_react_agent(dynamic_model, [basic_tool, advanced_tool])
|
||||
|
||||
# Test basic tool usage
|
||||
result = agent.invoke({"messages": [HumanMessage("basic request")]})
|
||||
@@ -1156,7 +1156,7 @@ def test_dynamic_model_with_context() -> None:
|
||||
else:
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
agent = create_agent(dynamic_model, [], context_schema=Context)
|
||||
agent = create_react_agent(dynamic_model, [], context_schema=Context)
|
||||
|
||||
# Test with basic user
|
||||
result = agent.invoke(
|
||||
@@ -1186,7 +1186,7 @@ def test_dynamic_model_with_state_schema() -> None:
|
||||
else:
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
agent = create_agent(dynamic_model, [], state_schema=CustomDynamicState)
|
||||
agent = create_react_agent(dynamic_model, [], state_schema=CustomDynamicState)
|
||||
|
||||
result = agent.invoke(
|
||||
{"messages": [HumanMessage("hello")], "model_preference": "advanced"}
|
||||
@@ -1202,7 +1202,7 @@ def test_dynamic_model_with_prompt() -> None:
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
# Test with string prompt
|
||||
agent = create_agent(dynamic_model, [], prompt="system_msg")
|
||||
agent = create_react_agent(dynamic_model, [], prompt="system_msg")
|
||||
result = agent.invoke({"messages": [HumanMessage("human_msg")]})
|
||||
assert result["messages"][-1].content == "system_msg-human_msg"
|
||||
|
||||
@@ -1211,7 +1211,7 @@ def test_dynamic_model_with_prompt() -> None:
|
||||
"""Generate a dynamic system message based on state."""
|
||||
return [{"role": "system", "content": "system_msg"}] + list(state["messages"])
|
||||
|
||||
agent = create_agent(dynamic_model, [], prompt=dynamic_prompt)
|
||||
agent = create_react_agent(dynamic_model, [], prompt=dynamic_prompt)
|
||||
result = agent.invoke({"messages": [HumanMessage("human_msg")]})
|
||||
assert result["messages"][-1].content == "system_msg-human_msg"
|
||||
|
||||
@@ -1222,7 +1222,7 @@ async def test_dynamic_model_async() -> None:
|
||||
def dynamic_model(state: AgentState, runtime: Runtime) -> BaseChatModel:
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
agent = create_agent(dynamic_model, [])
|
||||
agent = create_react_agent(dynamic_model, [])
|
||||
|
||||
result = await agent.ainvoke({"messages": [HumanMessage("hello async")]})
|
||||
assert len(result["messages"]) == 2
|
||||
@@ -1250,7 +1250,7 @@ def test_dynamic_model_with_structured_response() -> None:
|
||||
],
|
||||
)
|
||||
|
||||
agent = create_agent(dynamic_model, [], response_format=TestResponse)
|
||||
agent = create_react_agent(dynamic_model, [], response_format=TestResponse)
|
||||
|
||||
result = agent.invoke({"messages": [HumanMessage("hello")]})
|
||||
assert "structured_response" in result
|
||||
@@ -1274,7 +1274,7 @@ def test_dynamic_model_with_checkpointer(sync_checkpointer):
|
||||
index=call_count,
|
||||
)
|
||||
|
||||
agent = create_agent(dynamic_model, [], checkpointer=sync_checkpointer)
|
||||
agent = create_react_agent(dynamic_model, [], checkpointer=sync_checkpointer)
|
||||
config = {"configurable": {"thread_id": "test_dynamic"}}
|
||||
|
||||
# First call
|
||||
@@ -1313,7 +1313,7 @@ def test_dynamic_model_state_dependent_tools() -> None:
|
||||
tool_calls=[[{"args": {"x": 1}, "id": "1", "name": "tool_a"}], []]
|
||||
)
|
||||
|
||||
agent = create_agent(dynamic_model, [tool_a, tool_b])
|
||||
agent = create_react_agent(dynamic_model, [tool_a, tool_b])
|
||||
|
||||
# Ask to use tool B
|
||||
result = agent.invoke({"messages": [HumanMessage("use_b please")]})
|
||||
@@ -1336,7 +1336,7 @@ def test_dynamic_model_error_handling() -> None:
|
||||
raise ValueError("Dynamic model failed")
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
agent = create_agent(failing_dynamic_model, [])
|
||||
agent = create_react_agent(failing_dynamic_model, [])
|
||||
|
||||
# Normal operation should work
|
||||
result = agent.invoke({"messages": [HumanMessage("hello")]})
|
||||
@@ -1351,13 +1351,13 @@ def test_dynamic_model_vs_static_model_behavior():
|
||||
"""Test that dynamic and static models produce equivalent results when configured the same."""
|
||||
# Static model
|
||||
static_model = FakeToolCallingModel(tool_calls=[])
|
||||
static_agent = create_agent(static_model, [])
|
||||
static_agent = create_react_agent(static_model, [])
|
||||
|
||||
# Dynamic model returning the same model
|
||||
def dynamic_model(state, runtime: Runtime):
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
dynamic_agent = create_agent(dynamic_model, [])
|
||||
dynamic_agent = create_react_agent(dynamic_model, [])
|
||||
|
||||
input_msg = {"messages": [HumanMessage("test message")]}
|
||||
|
||||
@@ -1382,7 +1382,7 @@ def test_dynamic_model_receives_correct_state():
|
||||
received_states.append(state)
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
agent = create_agent(dynamic_model, [], state_schema=CustomAgentState)
|
||||
agent = create_react_agent(dynamic_model, [], state_schema=CustomAgentState)
|
||||
|
||||
# Test with initial state
|
||||
input_state = {"messages": [HumanMessage("hello")], "custom_field": "test_value"}
|
||||
@@ -1413,7 +1413,7 @@ async def test_dynamic_model_receives_correct_state_async():
|
||||
received_states.append(state)
|
||||
return FakeToolCallingModel(tool_calls=[])
|
||||
|
||||
agent = create_agent(dynamic_model, [], state_schema=CustomAgentStateAsync)
|
||||
agent = create_react_agent(dynamic_model, [], state_schema=CustomAgentStateAsync)
|
||||
|
||||
# Test with initial state
|
||||
input_state = {
|
||||
@@ -1443,7 +1443,7 @@ def test_pre_model_hook() -> None:
|
||||
def pre_model_hook(state: AgentState):
|
||||
return {"llm_input_messages": [HumanMessage("Hello!")]}
|
||||
|
||||
agent = create_agent(model, [], pre_model_hook=pre_model_hook)
|
||||
agent = create_react_agent(model, [], pre_model_hook=pre_model_hook)
|
||||
assert "pre_model_hook" in agent.nodes
|
||||
result = agent.invoke({"messages": [HumanMessage("hi?")]})
|
||||
assert result == {
|
||||
@@ -1459,7 +1459,7 @@ def test_pre_model_hook() -> None:
|
||||
"messages": [RemoveMessage(id=REMOVE_ALL_MESSAGES), HumanMessage("Hello!")]
|
||||
}
|
||||
|
||||
agent = create_agent(model, [], pre_model_hook=pre_model_hook)
|
||||
agent = create_react_agent(model, [], pre_model_hook=pre_model_hook)
|
||||
result = agent.invoke({"messages": [HumanMessage("hi?")]})
|
||||
assert result == {
|
||||
"messages": [
|
||||
@@ -1478,7 +1478,7 @@ def test_post_model_hook() -> None:
|
||||
def post_model_hook(state: FlagState) -> dict[str, bool]:
|
||||
return {"flag": True}
|
||||
|
||||
pmh_agent = create_agent(
|
||||
pmh_agent = create_react_agent(
|
||||
model, [], post_model_hook=post_model_hook, state_schema=FlagState
|
||||
)
|
||||
|
||||
@@ -1528,7 +1528,7 @@ def test_post_model_hook_with_structured_output() -> None:
|
||||
return {"flag": True}
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_weather],
|
||||
response_format=WeatherResponse,
|
||||
@@ -1546,7 +1546,7 @@ def test_post_model_hook_with_structured_output() -> None:
|
||||
|
||||
# Reset the state of the model
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_weather],
|
||||
response_format=WeatherResponse,
|
||||
@@ -1646,7 +1646,7 @@ def test_create_react_agent_inject_vars_with_post_model_hook() -> None:
|
||||
return {"foo": 2}
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=[[tool_call], []])
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
ToolNode([tool1], handle_tool_errors=False),
|
||||
state_schema=AgentStateExtraKey,
|
||||
@@ -1681,7 +1681,7 @@ def test_response_format_using_tool_choice() -> None:
|
||||
|
||||
expected_structured_response = WeatherResponse(temperature=75)
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_weather],
|
||||
response_format=WeatherResponse,
|
||||
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
from pydantic import BaseModel
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from langgraph.prebuilt import create_agent
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from tests.model import FakeToolCallingModel
|
||||
|
||||
model = FakeToolCallingModel()
|
||||
@@ -40,7 +40,7 @@ def test_react_agent_graph_structure(
|
||||
pre_model_hook: Union[Callable, None],
|
||||
post_model_hook: Union[Callable, None],
|
||||
) -> None:
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
tools=tools,
|
||||
pre_model_hook=pre_model_hook,
|
||||
|
||||
@@ -8,7 +8,7 @@ from langchain_core.messages import HumanMessage
|
||||
from pydantic import BaseModel, Field
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from langgraph.prebuilt import create_agent
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from langgraph.prebuilt.responses import (
|
||||
MultipleStructuredOutputsError,
|
||||
NativeOutput,
|
||||
@@ -120,7 +120,7 @@ class TestResponseFormatAsModel:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(model, [get_weather], response_format=WeatherBaseModel)
|
||||
agent = create_react_agent(model, [get_weather], response_format=WeatherBaseModel)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
|
||||
assert response["structured_response"] == EXPECTED_WEATHER_PYDANTIC
|
||||
@@ -141,7 +141,7 @@ class TestResponseFormatAsModel:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(model, [get_weather], response_format=WeatherDataclass)
|
||||
agent = create_react_agent(model, [get_weather], response_format=WeatherDataclass)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
|
||||
assert response["structured_response"] == EXPECTED_WEATHER_DATACLASS
|
||||
@@ -162,7 +162,7 @@ class TestResponseFormatAsModel:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(model, [get_weather], response_format=WeatherTypedDict)
|
||||
agent = create_react_agent(model, [get_weather], response_format=WeatherTypedDict)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
|
||||
assert response["structured_response"] == EXPECTED_WEATHER_DICT
|
||||
@@ -183,7 +183,7 @@ class TestResponseFormatAsModel:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(model, [get_weather], response_format=weather_json_schema)
|
||||
agent = create_react_agent(model, [get_weather], response_format=weather_json_schema)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
|
||||
assert response["structured_response"] == EXPECTED_WEATHER_DICT
|
||||
@@ -206,7 +206,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=ToolOutput(WeatherBaseModel)
|
||||
)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
@@ -229,7 +229,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=ToolOutput(WeatherDataclass)
|
||||
)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
@@ -252,7 +252,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=ToolOutput(WeatherTypedDict)
|
||||
)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
@@ -275,7 +275,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=ToolOutput(weather_json_schema)
|
||||
)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
@@ -298,7 +298,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_weather, get_location],
|
||||
response_format=ToolOutput(
|
||||
@@ -324,7 +324,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model_location = FakeToolCallingModel(tool_calls=tool_calls_location)
|
||||
|
||||
agent_location = create_agent(
|
||||
agent_location = create_react_agent(
|
||||
model_location,
|
||||
[get_weather, get_location],
|
||||
response_format=ToolOutput(
|
||||
@@ -356,7 +356,7 @@ class TestResponseFormatAsToolOutput:
|
||||
tool_calls=tool_calls
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_weather, get_location],
|
||||
response_format=ToolOutput(Union[WeatherBaseModel, LocationResponse]),
|
||||
@@ -380,7 +380,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model_location = FakeToolCallingModel(tool_calls=tool_calls_location)
|
||||
|
||||
agent_location = create_agent(
|
||||
agent_location = create_react_agent(
|
||||
model_location,
|
||||
[get_weather, get_location],
|
||||
response_format=ToolOutput(Union[WeatherBaseModel, LocationResponse]),
|
||||
@@ -411,7 +411,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[],
|
||||
response_format=ToolOutput(
|
||||
@@ -452,7 +452,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[],
|
||||
response_format=ToolOutput(
|
||||
@@ -481,7 +481,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[],
|
||||
response_format=ToolOutput(
|
||||
@@ -517,7 +517,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[],
|
||||
response_format=ToolOutput(
|
||||
@@ -563,7 +563,7 @@ class TestResponseFormatAsToolOutput:
|
||||
return "Custom error: Multiple outputs not allowed"
|
||||
return "Custom error"
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[],
|
||||
response_format=ToolOutput(
|
||||
@@ -607,7 +607,7 @@ class TestResponseFormatAsToolOutput:
|
||||
|
||||
model = FakeToolCallingModel(tool_calls=tool_calls)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[],
|
||||
response_format=ToolOutput(
|
||||
@@ -637,7 +637,7 @@ class TestResponseFormatAsNativeOutput:
|
||||
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_PYDANTIC
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=NativeOutput(WeatherBaseModel)
|
||||
)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
@@ -655,7 +655,7 @@ class TestResponseFormatAsNativeOutput:
|
||||
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DATACLASS
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=NativeOutput(WeatherDataclass)
|
||||
)
|
||||
response = agent.invoke(
|
||||
@@ -675,7 +675,7 @@ class TestResponseFormatAsNativeOutput:
|
||||
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DICT
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=NativeOutput(WeatherTypedDict)
|
||||
)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
@@ -693,7 +693,7 @@ class TestResponseFormatAsNativeOutput:
|
||||
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DICT
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model, [get_weather], response_format=NativeOutput(weather_json_schema)
|
||||
)
|
||||
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
||||
@@ -719,7 +719,7 @@ def test_union_of_types() -> None:
|
||||
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_PYDANTIC
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
[get_weather, get_location],
|
||||
response_format=ToolOutput(Union[WeatherBaseModel, LocationResponse]),
|
||||
@@ -736,7 +736,7 @@ def test_union_of_types() -> None:
|
||||
def test_inference_to_native_output() -> None:
|
||||
"""Test that native output is inferred when a model supports it."""
|
||||
model = ChatOpenAI(model="gpt-5")
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
prompt="You are a helpful weather assistant. Please call the get_weather tool, then use the WeatherReport tool to generate the final response.",
|
||||
tools=[get_weather],
|
||||
@@ -763,7 +763,7 @@ def test_inference_to_native_output() -> None:
|
||||
def test_inference_to_tool_output() -> None:
|
||||
"""Test that tool output is inferred when a model supports it."""
|
||||
model = ChatOpenAI(model="gpt-4")
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
prompt="You are a helpful weather assistant. Please call the get_weather tool, then use the WeatherReport tool to generate the final response.",
|
||||
tools=[get_weather],
|
||||
|
||||
@@ -9,7 +9,7 @@ from langchain_core.messages import HumanMessage
|
||||
from langchain_core.tools import tool
|
||||
from pydantic import BaseModel, create_model
|
||||
|
||||
from langgraph.prebuilt import create_agent
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from langgraph.prebuilt.responses import ToolOutput
|
||||
from tests.utils import BaseSchema, load_spec
|
||||
|
||||
@@ -129,7 +129,7 @@ def test_responses_integration_matrix(case: TestCase) -> None:
|
||||
http_client=http_client,
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
tools=[role_tool["tool"], dept_tool["tool"]],
|
||||
prompt=AGENT_PROMPT,
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
from langchain_core.messages import HumanMessage
|
||||
from langchain_core.tools import tool
|
||||
|
||||
from langgraph.prebuilt import create_agent
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from langgraph.prebuilt.responses import ToolOutput
|
||||
from tests.utils import BaseSchema, load_spec
|
||||
|
||||
@@ -79,14 +79,14 @@ def test_return_direct_integration_matrix(case: TestCase) -> None:
|
||||
)
|
||||
|
||||
if case.response_format:
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
tools=[poll_tool["tool"]],
|
||||
prompt=AGENT_PROMPT,
|
||||
response_format=ToolOutput(case.response_format),
|
||||
)
|
||||
else:
|
||||
agent = create_agent(
|
||||
agent = create_react_agent(
|
||||
model,
|
||||
tools=[poll_tool["tool"]],
|
||||
prompt=AGENT_PROMPT,
|
||||
|
||||
Reference in New Issue
Block a user