diff --git a/libs/langgraph/langgraph/graph/graph.py b/libs/langgraph/langgraph/graph/graph.py index 07ddd8381..65bc908b7 100644 --- a/libs/langgraph/langgraph/graph/graph.py +++ b/libs/langgraph/langgraph/graph/graph.py @@ -417,6 +417,7 @@ class Graph: interrupt_before: Optional[Union[All, list[str]]] = None, interrupt_after: Optional[Union[All, list[str]]] = None, debug: bool = False, + name: Optional[str] = None, ) -> "CompiledGraph": # assign default values interrupt_before = interrupt_before or [] @@ -445,6 +446,7 @@ class Graph: interrupt_after_nodes=interrupt_after, auto_validate=False, debug=debug, + name=name or "LangGraph", ) # attach nodes, edges, and branches diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index ae7c188ec..4d9f118a4 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -500,6 +500,7 @@ class StateGraph(Graph): interrupt_before: Optional[Union[All, list[str]]] = None, interrupt_after: Optional[Union[All, list[str]]] = None, debug: bool = False, + name: Optional[str] = None, ) -> "CompiledStateGraph": """Compiles the state graph into a `CompiledGraph` object. @@ -570,6 +571,7 @@ class StateGraph(Graph): auto_validate=False, debug=debug, store=store, + name=name or "LangGraph", ) compiled.attach_node(START, None) diff --git a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py index a09385c82..aaf3ae074 100644 --- a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py @@ -249,6 +249,7 @@ def create_react_agent( interrupt_after: Optional[list[str]] = None, debug: bool = False, version: Literal["v1", "v2"] = "v1", + name: Optional[str] = None, ) -> CompiledGraph: """Creates a graph that works with a chat model that utilizes tool calling. @@ -307,6 +308,9 @@ def create_react_agent( Tool calls are distributed across multiple instances of the tool node using the [Send](https://langchain-ai.github.io/langgraph/concepts/low_level/#send) API. + name: An optional name for the CompiledStateGraph. + This name will be automatically used when adding ReAct agent graph to another graph as a subgraph node - + particularly useful for building multi-agent systems. Returns: A compiled LangChain runnable that can be used for chat interactions. @@ -758,6 +762,7 @@ def create_react_agent( interrupt_before=interrupt_before, interrupt_after=interrupt_after, debug=debug, + name=name, ) # Define the function that determines whether to continue or not @@ -834,6 +839,7 @@ def create_react_agent( interrupt_before=interrupt_before, interrupt_after=interrupt_after, debug=debug, + name=name, )