Documentation menu
Documentation

Sessions and memory

Keep conversation history, context blocks, branches, search, and compaction close to the agent.

One session

Ayjnt’s createSession() returns Cloudflare’s Session builder backed by the agent’s SQLite. Add stable identity or instructions as a context block, and give learned memory a bounded token budget.

example
import { Agent } from "ayjnt";

export default class Assistant extends Agent {
  session = this.createSession()
    .withContext("soul", {
      provider: { get: async () => "You are a careful project assistant." },
    })
    .withContext("memory", {
      description: "Useful facts learned about the person",
      maxTokens: 1100,
    })
    .withCachedPrompt();

  async remember(message: Parameters<typeof this.session.appendMessage>[0]) {
    await this.session.appendMessage(message);
    return this.session.getHistory();
  }
}

Many sessions

Use createSession(id) when you already know the namespace, or createSessionManager() to create, list, branch, and archive multiple conversations inside one agent instance.

Session compaction summarizes older turns without rewriting your agent’s state. Search providers and context blocks let a harness load relevant memory instead of replaying everything.