> ## 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.base

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

<a id="camel.memories.base.MemoryBlock" />

## MemoryBlock

```python theme={"system"}
class MemoryBlock(ABC):
```

An abstract class serves as the fundamental component within the agent
memory system. This class is equipped with "write" and "clear" functions.
However, it intentionally does not define a retrieval interface, as the
structure of the data to be retrieved may vary in different types of
memory blocks.

<a id="camel.memories.base.MemoryBlock.write_records" />

### write\_records

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

Writes records to the memory, appending them to existing ones.

**Parameters:**

* **records** (List\[MemoryRecord]): Records to be added to the memory.

<a id="camel.memories.base.MemoryBlock.write_record" />

### write\_record

```python theme={"system"}
def write_record(self, record: MemoryRecord):
```

Writes a record to the memory, appending it to existing ones.

**Parameters:**

* **record** (MemoryRecord): Record to be added to the memory.

<a id="camel.memories.base.MemoryBlock.pop_records" />

### pop\_records

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

Removes records from the memory and returns the removed records.

**Parameters:**

* **count** (int): Number of records to remove.

**Returns:**

List\[MemoryRecord]: The records that were removed from the memory
in their original order.

<a id="camel.memories.base.MemoryBlock.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 the memory.

**Parameters:**

* **indices** (List\[int]): List of indices to remove. Indices should be valid positions in the current record list.

**Returns:**

List\[MemoryRecord]: The removed records in their original order.

<a id="camel.memories.base.MemoryBlock.clear" />

### clear

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

Clears all messages from the memory.

<a id="camel.memories.base.BaseContextCreator" />

## BaseContextCreator

```python theme={"system"}
class BaseContextCreator(ABC):
```

An abstract base class defining the interface for context creation
strategies.

This class provides a foundational structure for different strategies to
generate conversational context from a list of context records. The
primary goal is to create a context that is aligned with a specified token
count limit, allowing subclasses to define their specific approach.

Subclasses should implement the :obj:`token_counter`,:obj: `token_limit`,
and :obj:`create_context` methods to provide specific context creation
logic.

**Parameters:**

* **token\_counter** (BaseTokenCounter): A token counter instance responsible for counting tokens in a message.
* **token\_limit** (int): The maximum number of tokens allowed in the generated context.

<a id="camel.memories.base.BaseContextCreator.token_counter" />

### token\_counter

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

<a id="camel.memories.base.BaseContextCreator.token_limit" />

### token\_limit

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

<a id="camel.memories.base.BaseContextCreator.create_context" />

### create\_context

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

An abstract method to create conversational context from the chat
history.

Constructs the context from provided records. The specifics of how this
is done and how the token count is managed should be provided by
subclasses implementing this method. The output messages order
should keep same as the input order.

**Parameters:**

* **records** (List\[ContextRecord]): A list of context records from which to generate the context.

**Returns:**

Tuple\[List\[OpenAIMessage], int]: A tuple containing the constructed
context in OpenAIMessage format and the total token count.

<a id="camel.memories.base.AgentMemory" />

## AgentMemory

```python theme={"system"}
class AgentMemory(MemoryBlock, ABC):
```

Represents a specialized form of `MemoryBlock`, uniquely designed for
direct integration with an agent. Two key abstract functions, "retrieve"
and "get\_context\_creator", are used for generating model context based on
the memory records stored within the AgentMemory.

<a id="camel.memories.base.AgentMemory.agent_id" />

### agent\_id

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

<a id="camel.memories.base.AgentMemory.agent_id" />

### agent\_id

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

<a id="camel.memories.base.AgentMemory.retrieve" />

### retrieve

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

**Returns:**

List\[ContextRecord]: A record list for creating model context.

<a id="camel.memories.base.AgentMemory.get_context_creator" />

### get\_context\_creator

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

**Returns:**

BaseContextCreator: A model context creator.

<a id="camel.memories.base.AgentMemory.get_context" />

### get\_context

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

**Returns:**

(List\[OpenAIMessage], int): A tuple containing the constructed
context in OpenAIMessage format and the total token count.

<a id="camel.memories.base.AgentMemory.clean_tool_calls" />

### clean\_tool\_calls

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

Removes tool call messages from memory.
This is an optional method that can be overridden by subclasses
to implement cleaning of tool-related messages. By default, it
does nothing, maintaining backward compatibility.

<a id="camel.memories.base.AgentMemory.__repr__" />

### **repr**

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

**Returns:**

str: A string in the format 'ClassName(agent\_id=`<id>`)'
if agent\_id exists, otherwise just 'ClassName()'.
