Rename goto to jump_to

This commit is contained in:
Nuno Campos
2025-08-27 15:52:01 +01:00
parent cc97fad7e5
commit f67a089a68
4 changed files with 20 additions and 18 deletions
+14 -12
View File
@@ -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)
+3 -3
View File
@@ -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
@@ -277,7 +277,7 @@
'''
# ---
# name: test_create_agent_goto[memory]
# name: test_create_agent_jump[memory]
'''
---
config:
+2 -2
View File
@@ -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")