langchain.js
    Preparing search index...

    Interface Message<TStructure, TRole>

    Represents a message object that organizes context for an LLM.

    // Basic message with text content
    const message: Message = {
    id: "msg-123",
    name: "user",
    type: "human",
    content: [{ type: "text", text: "Hello!" }]
    };

    // Basic ai message interface extension
    interface MyMessage extends Message<StandardMessageStructure, "ai"> {
    // Additional AI-specific properties can be added here
    }
    `
    // Custom message structure
    interface CustomStructure extends MessageStructure {
    content: {
    ai: ContentBlock.Text | ContentBlock.ToolCall<"search", { query: string }>;
    human: ContentBlock.Text | ContentBlock.Multimodal.Image;
    };
    }

    // Create a message with custom structure
    const message: Message<CustomStructure> = {
    id: "msg-123",
    name: "user",
    type: "ai",
    content: [
    { type: "text", text: "Hello!" },
    {
    type: "tool_call",
    name: "search",
    args: { query: "What is the capital of France?" }
    }
    ]
    };
    interface Message<
        TStructure extends MessageStructure = StandardMessageStructure,
        TRole extends MessageType = MessageType,
    > {
        content: $InferMessageContent<TStructure, TRole>;
        id?: string;
        name?: string;
        response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;
        type: TRole;
    }

    Type Parameters

    Implemented by

    Index

    Properties

    Array of content blocks that make up the message content

    id?: string

    Unique identifier for this message

    name?: string

    Optional name/identifier for the entity that created this message

    response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>

    Metadata about the message

    type: TRole

    The message type/role