🔄 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.
Metadata
Release files for rsi-loop 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rsi_loop-0.1.0.tar.gz | 77.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rsi_loop-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 97.5 kB
Release files / rsi_loop-0.1.0.tar.gz
| Download URL | rsi_loop-0.1.0.tar.gz |
|---|---|
| Size | 77.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f416ac6d69eb22ce8e5c11b9ca067b55ce13d2fae07950b0b8fc470cad24601c
|
|
BLAKE2b-256 checksum How to use checksums |
f04fe76180095919d1ca971aad83e2c513b206136f400a84a4e58b8b35d85fc9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / rsi_loop-0.1.0-py3-none-any.whl
| Download URL | rsi_loop-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d606c2d0c6da141162df69e42cddec5605518c80eec7eeeaad0b97290521cf2
|
|
BLAKE2b-256 checksum How to use checksums |
ba9f27292bc71d79d2bf3167f3cdac1e05b957dcbe2cd39e8fe540ad91b37e2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for rsi-loop 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.