[GH-ISSUE #2444] [langchain]: Handoff context engineering example not working as intended #303

Open
opened 2026-02-17 17:19:35 -05:00 by yindo · 0 comments
Owner

Originally created by @MartijnLeplae on GitHub (Feb 3, 2026).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/2444

Type of issue

issue / bug

Language

N/A

Description

Both ts and Python pages mention context engineering on their docs for the Handoff multi-agent pattern. (https://docs.langchain.com/oss/python/langchain/multi-agent/handoffs#context-engineering, https://docs.langchain.com/oss/javascript/langchain/multi-agent/handoffs#context-engineering).

This is mentioned:

Why not pass all subagent messages? While you could include the full subagent conversation in the handoff, this often creates problems. The receiving agent may become confused by irrelevant internal reasoning, and token costs increase unnecessarily. By passing only the handoff pair, you keep the parent graph’s context focused on high-level coordination. If the receiving agent needs additional context, consider summarizing the subagent’s work in the ToolMessage content instead of passing raw message history.

I think the writer of the docs has this flow in mind:

User: "hello"
Sales-agent: "what do you want to buy?"
User: "i want technical help"
tool call "transfer to technical agent" + tool response
---- Fresh context for technical agent ----
AI: tool call "transfer to technical agent" + tool response
Technical agent: "hello, what technical issue can i help you with"
....

What I think is actually visible to the technical agent:
User: "hello"
Sales-agent: "what do you want to buy?"
User: "i want technical help"
AI: tool call "transfer to technical agent" + tool response
Technical agent: "hello, what technical issue can i help you with"

I implemented the example in the docs and I can indeed replicate that the input for the technical agent (after transfer), is this:

Image

The root cause of this, I think, is that the default reducer for the messages key in the state uses add_messages, which appends given messages to the messages list (and only replaces messages with a duplicate id).


Note: I did change the last part of the code with:

export async function graph() {
    return builder.compile()
}

put a reference to it in langgraph.json

and ran it with npx @langchain/langgraph-cli dev --port 2024 --config ./langgraph.json

And chatted with it using the chat-ui: https://agentchat.vercel.app/

Originally created by @MartijnLeplae on GitHub (Feb 3, 2026). Original GitHub issue: https://github.com/langchain-ai/docs/issues/2444 ### Type of issue issue / bug ### Language N/A ### Description Both ts and Python pages mention context engineering on their docs for the Handoff multi-agent pattern. (https://docs.langchain.com/oss/python/langchain/multi-agent/handoffs#context-engineering, https://docs.langchain.com/oss/javascript/langchain/multi-agent/handoffs#context-engineering). This is mentioned: > Why not pass all subagent messages? While you could include the full subagent conversation in the handoff, this often creates problems. The receiving agent may become confused by irrelevant internal reasoning, and token costs increase unnecessarily. By passing only the handoff pair, you keep the parent graph’s context focused on high-level coordination. If the receiving agent needs additional context, consider summarizing the subagent’s work in the ToolMessage content instead of passing raw message history. I think the writer of the docs has this flow in mind: User: "hello" Sales-agent: "what do you want to buy?" User: "i want technical help" tool call "transfer to technical agent" + tool response ---- Fresh context for technical agent ---- AI: tool call "transfer to technical agent" + tool response Technical agent: "hello, what technical issue can i help you with" .... What I think is actually visible to the technical agent: User: "hello" Sales-agent: "what do you want to buy?" User: "i want technical help" AI: tool call "transfer to technical agent" + tool response Technical agent: "hello, what technical issue can i help you with" I implemented the example in the docs and I can indeed replicate that the input for the technical agent (after transfer), is this: <img width="907" height="1461" alt="Image" src="https://github.com/user-attachments/assets/f9c72028-6ce9-4921-9571-fe019959481c" /> The root cause of this, I think, is that the default reducer for the messages key in the state uses `add_messages`, which appends given messages to the messages list (and only replaces messages with a duplicate id). ---- Note: I did change the last part of the code with: ```typescript export async function graph() { return builder.compile() } ``` put a reference to it in `langgraph.json` and ran it with `npx @langchain/langgraph-cli dev --port 2024 --config ./langgraph.json` And chatted with it using the chat-ui: https://agentchat.vercel.app/
yindo added the langchainexternal labels 2026-02-17 17:19:35 -05:00
yindo changed title from [langchain]: Handoff context engineering example not working as intended to [GH-ISSUE #2444] [langchain]: Handoff context engineering example not working as intended 2026-06-05 17:26:10 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#303