osyra_ome.adapters.langchain.memory
Private pre-release / network boundary: The currently usable customer surface is offline verification of an existing signed artifact against an out-of-band trust anchor. Memory/network RPC APIs and host snippets on this page describe protocol and interface shape; the public Edge bridge, package publication, and release acceptance remain pending. Do not treat
api.osyra.ai:443examples as a released customer route.
LangChain conversation-buffer memory backed by OME (forward-compat shim).
LangChain 0.x exposed a ``BaseMemory`` abstract that ``save_context`` / ``load_memory_variables`` plugged into. LangChain 1.x dropped that abstract in favour of :class:`~langchain_core.chat_history.BaseChatMessageHistory`
- :class:`~langchain_core.runnables.history.RunnableWithMessageHistory`.
This adapter provides :class:`OmeMemory`, a forward-compatible shim that wraps :class:`~osyra_ome.adapters.langchain.OmeChatMessageHistory` with a ``save_context`` / ``load_memory_variables`` surface so existing 0.x chains keep working while internally using the modern chat-message-history pattern.
For LangChain 1.x code-paths, prefer wiring :class:`OmeChatMessageHistory` directly into :class:`RunnableWithMessageHistory`.
Example::
from osyra_ome import OmeClient
from osyra_ome.adapters.langchain import OmeMemory
memory = OmeMemory(
client=OmeClient(...),
session_id="user-42",
memory_key="chat_history",
)
memory.save_context({"input": "hi"}, {"output": "hello"})
print(memory.load_memory_variables({}))Classes
class OmeMemory
Conversation-buffer-memory façade over :class:`OmeChatMessageHistory`.
Args:
client: a :class:osyra_ome.OmeClient.
session_id: identifier for the conversation thread.
memory_key: the key under which the buffered history is
returned by :meth:load_memory_variables. Defaults to
"history" to match the standard LangChain convention.
input_key: key in save_context inputs that carries the
user's utterance. Defaults to "input".
output_key: key in save_context outputs that carries the
assistant's response. Defaults to "output".
return_messages: when True, :meth:load_memory_variables
returns a list of :class:BaseMessage objects; when False,
it returns a single concatenated string (the LangChain 0.x
default). Defaults to True.
workspace_id: OME workspace UUID-like id; if omitted, defers to
the workspace_id bound on the wrapped client.
verify_on_read: bind each replayed body to the claim SIGNATURE
(DEFAULT True; forwarded to the wrapped
:class:OmeChatMessageHistory). See its docstring (ENG-2413).
trusted_signer_key: caller-pinned 32-byte Ed25519 trust anchor;
REQUIRED when verify_on_read is True (forwarded; H7).
Methods
__init__
def __init__(self, *, client: OmeClient, session_id: str, memory_key: str = 'history', input_key: str = 'input', output_key: str = 'output', return_messages: bool = True, workspace_id: str | None = None, verify_on_read: bool = True, trusted_signer_key: bytes | None = None) -> Nonechat_memory @property
def chat_memory(self) -> AnyThe wrapped chat-message-history (for direct access).
Returns the ``OmeChatMessageHistory`` instance — typed as ``Any`` because the class is built dynamically by a factory and mypy doesn't follow that pattern. Callers can rely on the runtime attributes documented on :class:`OmeChatMessageHistory`.
clear
def clear(self) -> NoneForget the in-memory buffer of written claim ids.
Mirrors :meth:`OmeChatMessageHistory.clear` — does NOT tombstone the underlying claims (v0.2 surface).
load_memory_variables
def load_memory_variables(self, inputs: dict[str, Any]) -> dict[str, Any]Return the buffered conversation under :attr:`memory_key`.
``inputs`` is part of the LangChain 0.x BaseMemory protocol signature; unused here but accepted for API compatibility.
memory_variables @property
def memory_variables(self) -> list[str]LangChain BaseMemory protocol — the keys this memory exposes.
save_context
def save_context(self, inputs: dict[str, Any], outputs: dict[str, Any]) -> NonePersist the latest user turn + assistant turn into OME.
Pulls ``inputs[input_key]`` + ``outputs[output_key]`` and writes two Claims (HumanMessage + AIMessage) via the underlying chat history. Raises KeyError if either field is missing.
session_id @property
def session_id(self) -> str