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
  • Openai Completions Stream
  • 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 ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainindexAIMessage
Class●Since v1.0

AIMessage

LangChain Messages

Copy
class AIMessage

Bases

BaseMessage<TStructure, "ai">

Used in Docs

  • Agent Evals
  • AI Elements
  • assistant-ui
  • Custom middleware
  • Generative UI
(9 more not shown)

Constructors

constructor
constructor

Properties

property
additional_kwargs: __type
property
content: TStructure["outputVersion"] extends "v1" ? $InferMessageContentBlocks<TStructure, "ai">[] : string | ContentBlock | Text[]
property
id: string
property
invalid_tool_calls: InvalidToolCall<string>[]
property
lc_kwargs: SerializedFields
property
lc_namespace: string[]
property
lc_serializable: boolean
property
name: string
property
response_metadata: NonNullable<BaseMessageFields<TStructure, TRole>["response_metadata"]>
property
tool_calls: $InferToolCalls<TStructure>[]
property
type: "ai"
property
usage_metadata: $InferMessageProperty<TStructure, "ai", "usage_metadata">
property
_printableFields: Record<string, unknown>
property
[toStringTag]: any
property
contentBlocks: Standard[]
property
lc_aliases: Record<string, string>
property
lc_attributes: SerializedFields | undefined
property
lc_id: string[]
property
lc_secrets: __type | undefined
property
lc_serializable_keys: string[] | undefined
property
text: string

Methods

method
_updateId
method
toDict→ StoredMessage
method
toFormattedString→ string
method
toJSON→ Serialized
method
toJSONNotImplemented→ SerializedNotImplemented
method
isInstance→ obj is BaseMessage<T, MessageType> & AIMessage<T>
method
lc_name→ string
deprecatedmethod
_getType→ MessageType
deprecatedmethod
getType→ MessageType

Inherited fromBaseMessage

Properties

Padditional_kwargs: __typePcontent: TStructure["outputVersion"] extends "v1" ? $InferMessageContentBlocks<TStructure, "ai">[] : string | ContentBlock | Text[]
—

Array of content blocks that make up the message content

Pid: string
—

Content block identifier, which can be either

Plc_kwargs: SerializedFieldsPlc_namespace: string[]
—

A path to the module that contains the class, eg. ["langchain", "llms"]

Plc_serializable: booleanPname: TName
—

The name of the tool being called

Presponse_metadata: NonNullable<BaseMessageFields<TStructure, TRole>["response_metadata"]>
—

Metadata about the message

Ptype: "image" | "audio" | "file"
—

Type of the content block

P_printableFields: Record<string, unknown>PcontentBlocks: Standard[]Plc_aliases: Record<string, string>Plc_attributes: SerializedFields | undefinedPlc_id: string[]Plc_secrets: __type | undefinedPlc_serializable_keys: string[] | undefinedPtext: string

Methods

M_getType→ MessageTypeM_updateIdMgetType→ MessageTypeMtoDict→ StoredMessageMtoFormattedString→ stringM

Inherited fromSerializable

Properties

Plc_kwargs: SerializedFieldsPlc_namespace: string[]
—

A path to the module that contains the class, eg. ["langchain", "llms"]

Plc_serializable: booleanPlc_aliases: Record<string, string>
View source on GitHub
toJSON
→ Serialized
MtoJSONNotImplemented→ SerializedNotImplemented
MisInstance→ obj is BaseMessage<T, MessageType> & AIMessage<T>
—

Type guard to check if an object is an AIMessage.

Mlc_name→ string
—

The name of the serializable. Override to provide an alias or

Plc_attributes: SerializedFields | undefined
Plc_id: string[]
Plc_secrets: __type | undefined
Plc_serializable_keys: string[] | undefined

Methods

MtoJSON→ SerializedMtoJSONNotImplemented→ SerializedNotImplementedMlc_name→ string
—

The name of the serializable. Override to provide an alias or

Array of content blocks that make up the message content

Content block identifier, which can be either

  • generated by the provider (e.g., a provider-specific ID)
  • generated by LangChain upon creation (a uuid prefixed with 'lc-')

A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.

The name of the tool being called

Metadata about the message

Type of the content block

Type guard to check if an object is an AIMessage. Preserves the MessageStructure type parameter when called with a typed BaseMessage. When called with a typed BaseMessage, preserves the TStructure type

The name of the serializable. Override to provide an alias or to preserve the serialized module name in minified environments.

Implemented as a static method to support loading logic.