Recursive router

From try-works/role-model · View interactive version

Recursive router is an AI agent skill from the GitHub repository try-works/role-model. Use when recursive-mode needs to route delegated audit, review, or bounded implementation work through external transports, CLIs, and models while preserving controller verification and fallback behavior.

How to use this skill

Skill file

recursive-router

Use this skill when recursive-mode and recursive-subagent have already established a delegated role and you want the route to be driven by a user-editable CLI/model policy instead of ad hoc controller choice.

This skill does not relax recursive-mode. Routed external output is still untrusted until the main agent verifies it against actual files, actual diffs, and actual recursive artifacts.

Controller Boundary

The main orchestrator remains the model the user is currently interacting with in their CLI, IDE, or agent session.

recursive-router does not become a second orchestrator or a second workflow spec. It only helps the current controller choose and invoke an external CLI/model for a bounded delegated role.

The current controller remains responsible for:

Invocation Boundary

Router setup, local CLI discovery, and route reconfiguration are opt-in because those operations may inspect local CLI installs plus provider/model configuration on the user's device. Only run init, probe, configure, or other discovery/configuration steps when routing has been explicitly requested or an already active routed policy needs a refreshed inventory to execute.

Valid explicit routing examples include phrases containing:

When that kind of language appears for new setup, ask the user first whether they want to set up model routing between providers for this repo. Do not inspect local device state or modify routing policy for a new setup until the user confirms.

If the user declines or only wants an explanation of router behavior, do not inspect the local device and do not modify routing policy.

Once the user has explicitly requested routed delegation, or the selected canonical role already has an active configured external route, the router is in scope and the controller should not ask again whether to use it for that delegated slot. An active configured external route means the role has enabled: true, mode: "external-cli", a non-null cli, and a non-null model in /.recursive/config/recursive-router.json, or the user supplied an explicit route binding for that role.

If recursive-router-resolve returns external-cli, dispatch through recursive-router-invoke. Local/self-audit execution is only an acceptable substitute when the effective route resolves to fallback-local, local-only, blocked, or ask-user, and that route outcome must be recorded in the phase artifact or subagent action record. The controller may reject routed output after verification and repair locally, but it must record that rejection/repair instead of treating the local repair as proof that the routed role performed the assignment.

If recursive-router-invoke returns success: false or a nonzero exit_code, treat that routed attempt as failed even when output_text contains useful assistant text. Preserve the output as diagnostic evidence, record the failed attempt, then repair the prompt/context or ask the same routed role to fix the reported issue and retry. Do not accept the routed role, mark a phase gate PASS, or claim tester/implementer/reviewer completion from a nonzero-exit attempt.

Purpose

Use recursive-router to:

Trigger Examples

Canonical Paths

Canonical scripts are recursive-router-*.

Legacy recursive-router-cli-* script names still exist only as compatibility wrappers; prefer the canonical names in new controller flows and docs.

Canonical Roles

orchestrator is explicit in the router policy so the controller role is visible in the same config surface, but it should remain local-only with fallback local-controller by default. It owns final integration, repair, and acceptance: other routed roles can propose bounded work, but the orchestrator must fix any defects they leave behind and make sure all required gates pass.

Legacy compatibility aliases still resolve to these stage-aligned roles:

Read Order

  1. Read /.recursive/RECURSIVE.md.
  2. Read /skills/recursive-subagent/SKILL.md.
  3. Read /.recursive/config/recursive-router.json.
  4. Read /.recursive/config/recursive-router-discovered.json.
  5. Read /.recursive/memory/skills/SKILLS.md plus any relevant delegated-review or capability notes when the phase is capability-sensitive.

recursive-mode and recursive-subagent still own phase sequencing, audit standards, review-bundle rules, and acceptance criteria. Do not restate or weaken those here.

Required Behavior

Discovery

Use the router scripts to initialize, probe, validate, and resolve routing:

python ./scripts/recursive-router-init.py --repo-root .
python ./scripts/recursive-router-probe.py --repo-root . --json
python ./scripts/recursive-router-configure.py --repo-root . --set code-reviewer=codex:gpt-5.4-mini --json
python ./scripts/recursive-router-invoke.py --repo-root . --role code-reviewer --prompt-file "./.recursive/run/<run-id>/router-prompts/code-reviewer-bundle.md" --json
python ./scripts/recursive-router-validate.py --repo-root .
python ./scripts/recursive-router-resolve.py --repo-root . --role code-reviewer --json
pwsh -NoProfile -File ./scripts/recursive-router-probe.ps1 -RepoRoot . -Json
pwsh -NoProfile -File ./scripts/recursive-router-configure.ps1 -RepoRoot . -Set code-reviewer=codex:gpt-5.4-mini -Json
pwsh -NoProfile -File ./scripts/recursive-router-invoke.ps1 -RepoRoot . -Role code-reviewer -PromptFile "./.recursive/run/<run-id>/router-prompts/code-reviewer-bundle.md" -Json

Built-in discovery targets are:

Built-in model discovery sources are:

For opencode, router discovery should use the CLI's configured/authenticated provider and model inventory, so the routed model choices come from the user's real opencode setup rather than a hardcoded list.

For opencode, provider-qualified model ids such as github-copilot/... and opencode/... are valid routed targets when they appear in the authenticated inventory.

For codex, routed transport should prefer the native app-server protocol rather than codex exec when a downstream dispatcher needs to actually send a prompt.

Do not rely on a nonexistent top-level codex model command for automation. For manual spot checks, codex exec -m <model> is useful, but discovery authority should still come from app-server model/list.

For kimi, do not treat /model as an automation surface. /model is an in-session interactive picker, not a top-level discovery command, and routed config must use invocable alias keys rather than the raw underlying model slug.

Launcher details can differ across operating systems, shells, and devices. Treat the built-in adapter commands as defaults only. If the real local launcher or invocation shape differs, explore the environment first and then record that machine-specific binding in cli_overrides for a built-in CLI or custom_clis for a fully custom adapter instead of hardcoding a repo-wide path or wrapper assumption.

Custom CLIs may also be defined in the routing policy.

Policy timeout behavior:

Windows launcher notes learned from live routing

Recommended Routing Workflow

  1. Run init if the repo does not already have router config scaffolding.
  2. Run probe and inspect /.recursive/config/recursive-router-discovered.json.
  3. Ask the user for any unresolved role bindings in compact role=cli:model form.
  4. Apply the requested bindings with recursive-router-configure.py or .ps1 so each route is verified before save.
  5. Build or refresh the canonical review bundle or routed prompt bundle for the exact delegated assignment using the contract from recursive-subagent.
  6. From the same repo/worktree that will dispatch the role, ensure /.recursive/config/recursive-router.json and /.recursive/config/recursive-router-discovered.json are present and current. Discovery inventory is local and may be untracked, so refresh or copy it before resolving a route in a new worktree.
  7. Run resolve for the specific role immediately before delegated execution so fallback behavior stays current with the live environment.
  8. If the decision is external-cli, dispatch the bounded assignment with recursive-router-invoke.py or .ps1, capture metadata/output paths, then verify the result against the real repo state before any acceptance.
  9. If the invocation failed, repair the context or dispatch prompt and rerun the same routed role. When the subagent output identifies issues it can fix, the controller should explicitly instruct that routed role to fix them within its bounded ownership, then rerun controller verification and the routed check.

Prefer the configure script over hand-editing policy whenever the controller is making the change, because configure-and-verify prevents bad or stale bindings from being saved silently.

Prefer the invoke script over bespoke shell snippets or one-off helper scripts when the controller actually dispatches routed work. That keeps the route resolution, launcher selection, transport handling, and output capture on the repo-supported path.

Delegation Payload Shape

The router should pass a concise dispatch prompt that references the real recursive artifacts rather than duplicating them. Typical payload ingredients are:

The router's job is to route that bundle to the selected CLI/model and return the output. The router should not invent substitute workflow rules.

User Prompting

When a routed role is unresolved, present a compact role-based question that cites:

Example prompt:

I found these CLIs in this environment:
- codex (available, version 1.2.3)
- kimi (available, version 1.32.0)

Please choose a CLI and model for these roles in /.recursive/config/recursive-router.json.
For valid CLI ids and model ids, check /.recursive/config/recursive-router-discovered.json.

Unresolved roles:
- analyst
- code-reviewer

Valid compact answers:

analyst=codex:gpt-5
code-reviewer=kimi:kimi-code/kimi-for-coding

After the user answers, prefer recursive-router-configure.py or .ps1 with one or more --set role=cli:model bindings. The configure command must verify each proposed route by sending a live prompt to the selected model before it writes /.recursive/config/recursive-router.json. If any verification fails, do not save partial changes. If the user edited the policy file directly, reread it instead of overwriting those manual edits blindly.

Verification guidance learned from live routing:

Fallback Behavior

Routing decisions may resolve to:

Fallbacks must be explicit and auditable. Do not silently drop from routed delegation to a local path without recording why.

Auditability

When routed delegation is used or attempted, phase artifacts and action records should record:

Use scripts/recursive-subagent-action.py or .ps1 to capture routed action-record details such as:

Store routed assistant output, raw stdout/stderr transcripts, and invoke metadata under the run evidence tree, for example /.recursive/run/<run-id>/evidence/router/. Keep initial prompt bundles under a run-scoped prompt-bundle location such as /.recursive/run/<run-id>/router-prompts/ and cite them as Prompt Bundle Path. Do not bootstrap top-level /.recursive/router-prompts/ in reusable repos. Do not store raw transcripts directly under /.recursive/run/<run-id>/subagents/; every Markdown file in subagents/ is a canonical subagent action record and must satisfy the action-record schema. The action record may cite transcript and metadata files from evidence/router/.

When routed prompts are sensitive to exact sectioning or citations, prefer a durable prompt bundle that includes:

Warnings

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.