Files
deepset-ai--haystack/docs-website/reference_versioned_docs/version-2.26/experiments-api/experimental_writers_api.md
T
wehub-resource-sync c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:22:28 +08:00

2.9 KiB

title, id, description, slug
title id description slug
Writers experimental-writers-api Writers for Haystack. /experimental-writers-api

Module haystack_experimental.components.writers.chat_message_writer

ChatMessageWriter

Writes chat messages to an underlying ChatMessageStore.

Usage example:

from haystack.dataclasses import ChatMessage
from haystack_experimental.components.writers import ChatMessageWriter
from haystack_experimental.chat_message_stores.in_memory import InMemoryChatMessageStore

messages = [
    ChatMessage.from_assistant("Hello, how can I help you?"),
    ChatMessage.from_user("I have a question about Python."),
]
message_store = InMemoryChatMessageStore()
writer = ChatMessageWriter(message_store)
writer.run(chat_history_id="user_456_session_123", messages=messages)

ChatMessageWriter.__init__

def __init__(chat_message_store: ChatMessageStore) -> None

Create a ChatMessageWriter component.

Arguments:

  • chat_message_store: The ChatMessageStore where the chat messages are to be written.

ChatMessageWriter.to_dict

def to_dict() -> dict[str, Any]

Serializes the component to a dictionary.

Returns:

Dictionary with serialized data.

ChatMessageWriter.from_dict

@classmethod
def from_dict(cls, data: dict[str, Any]) -> "ChatMessageWriter"

Deserializes the component from a dictionary.

Arguments:

  • data: The dictionary to deserialize from.

Raises:

  • DeserializationError: If the message store is not properly specified in the serialization data or its type cannot be imported.

Returns:

The deserialized component.

ChatMessageWriter.run

@component.output_types(messages_written=int)
def run(chat_history_id: str, messages: list[ChatMessage]) -> dict[str, int]

Run the ChatMessageWriter on the given input data.

Arguments:

  • chat_history_id: A unique identifier for the chat session or conversation whose messages should be retrieved. Each chat_history_id corresponds to a distinct chat history stored in the underlying ChatMessageStore. For example, use a session ID or conversation ID to isolate messages from different chat sessions.
  • messages: A list of chat messages to write to the store.

Returns:

  • messages_written: Number of messages written to the ChatMessageStore.