diff --git a/libs/langgraph/langgraph/agent/__init__.py b/libs/langgraph/langgraph/agent/__init__.py index cb6f18114..0373bdf8b 100644 --- a/libs/langgraph/langgraph/agent/__init__.py +++ b/libs/langgraph/langgraph/agent/__init__.py @@ -11,7 +11,7 @@ from langgraph.agent.types import ( AgentMiddleware, AgentState, AgentUpdate, - GoTo, + JumpTo, ModelRequest, ResponseFormat, ) @@ -188,17 +188,17 @@ def _make_model_request_node( return model_request -def _resolve_goto(goto: GoTo | None, first_node: str) -> str | None: - if goto == "model": +def _resolve_jump(jump_to: JumpTo | None, first_node: str) -> str | None: + if jump_to == "model": return first_node - elif goto: - return goto + elif jump_to: + return jump_to def _make_model_to_tools_edge(first_node: str) -> Callable[[AgentState], str | None]: def model_to_tools(state: AgentState) -> str | None: - if state.goto: - return _resolve_goto(state.goto, first_node) + if state.jump_to: + return _resolve_jump(state.jump_to, first_node) message = state.messages[-1] if isinstance(message, AIMessage) and message.tool_calls: return "tools" @@ -233,19 +233,21 @@ def _add_middleware_edge( model_destination: str, ) -> None: sig = signature(method) - uses_goto = sig.return_annotation is AgentGoTo or AgentGoTo in getattr( + uses_jump = sig.return_annotation is AgentGoTo or AgentGoTo in getattr( sig.return_annotation, "__args__", () ) - if uses_goto: + if uses_jump: - def goto_edge(state: AgentState) -> str: - return _resolve_goto(state.goto, model_destination) or default_destination + def jump_edge(state: AgentState) -> str: + return ( + _resolve_jump(state.jump_to, model_destination) or default_destination + ) destinations = [default_destination, END, "tools"] if name != model_destination: destinations.append(model_destination) - graph.add_conditional_edges(name, goto_edge, destinations) + graph.add_conditional_edges(name, jump_edge, destinations) else: graph.add_edge(name, default_destination) diff --git a/libs/langgraph/langgraph/agent/types.py b/libs/langgraph/langgraph/agent/types.py index f7bcd073b..8f828e953 100644 --- a/libs/langgraph/langgraph/agent/types.py +++ b/libs/langgraph/langgraph/agent/types.py @@ -14,7 +14,7 @@ from langgraph.channels.ephemeral_value import EphemeralValue from langgraph.graph.message import Messages, add_messages ResponseFormat = dict | type[BaseModel] -GoTo = Literal["tools", "model", "__end__"] +JumpTo = Literal["tools", "model", "__end__"] @dataclass @@ -53,11 +53,11 @@ class AgentUpdate(TypedDict, total=False): class AgentGoTo(TypedDict, total=False): messages: Messages - goto: GoTo + jump_to: JumpTo @dataclass class AgentState: messages: Annotated[list[AnyMessage], add_messages] - goto: Annotated[GoTo | None, EphemeralValue] = None + jump_to: Annotated[JumpTo | None, EphemeralValue] = None response: dict | None = None diff --git a/libs/langgraph/tests/__snapshots__/test_agent.ambr b/libs/langgraph/tests/__snapshots__/test_agent.ambr index 7d380c34e..4e1aff8fa 100644 --- a/libs/langgraph/tests/__snapshots__/test_agent.ambr +++ b/libs/langgraph/tests/__snapshots__/test_agent.ambr @@ -277,7 +277,7 @@ ''' # --- -# name: test_create_agent_goto[memory] +# name: test_create_agent_jump[memory] ''' --- config: diff --git a/libs/langgraph/tests/test_agent.py b/libs/langgraph/tests/test_agent.py index 9c6ecadcb..33bab2b27 100644 --- a/libs/langgraph/tests/test_agent.py +++ b/libs/langgraph/tests/test_agent.py @@ -240,7 +240,7 @@ def test_create_agent_invoke( ] -def test_create_agent_goto( +def test_create_agent_jump( snapshot: SnapshotAssertion, sync_checkpointer: BaseCheckpointSaver, ): @@ -260,7 +260,7 @@ def test_create_agent_goto( class NoopEight(AgentMiddleware): def before_model(self, state) -> AgentGoTo: calls.append("NoopEight.before_model") - return {"goto": END} + return {"jump_to": END} def modify_model_request(self, request, state): calls.append("NoopEight.modify_model_request")