@andy8647/pi-agent-loop
v0.1.2
Published
Universal agent loop with rate-limit detection and auto-recovery for pi coding agent
Maintainers
Readme
pi-agent-loop
Universal agent loop with rate-limit detection and auto-recovery for pi coding agent.
Inspired by claude-loop, but works cross-provider: when any LLM hits a rate limit (Anthropic, Kimi, DeepSeek, OpenAI, etc.), it detects the error, waits for the reset, then auto-resumes the task.
Install
pi install git:github.com/Andy8647/pi-agent-loopUsage
# Start a long-running task
/agent-loop start "build the entire project, fix all tests, deploy to staging"
# Check status
/agent-loop status
# Configure max cycles (0 = unlimited)
/agent-loop max-cycles 10
# Configure extra wait buffer after reset
/agent-loop buffer 120
# Stop the loop
/agent-loop stopHow It Works
┌─────────────────────────────────────────────────────┐
│ /agent-loop start "build everything" │
│ ┌──────────────────────────────────────────────┐ │
│ │ Cycle 1: agent runs task... │ │
│ │ ...hits rate limit! │ │
│ │ ┌──────────────────────────────────────┐ │ │
│ │ │ Detect: regex scan message content │ │ │
│ │ │ Parse: extract reset time │ │ │
│ │ │ Wait: sleep until reset + buffer │ │ │
│ │ │ Resume: send "continue" prompt │ │ │
│ │ └──────────────────────────────────────┘ │ │
│ │ Cycle 2: agent continues... │ │
│ │ ...task complete! │ │
│ └──────────────────────────────────────────────┘ │
│ Loop ends (no more rate limits detected) │
└─────────────────────────────────────────────────────┘Rate Limit Detection
| Provider | Detection Method |
|----------|-----------------|
| Anthropic | isApiErrorMessage + reset time parsing |
| Kimi | 5h coding plan limit detection |
| DeepSeek | Rate limit / quota message patterns |
| OpenAI | 429 + retry-after patterns |
| Generic | Regex: "rate limit", "too many requests", "try again in X", "resets at", "quota exceeded", HTTP 429 |
Commands
| Command | Description |
|---------|-------------|
| /agent-loop start <prompt> | Start a new agent loop |
| /agent-loop stop | Stop the current loop |
| /agent-loop status | Show current loop state |
| /agent-loop max-cycles <n> | Set max cycles (0=unlimited) |
| /agent-loop buffer <sec> | Extra wait seconds after reset |
License
MIT
