Skip to content

fix(deepagents): add parent_tool_call_id to subagent streaming metadata#1136

Open
Yo-sure wants to merge 3 commits intolangchain-ai:mainfrom
Yo-sure:Yo-sure/subagent-streaming-correlation
Open

fix(deepagents): add parent_tool_call_id to subagent streaming metadata#1136
Yo-sure wants to merge 3 commits intolangchain-ai:mainfrom
Yo-sure:Yo-sure/subagent-streaming-correlation

Conversation

@Yo-sure
Copy link
Contributor

@Yo-sure Yo-sure commented Feb 5, 2026

Summary

Closes #876

When streaming with subgraphs=True, parallel subagent chunks now include parent_tool_call_id in metadata, allowing clients to correlate streaming chunks with their originating task tool calls.

Problem

When multiple task tool calls are made in parallel, streaming chunks from different subagents arrive interleaved. Previously, clients had no way to correlate which chunks belonged to which task invocation.

Solution

  • Added _build_subagent_config() helper that merges the subagent's identity config (e.g., lc_agent_name) with parent_tool_call_id metadata
  • task() and atask() now pass this config to subagent.invoke()/ainvoke()
  • Uses merge_configs from langchain_core to preserve existing config propagation

Example

for ns, (chunk, metadata) in agent.stream(..., subgraphs=True):
    parent_id = metadata.get("parent_tool_call_id")
    if parent_id:
        # Correlate chunk with originating task call
        ui_panels[parent_id].append(chunk)

Test plan

  • Added test_parent_tool_call_id_in_streaming_metadata - single subagent case
  • Added test_parallel_subagents_streaming_correlation - parallel subagents case (core scenario)
  • Verified existing streaming metadata tests still pass (lc_agent_name, tags)
  • Tested with real LLM (OpenRouter/gpt-4o-mini) - parallel subagents correctly get unique parent_tool_call_id

Closes langchain-ai#876

When streaming with subgraphs=True, subagent chunks now include
parent_tool_call_id in metadata, allowing clients to correlate
streaming chunks with their originating task tool calls.
@github-actions github-actions bot added deepagents Related to the `deepagents` SDK / agent harness external User is not a member of the `langchain-ai` GitHub organization fix A bug fix (PATCH) and removed fix A bug fix (PATCH) labels Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepagents Related to the `deepagents` SDK / agent harness external User is not a member of the `langchain-ai` GitHub organization fix A bug fix (PATCH)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correlate subagent streaming chunks with parent task tool_call_id

1 participant