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.
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"]>>>| Name | Type | Description |
|---|---|---|
state* | InvokeStateParameter<Types> | The initial state for the agent execution. Can be:
|
config* | InvokeConfiguration<InferContextInput<Types["Context"] extends InteropZodObject | AnyAnnotationRoot ? any[any] : AnyAnnotationRoot> & InferMiddlewareContextInputs<Types["Middleware"]>> & __type | Runtime configuration including: |
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;