diff --git a/300 areas/350 AI/Pi Agent Extensions & Skills.md b/300 areas/350 AI/Pi Agent Extensions & Skills.md index ed65bbb..519893c 100644 --- a/300 areas/350 AI/Pi Agent Extensions & Skills.md +++ b/300 areas/350 AI/Pi Agent Extensions & Skills.md @@ -37,6 +37,7 @@ aliases: [] | **plannotator** | `~/.agents` | Interactive plan review with browser UI, annotations, code review | | **caveman** | `~/.agents` | Ultra-compressed communication mode | | **markitdown** | `~/.agents` | Convert files (PDF, Word, Excel, PPTX, images, HTML, etc.) to Markdown. Image analysis via Qwen 2.5 VL 72B on OpenRouter. | +| **smart-router** | `~/.agents` | Dynamic prompt routing — analyzes intent and routes to optimal model. `/lock-model` and `/unlock-model` for manual override. | --- @@ -158,67 +159,59 @@ The **npm-security** skill instructs the Pi agent to follow this workflow before --- -## Prompt Templates +## Smart Router -Prompt templates are `.md` files in `~/.pi/agent/prompts/` with YAML frontmatter. Each defines a slash command that auto-switches model, thinking level, and injects skills — then restores your previous model when done. +The smart-router extension (`~/.agents/extensions/smart-router/`) is a **prompt interceptor** that analyzes every incoming prompt and dynamically routes it to the most appropriate model based on intent. It replaces the old `/do-*` prompt templates with automatic, invisible routing. -### Installed Templates +### How it works -| Command | Tier | Model | Use | -| ------------ | -------- | ------------------------ | ---------------------------------------------------------- | -| `/do-quick` | ⚡ flash | deepseek-v4-flash (opencode-go) | General everyday tasks | -| `/do-think` | 🧠 ultra | openrouter/deepseek/deepseek-v4-pro | Deep thinking, hard problems | -| `/do-check` | 🔷 pro | opencode-go/deepseek-v4-pro | Code review, quality checks | -| `/do-nix-check` | ⚡ flash | deepseek-v4-flash (opencode-go) | Nix flake checks, config debug | -| `/do-note` | ⚡ flash | deepseek-v4-flash (opencode-go) | Create Obsidian .md with frontmatter | -| `/do-sort` | 🔷 pro | opencode-go/deepseek-v4-pro | Classify files, suggest Obsidian folder | -| `/do-read` | ⚡ flash | deepseek-v4-flash (opencode-go) | Batch read and synthesize many files | -| `/do-debug` | 🧠 ultra | openrouter/deepseek/deepseek-v4-pro | Complex NixOS/infra debugging | -| `/do-vault` | 🔷 pro | opencode-go/deepseek-v4-pro | Obsidian vault setup and management | -| `/do-chat` | ⚡ flash | deepseek-v4-flash (opencode-go) | Chat with automatic web search | -| `/do-img` | 🧠 ultra | openrouter/deepseek/deepseek-v4-pro | Image analysis and description | -| `/do-make-img` | ⚡ flash | deepseek-v4-flash (opencode-go) | Generate images via OpenRouter (GPT/Image Mini, Gemini) | +1. Every prompt is intercepted before the agent loop starts +2. A free model (`openrouter/owl-alpha`) analyzes the intent +3. The prompt is classified into one of 10 tags (read, discuss, search, devops-low, devops-high, code-analysis-low, code-analysis-high, codewrite-low, codewrite-high) +4. The router selects the optimal model based on tag + language +5. The selected model is set via `pi.setModel()` +6. Routing decisions appear in the **footer status bar** (e.g. `🎯 devops-low → qwen/qwen3.6-flash`) -> **Audio/Voice note:** Pi runs in a text-based terminal (TUI) with no microphone access or audio playback. Qwen supports audio processing, but it's not practical in Pi's current architecture regardless of model. +### Routing table -### How to use +| Tag | Model | Use case | +|-----|-------|----------| +| `read`, `discuss`, `search` | `openrouter/owl-alpha` | Reading docs, general chat, web search | +| `devops-low` | `qwen/qwen3.6-flash` | Simple YAML, Docker, bash | +| `devops-high` | `qwen/qwen-2.5-72b-instruct` | Complex multi-container, server crashes | +| `code-analysis-low` | `openrouter/owl-alpha` | Finding bugs in short files | +| `code-analysis-high` | `moonshotai/kimi-k2.6` | Refactoring large codebases (262K context) | +| `codewrite-low` | `deepseek/deepseek-v4-flash` | Boilerplate, simple functions | +| `codewrite-high` (React) | `qwen/qwen3-coder-plus` | Complex React/JS | +| `codewrite-high` (other) | `deepseek/deepseek-v4-pro` | Complex PHP, dense logic | +| Short prompts (<15 chars) | `openrouter/owl-alpha` | Quick responses, greetings | + +### Manual override ``` -/do-quick what's the weather? -/do-think design the architecture for this feature -/do-check review the changes in this file -/do-nix-check analyze the nix flake check output -/do-note document the new service setup -/do-sort read this config file and tell me where it goes -/do-read skim these three config files and compare them -/do-debug why is my NixOS build failing? -/do-vault set up a template for daily notes -/do-chat what's new in NixOS 25.11? -/do-img what's wrong in this screenshot? -/do-make-img a futuristic cityscape with neon lights +# Lock to a specific model (disables routing) +/lock-model openrouter/anthropic/claude-3.5-sonnet + +# Re-enable dynamic routing +/unlock-model ``` -### Template format +When locked, all prompts go directly to the specified model until `/unlock-model` is called. -```yaml ---- -description: Quick task — fast model, minimal thinking -model: openrouter/deepseek-v4-flash -restore: true ---- -$@ -``` +### What about `/do-*` commands? -Key frontmatter fields: -- **`model`** — provider/model-id or comma-separated fallback list -- **`thinking`** — off, minimal, low, medium, high, xhigh -- **`restore`** — (default true) restore previous model when done -- **`skill`** — auto-inject a skill -- **`deterministic`** — run a command/script before the LLM turn (e.g. `nix eval .#checks`) +The `/do-*` prompt templates are **no longer needed** for model selection. The smart-router handles all routing automatically. However, `/do-img` and `/do-make-img` are still available for image analysis/generation since those use specialized tool calls rather than just model selection. -### Adding new templates +### Configuration -Create a new `.md` file in `~/.pi/agent/prompts/` with frontmatter. The filename becomes the command name. Restart Pi or run any extension command to pick them up. +Model mappings are defined in `~/.agents/extensions/smart-router/index.ts`. To change which model a tag routes to, edit the `MODELS` table and run `/reload`. + +### Files + +| File | Purpose | +|------|---------| +| `~/.agents/extensions/smart-router/index.ts` | Extension source | +| `~/.pi/agent/extensions/smart-router/index.ts` | Synced copy (Gitea backup) | --- @@ -274,18 +267,8 @@ pi-mcp-adapter connects Pi to external services via the Model Context Protocol. | Command | What it does | |---|---| -| `/do-quick ` | ⚡ Fast model for everyday tasks | -| `/do-think ` | 🧠 Ultra model for deep analysis | -| `/do-check ` | 🔷 Pro model for code review | -| `/do-nix-check ` | ⚡ Nix-specific analysis | -| `/do-note ` | ⚡ Create Obsidian note with frontmatter | -| `/do-sort ` | 🔷 Classify file, suggest Obsidian folder | -| `/do-read ` | ⚡ Batch read and synthesize files | -| `/do-debug ` | 🧠 Complex NixOS/infra debugging | -| `/do-vault ` | 🔷 Obsidian vault setup and management | -| `/do-chat ` | ⚡ Conversation with web search | -| `/do-img ` | 🧠 Image analysis and description | -| `/do-make-img ` | ⚡ Generate image via OpenRouter (GPT/Image Mini, Gemini) | +| `/lock-model ` | Lock routing to a specific model (e.g. `openrouter/anthropic/claude-3.5-sonnet`) | +| `/unlock-model` | Re-enable dynamic prompt routing | | `/config-setup` | One-shot: creates `.pi/`, `settings.json`, memory vault in current folder | | `/config-add ext ` | Activate an extension from `~/.agents` | | `/config-add skill ` | Activate a skill from `~/.agents` | @@ -323,4 +306,5 @@ pi-mcp-adapter connects Pi to external services via the Model Context Protocol. - [ ] Add more prompt templates to `~/.pi/agent/prompts/` as needed - [ ] Verify video-extract works with Gemini - [x] Add markitdown skill to Obsidian skills page +- [x] Add smart-router extension and update Obsidian docs - [ ] Clean up workspace-map.json entries for any stale memory packs