altk-evolve icon indicating copy to clipboard operation
altk-evolve copied to clipboard

feat: add purpose-directed gist memory for user personalization

Open jayaramkr opened this issue 8 months ago • 2 comments

Implement Innovation 1 & 2 from the gist memory disclosure: storage-optimized and use-optimized gisting for conversation memory.

Core module (kaizen/llm/gist/):

  • generate_gist() with rolling cumulative chunking (context budget: 64k)
  • Purpose-directed Jinja2 prompt optimized for extracting user attributes
  • 3-retry pattern with constrained decoding support
  • "no user signal" filtering for low-signal conversations

Schema & config:

  • GistResponse (Pydantic) + GistResult (frozen dataclass)
  • KAIZEN_GIST_MODEL, KAIZEN_GIST_CONTEXT_BUDGET, KAIZEN_GIST_TRIGGER_INTERVAL

KaizenClient methods:

  • store_gists(): rolling consolidation (delete-and-replace per conversation_id)
  • retrieve_gists(): semantic search over gist entities
  • retrieve_gist_with_source(): gists paired with original messages

MCP server tools:

  • store_gist: generate and store gists from conversation JSON
  • get_gists: retrieve relevant gists by semantic query

Claude Code plugin (Kaizen Lite):

  • /kaizen:gist skill for inline gist generation
  • Recall hook extended to inject gists in a separate section

Demo scenario (demo/gist-memory/):

  • Buried preference recall test (Section 9.1 probe from disclosure)
  • Session 1: preference embedded in unrelated K8s conversation
  • Session 2: preference recall verification prompts

Summary by CodeRabbit

  • New Features

    • Gist Memory: capture and store user preferences and signals from conversations
    • New MCP tools for storing and retrieving conversation gists
    • Claude plugin skill for automated gist generation and extraction
  • Documentation

    • Complete Gist Memory demo guide with setup instructions and verification workflows
    • Gist skill specification for Claude plugins
  • Configuration

    • Added configurable gist context budget and trigger interval settings
  • Tests

    • Comprehensive unit tests for gist generation functionality

jayaramkr avatar Mar 23 '26 16:03 jayaramkr

📝 Walkthrough

Walkthrough

This pull request introduces a "gist memory" feature that extracts and stores user preferences buried in multi-turn conversations, enabling later recall via semantic search. The implementation spans configuration, client APIs, LLM-based generation, MCP tools, plugin integration, documentation, and tests.

Changes

Cohort / File(s) Summary
Configuration
kaizen/config/kaizen.py, kaizen/config/llm.py
Added gist_context_budget (64000 tokens) and gist_trigger_interval (5) settings to KaizenConfig, plus gist_model field to LLMSettings to configure model used for gist generation.
Core Gist Generation
kaizen/llm/gist/gist.py, kaizen/schema/gist.py, kaizen/llm/gist/prompts/generate_gist.jinja2
Implemented generate_gist() function with token estimation, message chunking, and LLM-based extraction of user signals; added GistResponse Pydantic model and GistResult dataclass for structured output; created Jinja2 prompt template instructing models to produce vector-database-ready gists.
Client API Layer
kaizen/frontend/client/kaizen_client.py
Added store_gists() (persists gist and source entities with rolling replacement), retrieve_gists() (semantic search), and retrieve_gist_with_source() (returns gists with associated source messages) methods to KaizenClient.
MCP Server Integration
kaizen/frontend/mcp/mcp_server.py
Added store_gist and get_gists FastMCP tools wrapping the client layer, enabling conversation gist persistence and retrieval via the MCP protocol.
Plugin Integration
platform-integrations/claude/plugins/kaizen-lite/skills/gist/SKILL.md, platform-integrations/claude/plugins/kaizen-lite/skills/recall/scripts/retrieve_entities.py
Introduced "gist" skill definition for Claude plugin; updated retrieve_entities.py to format gist entities in a separate "Conversation Gists" section during recall.
Demo & Documentation
demo/gist-memory/README.md, demo/gist-memory/session1_script.md, demo/gist-memory/session2_script.md
Added demo scenario ("Buried Preference Recall") with setup instructions for both Lite and Full Kaizen paths, two-session workflow (preference embedding, then verification), and expected gist output examples.
Tests
tests/unit/test_gist.py
Comprehensive unit tests validating token estimation, message chunking, gist generation with and without JSON-schema support, retry logic, and empty input handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly related PRs

  • AgentToolkit/kaizen#95: Modifies platform-integrations/claude/plugins/kaizen-lite/skills/recall/scripts/retrieve_entities.py (same file updated here) with related changes to format_entities behavior for entity categorization.

Suggested reviewers

  • visahak
  • illeatmyhat
  • vinodmut

Poem

🐰 A gist of wisdom, tucked away deep,
In conversation's weaving, secrets we keep.
Buried preferences now resurface with care,
Vector dreams help memories find their lair!
─ Hoppy Revision

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a gist memory feature for user personalization across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Mar 23 '26 16:03 coderabbitai[bot]

can we hold off merging this for now?

visahak avatar Mar 23 '26 22:03 visahak