Skip to content

Sessions API


FileSessionManager

python
from elsai.session import FileSessionManager

Persists sessions to the local filesystem.

python
FileSessionManager(
    session_id="chat-alice",
    storage_dir="./sessions",
)
ParameterRequiredDefaultDescription
session_idYesSession identifier (no path separators)
storage_dirNotemp dir under elsai/sessionsDirectory for session files

S3SessionManager

python
from elsai.session import S3SessionManager

Persists sessions to Amazon S3.

python
S3SessionManager(
    session_id="chat-alice",
    bucket="my-sessions-bucket",
    prefix="sessions/",
    region_name="us-west-2",
)
ParameterRequiredDefaultDescription
session_idYesSession identifier (no path separators)
bucketYesS3 bucket name
prefixNo""Key prefix (e.g. "sessions/")
boto_sessionNoNoneCustom boto3 session
boto_client_configNoNoneOptional boto3 client configuration
region_nameNoNoneAWS region for S3

RepositorySessionManager

python
from elsai.session import RepositorySessionManager

Generic session manager backed by a SessionRepository.

python
RepositorySessionManager(
    session_id="chat-alice",
    session_repository=my_repository,
)
ParameterRequiredDescription
session_idYesSession identifier
session_repositoryYesSessionRepository implementation

SessionRepository

python
from elsai.session import SessionRepository

Abstract base for custom storage backends:

python
class SessionRepository:
    def create_session(self, session: Session, **kwargs) -> Session: ...
    def read_session(self, session_id: str, **kwargs) -> Session | None: ...
    def create_agent(self, session_id: str, session_agent: SessionAgent, **kwargs) -> None: ...
    def read_agent(self, session_id: str, agent_id: str, **kwargs) -> SessionAgent | None: ...
    def update_agent(self, session_id: str, session_agent: SessionAgent, **kwargs) -> None: ...
    def create_message(
        self, session_id: str, agent_id: str, session_message: SessionMessage, **kwargs
    ) -> None: ...
    def read_message(
        self, session_id: str, agent_id: str, message_id: int, **kwargs
    ) -> SessionMessage | None: ...
    def update_message(
        self, session_id: str, agent_id: str, session_message: SessionMessage, **kwargs
    ) -> None: ...
    def list_messages(
        self, session_id: str, agent_id: str, limit: int | None = None, offset: int = 0, **kwargs
    ) -> list[SessionMessage]: ...

Types Session, SessionAgent, and SessionMessage are imported from elsai.session.


Snapshot

python
from elsai.agent import Snapshot, SnapshotPreset, SnapshotField

An in-memory snapshot of agent state.

SnapshotPreset

ValueIncluded fields
"session"messages, state, conversation_manager_state, interrupt_state

SnapshotField

Valid field names: "messages", "state", "conversation_manager_state", "interrupt_state", "system_prompt"

Taking a snapshot

python
snapshot = agent.take_snapshot(preset="session")
snapshot = agent.take_snapshot(include=["messages", "state"])
snapshot = agent.take_snapshot(preset="session", exclude=["interrupt_state"])
snapshot = agent.take_snapshot(preset="session", app_data={"version": "1.0"})

Restoring from snapshot

python
agent.load_snapshot(snapshot)

Serialising

python
import json

# Serialise
snapshot_dict = snapshot.model_dump()
json_str = json.dumps(snapshot_dict)

# Deserialise
from elsai.agent import Snapshot
snapshot = Snapshot(**json.loads(json_str))
agent.load_snapshot(snapshot)

  • Sessions — file, S3, repository, and A2A session patterns
  • A2A sessionscontext_id mapping and S3 production backing
  • A2A APIA2ASessionStore and session options on A2AServer

Copyright © 2026 elsai foundry.