Universal self-improvement loop for AI agents. Observe → Analyze → Fix → Verify.
Project description
🔄 RSI Loop
Every AI agent makes mistakes. RSI Loop makes them learn.
The Problem
AI agents repeat the same failures. They hit rate limits, return empty responses, lose context, pick the wrong model — and do it all again next session. There's no feedback loop. No memory of what went wrong. No automatic improvement.
RSI Loop is the missing primitive: a universal recursive self-improvement loop that works with any agent framework.
How It Works
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ OBSERVE │────▶│ ANALYZE │────▶│ FIX │────▶│ VERIFY │
│ │ │ │ │ │ │ │
│ Record │ │ Detect │ │ Generate │ │ Check │
│ outcomes │ │ patterns │ │ & apply │ │ health │
└──────────┘ └──────────┘ └──────────┘ └────┬─────┘
▲ │
└───────────────────────────────────────────────────┘
- Observe — Record task outcomes: success/failure, quality, errors, model used, duration
- Analyze — Detect patterns: recurring failures, error clusters, cross-source correlations
- Fix — Auto-fix safe categories (routing, retries, thresholds); propose fixes for the rest
- Verify — Track health score over time; confirm fixes reduced failure rates
Quick Start
uv add rsi-loop
Not using uv?
uv add rsi-loopworks too.
from rsi_loop import RSILoop
loop = RSILoop()
loop.observer.record_simple("code_generation", success=True, model="sonnet-4.6")
loop.observer.record_simple("api_call", success=False, error="429 Too Many Requests")
loop.observer.record_simple("api_call", success=False, error="429 Too Many Requests")
loop.observer.record_simple("api_call", success=False, error="429 Too Many Requests")
# Run improvement cycle
patterns = loop.run_cycle()
print(f"Health: {loop.health_score():.0%}")
print(f"Patterns found: {len(patterns)}")
Framework Integrations
Claude Code / OpenClaw
from rsi_loop.integrations.claude_code import ClaudeCodeAdapter
adapter = ClaudeCodeAdapter(data_dir="./rsi_data")
adapter.on_task_complete("code_review", success=True, model="claude-sonnet-4")
adapter.on_model_fallback("claude-opus-4", "claude-sonnet-4", "rate_limit")
adapter.on_session_reset()
Generic (File-Based)
Drop JSON files into a watch directory — works with any agent:
from rsi_loop.integrations.generic import GenericAdapter
adapter = GenericAdapter(watch_dir="./rsi_inbox")
# Your agent writes: {"task": "search", "success": false, "error": "timeout"}
# RSI picks it up automatically
outcomes = adapter.poll()
Webhook
from rsi_loop.integrations.webhook import WebhookAdapter
app = WebhookAdapter(data_dir="./rsi_data").create_app()
# POST /observe {"task": "code_gen", "success": true, "quality": 4}
# GET /health
# GET /patterns
Features
- Auto-classification — Categorizes errors automatically: rate_limit, empty_response, timeout, context_loss, etc.
- Recurrence detection — Flags issues that repeat 3+ times within the analysis window
- Health scoring — 0.0 (broken) to 1.0 (healthy), recency-weighted
- Cross-source correlation — Detects related issues across different agent sources
- Error clustering — Groups similar error messages even with different IDs/numbers
- Safe auto-fix — Automatically applies fixes for safe categories (routing, retries, thresholds)
- Fix proposals — Generates detailed proposals for unsafe categories, saved for human review
- Background loop — Run continuous improvement cycles in a background thread
- Framework-agnostic — Works with Claude Code, Cursor, Codex, or any custom agent
- Zero dependencies — Core package has no external dependencies (integrations optional)
Documentation
- Architecture — How RSI Loop works internally
- Source Taxonomy — Source classification and cross-source correlation
- Auto-Fix — How auto-fix works, safe categories, and fix templates
Examples
Built by ClawInfra — infrastructure for autonomous agents.
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 rsi_loop-0.1.0.tar.gz.
File metadata
- Download URL: rsi_loop-0.1.0.tar.gz
- Upload date:
- Size: 77.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f416ac6d69eb22ce8e5c11b9ca067b55ce13d2fae07950b0b8fc470cad24601c
|
|
| MD5 |
3d3fe9d6c58393fd4ddca7d400204da3
|
|
| BLAKE2b-256 |
f04fe76180095919d1ca971aad83e2c513b206136f400a84a4e58b8b35d85fc9
|
File details
Details for the file rsi_loop-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rsi_loop-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d606c2d0c6da141162df69e42cddec5605518c80eec7eeeaad0b97290521cf2
|
|
| MD5 |
6c49e31dd0ec3c569fcdb23922fffa3e
|
|
| BLAKE2b-256 |
ba9f27292bc71d79d2bf3167f3cdac1e05b957dcbe2cd39e8fe540ad91b37e2d
|