> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bindai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 04.3 conversation memory

# Conversation Memory

Conversation Memory allows BindAI agents to remember previous interactions with a user.

Instead of treating every request as completely independent, the agent can retrieve earlier messages and use them as context when generating new responses.

This creates conversations that feel continuous and natural.

***

# What is Conversation Memory?

Conversation Memory stores the sequence of messages exchanged between a user and an agent.

For example:

```text id="k3n8tm" theme={null}
User:
My favorite language is Python.

Assistant:
Python is an excellent choice.
```

Later:

```text id="f8r2qc" theme={null}
User:
Which language did I say I liked?
```

With conversation memory enabled:

```text id="m7v4yb" theme={null}
Assistant:
You said your favorite language is Python.
```

***

# How It Works

Every interaction follows the same lifecycle.

```text id="t4q6ah" theme={null}
Load Previous Messages

↓

Append User Message

↓

Generate Response

↓

Store New Messages
```

The process is automatic once memory is attached to an agent.

***

# Automatic Integration

Attach a memory instance to an agent.

```python id="d1m5rp" theme={null}
agent.use_memory(
    memory,
)
```

The execution engine handles the rest.

There is no need to manually save or retrieve conversation history.

***

# Conversation Timeline

A conversation gradually grows over time.

```text id="v6j8lx" theme={null}
User

↓

Assistant

↓

User

↓

Assistant

↓

User

↓

Assistant
```

Every message becomes part of the conversation history.

***

# Building the Prompt

Before calling the language model, BindAI constructs a prompt containing:

* system instructions
* previous conversation
* current user message

Conceptually:

```text id="r5k9zn" theme={null}
System Prompt

+

Conversation History

+

Current User Message

↓

Language Model
```

This allows the model to understand the ongoing discussion.

***

# Example

Conversation begins.

```text id="g4w7qe" theme={null}
User:
My company is Acme.
```

Later:

```text id="j8d2ma" theme={null}
User:
Write an email to my company.
```

Because earlier messages are available, the assistant understands that "my company" refers to Acme.

***

# Multiple Conversations

Memory is usually organized by conversation or session.

```text id="y2h6cf" theme={null}
Conversation A

↓

Messages A

Conversation B

↓

Messages B
```

This prevents unrelated users or chats from sharing context.

***

# Conversation Growth

Over time, conversations become larger.

```text id="c8p4xu" theme={null}
Message 1

↓

Message 2

↓

Message 3

↓

...

↓

Message N
```

Depending on the memory provider, applications may choose to:

* retain everything
* summarize older messages
* archive conversations
* remove outdated history

***

# Memory and Context Windows

Language models have context limits.

Very long conversations may exceed those limits.

Applications commonly address this by:

* summarizing older messages
* keeping only recent interactions
* retrieving only relevant history
* combining conversation memory with RAG

***

# Conversation Memory vs Knowledge

Conversation Memory remembers interactions.

Knowledge retrieves external information.

| Conversation Memory | Knowledge          |
| ------------------- | ------------------ |
| Previous messages   | Documents          |
| User history        | Company data       |
| Personal context    | Reference material |
| Dynamic             | Usually static     |

Both can be used together during execution.

***

# Conversation Memory in Workflows

Conversation memory is also available inside workflows.

Example:

```text id="z3l5wt" theme={null}
Start

↓

Agent

↓

Conversation Updated

↓

Another Agent

↓

Conversation Available
```

Later workflow steps can continue the same conversation without additional configuration.

***

# Clearing Conversations

Applications may choose to clear memory when a conversation ends.

Conceptually:

```text id="h9q1sv" theme={null}
Conversation Ends

↓

Memory Cleared

↓

New Conversation Starts
```

This behavior depends on the selected provider and application requirements.

***

# Best Practices

* Keep conversations focused.
* Avoid storing unnecessary messages.
* Clear memory when appropriate.
* Use summaries for long conversations.
* Combine conversation memory with knowledge retrieval for better results.
* Choose a provider that supports your persistence requirements.

***

# Summary

Conversation Memory allows BindAI agents to maintain context across multiple interactions.

By automatically loading previous messages before generation and storing new messages afterward, agents can deliver more coherent, personalized, and natural conversations with minimal application code.
