LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraph-sdkuiUseAgentStream
Interface●Since v1.7

UseAgentStream

Stream interface for ReactAgent instances created with createAgent.

Extends UseGraphStream with tool calling capabilities. Tool calls are automatically typed based on the agent's tools configuration.

Use this interface when streaming from an agent created with createAgent. For subagent streaming capabilities, use UseDeepAgentStream with createDeepAgent.

This interface is subject to change.

Copy
interface UseAgentStream

Bases

BaseStream<StateType, ToolCall, Bag>

This interface adds tool calling on top of UseGraphStream:

  • toolCalls - Array of tool calls paired with their results
  • getToolCalls(message) - Get tool calls for a specific AI message

It does NOT include subagent streaming features. For those, use UseDeepAgentStream with createDeepAgent.

Example

Copy
import { createAgent, tool } from "@langchain/langgraph";
import { useStream } from "@langchain/langgraph-sdk/react";
import { z } from "zod";

// Define tools with typed schemas
const searchTool = tool(
  async ({ query }) => `Results for: ${query}`,
  { name: "search", schema: z.object({ query: z.string() }) }
);

const calculatorTool = tool(
  async ({ expression }) => eval(expression).toString(),
  { name: "calculator", schema: z.object({ expression: z.string() }) }
);

// Create the agent
const agent = createAgent({
  model: "gpt-4",
  tools: [searchTool, calculatorTool],
});

// In React component:
function Chat() {
  const stream = useStream<typeof agent>({
    assistantId: "my-agent",
    apiUrl: "http://localhost:2024",
  });

  // Tool calls are typed!
  stream.toolCalls.forEach(tc => {
    if (tc.call.name === "search") {
      // tc.call.args is typed as { query: string }
      console.log("Searching for:", tc.call.args.query);
    } else if (tc.call.name === "calculator") {
      // tc.call.args is typed as { expression: string }
      console.log("Calculating:", tc.call.args.expression);
    }
  });
}

Properties

property
assistantId: string

The ID of the assistant to use.

property
branch: string

The current branch of the thread. Used for navigating between different conversation branches.

property
client: Client

LangGraph SDK client used to send requests and receive responses.

property
error: unknown

Last seen error from the stream, if any. Reset to undefined when a new stream starts.

property
experimental_branchTree: Sequence<StateType>

Tree of all branches for the thread. This API is experimental and subject to change.

property
getMessagesMetadata: (message: Message<ToolCall>, index?: number) => MessageMetadata<StateType> | undefined

Get the metadata for a message, such as first thread state the message was seen in and branch information.

property
getToolCalls: (message: AIMessage<ToolCall>) => ToolCallWithResult<ToolCall>[]

Get tool calls for a specific AI message.

Use this to find which tool calls were initiated by a particular assistant message, useful for rendering tool calls inline with messages.

Copy
messages.map(message => {
  if (message.type === "ai") {
    const calls = stream.getToolCalls(message);
    return (
      <>
        <MessageBubble message={message} />
        {calls.map(tc => <ToolCallCard key={tc.call.id} {...tc} />)}
      </>
    );
  }
  return <MessageBubble message={message} />;
});
property
history: ThreadState<StateType>[]

Flattened history of thread states of a thread. Contains all states in the current branch's history.

property
interrupt: Interrupt<GetInterruptType<Bag>> | undefined

Current interrupt, if the stream is interrupted. Convenience alias for interrupts[0]. For workflows with multiple concurrent interrupts, use interrupts instead.

property
interrupts: Interrupt<GetInterruptType<Bag>>[]

All current interrupts from the stream. When using Send() fan-out with per-task interrupt() calls, multiple interrupts may be pending simultaneously.

property
isLoading: boolean

Whether the stream is currently running. true while streaming, false when idle or completed.

property
isThreadLoading: boolean

Whether the thread is currently being loaded. true during initial thread data fetch.

property
joinStream: (runId: string, lastEventId?: string, options?: __type) => Promise<void>

Join an active stream that's already running.

property
messages: Message<ToolCall>[]

Messages accumulated during the stream. Includes both human and AI messages. AI messages include typed tool calls based on the agent's tools.

property
queue: QueueInterface<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>

Server-side submission queue. Pending runs created via multitaskStrategy: "enqueue" when submitting while the agent is busy.

property
setBranch: (branch: string) => void

Set the branch of the thread.

property
stop: () => Promise<void>

Stops the currently running stream.

property
submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>

Create and stream a run to the thread.

property
switchThread: (newThreadId: string | null) => void

Switch to a different thread, clearing the current stream state. Pass null to reset to no thread (a new thread will be created on next submit).

property
toolCalls: ToolCallWithResult<ToolCall>[]

Tool calls paired with their results.

Each entry contains the tool call request and its corresponding result. Useful for rendering tool invocations and their outputs together.

Copy
stream.toolCalls.map(({ call, result }) => (
  <ToolCallCard
    name={call.name}
    args={call.args}
    result={result}
  />
));
property
toolProgress: ToolProgress[]

Progress of tool executions during streaming. Populated when stream mode includes "tools" and tools yield or report progress.

property
values: StateType

The current state values of the stream. Updated as streaming events are received.

Inherited fromBaseStream

Properties

PassistantId: string
—

The ID of the assistant to use.

Pbranch: string
—

The current branch of the thread.

Pclient: Client
—

LangGraph SDK client used to send requests and receive responses.

Perror: unknown
—

Last seen error from the stream, if any.

Pexperimental_branchTree: Sequence<StateType>
—

Tree of all branches for the thread.

PgetMessagesMetadata: (message: Message<ToolCall>, index?: number)
—

Get the metadata for a message, such as first thread state the message

Phistory: ThreadState<StateType>[]
—

Flattened history of thread states of a thread.

Pinterrupt: Interrupt<GetInterruptType<Bag>> | undefined
—

Current interrupt, if the stream is interrupted.

Pinterrupts: Interrupt<GetInterruptType<Bag>>[]
—

All current interrupts from the stream.

PisLoading: boolean
—

Whether the stream is currently running.

PisThreadLoading: boolean
—

Whether the thread is currently being loaded.

PjoinStream: (runId: string, lastEventId?: string, options?: __type)
—

Join an active stream that's already running.

Pmessages: Message<ToolCall>[]
—

Messages accumulated during the stream.

Pqueue: QueueInterface<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>
—

Server-side submission queue. Pending runs created via

PsetBranch: (branch: string)
—

Set the branch of the thread.

Pstop: ()
—

Stops the currently running stream.

Psubmit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>)
—

Create and stream a run to the thread.

PswitchThread: (newThreadId: string | null)
—

Switch to a different thread, clearing the current stream state.

PtoolProgress: ToolProgress[]
—

Progress of tool executions during streaming. Populated when stream mode includes "tools"

Pvalues: StateType
—

The current state values of the stream.

View source on GitHub