Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix example in docs of state_schema in create_react_agent #2109

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libs/langgraph/langgraph/prebuilt/chat_agent_executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Literal, Optional, Sequence, Type, TypeVar, Union, cast

Check notice on line 1 in libs/langgraph/langgraph/prebuilt/chat_agent_executor.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 48.2 ms +- 1.0 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 45.6 ms +- 3.0 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 76.4 ms +- 1.8 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 84.7 ms +- 0.7 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 466 ms +- 10 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 432 ms +- 12 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 793 ms +- 58 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 834 ms +- 16 ms ......................................... react_agent_10x: Mean +- std dev: 28.7 ms +- 0.7 ms ......................................... react_agent_10x_sync: Mean +- std dev: 22.0 ms +- 1.5 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 46.6 ms +- 3.0 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 36.3 ms +- 2.9 ms ......................................... react_agent_100x: Mean +- std dev: 325 ms +- 13 ms ......................................... react_agent_100x_sync: Mean +- std dev: 258 ms +- 12 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 905 ms +- 14 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 807 ms +- 13 ms ......................................... wide_state_25x300: Mean +- std dev: 18.4 ms +- 0.3 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 10.9 ms +- 0.1 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 273 ms +- 4 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 260 ms +- 3 ms ......................................... wide_state_15x600: Mean +- std dev: 21.3 ms +- 0.5 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 12.5 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 473 ms +- 7 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 457 ms +- 4 ms ......................................... wide_state_9x1200: Mean +- std dev: 21.3 ms +- 0.4 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 12.5 ms +- 0.1 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 306 ms +- 7 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 292 ms +- 5 ms

Check notice on line 1 in libs/langgraph/langgraph/prebuilt/chat_agent_executor.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+----------------------------------------+---------+-----------------------+ | Benchmark | main | changes | +========================================+=========+=======================+ | react_agent_100x_checkpoint | 928 ms | 905 ms: 1.03x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x | 477 ms | 466 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 826 ms | 807 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint | 47.6 ms | 46.6 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 807 ms | 793 ms: 1.02x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600 | 21.5 ms | 21.3 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200 | 21.5 ms | 21.3 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 85.4 ms | 84.7 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_25x300 | 18.5 ms | 18.4 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_25x300_checkpoint_sync | 262 ms | 260 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_sync | 12.6 ms | 12.5 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint_sync | 461 ms | 457 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 476 ms | 473 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint | 77.0 ms | 76.4 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint_sync | 294 ms | 292 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | react_agent_10x | 28.8 ms | 28.7 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 12.6 ms | 12.5 ms: 1.01x faster | +----------------------------------------+---------+-----------------------+ | wide_state_9x1200_checkpoint | 308 ms | 306 ms: 1.00x faster | +----------------------------------------+---------+-----------------------+ | wide_state_25x300_sync | 10.9 ms | 10.9 ms: 1.00x faster | +----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.01x faster | +----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (9): react_agent_10x_checkpoint_sync, fanout_to_subgraph_10x_sync, react_agent_10x_sync, fanout_to_subgraph_100x_sync, fanout_to_subgraph_100x_checkpoint_sync, react_agent_100x, wide_state_25x300_checkpoint, react_agent_100x_sync, fanout_to_subgraph_10x

from langchain_core.language_models import BaseChatModel, LanguageModelLike
from langchain_core.messages import AIMessage, BaseMessage, SystemMessage, ToolMessage
Expand Down Expand Up @@ -349,6 +349,8 @@

```pycon
>>> from typing import TypedDict
>>>
>>> from langgraph.managed import IsLastStep
>>> prompt = ChatPromptTemplate.from_messages(
... [
... ("system", "Today is {today}"),
Expand All @@ -359,7 +361,7 @@
>>> class CustomState(TypedDict):
... today: str
... messages: Annotated[list[BaseMessage], add_messages]
... is_last_step: str
... is_last_step: IsLastStep
>>>
>>> graph = create_react_agent(model, tools, state_schema=CustomState, state_modifier=prompt)
>>> inputs = {"messages": [("user", "What's today's date? And what's the weather in SF?")], "today": "July 16, 2004"}
Expand Down
Loading