Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

Mem0MemoryWriter

Write ChatMessage objects as memories to a Mem0 memory store, persisting conversation context for use in future pipeline runs.

Key Features​

  • Persists conversation messages to Mem0 memory storage so agents can recall past interactions.
  • Supports scoping by user_id, run_id, agent_id, or app_id, allowing a single pipeline instance to serve multiple users or agents.
  • The infer setting controls whether Mem0 extracts key facts from messages or stores message text verbatim.
  • Returns a count of the memory items written, useful for logging and conditional branching.
  • No API key is required when using a self-hosted Mem0 instance.

Configuration​

  1. Drag the Mem0MemoryWriter component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    • Configure the Mem0MemoryStore with your Mem0 API credentials.
    • Set infer to true to have Mem0 extract facts from messages, or false to store message text as-is.

Connections​

Mem0MemoryWriter receives a list of ChatMessage objects, typically from the output of a chat generator or agent, along with optional scoping parameters such as user_id. It returns the count of written memory items through its memories_written output.

Source Code​

To check this component's source code, open writer.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

Mem0MemoryWriter:
type: haystack_integrations.components.writers.mem0.writer.Mem0MemoryWriter
init_parameters:
infer: true
memory_store:
type: haystack_integrations.memory_stores.mem0.memory_store.Mem0MemoryStore
init_parameters:
api_key: YOUR_MEM0_API_KEY

Using the Component in a Pipeline​

# haystack-pipeline
components:
Mem0MemoryWriter:
type: haystack_integrations.components.writers.mem0.writer.Mem0MemoryWriter
init_parameters:
infer: true
memory_store:
type: haystack_integrations.memory_stores.mem0.memory_store.Mem0MemoryStore
init_parameters:
api_key: YOUR_MEM0_API_KEY

connections: []

max_runs_per_component: 100

metadata: {}

inputs:
messages:
- Mem0MemoryWriter.messages
user_id:
- Mem0MemoryWriter.user_id

outputs:
memories_written: Mem0MemoryWriter.memories_written

Parameters​

Inputs​

ParameterTypeDescription
messagesList[ChatMessage]List of ChatMessage objects to store as memories.
user_idOptional[str]User ID to scope the stored memories.
run_idOptional[str]Run ID to scope the stored memories.
agent_idOptional[str]Agent ID to scope the stored memories.
app_idOptional[str]App ID to scope the stored memories.

Outputs​

ParameterTypeDescription
memories_writtenintCount of memory items stored in Mem0.

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
memory_storeMem0MemoryStoreAn instance of Mem0MemoryStore to write memories to.
inferboolTrueIf True, Mem0 extracts key facts from messages. If False, Mem0 stores message text verbatim.

Run Method Parameters​

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
messagesList[ChatMessage]List of ChatMessage objects to store.
user_idOptional[str]NoneUser ID to scope the stored memories.
run_idOptional[str]NoneRun ID to scope the stored memories.
agent_idOptional[str]NoneAgent ID to scope the stored memories.
app_idOptional[str]NoneApp ID to scope the stored memories.