Skip to main content

Continual learning layer for coding agents and software projects.

Project description

Lerim Logo

Your coding agents forget everything after each session.
Lerim learns — across all of them.

PyPI version Python versions License Tests GitHub stars

lerim.dev · docs · pypi

The Problem

You spend 20 minutes explaining context to your coding agent. It writes great code. Next session? It's forgotten everything. Every decision, every pattern, every "we tried X and it didn't work" -- gone.

And if you use multiple agents -- Claude Code at the terminal, Cursor in the IDE, Codex for reviews -- none of them know what the others learned. Your project knowledge is scattered across isolated sessions with no shared intelligence.

This is agent context amnesia, and it's the biggest productivity drain in AI-assisted development.

The Solution

Lerim is the continual learning and context graph layer for AI coding agents — it watches sessions, extracts structured knowledge, and builds a shared intelligence graph across agents, projects, and teams.

  • Watches your agent sessions across all supported coding agents
  • Extracts decisions and learnings automatically using LLM pipelines (DSPy + PydanticAI)
  • Stores everything as plain markdown files in your repo (.lerim/)
  • Refines knowledge continuously -- merges duplicates, archives stale entries, applies time-based decay
  • Connects learnings into a context graph -- related decisions and patterns are linked
  • Unifies knowledge across all your agents -- what one agent learns, every other can recall
  • Answers questions about past context: lerim ask "why did we choose Postgres?"

No proprietary format. No database lock-in. Just markdown files that both humans and agents can read. Knowledge compounds over time, not stale.

Supported Agents

Lerim works with any coding agent that produces session traces. Current adapters:

Agent Session Format Status
Claude Code JSONL traces Supported
Codex CLI JSONL traces Supported
Cursor SQLite to JSONL Supported
OpenCode SQLite to JSONL Supported

Adding a new agent adapter is straightforward -- PRs welcome! See src/lerim/adapters/ for examples.

How It Works

Lerim is file-first and primitive-first.

  • Primitive folders: decisions, learnings, summaries
  • Project memory: <repo>/.lerim/
  • Global fallback: ~/.lerim/
  • Search: file-based (no index required)
  • Orchestration: pydantic-ai lead agent + read-only explorer subagent
  • Extraction/summarization: dspy.ChainOfThought with transcript windowing

Sync path

Sync path

The sync path processes new agent sessions: reads transcript archives, extracts decision and learning candidates via DSPy, deduplicates against existing knowledge, and writes new entries to the project's knowledge store.

Maintain path

Maintain path

The maintain path runs offline refinement over stored knowledge: merges duplicates, archives low-value entries, consolidates related learnings, and applies time-based decay to keep the context graph clean and relevant.

Quick start

1. Install

pip install lerim

Prerequisites: Python 3.10+, Docker (optional)

2. Set up

lerim init                     # interactive setup — detects your coding agents
lerim project add .            # add current project (repeat for other repos)

3. Set API keys

Set keys for the providers you configure (defaults: MiniMax primary, Z.AI fallback):

export MINIMAX_API_KEY="..."   # if using MiniMax (default)
export ZAI_API_KEY="..."       # if using Z.AI (default fallback)

You only need keys for providers referenced in your [roles.*] config. See model roles.

4. Start Lerim

lerim up

That's it. Lerim is now running as a Docker service — syncing sessions, extracting decisions and learnings, refining memories, and serving a dashboard at http://localhost:8765.

5. Teach your agent about Lerim

Install the Lerim skill so your agent knows how to query past context:

lerim skill install

This copies skill files (SKILL.md, cli-reference.md) into your agent's skill directory.

6. Get the most out of Lerim

At the start of a session, tell your agent:

Check lerim for any relevant memories about [topic you're working on].

Your agent will run lerim ask or lerim memory search to pull in past decisions and learnings before it starts working.

Running without Docker

If you prefer not to use Docker, Lerim works directly:

lerim connect auto             # detect agent platforms
lerim serve                    # run HTTP server + daemon loop

Local models (Ollama)

Lerim works with local models via Ollama. Set provider = "ollama" in your role config and Lerim will automatically load models into GPU/RAM before each sync/maintain cycle and unload them after to free memory (auto_unload = true in [providers]).

ollama serve                   # start Ollama (runs outside Docker)

For Docker deployments, set ollama = "http://host.docker.internal:11434" in [providers] so the container can reach the host Ollama instance. See model roles for full configuration.

Dashboard

The dashboard gives you a local UI for session analytics, knowledge browsing, and runtime status.

Lerim dashboard

Tabs

  • Overview: high-level metrics and charts (sessions, messages, tools, errors, tokens, activity by day/hour, model usage).
  • Runs: searchable session list with status and metadata; open any run in a full-screen chat viewer.
  • Memories: library + editor for memory records (filter, inspect, edit title/body/kind/confidence/tags).
  • Pipeline: sync/maintain status, extraction queue state, and latest extraction report.
  • Settings: dashboard-editable config for server, model roles, and tracing; saves to ~/.lerim/config.toml.

CLI reference

Full command reference: skills/lerim/cli-reference.md

# Setup (host-only)
lerim init                                  # interactive setup wizard
lerim project add ~/codes/my-app            # register a project
lerim project list                          # list registered projects

# Docker service
lerim up                                    # start Lerim container
lerim down                                  # stop it
lerim logs --follow                         # tail logs

# Alternative: run directly without Docker
lerim serve                                 # start HTTP server + daemon loop

# Service commands (require lerim up or lerim serve running)
lerim ask "Why did we choose this?"          # query memories
lerim sync                                  # one-shot: sync sessions + extract
lerim maintain                              # one-shot: merge, archive, decay
lerim status                                # runtime state

# Local commands (run on host, no server needed)
lerim memory search "auth pattern"          # keyword search
lerim memory list                           # list all memories
lerim memory add --title "..." --body "..." # manual memory
lerim connect auto                          # detect and connect platforms
lerim skill install                         # install skill into agent directories

Configuration

TOML-layered config (low to high priority):

  1. src/lerim/config/default.toml (shipped with package -- all defaults)
  2. ~/.lerim/config.toml (user global)
  3. <repo>/.lerim/config.toml (project overrides)
  4. LERIM_CONFIG env var path (explicit override, for CI/tests)

API keys come from environment variables only. Set keys for the providers you use:

Variable Provider Default role
MINIMAX_API_KEY MiniMax Primary (all roles)
ZAI_API_KEY Z.AI Fallback
OPENROUTER_API_KEY OpenRouter Optional alternative
OPENAI_API_KEY OpenAI Optional alternative
ANTHROPIC_API_KEY Anthropic Optional alternative

Default model config (from src/lerim/config/default.toml):

  • All roles: provider=minimax, model=MiniMax-M2.5
  • Fallback: zai:glm-4.7 (lead/explorer), zai:glm-4.5-air (extract/summarize)

Development

uv venv && source .venv/bin/activate
uv pip install -e '.[test]'
lerim init                    # first-time config
lerim project add .           # track this repo
lerim up                      # start the service
tests/run_tests.sh unit
tests/run_tests.sh all

Tracing (OpenTelemetry)

Lerim uses PydanticAI's built-in OpenTelemetry instrumentation for agent observability.

# Enable tracing
LERIM_TRACING=1 lerim sync

# or in config
# .lerim/config.toml
[tracing]
enabled = true

View traces at https://logfire.pydantic.dev.

Memory layout

Project scope:

<repo>/.lerim/
  config.toml              # project overrides
  memory/
    decisions/
    learnings/
    summaries/
      YYYYMMDD/
        HHMMSS/
          {slug}.md
    archived/
      decisions/
      learnings/
  workspace/
    sync-<YYYYMMDD-HHMMSS>-<shortid>/
    maintain-<YYYYMMDD-HHMMSS>-<shortid>/
  index/   # reserved

Global fallback scope follows the same layout under ~/.lerim/.

Contributing

Lerim is open to contributions. Whether it's a new agent adapter, a bug fix, or a documentation improvement, PRs are welcome.

Docs

Full documentation: docs.lerim.dev


If Lerim saves you from re-explaining context to your agent, give it a ⭐
Star on GitHub

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lerim-0.1.66.tar.gz (121.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lerim-0.1.66-py3-none-any.whl (140.8 kB view details)

Uploaded Python 3

File details

Details for the file lerim-0.1.66.tar.gz.

File metadata

  • Download URL: lerim-0.1.66.tar.gz
  • Upload date:
  • Size: 121.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lerim-0.1.66.tar.gz
Algorithm Hash digest
SHA256 cca19266ae4a484073b81ec9bbdc39cd2824e94f6d087b155b6cf257f122f2c8
MD5 ce5401c099f02849ed628c29a080fd8e
BLAKE2b-256 bcabc2b418184a40711c1d341d2613018861cb36b366e8467a7188356f9e3995

See more details on using hashes here.

Provenance

The following attestation bundles were made for lerim-0.1.66.tar.gz:

Publisher: publish.yml on lerim-dev/lerim-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lerim-0.1.66-py3-none-any.whl.

File metadata

  • Download URL: lerim-0.1.66-py3-none-any.whl
  • Upload date:
  • Size: 140.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lerim-0.1.66-py3-none-any.whl
Algorithm Hash digest
SHA256 a376c13a6d7bb6a73ec79f6b501f8d99423eddbac39528f44e6961f2d5c13efa
MD5 3eb7461fdd9bd3f2adf1a55ad1b759ef
BLAKE2b-256 3bf0273b59edffba3ef03fdd1429cdc7474f74cf49d95b04dc835c5ca2802f38

See more details on using hashes here.

Provenance

The following attestation bundles were made for lerim-0.1.66-py3-none-any.whl:

Publisher: publish.yml on lerim-dev/lerim-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page