LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainindexReactAgentstreamEvents
Methodā—Since v1.4

streamEvents

Executes the agent with the v3 streaming interface, returning an AgentRunStream that provides ergonomic, typed projections for messages, tool calls, and middleware events — without requiring knowledge of Pregel channels, stream modes, or namespace routing.

Pass version: "v3" to opt into this projection-oriented stream. Omitting version preserves the legacy internal LangGraph event-stream behavior for compatibility with LangGraph Platform integrations.

This v3 stream is experimental and its API may change in future releases. It will become the default in a future major release.

Copy
streamEvents(
  state: InvokeStateParameter<Types>,
  config: InvokeConfiguration<InferContextInput<Types["Context"] extends InteropZodObject | AnyAnnotationRoot  any[any] : AnyAnnotationRoot>  InferMiddlewareContextInputs<Types["Middleware"]>>  __type
): Promise<AgentRunStream<MergedAgentState<Types>, Types["Tools"], InferStreamExtensions<Types["StreamTransformers"]>>>

Parameters

NameTypeDescription
state*InvokeStateParameter<Types>

The initial state for the agent execution. Can be:

  • An object containing messages array and any middleware-specific state properties
  • A Command object for more advanced control flow
config*InvokeConfiguration<InferContextInput<Types["Context"] extends InteropZodObject | AnyAnnotationRoot ? any[any] : AnyAnnotationRoot> & InferMiddlewareContextInputs<Types["Middleware"]>> & __type

Runtime configuration including:

Example

Copy
const run = await agent.streamEvents(
  {
    messages: [{ role: "user", content: "What's the weather in Paris?" }],
  },
  { version: "v3" }
);

// Stream all messages
for await (const msg of run.messages) {
  for await (const token of msg.text) {
    process.stdout.write(token);
  }
}

// Observe tool calls
for await (const call of run.toolCalls) {
  console.log(`Tool: ${call.name}`, call.input);
  console.log(`Result:`, await call.output);
}

// Get final state
const state = await run.output;
View source on GitHub