Self-improving memory for AI coding agents. Observes agent hooks, distills recurring patterns into rules, surfaces them before each task.
Project description
learned-behavior
Self-improving memory for AI coding agents (Claude Code, Codex, Copilot).
Observes what your agent does, distills recurring patterns into lessons, surfaces the relevant ones before each task, and auto-promotes rules that keep proving themselves while decaying stale ones.
No self-report. No LLM in the loop. Pure behavioral signal mined from agent hook events.
What it captures
- Repeated failures — same error pattern recurring across sessions
- Skill bypasses — raw
aws logswhen acasino-logsskill is available, rawkubectlwhen ak3sskill is available, etc. (project-configurable) - Repeated Edit self-corrections — the agent keeps writing
Xand replacing it withY; the rule should be "write Y directly next time" - PreToolUse blocks — every time a guard denies a command, we record it. Recurring blocks surface training gaps.
What it produces
A durable, project-scoped list of rules your agents see before their next task:
$ learned-behavior advice --workspace "$PWD"
1. laravelphp/vapor image has no bash — use `sh -c`, not `bash -lc`
2. After composer install on a new worktree, run `php artisan package:discover`
3. Never --force-push to production/staging — use --force-with-lease on feature branches only
How it improves itself
Every lesson has a confidence score and a status (candidate → approved → dormant).
- Promotion: candidates with ≥ N observations over ≥ M days with no contradicting signal graduate to
approved. - Decay: approved lessons whose pattern hasn't been seen in X days lose confidence, eventually going
dormantand dropping out ofadvice. - Reinforcement: when a lesson is surfaced and the warned-about pattern doesn't recur in that session, confidence ticks up.
Run learned-behavior promote and learned-behavior decay nightly (or via a cron/Stop hook) and the corpus gets better without human curation.
Requirements
- Python 3.10+ (uses PEP 604 union syntax and built-in generic type parameters)
- SQLite 3 (ships with Python's
sqlite3module) - No third-party runtime dependencies
Install
git clone https://github.com/lisn0/learned-behavior ~/workshop/learned-behavior
bash ~/workshop/learned-behavior/install.sh
Installer symlinks the CLI into ~/.local/bin/learned-behavior and creates the data directory at ~/.local/share/learned-behavior/ (or $LEARNED_BEHAVIOR_HOME if set).
Per-agent setup
Claude Code is the only agent that supports automatic observation (via its settings.local.json hook system). Every other agent integration below is a manual "paste advice into the model's context, record lessons by hand when something goes wrong" flow. The lesson corpus is shared — if you run Claude Code alongside another tool, its mined lessons surface everywhere.
| Agent | Integration | Docs |
|---|---|---|
| Claude Code | Automatic — hooks observe every tool call | docs/claude-code.md |
| Codex (OpenAI CLI / VS Code) | Manual | docs/codex.md |
| GitHub Copilot | Manual (rules file or Copilot Chat paste) | docs/copilot.md |
| Cursor | Manual (writes to .cursor/rules/) |
docs/cursor.md |
| Windsurf / Codeium Cascade | Manual (writes to .windsurfrules) |
docs/windsurf.md |
| Google Antigravity | Manual | docs/antigravity.md |
| Gemini / Jules / Gemini Code Assist | Manual (writes to GEMINI.md) |
docs/gemini.md |
| Aider | Manual (aider --read CONVENTIONS.md) |
docs/aider.md |
| Continue.dev | Manual (writes to .continue/rules/) |
docs/continue.md |
Have another agent that should be here? PRs welcome — the CLI is agent-neutral (the --agent flag just tags provenance) so adding a new one is mostly a docs task.
Per-project skill registry (optional)
In any project, create .claude/learned-behavior.json to declare skill-bypass rules:
{
"skill_registry": [
{ "pattern": "\\baws\\s+logs\\b", "skill": "casino-logs",
"reason": "Use casino-logs skill, not raw `aws logs`" }
]
}
Patterns are Python regex. Project config is merged over the default registry.
CLI
learned-behavior advice --workspace "$PWD" # lessons relevant to this project
learned-behavior learn ... # persist a new lesson manually
learned-behavior review --workspace "$PWD" # summary of lessons + recurring errors
learned-behavior mine --workspace "$PWD" # cluster error events into candidates
learned-behavior mine-edits --workspace "$PWD" # cluster repeated Edit self-corrections
learned-behavior mine-skill-miss --workspace "$PWD" # commands that bypass skills
learned-behavior mine-blocks --days 30 # PreToolUse guard blocks
learned-behavior promote --dry-run # preview candidates ready to approve
learned-behavior decay --dry-run # preview lessons going dormant
learned-behavior reinforce --session-id <id> # +/- confidence based on whether surfaced advice held
learned-behavior suggest-hooks --workspace "$PWD" # report missing hook wiring for this project
learned-behavior suggest-skills --workspace "$PWD" # surface repeated raw commands that deserve a skill
learned-behavior maintain --write # rate-limited nightly promote+decay
Add --write (or drop --dry-run) to apply.
Development
pip install -e ".[dev]"
pytest tests/
Tests are self-contained — they spin up an ephemeral SQLite DB in a tmp dir; nothing touches your real learning DB.
Design
See DESIGN.md for the state machine, scoring formula, and why we chose behavioral signal over self-report.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file learned_behavior-0.1.0.tar.gz.
File metadata
- Download URL: learned_behavior-0.1.0.tar.gz
- Upload date:
- Size: 30.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d97d36b2b30a2587d0addbeee51030407097bf6de205f04a7386ea589c022917
|
|
| MD5 |
59723f4681e3d21224b0f1057dfd5cab
|
|
| BLAKE2b-256 |
02c5b1ac49ab68a645887c6647eab60ef0714e56c23284d093cdbfa62611a1ae
|
File details
Details for the file learned_behavior-0.1.0-py3-none-any.whl.
File metadata
- Download URL: learned_behavior-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
636f62659abbd907f3c7b68cc12ec24c30fea37d28f2d9d28c6e9de8cbcb473b
|
|
| MD5 |
bcaa365559036b17da3066d5d65e6813
|
|
| BLAKE2b-256 |
450d9a1e75ac2957babcfe9a243871e6238d8ea4b3fbf01b553f99ce16e6a463
|