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.0.tar.gz (467.7 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.0-py3-none-any.whl (397.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gradata-0.2.0.tar.gz
  • Upload date:
  • Size: 467.7 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.0.tar.gz
Algorithm Hash digest
SHA256 b9f7c1a57d4647798dde5de94b066365c228a289cd22b0d4f801514b2984b345
MD5 5d456592dcb2f91f3ade60c75e7afaef
BLAKE2b-256 13ed9786420621a3b0a17f366529eaf58e75b8cbf59f178add4385a48c4280a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradata-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 397.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d08d25f23932f4a32bcf301584e075ea98ba66a3b6bc307b3f08951ac0b33213
MD5 43276669c85e123600732d28fc8359bc
BLAKE2b-256 52877be396ad808114e89772fb0423dc9a8ac0bce157404f9c3d296d453ab334

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