Install
Install with PiG
pig install npm:@bismawy/pi-agentrouterInstall with Pi
pi install npm:@bismawy/pi-agentrouterPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"image": "https://raw.githubusercontent.com/bismawy/pi-agentrouter/main/assets/banner.webp",
"extensions": [
"./index.ts"
]
}README
Written by the package's publisher, shown as published in version 1.7.1 (README.md). PiG does not review it.
AgentRouter
Unified frontier models. Self-healing WAF recovery. Zero workflow interruption.

Overview
pi-agentrouter provides a unified provider for AgentRouter in Pi — routing GPT-6 Astra, GPT-5.6 Sol, Claude Opus 4.8 / 5, DeepSeek V4 Flash, and GLM 5.3 under a single agentrouter/ namespace with self-healing WAF recovery.
- Protocol Routing: GPT-6 Astra routes via OpenAI Responses, Claude models via Anthropic Messages, and others via OpenAI Completions under one provider.
- WAF Header & Language Guard: Forces Pi's canonical system header to byte 0 and applies language framing on user turns.
- Self-Healing Recovery: Redacts older history turns in two stages on content-filter triggers, and automatically translates the latest turn to English when needed.
- Payload Sanitization: Strips ANSI escape codes, null bytes, control characters, and orphan Unicode surrogates before dispatch.
- Session Affinity: Injects
sendSessionAffinityHeaders: trueby default to maximize server-side cache hits.
Model Catalog
The catalog is discovered live: on every pi model refresh (startup and right after /login), the extension probes GET https://agentrouter.org/v1/models with your key and registers exactly what the account lists — no manual model entries. Any probe failure (offline, missing key, WAF) falls back to the last confirmed snapshot. Current snapshot and verified wire configs:
| Model | Context | Input | Protocol | Thinking |
|---|---|---|---|---|
agentrouter/gpt-6-astra | 272k | text, image | OpenAI Responses | low – xhigh |
agentrouter/gpt-5.6-sol | 272k | text, image | OpenAI Completions | low – xhigh |
agentrouter/gpt-6.1-sol | 272k | text, image | OpenAI Responses | low – xhigh |
Catalog ids without a verified config register with a conservative text-only default. Retired ids keep their wire configs in MODEL_BLUEPRINTS, so a relisted model (e.g. claude-opus-5, glm-5.3, deepseek-v4-flash) automatically comes back with the right protocol.
Install
pi install npm:@bismawy/pi-agentrouter
Supply your API key via /login agentrouter, export AGENTROUTER_API_KEY="your-key", or in ~/.pi/agent/models.json.
No account yet? Register on AgentRouter for a $50 bonus.
To test locally without installing:
pi -e ./index.ts
Commands
| Command | Action |
|---|---|
/agentrouter | Interactive menu with Status and Usage panels |
/agentrouter status | View active models, status, and balance in a styled TUI panel |
/agentrouter usage | Inspect session usage metrics and cost estimates |
Architecture
WAF Auto-Recovery Lifecycle
- Forces Pi's system prompt header to the very start of the payload.
- On
content-blockedor sensitive-words errors, marks the turn retryable for automatic recovery. - Stage 1 redacts older user turns; Stage 2 escalates to assistant turns while preserving tool pairs.
- Stage 3 translates the newest turn to English if redaction is exhausted, avoiding user turn deletion.
- Redaction depth resets on new conversations or compaction.
Development
npm test # Runs check-framing.ts self-checks
License
Distributed under the MIT license.