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

# Camel.memories.agent memories

<a id="camel.memories.agent_memories" />

<a id="camel.memories.agent_memories.ChatHistoryMemory" />

## ChatHistoryMemory

```python theme={"system"}
class ChatHistoryMemory(AgentMemory):
```

An agent memory wrapper of :obj:`ChatHistoryBlock`.

**Parameters:**

* **context\_creator** (BaseContextCreator): A model context creator.
* **storage** (BaseKeyValueStorage, optional): A storage backend for storing chat history. If `None`, an :obj:`InMemoryKeyValueStorage` will be used. (default: :obj:`None`)
* **window\_size** (int, optional): The number of recent chat messages to retrieve. If not provided, the entire chat history will be retrieved. (default: :obj:`None`)
* **agent\_id** (str, optional): The ID of the agent associated with the chat history.

<a id="camel.memories.agent_memories.ChatHistoryMemory.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    context_creator: BaseContextCreator,
    storage: Optional[BaseKeyValueStorage] = None,
    window_size: Optional[int] = None,
    agent_id: Optional[str] = None
):
```

<a id="camel.memories.agent_memories.ChatHistoryMemory.agent_id" />

### agent\_id

```python theme={"system"}
def agent_id(self):
```

<a id="camel.memories.agent_memories.ChatHistoryMemory.agent_id" />

### agent\_id

```python theme={"system"}
def agent_id(self, val: Optional[str]):
```

<a id="camel.memories.agent_memories.ChatHistoryMemory.retrieve" />

### retrieve

```python theme={"system"}
def retrieve(self):
```

<a id="camel.memories.agent_memories.ChatHistoryMemory.write_records" />

### write\_records

```python theme={"system"}
def write_records(self, records: List[MemoryRecord]):
```

<a id="camel.memories.agent_memories.ChatHistoryMemory.get_context_creator" />

### get\_context\_creator

```python theme={"system"}
def get_context_creator(self):
```

<a id="camel.memories.agent_memories.ChatHistoryMemory.clear" />

### clear

```python theme={"system"}
def clear(self):
```

<a id="camel.memories.agent_memories.ChatHistoryMemory.clean_tool_calls" />

### clean\_tool\_calls

```python theme={"system"}
def clean_tool_calls(self):
```

Removes tool call messages from memory.
This method removes all FUNCTION/TOOL role messages and any ASSISTANT
messages that contain tool\_calls in their meta\_dict to save token
usage.

<a id="camel.memories.agent_memories.ChatHistoryMemory.pop_records" />

### pop\_records

```python theme={"system"}
def pop_records(self, count: int):
```

Removes the most recent records from chat history memory.

<a id="camel.memories.agent_memories.ChatHistoryMemory.remove_records_by_indices" />

### remove\_records\_by\_indices

```python theme={"system"}
def remove_records_by_indices(self, indices: List[int]):
```

Removes records at specified indices from chat history memory.

<a id="camel.memories.agent_memories.VectorDBMemory" />

## VectorDBMemory

```python theme={"system"}
class VectorDBMemory(AgentMemory):
```

An agent memory wrapper of :obj:`VectorDBBlock`. This memory queries
messages stored in the vector database. Notice that the most recent
messages will not be added to the context.

**Parameters:**

* **context\_creator** (BaseContextCreator): A model context creator.
* **storage** (BaseVectorStorage, optional): A vector storage storage. If `None`, an :obj:`QdrantStorage` will be used. (default: :obj:`None`)
* **retrieve\_limit** (int, optional): The maximum number of messages to be added into the context. (default: :obj:`3`)
* **agent\_id** (str, optional): The ID of the agent associated with the messages stored in the vector database.

<a id="camel.memories.agent_memories.VectorDBMemory.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    context_creator: BaseContextCreator,
    storage: Optional[BaseVectorStorage] = None,
    retrieve_limit: int = 3,
    agent_id: Optional[str] = None
):
```

<a id="camel.memories.agent_memories.VectorDBMemory.agent_id" />

### agent\_id

```python theme={"system"}
def agent_id(self):
```

<a id="camel.memories.agent_memories.VectorDBMemory.agent_id" />

### agent\_id

```python theme={"system"}
def agent_id(self, val: Optional[str]):
```

<a id="camel.memories.agent_memories.VectorDBMemory.retrieve" />

### retrieve

```python theme={"system"}
def retrieve(self):
```

<a id="camel.memories.agent_memories.VectorDBMemory.write_records" />

### write\_records

```python theme={"system"}
def write_records(self, records: List[MemoryRecord]):
```

<a id="camel.memories.agent_memories.VectorDBMemory.get_context_creator" />

### get\_context\_creator

```python theme={"system"}
def get_context_creator(self):
```

<a id="camel.memories.agent_memories.VectorDBMemory.clear" />

### clear

```python theme={"system"}
def clear(self):
```

Removes all records from the vector database memory.

<a id="camel.memories.agent_memories.VectorDBMemory.pop_records" />

### pop\_records

```python theme={"system"}
def pop_records(self, count: int):
```

Rolling back is unsupported for vector database memory.

<a id="camel.memories.agent_memories.VectorDBMemory.remove_records_by_indices" />

### remove\_records\_by\_indices

```python theme={"system"}
def remove_records_by_indices(self, indices: List[int]):
```

Removing by indices is unsupported for vector database memory.

<a id="camel.memories.agent_memories.LongtermAgentMemory" />

## LongtermAgentMemory

```python theme={"system"}
class LongtermAgentMemory(AgentMemory):
```

An implementation of the :obj:`AgentMemory` abstract base class for
augmenting ChatHistoryMemory with VectorDBMemory.

**Parameters:**

* **context\_creator** (BaseContextCreator): A model context creator.
* **chat\_history\_block** (Optional\[ChatHistoryBlock], optional): A chat history block. If `None`, a :obj:`ChatHistoryBlock` will be used. (default: :obj:`None`)
* **vector\_db\_block** (Optional\[VectorDBBlock], optional): A vector database block. If `None`, a :obj:`VectorDBBlock` will be used. (default: :obj:`None`)
* **retrieve\_limit** (int, optional): The maximum number of messages to be added into the context. (default: :obj:`3`)
* **agent\_id** (str, optional): The ID of the agent associated with the chat history and the messages stored in the vector database.

<a id="camel.memories.agent_memories.LongtermAgentMemory.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    context_creator: BaseContextCreator,
    chat_history_block: Optional[ChatHistoryBlock] = None,
    vector_db_block: Optional[VectorDBBlock] = None,
    retrieve_limit: int = 3,
    agent_id: Optional[str] = None
):
```

<a id="camel.memories.agent_memories.LongtermAgentMemory.agent_id" />

### agent\_id

```python theme={"system"}
def agent_id(self):
```

<a id="camel.memories.agent_memories.LongtermAgentMemory.agent_id" />

### agent\_id

```python theme={"system"}
def agent_id(self, val: Optional[str]):
```

<a id="camel.memories.agent_memories.LongtermAgentMemory.get_context_creator" />

### get\_context\_creator

```python theme={"system"}
def get_context_creator(self):
```

**Returns:**

BaseContextCreator: The context creator used by the memory.

<a id="camel.memories.agent_memories.LongtermAgentMemory.retrieve" />

### retrieve

```python theme={"system"}
def retrieve(self):
```

**Returns:**

List\[ContextRecord]: A list of context records retrieved from both
the chat history and the vector database.

<a id="camel.memories.agent_memories.LongtermAgentMemory.write_records" />

### write\_records

```python theme={"system"}
def write_records(self, records: List[MemoryRecord]):
```

Converts the provided chat messages into vector representations and
writes them to the vector database.

**Parameters:**

* **records** (List\[MemoryRecord]): Messages to be added to the vector database.

<a id="camel.memories.agent_memories.LongtermAgentMemory.clear" />

### clear

```python theme={"system"}
def clear(self):
```

Removes all records from the memory.

<a id="camel.memories.agent_memories.LongtermAgentMemory.pop_records" />

### pop\_records

```python theme={"system"}
def pop_records(self, count: int):
```

Removes recent chat history records while leaving vector memory.

<a id="camel.memories.agent_memories.LongtermAgentMemory.remove_records_by_indices" />

### remove\_records\_by\_indices

```python theme={"system"}
def remove_records_by_indices(self, indices: List[int]):
```

Removes records at specified indices from chat history.
