🦫 capybala (v0.8.0)
Context-Aware Pruning for Yielding & Backtrack-Aligned Loop Avoidance
The Requests-Grade, Self-Healing Runtime for Autonomous AI Agents.
⚡ The Problem: Cognitive Deadlocks & Context Bleed
When an autonomous coding agent (Claude 3.7, GPT-4o, Llama 3.3, DeepSeek-V3) gets stuck:
- It loops repeatedly on the exact same failing command or alternates between broken patches.
- Context window floods with 15,000+ tokens of identical traceback spam.
- Infinite Healing Loops: The agent repeatedly fails, gets healed, fails another way, burning developer budgets.
- Session crashes or burns through developer credit card budgets.
Existing tools merely detect loops and kill the agent (raise RuntimeError).
capybala heals the agent, prevents meta-deadlocks via Circuit Breakers, and keeps it alive to finish the job.
🚀 The 1-Line Developer Experience
1. Drop-In Client Wrapper (Sync & Async)
Zero code changes to your agent loop. Wrap your client and you're protected:
from openai import OpenAI
import capybala as cb
# Explicit, type-safe, zero global side-effects:
client = cb.watch(OpenAI())
# Use client exactly as you always do (including stream=True!):
response = client.chat.completions.create(
model="gpt-4o",
messages=messages
)
Also Works Flawlessly with AsyncOpenAI & AsyncAnthropic:
from openai import AsyncOpenAI
import capybala as cb
# Fully preserves inspect.iscoroutinefunction() and offloads CPU regex to worker threads:
async_client = cb.watch(AsyncOpenAI())
response = await async_client.chat.completions.create(
model="gpt-4o",
messages=messages
)
When an agent enters an infinite loop, Capybala intercepts it and prints the Flight Recorder to stderr:
─────────────────────────────────────────────────────────────────
🦫 Capybala Cycle Intercepted [pytest tests/test_core.py]
├── Cycle Length: 3 turns | Recovered: ~3,200 tokens (~$0.019)
└── Resolution: Atomic Rollback + Grounded Reflection Injected
─────────────────────────────────────────────────────────────────
2. Pure Functional 1-Liner (For Custom Agent Frameworks)
import capybala as cb
# In-place mutation guarantees developer outer history lists never experience Ghost Desync:
messages = cb.heal(messages)
🛡️ Production Invariant Guarantees (v0.4.0 Enterprise Hardened)
Unlike naive loop detectors, Capybala guarantees zero protocol crashes in production:
| Production Hazard | Naive Loop Breakers | capybala v0.4.0 Guarantee |
|---|---|---|
| Infinite Healing Loops (Meta-Deadlocks) | Blindly heals forever, burning thousands of dollars | Autonomous Circuit Breaker: Halts infinite healing loops after max_interventions=5 (DeadlockEmergencyStop). |
| Volatile Dynamic Arguments | Hashes raw args; blinded by changing timestamps/nonces | JSON Key Sanitizer: Strips volatile fields (timestamp, nonce, request_id) and canonicalizes JSON dicts. |
| Autoregressive Reflection Echo | Static reflection becomes an attractor token loop | Progressive Escalation Healer: Levels 1, 2, 3+ escalate from local diagnostics to radical hypothesis resets. |
Streaming Completions (stream=True) |
Breaks generators and crashes chunk streaming | Streaming Generator Passthrough: Preserves chunk streaming and async generators without disruption. |
| Anthropic Role Alternation | Injects back-to-back user messages; triggers 400 Bad Request |
Strict Claude Role Hygiene: Merges guidance into existing user turns; strictly maintains turn alternation. |
| AsyncIO Event Loop Starvation | Stalls main loop with heavy regexes; strips coroutine flags | Async-Native Offloading: Preserves iscoroutinefunction, offloads CPU work via asyncio.to_thread. |
| Ghost Pruning Desync | Returns new list while developer's outer loop keeps old bloated list | In-Place Mutation: messages[:] = clean_history synchronizes caller state automatically. |
| Memory Leaks in Ring Buffers | Stores raw strings, pinning 800MB+ in RAM per agent | Zero Memory Pinning: Stores 16-byte SHA digests and bounds regex passes to 32KB. |
| OpenAI Parallel Tool Calls | Splits message, triggers fatal 400 Bad Request |
Atomic Checkpoint Rollback: Never separates tool_calls from paired tool responses. |
| Legitimate Polling | Kills curl /health, kubectl, ps aux after 3 runs |
Dynamic Polling Exemption: Whitelists waiting and status commands. |
| Oscillating Loops (Period-2 & 3) | Fails to detect alternating patches (A -> B -> C -> A...) | Multi-Step Oscillation Engine: Intercepts complex cyclic thrashing. |
📊 Verification & Benchmarks
Validated against 200 real SWE-bench Deadlock Trajectories (AnalogJ, PyTorch Lightning, etc.):
- 100.0% Recall on repetitive cognitive deadlocks ($\ge 3$ turns).
- 0.0% False Positive Rate on exploratory Git operations and healthy polling.
- 78.8% Token Waste Prevented per session across benchmark dataset.
- < 0.06 ms Mean Execution Latency (pure Python, 0 extra tokens).
📜 License
Apache-2.0 License. Built for the Meta Global AI Developer Hackathon 2026.
Metadata
Release files for capybala 0.8.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 | Actions |
|---|---|---|---|---|
| capybala-0.8.0.tar.gz | 65.3 kB | Without provenance | Details for capybala-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| capybala-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for capybala-0.8.0-py3-none-any.whl |
Total release size: 115.3 kB
Release files / capybala-0.8.0.tar.gz
| Download URL | capybala-0.8.0.tar.gz |
|---|---|
| Size | 65.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48a4be7f663f5ea046f78ea06153e6ad41cdd29fc1b1fd7e06c8265ea56cd9fb
|
|
BLAKE2b-256 checksum How to use checksums |
84b2257fb47dbd7e4c9a1bb2e4c33c1c77363068e00352728dcfb246cdaa15b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / capybala-0.8.0-py3-none-any.whl
| Download URL | capybala-0.8.0-py3-none-any.whl |
|---|---|
| Size | 49.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d1e0dd7d98ec33729b43be81270a00b37d899beea30542cf2f3ed850f7e332b2
|
|
BLAKE2b-256 checksum How to use checksums |
315c134510694e5b43b93004c122a11979b334f0d12db29274121e6da1290c7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for capybala 0.8.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.