LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • 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
ClientAuthReactLoggingReact UiServer
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-sdkindexAIMessage
Type●Since v0.0

AIMessage

AI message type that can be parameterized with custom tool call types.

Copy
AIMessage: BaseMessage  __type

Used in Docs

  • Build a custom RAG agent with LangGraph
  • Build a custom SQL agent
  • Custom middleware
  • Frontend
  • Frontend
(5 more not shown)

Example

Copy
// Define typed tool calls as a discriminated union
type MyToolCalls =
  | { name: "get_weather"; args: { location: string }; id?: string }
  | { name: "search"; args: { query: string; limit?: number }; id?: string };

// Use with AIMessage
const message: AIMessage<MyToolCalls> = ...;

// Now tool.name === "get_weather" narrows tool.args type
if (message.tool_calls) {
  for (const tool of message.tool_calls) {
    if (tool.name === "get_weather") {
      // tool.args is now { location: string }
      console.log(tool.args.location);
    }
  }
}
View source on GitHub