> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-cta2-1778260809-ad7a43f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Event streaming

> Stream subagents, messages, tool calls, and final output from Deep Agents.

Deep Agents build on LangGraph's [event streaming](/oss/javascript/langgraph/streaming/event-streaming) model and add a first-class `subagents` projection. Use it when you want application-facing streams for the coordinator agent, delegated subagents, nested messages, tool calls, and final state.

<Tip>
  Check out the [streaming cookbook](https://github.com/langchain-ai/streaming-cookbook) for runnable examples and links to detailed reference documentation.
</Tip>

<Note>
  For information about lower-level Pregel stream modes, refer to the [Deep Agents streaming](/oss/javascript/deepagents/streaming) docs.
</Note>

## Stream subagents

Deep Agents add a subagent projection on top of LangGraph streaming. Use `run.subagents` when you want one stream handle per delegated `task` call. The projection discovers subagent tasks first, then opens message, tool-call, and value streams when you access them on a subagent handle.

```typescript theme={null}
const run = await agent.streamEvents(
  { messages: [{ role: "user", content: "Write me a haiku about the sea" }] },
  { version: "v3" }
);

for await (const subagent of run.subagents) {
  console.log(subagent.name);
  console.log(await subagent.taskInput);

  for await (const message of subagent.messages) {
    console.log(await message.text);
  }
}
```

## Subagent stream fields

Each subagent stream exposes the same kinds of projections as the parent run, such as messages, tool calls, nested subagents, and final output. For the general parent-run streaming model, see [LangChain Event Streaming](/oss/javascript/langchain/event-streaming).

TypeScript uses camelCase projection names such as `toolCalls` and `taskInput`.

| Field       | Description                                                        |
| ----------- | ------------------------------------------------------------------ |
| `name`      | Subagent name.                                                     |
| `messages`  | Messages emitted by the subagent.                                  |
| `subagents` | Nested subagent invocations.                                       |
| `output`    | Final subagent state, or completion signal for the delegated task. |

\| `taskInput` | Promise for the prompt passed to the task tool. |
\| `callId` | Tool-call ID for the delegated task. |
\| `namespace` | Namespace path for the subagent run. |
\| `toolCalls` | Tool calls scoped to the subagent. |

## Track subagent lifecycle

Use `run.subagents` when you only need to show which subagents started and finished. You do not need to subscribe to message or value streams unless you access those projections on an individual subagent.

```typescript theme={null}
const run = await agent.streamEvents(input, { version: "v3" });

let running = 0;
let completed = 0;
let failed = 0;
const watchers: Promise<void>[] = [];

for await (const subagent of run.subagents) {
  running += 1;
  console.log(`${subagent.name}: started (${subagent.callId})`);

  watchers.push(
    subagent.output.then(
      () => {
        running -= 1;
        completed += 1;
        console.log(`${subagent.name}: completed`);
      },
      () => {
        running -= 1;
        failed += 1;
        console.log(`${subagent.name}: failed`);
      }
    )
  );
}

await Promise.all(watchers);
console.log({ running, completed, failed });
```

## Stream messages and tools

Deep Agents can emit messages and tool calls from the coordinator agent and from delegated subagents. Use `run.messages` or `run.tool_calls` for coordinator streams, then access the same projections on each subagent.

```typescript theme={null}
const run = await agent.streamEvents(input, { version: "v3" });

for await (const message of run.messages) {
  console.log("[coordinator]", await message.text);
}

for await (const subagent of run.subagents) {
  for await (const message of subagent.messages) {
    console.log(`[${subagent.name}]`, await message.text);
  }

  for await (const call of subagent.toolCalls) {
    console.log(`[${subagent.name} tool]`, call.name, call.input);
    console.log(await call.status);
  }
}
```

## Consume concurrently

Coordinator and subagent output often interleave. Consume projections concurrently when you need live UI updates.

Use concurrent consumers in JavaScript:

```typescript theme={null}
const run = await agent.streamEvents(input, { version: "v3" });

await Promise.all([
  (async () => {
    for await (const message of run.messages) {
      console.log("[coordinator]", await message.text);
    }
  })(),
  (async () => {
    for await (const subagent of run.subagents) {
      void (async () => {
        for await (const message of subagent.messages) {
          console.log(`[${subagent.name}]`, await message.text);
        }
      })();
    }
  })(),
]);
```

## Related

* [Streaming cookbook](https://github.com/langchain-ai/streaming-cookbook) shows runnable Event Streaming examples.
* [LangChain Event Streaming](/oss/javascript/langchain/event-streaming) covers general agent message and tool-call streaming concepts.
* [Subagent frontend streaming](/oss/javascript/deepagents/frontend/subagent-streaming) shows UI patterns that separate coordinator messages from subagent cards.
* [LangGraph Event Streaming](/oss/javascript/langgraph/streaming/event-streaming) covers the underlying graph streaming model.

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/deepagents/event-streaming.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
