RecencyMemory¶
Recency-based episodic memory.
RecencyMemory
¶
Bases: BaseMemory
Recency-based episodic memory.
Recalls the last N episodes from the store and formats them for prompt injection. The simplest possible memory implementation: append on write, last-N on recall.
Attributes:
| Name | Type | Description |
|---|---|---|
store |
BaseMemoryStore
|
The underlying memory store. |
n |
int
|
Number of most recent episodes to recall. |
Source code in src/llm_agents_from_scratch/memory/recency.py
__init__
¶
Initialize a RecencyMemory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
BaseMemoryStore
|
The memory store to read from and write to. |
required |
n
|
int
|
Number of most recent episodes to include in recall. Defaults to 3. |
3
|
Source code in src/llm_agents_from_scratch/memory/recency.py
recall
async
¶
Retrieve the N most recent episodes as a formatted string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
The incoming task (unused — recency recall is unconditional). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Newline-separated episode strings, or empty string if the store is empty. |
Source code in src/llm_agents_from_scratch/memory/recency.py
record
async
¶
Persist a completed episode to the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
episode
|
Episode
|
The completed episode to store. |
required |
summary
async
¶
Return a human-readable summary of the memory and its store.
Describes the recall strategy (last N), then delegates to the store for substrate-level facts (count, oldest, newest).
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Multi-line summary of the memory and its store. |