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
  • Gateway
  • 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 CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/coremessagesMessageStructure
Interfaceā—Since v1.0

MessageStructure

Copy
interface MessageStructure

Properties

View source on GitHub

Example

property
content: Partial<__type>
property
outputVersion: MessageOutputVersion
property
properties: Partial<__type>
property
tools: TTools

Core interface that defines the structure of messages.

Optional mapping of message types to their allowed content blocks. Each message type can specify what content block types it supports (text, images, etc).

Optional output version for the message structure. If not provided, defaults to "v0".

Optional mapping of message types to arbitrary property objects. Allows attaching custom metadata or other information to specific message types.

Optional set of tool definitions that can be used in messages. Each tool is defined with input/output types and can be referenced in tool messages.

Copy
// Basic message structure with just content blocks
interface SimpleMessageStructure extends MessageStructure {
  content: {
    human: ContentBlock.Text;
    // allows for text + reasoning blocks in ai messages
    ai: ContentBlock.Text | ContentBlock.Reasoning;
  }
}

// Message structure with tools and properties
interface AdvancedMessageStructure extends MessageStructure {
  tools: {
    calculator: MessageToolDefinition<
      { operation: string; numbers: number[] },
      number
    >;
  };
  content: {
    // allows for text + image blocks in human messages
    human: ContentBlock.Text | ContentBlock.Multimodal.Image;
    // only allows for text blocks in ai messages
    ai: ContentBlock.Text;
  };
  properties: {
    // pins properties to ai messages
    ai: {
      response_metadata: {
        confidence: number;
        model: string;
      };
    };
  }
}

// Using with $MergeMessageStructure to combine structures
// The resulting type when passed into BaseMessage will have a calculator tool,
// allow for text + image blocks in human messages,
// and text + reasoning blocks + additional arbitrary properties in ai messages.
type CombinedStructure = $MergeMessageStructure<
  SimpleMessageStructure,
  AdvancedMessageStructure
>;

// Using in a Message object
const message: Message<CombinedStructure> = {
  id: "msg-123",
  type: "human",
  content: [
    { type: "text", text: "Hello!" }
    { type: "image", mimeType: "image/jpeg", url: "https://example.com/image.jpg" }
    // this block will throw an error because it's not defined in the structure
    { type: "reasoning", reasoning: "The answer is 42" }
  ]
};