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.

LangChain agents are built on LangGraph, so they support the same Event Streaming model with agent-focused projections for messages, tool calls, state, and custom updates. For most application and frontend use cases, use Event Streaming through stream_events(..., version="v3"). Event Streaming returns a run object with typed projections, so you can choose the view you need instead of parsing stream-mode tuples.
Check out the streaming cookbook for runnable examples and links to detailed reference documentation.
Interested in streaming Pregel modes such as updates, messages, or custom directly? See the Streaming page.
from langchain.agents import create_agent


def get_weather(city: str) -> str:
    """Get weather for a city."""
    return f"It's always sunny in {city}!"


agent = create_agent(
    model="gpt-5-nano",
    tools=[get_weather],
)

run = agent.stream_events(
    {"messages": [{"role": "user", "content": "What is the weather in SF?"}]},
    version="v3",
)

for message in run.messages:
    for delta in message.text:
        print(delta, end="", flush=True)

final_state = run.output

What you can stream

ProjectionUse
for event in runRaw protocol events when you need exact arrival order.
run.messagesModel message streams, one per LLM call.
message.textText deltas and final text for a message.
message.reasoningReasoning deltas for models that expose reasoning content.
message.tool_callsTool-call argument chunks and finalized tool calls.
message.outputFinal message object after the model call completes.
message.usageToken usage metadata when the provider returns it.
run.valuesAgent state snapshots.
run.outputFinal agent state.
run.extensionsCustom transformer projections.
run.tool_callsTool execution lifecycle, inputs, output deltas, final output, and errors.
run.messages yields ChatModelStream objects. Each message stream exposes .text, .reasoning, .tool_calls, and .output. Sync projections are iterable for live deltas and drainable for final values.

Stream agent messages

Use run.messages when you want model output from each LLM call.
run = agent.stream_events(input, version="v3")

for message in run.messages:
    print(f"[{message.node}] ", end="")
    for delta in message.text:
        print(delta, end="", flush=True)

    full_message = message.output
    usage = full_message.usage_metadata
    if usage:
        print(usage)

Stream tool calls

There are two useful tool-call projections:
  • message.tool_calls streams tool-call argument chunks while the model is producing the tool call.
  • run.tool_calls streams the lifecycle of tool execution after the tool call starts.
run = agent.stream_events(input, version="v3")

for message in run.messages:
    for chunk in message.tool_calls:
        print(f"tool call chunk: {chunk}")

    finalized = message.tool_calls.get()
    if finalized:
        print(f"finalized tool calls: {finalized}")

for call in run.tool_calls:
    print(f"{call.tool_name}({call.input})")
    for delta in call.output_deltas:
        print(delta, end="", flush=True)
    print(call.output, call.error)

Stream state and final output

Use run.values for state snapshots and run.output for the final agent state.
run = agent.stream_events(input, version="v3")

for snapshot in run.values:
    print(snapshot)

final_state = run.output