Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.langchain.com/llms.txt

Use this file to discover all available pages before exploring further.

Deep Agents build on LangGraph’s 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.
Check out the streaming cookbook for runnable examples and links to detailed reference documentation.
For information about lower-level Pregel stream modes, refer to the Deep Agents streaming docs.

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.
run = agent.stream_events(
    {"messages": [{"role": "user", "content": "Write me a haiku about the sea"}]},
    version="v3",
)

for subagent in run.subagents:
    print(subagent.name, subagent.path, subagent.status)

    for message in subagent.messages:
        print(str(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. Python uses snake_case projection names such as tool_calls. Each subagent stream can expose .messages, .tool_calls, .values, .subagents, and .output.
FieldDescription
nameSubagent name.
messagesMessages emitted by the subagent.
subagentsNested subagent invocations.
outputFinal subagent state, or completion signal for the delegated task.
task_inputPrompt or input passed to the task tool.
pathNamespace path for the subagent run.
statusLifecycle status such as started, running, completed, failed, or interrupted.
tool_callsTool 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.
run = agent.stream_events(input, version="v3")

running = 0
completed = 0
failed = 0

for subagent in run.subagents:
    running += 1
    print(f"{subagent.name}: started")

    try:
        _ = subagent.output
        running -= 1
        completed += 1
        print(f"{subagent.name}: completed")
    except Exception:
        running -= 1
        failed += 1
        print(f"{subagent.name}: 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.
run = agent.stream_events(input, version="v3")

for message in run.messages:
    print("[coordinator]", str(message.text))

for subagent in run.subagents:
    for message in subagent.messages:
        print(f"[{subagent.name}]", str(message.text))

    for call in subagent.tool_calls:
        print(f"[{subagent.name} tool]", call.tool_name, call.input)
        for delta in call.output_deltas:
            print(delta, end="", flush=True)

Consume concurrently

Coordinator and subagent output often interleave. Consume projections concurrently when you need live UI updates. Use run.interleave(...) when you want one sync loop over multiple projections:
run = agent.stream_events(input, version="v3")

for name, item in run.interleave("messages", "subagents"):
    if name == "messages":
        print("[coordinator]", str(item.text))
    else:
        for message in item.messages:
            print(f"[{item.name}]", str(message.text))