windlass.interfaces.memory¶
memory
¶
The memory interface.
Memory is what turns a stateless model call into a conversation. Windlass separates two concerns that are often conflated:
- Conversation memory — the recent transcript, replayed into the prompt. Buffer, sliding-window and summarising strategies live here.
- Long-term memory — durable facts recalled by relevance rather than recency, backed by a vector store.
Both implement this interface, so an agent can hold one, the other, or a composite of both without knowing the difference.
Implementers override :meth:Memory.aadd and :meth:Memory.aget.
Example
from windlass.providers.memory.conversation import BufferMemory from windlass.core.types import Message m = BufferMemory() m.add(Message.user("hi")) len(m.get()) 1
Memory
¶
Memory(
*,
max_messages: int | None = None,
return_system: bool = False,
name: str | None = None,
**config: Any
)
Bases: Component
Abstract conversation / long-term memory.
Memory is keyed by thread_id so one instance can serve many concurrent
users — an agent handling a hundred chat sessions needs one memory object,
not a hundred.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_messages
|
int | None
|
Ceiling on how many messages :meth: |
None
|
return_system
|
bool
|
Whether system messages are included in recall. Usually False: the system prompt is supplied by the agent, not the history. |
False
|
name
|
str | None
|
Component name for traces. |
None
|
**config
|
Any
|
Strategy-specific options. |
{}
|
Example
Implementing a memory takes two methods::
class NullMemory(Memory):
provider_name = "null"
async def aadd(self, messages, *, thread_id="default"): ...
async def aget(self, *, thread_id="default", query=None):
return []
Source code in src\windlass\interfaces\memory.py
aadd
abstractmethod
async
¶
Record one or more messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
Message | Sequence[Message]
|
A message or a sequence of them. |
required |
thread_id
|
str
|
Conversation this belongs to. |
DEFAULT_THREAD
|
Raises:
| Type | Description |
|---|---|
MemoryError_
|
When the backend cannot persist the messages. |
Source code in src\windlass\interfaces\memory.py
aget
abstractmethod
async
¶
aget(
*,
thread_id: str = DEFAULT_THREAD,
query: str | None = None,
limit: int | None = None
) -> list[Message]
Recall messages for a thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
Conversation to recall. |
DEFAULT_THREAD
|
query
|
str | None
|
Current user input. Semantic memories use it to rank recall; recency-based memories ignore it. |
None
|
limit
|
int | None
|
Override for :attr: |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
Messages in chronological order, oldest first. |
Source code in src\windlass\interfaces\memory.py
aclear
async
¶
Forget a thread, or everything when thread_id is None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str | None
|
Thread to clear. |
None
|
athreads
async
¶
add
¶
get
¶
get(
*,
thread_id: str = DEFAULT_THREAD,
query: str | None = None,
limit: int | None = None
) -> list[Message]
Blocking :meth:aget.