diff --git a/langgraph_swarm/handoff.py b/langgraph_swarm/handoff.py index 84ca11d..0bc1dcc 100644 --- a/langgraph_swarm/handoff.py +++ b/langgraph_swarm/handoff.py @@ -2,8 +2,9 @@ from dataclasses import is_dataclass from typing import Annotated, Any -from langchain_core.messages import ToolMessage +from langchain_core.messages import ToolMessage, RemoveMessage from langchain_core.tools import BaseTool, InjectedToolCallId, tool +from langgraph.graph.message import REMOVE_ALL_MESSAGES from langgraph.graph.state import CompiledStateGraph from langgraph.prebuilt import InjectedState, ToolNode from langgraph.types import Command @@ -84,7 +85,7 @@ def handoff_to_agent( goto=agent_name, graph=Command.PARENT, update={ - "messages": [*_get_field(state, "messages"), tool_message], + "messages": [RemoveMessage(REMOVE_ALL_MESSAGES), *_get_field(state, "messages"), tool_message], "active_agent": agent_name, }, )