Skip to content

Is subagent streaming supported in the JS version of deepagents? If so, what's the correct configuration? The Python docs show this is possible, but I can't find equivalent functionality in the JS implementation. #284

@lkm1developer

Description

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title.
  • I searched existing issues and didn't find this.
  • I can reproduce this with the latest released version.
  • I included a minimal reproducible example and steps to reproduce.

Area (Required)

  • deepagents (SDK)
  • cli

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

// StreamProvider.jsx
const streamValue = useStream({
  apiUrl: "http://localhost:5007",
  apiKey: token,
  assistantId: "widget-chat",
  threadId: threadId,
  filterSubagentMessages: true,
  streamSubgraphs: true,
});

// Submit options
stream.submit(
  { messages: [...] },
  { streamSubgraphs: true, streamMode: ["values", "messages"] }
);
backend
import { createDeepAgent } from "deepagents";

const agent = createDeepAgent({
  model: llm,
  tools: [...],
  subagents: [
    {
      name: "CEO Finder",
      description: "Find CEO information",
      systemPrompt: "...",
      tools: [...],
    },
    // ...more subagents
  ],
});

Error Message and Stack Trace (if applicable)

Description

When using deepagents (JS/TypeScript) with @langchain/langgraph-sdk's useStream hook, the stream.subagents Map and stream.activeSubagents array are always empty, even though the task tool is successfully spawning and running subagents.

Environment

  • deepagents: 1.8.1
  • @langchain/langgraph-sdk: 1.6.5
  • @langchain/langgraph-api: 1.1.14
  • Node.js: 20.x
  • Platform: Windows

Frontend Configuration

// StreamProvider.jsx
const streamValue = useStream({
  apiUrl: "http://localhost:5007",
  apiKey: token,
  assistantId: "widget-chat",
  threadId: threadId,
  filterSubagentMessages: true,
  streamSubgraphs: true,
});

// Submit options
stream.submit(
  { messages: [...] },
  { streamSubgraphs: true, streamMode: ["values", "messages"] }
);
import { createDeepAgent } from "deepagents";

const agent = createDeepAgent({
  model: llm,
  tools: [...],
  subagents: [
    {
      name: "CEO Finder",
      description: "Find CEO information",
      systemPrompt: "...",
      tools: [...],
    },
    // ...more subagents
  ],
});
Expected Behavior
When a subagent is spawned via the task tool:
stream.subagents should contain the subagent's streaming data
stream.activeSubagents should list currently running subagents
Subagent internal tool calls should be visible
Actual Behavior
stream.subagents: Map(0) (always empty)
stream.activeSubagents: [] (always empty)
stream.toolProgress shows task tool calls correctly
Subagents execute successfully, but no streaming events are emitted
Root Cause Investigation
I traced the issue to createTaskTool in node_modules/deepagents/dist/index.js (line ~1428):

const result = await subagent.invoke(subagentState, config);
The subagent is invoked with invoke() which doesn't emit streaming events. The Python documentation mentions using stream() with subgraphs=True to get subagent events:

for namespace, chunk in agent.stream(
    {"messages": [...]},
    stream_mode="updates",
    subgraphs=True,
):
    if namespace:  # Subagent event
        print(f"[subagent: {namespace}]")
Attempted Fix
I tried patching invoke() to stream() with subgraphs: true:

let result = null;
const streamConfig = { ...config, subgraphs: true };
for await (const chunk of await subagent.stream(subagentState, streamConfig)) {
  result = chunk;
}
This didn't work because the streaming events are consumed inside the tool closure and not propagated to the parent graph's stream.

### Environment / System Info

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions