feat(memory): add rewound kwarg to on_session_switch hook

This commit is contained in:
SaguaroDev
2026-05-10 18:17:57 -04:00
committed by Teknium
parent 3e59be0c41
commit 31cfa08c66
2 changed files with 11 additions and 0 deletions

View File

@ -491,6 +491,7 @@ class MemoryManager:
*, *,
parent_session_id: str = "", parent_session_id: str = "",
reset: bool = False, reset: bool = False,
rewound: bool = False,
**kwargs, **kwargs,
) -> None: ) -> None:
"""Notify all providers that the agent's session_id has rotated. """Notify all providers that the agent's session_id has rotated.
@ -503,6 +504,10 @@ class MemoryManager:
per-session state so subsequent writes land in the correct per-session state so subsequent writes land in the correct
session's record. See ``MemoryProvider.on_session_switch`` for session's record. See ``MemoryProvider.on_session_switch`` for
the full contract. the full contract.
``rewound=True`` signals that session_id is unchanged but the
transcript was truncated; providers caching per-turn document
state should invalidate.
""" """
if not new_session_id: if not new_session_id:
return return
@ -512,6 +517,7 @@ class MemoryManager:
new_session_id, new_session_id,
parent_session_id=parent_session_id, parent_session_id=parent_session_id,
reset=reset, reset=reset,
rewound=rewound,
**kwargs, **kwargs,
) )
except Exception as e: except Exception as e:

View File

@ -178,6 +178,7 @@ class MemoryProvider(ABC):
*, *,
parent_session_id: str = "", parent_session_id: str = "",
reset: bool = False, reset: bool = False,
rewound: bool = False,
**kwargs, **kwargs,
) -> None: ) -> None:
"""Called when the agent switches session_id mid-process. """Called when the agent switches session_id mid-process.
@ -207,6 +208,10 @@ class MemoryProvider(ABC):
(``_session_turns``, ``_turn_counter``, etc.) when this is (``_session_turns``, ``_turn_counter``, etc.) when this is
set. ``False`` for ``/resume`` / ``/branch`` / compression set. ``False`` for ``/resume`` / ``/branch`` / compression
where the logical conversation continues under the new id. where the logical conversation continues under the new id.
rewound:
``True`` if session_id is unchanged but the transcript was
truncated; providers caching per-turn document state should
invalidate.
Default is no-op for backward compatibility. Default is no-op for backward compatibility.
""" """