Nous.Persistence.ETS (nous v0.17.2)

Copy Markdown View Source

ETS-based persistence backend.

Stores serialized context data in a named ETS table. The table is owned by a dedicated GenServer started under the Nous application supervisor, so the table outlives transient callers - previously the table died with whichever process happened to call save/load first.

Reads AND writes go straight to ETS from the calling process; the owner exists to keep the table alive, sweep expired sessions, and enforce the size cap. Routing every save/2 through the owner as a GenServer.call used to copy a serialized context three times (caller → owner mailbox → ETS) and serialise all writers behind one process.

Data does not survive node restarts. Useful for development, testing, and short-lived sessions.

Usage

# In AgentServer config
AgentServer.start_link(
  session_id: "session_123",
  agent_config: %{model: "openai:gpt-4", instructions: "Be helpful"},
  persistence: Nous.Persistence.ETS
)

Summary

Functions

Remove all persisted sessions. Useful for tests.

Block until the owner has processed every size-cap check queued before this call. Only needed by callers that want to observe the cap synchronously (tests); save/2 itself never waits for it.

Functions

clear()

@spec clear() :: :ok

Remove all persisted sessions. Useful for tests.

sync()

@spec sync() :: :ok

Block until the owner has processed every size-cap check queued before this call. Only needed by callers that want to observe the cap synchronously (tests); save/2 itself never waits for it.