LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Graphs
  • Functional API
  • Pregel
  • Checkpointing
  • Storage
  • Caching
  • Types
  • Runtime
  • Config
  • Errors
  • Constants
  • Channels
  • Agents
LangGraph CLI
LangGraph SDK
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
LangGraph CLI
LangGraph SDK
LangGraph Supervisor
LangGraph Swarm
Language
Theme
PythonlanggraphpregelmainPregelastream
Methodā—Since v0.6

astream

Asynchronously stream graph steps for a single input.

Copy
astream(
  self,
  input: InputT | Command | None,
  config: RunnableConfig | None = None,
  *,
  context: ContextT | None = None,
  stream_mode: StreamMode | Sequence[StreamMode] | None = None,
  print_mode: StreamMode | Sequence[StreamMode] = (),
  output_keys: str | Sequence[str] | None = None,
  interrupt_before: All | Sequence[str] | None = None,
  interrupt_after: All | Sequence[str] | None = None,
  durability: Durability | None = None,
  subgraphs: bool = False,
  debug: bool | None = None,
  **kwargs: Unpack[DeprecatedKwargs] = {}
) -> AsyncIterator[dict[str, Any] | Any]

Parameters

NameTypeDescription
input*InputT | Command | None

The input to the graph.

configRunnableConfig | None
Default:None

The configuration to use for the run.

contextContextT | None
Default:None

The static context to use for the run.

stream_modeStreamMode | Sequence[StreamMode] | None
Default:None

The mode to stream output, defaults to self.stream_mode.

Options are:

  • "values": Emit all values in the state after each step, including interrupts. When used with functional API, values are emitted once at the end of the workflow.
  • "updates": Emit only the node or task names and updates returned by the nodes or tasks after each step. If multiple updates are made in the same step (e.g. multiple nodes are run) then those updates are emitted separately.
  • "custom": Emit custom data from inside nodes or tasks using StreamWriter.
  • "messages": Emit LLM messages token-by-token together with metadata for any LLM invocations inside nodes or tasks.
    • Will be emitted as 2-tuples (LLM token, metadata).
  • "checkpoints": Emit an event when a checkpoint is created, in the same format as returned by get_state().
  • "tasks": Emit events when tasks start and finish, including their results and errors.
  • "debug": Emit debug events with as much information as possible for each step.

You can pass a list as the stream_mode parameter to stream multiple modes at once. The streamed outputs will be tuples of (mode, data).

See LangGraph streaming guide for more details.

print_modeStreamMode | Sequence[StreamMode]
Default:()

Accepts the same values as stream_mode, but only prints the output to the console, for debugging purposes.

Does not affect the output of the graph in any way.

output_keysstr | Sequence[str] | None
Default:None

The keys to stream, defaults to all non-context channels.

interrupt_beforeAll | Sequence[str] | None
Default:None

Nodes to interrupt before, defaults to all nodes in the graph.

interrupt_afterAll | Sequence[str] | None
Default:None

Nodes to interrupt after, defaults to all nodes in the graph.

durabilityDurability | None
Default:None

The durability mode for the graph execution, defaults to "async".

Options are:

  • "sync": Changes are persisted synchronously before the next step starts.
  • "async": Changes are persisted asynchronously while the next step executes.
  • "exit": Changes are persisted only when the graph exits.
subgraphsbool
Default:False

Whether to stream events from inside subgraphs, defaults to False.

If True, the events will be emitted as tuples (namespace, data), or (namespace, mode, data) if stream_mode is a list, where namespace is a tuple with the path to the node where a subgraph is invoked, e.g. ("parent_node:<task_id>", "child_node:<task_id>").

See LangGraph streaming guide for more details.

View source on GitHub