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

mark system prompt configurable #2864

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
3 changes: 1 addition & 2 deletions 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: 60.5 ms +- 0.9 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 51.8 ms +- 0.7 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 73.8 ms +- 1.0 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 94.0 ms +- 1.6 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 604 ms +- 23 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 510 ms +- 6 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 748 ms +- 17 ms ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 942 ms +- 19 ms ......................................... react_agent_10x: Mean +- std dev: 30.7 ms +- 0.8 ms ......................................... react_agent_10x_sync: Mean +- std dev: 22.8 ms +- 0.3 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 37.8 ms +- 0.7 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 36.8 ms +- 0.4 ms ......................................... react_agent_100x: Mean +- std dev: 340 ms +- 7 ms ......................................... react_agent_100x_sync: Mean +- std dev: 274 ms +- 2 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 837 ms +- 8 ms ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 828 ms +- 7 ms ......................................... wide_state_25x300: Mean +- std dev: 22.9 ms +- 0.5 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 14.7 ms +- 0.3 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 274 ms +- 13 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 271 ms +- 12 ms ......................................... wide_state_15x600: Mean +- std dev: 26.6 ms +- 0.5 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 17.1 ms +- 0.1 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 470 ms +- 13 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 470 ms +- 13 ms ......................................... wide_state_9x1200: Mean +- std dev: 26.8 ms +- 0.5 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 17.1 ms +- 0.2 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 308 ms +- 13 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 304 ms +- 14 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 | +=========================================+=========+=======================+ | wide_state_25x300_checkpoint_sync | 276 ms | 271 ms: 1.02x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint | 477 ms | 470 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_sync | 17.3 ms | 17.1 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | wide_state_15x600_checkpoint_sync | 474 ms | 470 ms: 1.01x faster | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_checkpoint_sync | 830 ms | 828 ms: 1.00x faster | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_sync | 51.6 ms | 51.8 ms: 1.00x slower | +-----------------------------------------+---------+-----------------------+ | react_agent_100x_sync | 273 ms | 274 ms: 1.00x slower | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_sync | 22.7 ms | 22.8 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | react_agent_10x_checkpoint_sync | 36.5 ms | 36.8 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint | 73.3 ms | 73.8 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x | 60.2 ms | 60.5 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | wide_state_25x300 | 22.8 ms | 22.9 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | wide_state_9x1200 | 26.5 ms | 26.8 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | react_agent_10x | 30.5 ms | 30.7 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 93.2 ms | 94.0 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_sync | 505 ms | 510 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint_sync | 929 ms | 942 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | react_agent_100x | 335 ms | 340 ms: 1.01x slower | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x_checkpoint | 730 ms | 748 ms: 1.02x slower | +-----------------------------------------+---------+-----------------------+ | fanout_to_subgraph_100x | 589 ms | 604 ms: 1.03x slower | +-----------------------------------------+---------+-----------------------+ | Geometric mean | (ref) | 1.00x slower | +-----------------------------------------+---------+-----------------------+ Benchmark hidden because not significant (8): wide_state_25x300_checkpoint, wide_state_9x1200_checkpoint_sync, wide_state_15x600, wide_state_25x300_sync, react_agent_10x_checkpoint, react_agent_100x_checkpoint, wide_state_9x1200_sync, wide_state_9x1200_checkpoint

from langchain_core.language_models import BaseChatModel, LanguageModelLike
from langchain_core.messages import AIMessage, BaseMessage, SystemMessage, ToolMessage
Expand Down Expand Up @@ -66,9 +66,8 @@
lambda state: state["messages"], name=STATE_MODIFIER_RUNNABLE_NAME
)
elif isinstance(state_modifier, str):
_system_message: BaseMessage = SystemMessage(content=state_modifier)
state_modifier_runnable = RunnableCallable(
lambda state: [_system_message] + state["messages"],
lambda state, config: [SystemMessage(config['configurable'].get('system_prompt', state_modifier))] + state["messages"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general i don't mind this, but i think it makes more sense for it to be in the above if branch (when state_modifier is None)

name=STATE_MODIFIER_RUNNABLE_NAME,
)
elif isinstance(state_modifier, SystemMessage):
Expand Down
Loading