-
Notifications
You must be signed in to change notification settings - Fork 229
Open
Description
Current behavior
The supervisor handoff currently sends the entire message context to the sub-agent.
Problem
This increases token usage and can make the sub-agent more likely to hallucinate or misinterpret intent.
Proposal
Add an option to the handoff tool to accept a query: str so it sends just a single HumanMessage (from the query) to the sub-agent, not the full message history.
Example implementation:
def create_handoff_tool(*,
agent_name: str,
name: str | None = None,
description: str|None = None,
add_handoff_messages: bool = True,
) -> BaseTool:
if name is None:
name = f"transfer_to_{_normalize_agent_name(agent_name)}"
if description is None:
description = f"Ask agent '{agent_name}' for help"
@tool(name, description=description)
def handoff_to_agent(
query: Annotated[str, f'specific query to pass to {name} agent'],
state: Annotated[dict, InjectedState],
tool_call_id: Annotated[str, InjectedToolCallId],
) -> Command:
_message = HumanMessage(content=query)
tool_message = ToolMessage(
content=f"successfully transferred to {agent_name}",
name=name,
tool_call_id=tool_call_id,
response_metadata={METADATA_KEY_HANDOFF_DESTINATION: agent_name},
)
if add_handoff_messages:
update_message = state["messages"] + [tool_message]
else:
update_message = state["messages"][:-1]
return Command(
graph=Command.PARENT,
update={**state, "messages": update_message},
goto=Send(agent_name, {"messages": [_message]}),
)Benefits
- Saves tokens / cost
- Gives the sub-agent only the relevant query, reducing hallucinations
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels