Skip to content

Documentation / @agentick/core / SessionStore

Interface: SessionStore ​

Defined in: core/src/app/types.ts:269

Storage adapter for persisting session snapshots.

Implement this interface to enable session persistence with your storage backend (Redis, database, filesystem, etc.).

Examples ​

typescript
class MemorySessionStore implements SessionStore {
  private store = new Map<string, SessionSnapshot>();

  async save(sessionId: string, snapshot: SessionSnapshot) {
    this.store.set(sessionId, snapshot);
  }

  async load(sessionId: string) {
    return this.store.get(sessionId) ?? null;
  }

  async delete(sessionId: string) {
    this.store.delete(sessionId);
  }
}
typescript
class RedisSessionStore implements SessionStore {
  constructor(private redis: Redis, private prefix = 'session:') {}

  async save(sessionId: string, snapshot: SessionSnapshot) {
    await this.redis.set(
      this.prefix + sessionId,
      JSON.stringify(snapshot),
      'EX', 86400 // 24 hour TTL
    );
  }

  async load(sessionId: string) {
    const data = await this.redis.get(this.prefix + sessionId);
    return data ? JSON.parse(data) : null;
  }

  async delete(sessionId: string) {
    await this.redis.del(this.prefix + sessionId);
  }
}

Methods ​

delete() ​

delete(sessionId): Promise<void>

Defined in: core/src/app/types.ts:287

Delete a session snapshot from storage. Called when a session is permanently closed.

Parameters ​

sessionId ​

string

Returns ​

Promise<void>


has()? ​

optional has(sessionId): Promise<boolean>

Defined in: core/src/app/types.ts:299

Check if a persisted session exists. Optional - optimization to avoid full load when checking existence.

Parameters ​

sessionId ​

string

Returns ​

Promise<boolean>


list()? ​

optional list(): Promise<string[]>

Defined in: core/src/app/types.ts:293

List all persisted session IDs. Optional - used for session discovery/management.

Returns ​

Promise<string[]>


load() ​

load(sessionId): Promise<SessionSnapshot | null>

Defined in: core/src/app/types.ts:281

Load a session snapshot from storage. Called when restoring a session via app.session(id). Returns null if session not found.

Parameters ​

sessionId ​

string

Returns ​

Promise<SessionSnapshot | null>


save() ​

save(sessionId, snapshot): Promise<void>

Defined in: core/src/app/types.ts:274

Save a session snapshot to storage. Called after each execution (auto-persist).

Parameters ​

sessionId ​

string

snapshot ​

SessionSnapshot

Returns ​

Promise<void>

Released under the ISC License.