Skip to content

robotsix_chat.memory

Persistent agent memory for robotsix-chat.

The chat agent is otherwise stateless (one independent query per message). This package adds long-term memory the agent recalls from before each reply, so knowledge accumulates across conversations.

The backend is the robotsix-memory component (a fleet service wrapping a Hindsight memory engine) — see :class:~robotsix_chat.memory.component.ComponentMemory. Recall is a cheap HTTP lookup rendered at the end of the agent prompt; writes belong to the evergoing summary pipeline (:mod:robotsix_chat.memory.push) and the agent's explicit skill calls. When the component is disabled a :class:NullMemory no-op is used and the agent behaves statelessly.

The public surface is the :class:ChatMemory protocol — setup / recall / remember — so the agent depends on the interface, never on the engine. (The previous in-process cognee backend was removed 2026-09-04 after repeated storage-engine failures; see the robotsix-memory component.)

ChatMemory

Bases: Protocol

Interface the chat agent uses to recall and persist memory.

Implementations must be safe by construction: recall and remember must never raise into the chat request path — a memory backend that is misconfigured or unreachable degrades to "no memory", never a failed reply.

Source code in src/robotsix_chat/memory/base.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@runtime_checkable
class ChatMemory(Protocol):
    """Interface the chat agent uses to recall and persist memory.

    Implementations must be *safe by construction*: ``recall`` and ``remember``
    must never raise into the chat request path — a memory backend that is
    misconfigured or unreachable degrades to "no memory", never a failed reply.
    """

    async def setup(self) -> None:
        """Initialise the backend once (idempotent). Safe to call repeatedly."""
        ...

    async def recall(self, query: str, *, session_id: str | None = None) -> str:
        """Return memory relevant to *query* as a context string (``""`` if none).

        *session_id* scopes the recall to one conversation so that
        session-level guidance (goals, rules, preferences) is isolated
        across concurrent windows.
        """
        ...

    async def remember(
        self,
        user_message: str,
        assistant_message: str,
        *,
        session_id: str | None = None,
    ) -> None:
        """Persist a completed exchange into long-term memory.

        *session_id* scopes the write to one conversation so that
        session-level guidance stays per-window.
        """
        ...

    def status(self) -> dict[str, Any]:
        """Return a small health snapshot (``{"degraded": bool, ...}``).

        Read by ``GET /health`` so a frozen store is externally visible.
        Must never raise.
        """
        ...

    def set_recovery_callback(self, callback: RecoverCallback | None) -> None:
        """Register (or clear) the out-of-band recovery callback.

        A backend that can detect a persistent freeze uses this to trigger a
        self-restart.  Backends with no recovery path may ignore it.
        """
        ...

    def set_notify_callback(self, callback: NotifyCallback | None) -> None:
        """Register (or clear) the user-facing escalation callback.

        A backend that detects a fault auto-recovery cannot safely heal uses
        this to escalate to the user.  Backends with no escalation path may
        ignore it.
        """
        ...

recall(query, *, session_id=None) async

Return memory relevant to query as a context string ("" if none).

session_id scopes the recall to one conversation so that session-level guidance (goals, rules, preferences) is isolated across concurrent windows.

Source code in src/robotsix_chat/memory/base.py
33
34
35
36
37
38
39
40
async def recall(self, query: str, *, session_id: str | None = None) -> str:
    """Return memory relevant to *query* as a context string (``""`` if none).

    *session_id* scopes the recall to one conversation so that
    session-level guidance (goals, rules, preferences) is isolated
    across concurrent windows.
    """
    ...

remember(user_message, assistant_message, *, session_id=None) async

Persist a completed exchange into long-term memory.

session_id scopes the write to one conversation so that session-level guidance stays per-window.

Source code in src/robotsix_chat/memory/base.py
42
43
44
45
46
47
48
49
50
51
52
53
54
async def remember(
    self,
    user_message: str,
    assistant_message: str,
    *,
    session_id: str | None = None,
) -> None:
    """Persist a completed exchange into long-term memory.

    *session_id* scopes the write to one conversation so that
    session-level guidance stays per-window.
    """
    ...

set_notify_callback(callback)

Register (or clear) the user-facing escalation callback.

A backend that detects a fault auto-recovery cannot safely heal uses this to escalate to the user. Backends with no escalation path may ignore it.

Source code in src/robotsix_chat/memory/base.py
72
73
74
75
76
77
78
79
def set_notify_callback(self, callback: NotifyCallback | None) -> None:
    """Register (or clear) the user-facing escalation callback.

    A backend that detects a fault auto-recovery cannot safely heal uses
    this to escalate to the user.  Backends with no escalation path may
    ignore it.
    """
    ...

set_recovery_callback(callback)

Register (or clear) the out-of-band recovery callback.

A backend that can detect a persistent freeze uses this to trigger a self-restart. Backends with no recovery path may ignore it.

Source code in src/robotsix_chat/memory/base.py
64
65
66
67
68
69
70
def set_recovery_callback(self, callback: RecoverCallback | None) -> None:
    """Register (or clear) the out-of-band recovery callback.

    A backend that can detect a persistent freeze uses this to trigger a
    self-restart.  Backends with no recovery path may ignore it.
    """
    ...

setup() async

Initialise the backend once (idempotent). Safe to call repeatedly.

Source code in src/robotsix_chat/memory/base.py
29
30
31
async def setup(self) -> None:
    """Initialise the backend once (idempotent). Safe to call repeatedly."""
    ...

status()

Return a small health snapshot ({"degraded": bool, ...}).

Read by GET /health so a frozen store is externally visible. Must never raise.

Source code in src/robotsix_chat/memory/base.py
56
57
58
59
60
61
62
def status(self) -> dict[str, Any]:
    """Return a small health snapshot (``{"degraded": bool, ...}``).

    Read by ``GET /health`` so a frozen store is externally visible.
    Must never raise.
    """
    ...

NullMemory

A :class:ChatMemory that stores nothing and recalls nothing.

Used when memory is disabled or the backend is unavailable, so the agent keeps working with zero memory behaviour and no extra dependencies.

Source code in src/robotsix_chat/memory/base.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class NullMemory:
    """A :class:`ChatMemory` that stores nothing and recalls nothing.

    Used when memory is disabled or the backend is unavailable, so the agent
    keeps working with zero memory behaviour and no extra dependencies.
    """

    async def setup(self) -> None:
        """No-op: nothing to initialise."""
        return None

    async def recall(self, query: str, *, session_id: str | None = None) -> str:
        """Return an empty string (no memory stored)."""
        return ""

    async def remember(
        self,
        user_message: str,
        assistant_message: str,
        *,
        session_id: str | None = None,
    ) -> None:
        """Discard the exchange (no memory backend)."""
        return None

    def status(self) -> dict[str, Any]:
        """Report a non-degraded no-op backend."""
        return {"backend": "null", "degraded": False}

    def set_recovery_callback(self, callback: RecoverCallback | None) -> None:
        """No-op: a null backend has nothing to recover."""
        return None

    def set_notify_callback(self, callback: NotifyCallback | None) -> None:
        """No-op: a null backend has nothing to escalate."""
        return None

recall(query, *, session_id=None) async

Return an empty string (no memory stored).

Source code in src/robotsix_chat/memory/base.py
93
94
95
async def recall(self, query: str, *, session_id: str | None = None) -> str:
    """Return an empty string (no memory stored)."""
    return ""

remember(user_message, assistant_message, *, session_id=None) async

Discard the exchange (no memory backend).

Source code in src/robotsix_chat/memory/base.py
 97
 98
 99
100
101
102
103
104
105
async def remember(
    self,
    user_message: str,
    assistant_message: str,
    *,
    session_id: str | None = None,
) -> None:
    """Discard the exchange (no memory backend)."""
    return None

set_notify_callback(callback)

No-op: a null backend has nothing to escalate.

Source code in src/robotsix_chat/memory/base.py
115
116
117
def set_notify_callback(self, callback: NotifyCallback | None) -> None:
    """No-op: a null backend has nothing to escalate."""
    return None

set_recovery_callback(callback)

No-op: a null backend has nothing to recover.

Source code in src/robotsix_chat/memory/base.py
111
112
113
def set_recovery_callback(self, callback: RecoverCallback | None) -> None:
    """No-op: a null backend has nothing to recover."""
    return None

setup() async

No-op: nothing to initialise.

Source code in src/robotsix_chat/memory/base.py
89
90
91
async def setup(self) -> None:
    """No-op: nothing to initialise."""
    return None

status()

Report a non-degraded no-op backend.

Source code in src/robotsix_chat/memory/base.py
107
108
109
def status(self) -> dict[str, Any]:
    """Report a non-degraded no-op backend."""
    return {"backend": "null", "degraded": False}

ReadOnlyMemory

Wraps a :class:ChatMemory so it can recall but never write.

Recall and cognify have wildly different costs. Recall is a retrieval-only vector lookup (~0.4 s warm, no LLM call); remember historically ran an multi-minute LLM extraction pipeline and contends with every concurrent recall for the same stores.

Background agents — subsessions and periodic session turns — run unattended around the clock, so letting them cognify every turn is what produced the ~$22/day bill and the write contention that slows interactive chat. But there is no reason to deny them reading what the main conversation has already learned.

This wrapper is that middle setting: full recall (including the deep search_memory tool, which is forwarded), writes silently dropped.

Source code in src/robotsix_chat/memory/base.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
class ReadOnlyMemory:
    """Wraps a :class:`ChatMemory` so it can recall but never write.

    Recall and cognify have wildly different costs. Recall is a retrieval-only
    vector lookup (~0.4 s warm, no LLM call); ``remember`` historically ran an
    multi-minute LLM extraction pipeline and contends with every concurrent
    recall for the same stores.

    Background agents — subsessions and periodic session turns —
    run unattended around the clock, so letting them cognify every turn is
    what produced the ~$22/day bill and the write contention that
    slows interactive chat. But there is no reason to deny them *reading*
    what the main conversation has already learned.

    This wrapper is that middle setting: full recall (including the deep
    ``search_memory`` tool, which is forwarded), writes silently dropped.
    """

    def __init__(self, inner: ChatMemory) -> None:
        """Wrap *inner*, exposing its reads and discarding its writes."""
        self._inner = inner

    async def setup(self) -> None:
        """Initialise the wrapped backend."""
        await self._inner.setup()

    async def recall(self, query: str, *, session_id: str | None = None) -> str:
        """Delegate to the wrapped backend — reads are the whole point."""
        return await self._inner.recall(query, session_id=session_id)

    def __getattr__(self, name: str) -> Any:
        """Forward unknown attributes (notably ``recall_deep``) to the backend.

        Dynamic rather than an explicit ``recall_deep`` method so the
        attribute is *absent* when the wrapped backend lacks it — that is
        exactly what ``build_memory_tools`` probes to decide whether to offer
        the ``search_memory`` tool. An explicit method would always be
        present and would advertise a tool that then raises.

        Only reached for names not defined on this class, so the write-side
        overrides above can never be bypassed.
        """
        return getattr(self._inner, name)

    async def remember(
        self,
        user_message: str,
        assistant_message: str,
        *,
        session_id: str | None = None,
    ) -> None:
        """Discard the exchange — background agents must not cognify."""
        return None

    def status(self) -> dict[str, Any]:
        """Report the wrapped backend's health, flagged read-only."""
        inner_status = dict(self._inner.status())
        inner_status["read_only"] = True
        return inner_status

    def set_recovery_callback(self, callback: RecoverCallback | None) -> None:
        """No-op: recovery is driven by the writing (main-chat) agent."""
        return None

    def set_notify_callback(self, callback: NotifyCallback | None) -> None:
        """No-op: escalation is driven by the writing (main-chat) agent."""
        return None

__getattr__(name)

Forward unknown attributes (notably recall_deep) to the backend.

Dynamic rather than an explicit recall_deep method so the attribute is absent when the wrapped backend lacks it — that is exactly what build_memory_tools probes to decide whether to offer the search_memory tool. An explicit method would always be present and would advertise a tool that then raises.

Only reached for names not defined on this class, so the write-side overrides above can never be bypassed.

Source code in src/robotsix_chat/memory/base.py
150
151
152
153
154
155
156
157
158
159
160
161
162
def __getattr__(self, name: str) -> Any:
    """Forward unknown attributes (notably ``recall_deep``) to the backend.

    Dynamic rather than an explicit ``recall_deep`` method so the
    attribute is *absent* when the wrapped backend lacks it — that is
    exactly what ``build_memory_tools`` probes to decide whether to offer
    the ``search_memory`` tool. An explicit method would always be
    present and would advertise a tool that then raises.

    Only reached for names not defined on this class, so the write-side
    overrides above can never be bypassed.
    """
    return getattr(self._inner, name)

__init__(inner)

Wrap inner, exposing its reads and discarding its writes.

Source code in src/robotsix_chat/memory/base.py
138
139
140
def __init__(self, inner: ChatMemory) -> None:
    """Wrap *inner*, exposing its reads and discarding its writes."""
    self._inner = inner

recall(query, *, session_id=None) async

Delegate to the wrapped backend — reads are the whole point.

Source code in src/robotsix_chat/memory/base.py
146
147
148
async def recall(self, query: str, *, session_id: str | None = None) -> str:
    """Delegate to the wrapped backend — reads are the whole point."""
    return await self._inner.recall(query, session_id=session_id)

remember(user_message, assistant_message, *, session_id=None) async

Discard the exchange — background agents must not cognify.

Source code in src/robotsix_chat/memory/base.py
164
165
166
167
168
169
170
171
172
async def remember(
    self,
    user_message: str,
    assistant_message: str,
    *,
    session_id: str | None = None,
) -> None:
    """Discard the exchange — background agents must not cognify."""
    return None

set_notify_callback(callback)

No-op: escalation is driven by the writing (main-chat) agent.

Source code in src/robotsix_chat/memory/base.py
184
185
186
def set_notify_callback(self, callback: NotifyCallback | None) -> None:
    """No-op: escalation is driven by the writing (main-chat) agent."""
    return None

set_recovery_callback(callback)

No-op: recovery is driven by the writing (main-chat) agent.

Source code in src/robotsix_chat/memory/base.py
180
181
182
def set_recovery_callback(self, callback: RecoverCallback | None) -> None:
    """No-op: recovery is driven by the writing (main-chat) agent."""
    return None

setup() async

Initialise the wrapped backend.

Source code in src/robotsix_chat/memory/base.py
142
143
144
async def setup(self) -> None:
    """Initialise the wrapped backend."""
    await self._inner.setup()

status()

Report the wrapped backend's health, flagged read-only.

Source code in src/robotsix_chat/memory/base.py
174
175
176
177
178
def status(self) -> dict[str, Any]:
    """Report the wrapped backend's health, flagged read-only."""
    inner_status = dict(self._inner.status())
    inner_status["read_only"] = True
    return inner_status

build_memory(memory_component=None)

Return the :class:ChatMemory for the given component settings.

Returns a :class:~robotsix_chat.memory.component.ComponentMemory when the robotsix-memory component is enabled, a :class:NullMemory no-op otherwise. Calls with equal configuration return the same backend instance — see _MEMORY_CACHE.

Parameters:

Name Type Description Default
memory_component MemoryComponentSettings | Any

:class:~robotsix_chat.config.models.MemoryComponentSettings (or None to disable memory).

None
Source code in src/robotsix_chat/memory/__init__.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def build_memory(
    memory_component: MemoryComponentSettings | Any = None,
) -> ChatMemory:
    """Return the :class:`ChatMemory` for the given component settings.

    Returns a :class:`~robotsix_chat.memory.component.ComponentMemory` when
    the robotsix-memory component is enabled, a :class:`NullMemory` no-op
    otherwise. Calls with equal configuration return the **same** backend
    instance — see ``_MEMORY_CACHE``.

    Args:
        memory_component:
            :class:`~robotsix_chat.config.models.MemoryComponentSettings`
            (or ``None`` to disable memory).

    """
    if memory_component is None or not getattr(memory_component, "enabled", False):
        return NullMemory()

    key = "component|" + memory_component.model_dump_json()
    cached = _MEMORY_CACHE.get(key)
    if cached is not None:
        return cached

    from .component import ComponentMemory

    component_memory = ComponentMemory(
        memory_component.url,
        timeout_seconds=memory_component.timeout_seconds,
    )
    _MEMORY_CACHE[key] = component_memory
    return component_memory

reset_build_memory_cache()

Drop all cached backends (test isolation only).

Each pytest case runs on a fresh event loop; a cached backend holds asyncio primitives bound to the loop it was first awaited on, so leaking one across tests raises "bound to a different event loop" in whichever test comes second.

Source code in src/robotsix_chat/memory/__init__.py
45
46
47
48
49
50
51
52
53
def reset_build_memory_cache() -> None:
    """Drop all cached backends (test isolation only).

    Each pytest case runs on a fresh event loop; a cached backend holds asyncio
    primitives bound to the loop it was first awaited on, so leaking one across
    tests raises "bound to a different event loop" in whichever test comes
    second.
    """
    _MEMORY_CACHE.clear()