@bismawy/pi-agentrouter

AgentRouter provider for Pi: access frontier models under one namespace with self-healing WAF recovery and automatic turn translation.

Packages

Package details

extension

Install @bismawy/pi-agentrouter from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@bismawy/pi-agentrouter
Package
@bismawy/pi-agentrouter
Version
1.6.2
Published
Sep 30, 2026
Downloads
1,266/mo · 69/wk
Author
bismawy
License
MIT
Types
extension
Size
81.7 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "image": "https://raw.githubusercontent.com/bismawy/pi-agentrouter/main/assets/banner.webp",
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

AgentRouter

Unified frontier models. Self-healing WAF recovery. Zero workflow interruption.

Custom badge badge license

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: true by default to maximize server-side cache hits.

Registered Models

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/claude-opus-5 200k text, image Anthropic Messages low – xhigh
agentrouter/claude-opus-4-8 200k text, image Anthropic Messages low – xhigh
agentrouter/deepseek-v4-flash 131k text OpenAI Completions low – xhigh
agentrouter/glm-5.3 131k text OpenAI Completions low – xhigh

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

  1. Forces Pi's system prompt header to the very start of the payload.
  2. On content-blocked or sensitive-words errors, marks the turn retryable for automatic recovery.
  3. Stage 1 redacts older user turns; Stage 2 escalates to assistant turns while preserving tool pairs.
  4. Stage 3 translates the newest turn to English if redaction is exhausted, avoiding user turn deletion.
  5. Redaction depth resets on new conversations or compaction.
npm test # Runs check-framing.ts self-checks

License

Distributed under the MIT license.

Author

Bisma