Skip to main content

Procedural memory for AI agents. Corrections become behavioral rules that compound over time.

Project description

Gradata

Procedural memory for AI agents. Corrections become behavioral rules that compound over time.

Your AI keeps making the same mistakes. Gradata fixes that.

pip install gradata

Zero dependencies. Python 3.11+.

Quick Start

from gradata import Brain

brain = Brain.init("./my-brain")

# Your AI produces output. You fix it.
brain.correct(
    draft="We are pleased to inform you of our new product offering.",
    final="Hey, check out what we just shipped."
)

# Brain learns. Next time, inject rules into the prompt:
rules = brain.apply_brain_rules("write an email")
# → "[RULE:0.92] TONE: Use casual, direct language..."

# Prove the brain is getting better:
manifest = brain.manifest()

How It Works

Human corrects AI output
       ↓
brain.correct(draft, final)
       ↓
Diff computed → severity classified → lesson created
       ↓
Confidence grows with each reinforcement:
  0.40 = INSTINCT (new, unproven)
  0.60 = PATTERN  (seen enough to trust)
  0.90 = RULE     (injected into every prompt)
       ↓
3+ related rules → META-RULE (general principle)
       ↓
brain.apply_brain_rules() → AI stops making that mistake

Features

Core learning loop:

  • brain.correct(draft, final) — capture corrections with automatic diff + severity classification
  • brain.apply_brain_rules(task) — inject graduated rules into prompts
  • brain.manifest() — mathematical proof the brain is improving (compound score)
  • brain.prove() — paired t-test showing correction rate decreased after graduation

Human-in-the-loop approval:

  • brain.review_pending() — list lessons awaiting approval
  • brain.approve_lesson(id) / brain.reject_lesson(id) — pre-graduation veto gate
  • gradata review CLI — approve/reject from terminal

Encryption at rest:

  • pip install gradata[encrypted] — AES-128 via Fernet
  • Brain("./my-brain", encryption_key="...") or GRADATA_ENCRYPTION_KEY env var
  • Encrypt-on-close, decrypt-on-open. Zero plaintext at rest.

Correction provenance:

  • Every lesson tracks which correction events created it
  • Meta-rules link back to their source lessons
  • Full audit trail: correction → lesson → rule → meta-rule

23 optional agentic patterns (from gradata.contrib.patterns import ...): Pipeline, Guard, RAG, Reflection, Memory, MCP, Orchestrator, Q-Learning Router, and more. Pure Python, no dependencies.

Integrations: OpenAI, Anthropic, LangChain, CrewAI adapters included.

CLI

gradata init ./my-brain              # Create a brain
gradata correct --draft "..." --final "..."  # Log a correction
gradata review                       # Approve/reject pending lessons
gradata stats                        # Brain health
gradata manifest --json              # Quality metrics
gradata search "topic"               # Search brain knowledge
gradata export                       # Package for sharing
gradata doctor                       # Diagnose issues

MCP Server

Works with Claude Code, Cursor, Windsurf, and any MCP-compatible host:

{
  "mcpServers": {
    "gradata": {
      "command": "python",
      "args": ["-m", "gradata.mcp_server"]
    }
  }
}

Scaffolder

npx create-gradata ./my-brain

Auto-installs the SDK, runs the onboarding interview, brain ready in 30 seconds.

What Makes This Different

System Remembers Learns from corrections Graduates rules Proves improvement
Mem0 Yes No No No
Letta (MemGPT) Yes No No No
LangChain Memory Yes No No No
Gradata Yes Yes Yes Yes

Everyone else builds declarative memory — "remember that I like short emails."

Gradata builds procedural memory — "after 12 corrections on email tone, graduated a RULE at 0.92 confidence: use casual, direct language." That's a learned behavior with a proof trail.

Optional Extras

pip install gradata[encrypted]    # Encryption at rest (Fernet AES)
pip install gradata[embeddings]   # Local sentence-transformers
pip install gradata[all]          # Everything

Architecture

src/gradata/
├── brain.py              # Brain class (public API)
├── _core.py              # Correction detection, diff engine
├── _events.py            # Append-only event log (JSONL + SQLite)
├── _types.py             # Lesson, LessonState, typed models
├── enhancements/
│   ├── self_improvement.py   # Graduation pipeline
│   ├── meta_rules.py         # Meta-rule emergence
│   └── diff_engine.py        # Edit distance, severity
├── rules/
│   ├── rule_engine.py        # Inject rules into prompts
│   └── scope.py              # Task classification
└── contrib/patterns/         # Optional agentic patterns

Caveats

  • v0.2.0 — API may change
  • Local-only for now
  • The graduation engine needs multiple sessions to produce rules. Don't expect results in one sitting.

Contributing

See CONTRIBUTING.md.

License

AGPL-3.0. Commercial license available for teams that need it.

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

gradata-0.2.1.tar.gz (467.9 kB view details)

Uploaded Source

Built Distribution

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

gradata-0.2.1-py3-none-any.whl (397.9 kB view details)

Uploaded Python 3

File details

Details for the file gradata-0.2.1.tar.gz.

File metadata

  • Download URL: gradata-0.2.1.tar.gz
  • Upload date:
  • Size: 467.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for gradata-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5f06b3b3cf612b9ccaa128dd36a03681ff0160665f8a7aef0f31cdb8c2632061
MD5 d513a89a685d25f04f361db7c3eee3cd
BLAKE2b-256 b65b4be682e08fdd586124bb2e1283c626e41c478be72a6ec90846630b52e355

See more details on using hashes here.

File details

Details for the file gradata-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: gradata-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 397.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for gradata-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 414d9c7f8090c2383eb1cddd0ac3b28b37a8ccdd5900f7711c29f3b6e0caec2b
MD5 31044f19e21342ebed6048e43a64d5eb
BLAKE2b-256 82ab5a5f5206d44f6f42e868a590273adee25725519b1631229a0f37694ca40d

See more details on using hashes here.

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