Skip to content

Memory and context persistence #5

Closed

Description

@pavelanni

Summary

Add memory and context persistence so agents can retain information across conversations.

Motivation

Stateless agents lose all context between requests. For business use cases (ongoing document review, multi-session projects), agents need persistent memory.

Evaluation targets

  • Letta — open source, agent memory management framework
  • Mem0 — open source, structured memory layer for LLM apps
  • Graphiti — open source, temporal knowledge graph for agent memory

All candidates should be evaluated for OpenShift compatibility, resource requirements, and integration complexity.

Acceptance criteria

  • Evaluate candidates against OpenShift deployment constraints
  • Prototype integration with at least one memory backend
  • Memory accessible via tool interface in the agentic loop
  • Configuration via agent-config.yaml

From roadmap: docs/slides/docsclaw-intro.html, slide 6

Activity

  1. m13v commented on Apr 14, 2026

    @m13v

    ran into this exact problem running agents for recurring business workflows (weekly client reports, follow-up sequences, invoice reconciliation). tested all three of your candidates over about two months.

    the thing nobody warns you about: structured memory (Mem0) works great for factual recall but falls apart for procedural memory. your agent remembers that Client X prefers PDF invoices but forgets the 6-step sequence it learned for generating them. Graphiti handles temporal relationships better but the resource footprint on constrained environments is rough, we saw 2-3GB baseline just for the graph store.

    what actually worked for us was a dead simple file-based approach: markdown files with YAML frontmatter, organized by type (user preferences, workflow feedback, project state). agent reads an index file at conversation start, pulls in relevant memory files as needed. total overhead is basically zero, deploys anywhere, and the memory is human-readable so you can debug it by just opening a file.

    for your OpenShift constraints i'd honestly prototype the flat-file approach first before committing to infrastructure. curious what kind of agent workflows you're targeting, because that changes the memory architecture significantly. document review with stable context is very different from multi-session projects where the state graph keeps growing.

  2. pavelanni commented on Apr 24, 2026

    @pavelanni
    CollaboratorAuthor

    Phase 1: Server-side session management (from #37)

    Before adding persistent memory, we need basic multi-turn session state on the server side. Currently the server is stateless — the chat TUI works around this by prepending full conversation history as text into each request.

    Session model

    Session {
      ID          string
      AgentConfig string        // which agent personality
      Messages    []Message     // accumulated conversation
      CreatedAt   time.Time
      LastActive  time.Time
      TTL         time.Duration // auto-expire idle sessions
    }
    

    Storage backends (in order of implementation)

    1. In-memory (map + mutex) — sufficient for single-replica demos, zero dependencies
    2. Redis — for multi-replica deployments with shared state
    3. SQLite — for single-replica with persistence across restarts

    Integration points

    • A2A executor uses taskId from the protocol to look up or create sessions
    • processMessage in serve.go retrieves session history and appends new messages
    • Session TTL prevents unbounded memory growth
    • Chat TUI can optionally switch from client-side to server-side history

    Design constraints

    • Default must remain stateless (no required external dependencies)
    • Session store is opt-in via agent-config.yaml
    • Memory overhead per session must be bounded (configurable max history length)

    This is a prerequisite for Phase 2 (persistent memory via Letta/Mem0/Graphiti).

  3. pavelanni commented on May 4, 2026

    @pavelanni
    CollaboratorAuthor

    Phase 3: Context compaction (from pi-mono analysis)

    Once sessions persist message history (Phase 1), long conversations will hit context window limits. We need automatic compaction — summarizing older messages while preserving recent context.

    Approach (modeled on pi-mono's implementation)

    1. Token estimation: len(chars) / 4 heuristic for quick estimates; use actual usage.totalTokens from provider responses when available
    2. Trigger: compact when estimatedTokens > (contextWindow - reserveTokens), with configurable reserveTokens (default 16384) and keepRecentTokens (default 20000)
    3. Cut point selection: walk backwards from newest message, accumulate token sizes, stop at keepRecentTokens; never cut mid-turn (keep tool results with their tool calls)
    4. Summarization: send discarded messages to the LLM with a structured summarization prompt producing: Goal, Constraints, Progress, Decisions, Next Steps, Critical Context
    5. Iterative updates: on subsequent compactions, merge new messages into the previous summary rather than re-summarizing everything

    Key design decisions

    • Compaction runs automatically but can also be triggered manually (e.g., /compact command in chat TUI)
    • File operations (reads/writes) should be tracked across compaction boundaries so the agent knows what files it has touched
    • The summary replaces old messages in the session — original history stays in the persisted session file for audit

    Depends on

    Identified from analysis of pi-mono's compaction system in packages/coding-agent/src/core/compaction/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions