Skip to content

Repository files navigation

Adaptive Reasoning Router / 自適應推理路由器

A lightweight Codex skill for stable task-level reasoning allocation, tamper-evident decision history, and honest savings estimates.

一個輕量的 Codex 技能,用工作單邊界管理 MEDIUMHIGHEXTRA_HIGH 推理投入,並提供可驗證歷程與誠實的節省估計。

Why / 為什麼需要它

Using the deepest reasoning level for every task wastes latency and quota. Switching levels after every tool result creates instability. This skill keeps HIGH as the default, changes level only at meaningful boundaries, and records enough evidence to measure whether routing actually helps.

每張工作單都使用最高推理層級會浪費時間與額度;每次工具輸出後切換又會造成震盪。 本技能預設維持 HIGH,只在工作單邊界或重大風險出現時切換,並留下可統計的證據。

Level Use / 用途
MEDIUM Fully specified, deterministic, low-risk work / 明確、機械式、低風險工作
HIGH Default engineering and project work / 預設工程與專案工作
EXTRA_HIGH Architecture, release, signoff, contradictory evidence, or major rework risk / 架構、發布、簽核、證據矛盾或重大重工風險

Why It Is Different / 核心優勢

Adaptive Reasoning Router is not just a reasoning-level selector. It combines stable task-boundary routing, validation-scope control, tamper-evident measurement, and honest cost estimation without running a background service.

**自適應推理路由器不只是推理層級選擇器。**它把工作單邊界判斷、驗證範圍控制、 防竄改歷程與誠實的成本估算整合在一起,而且不需要常駐服務。

  • Stable routing / 穩定路由: Keep HIGH as the default and re-evaluate at meaningful work-order boundaries instead of reacting to every tool result.
  • Two-way classification / 雙向判斷: Route deterministic low-risk work toward MEDIUM, and architecture, release, signoff, or conflicting evidence toward EXTRA_HIGH (xhigh in Codex host settings).
  • Validation-aware / 驗證範圍聯動: Pair reasoning policy with focused, domain, integration, or release validation so small changes do not automatically trigger full-project checks.
  • Auditable / 可稽核: Record outcomes, duration, retries, and transitions in a SHA-256 hash-chained JSONL history.
  • Honest measurement / 誠實量測: Keep measured duration and optional token data separate from counterfactual cost estimates, including unfavorable comparisons.
  • Lightweight and private / 輕量且重視隱私: Use no daemon or database, and do not record raw prompts, source code, or credentials.

The skill supplies a routing policy and instructs the agent to record decisions. It does not by itself guarantee that the Codex host changed its runtime reasoning setting; that depends on platform support. Likewise, decision records exist only when the bundled logger is invoked.

本技能提供路由政策並指示代理留下紀錄,但無法自行保證 Codex 宿主已切換實際推理設定; 這取決於平台支援。只有在呼叫內附記錄器時,才會真正寫入決策紀錄。

Features / 功能

  • Stable HIGH default with anti-oscillation rules.
  • Automatic project identification from explicit ID, environment, Git origin, or directory.
  • One shared JSONL log with SHA-256 hash chaining.
  • Per-project and combined summaries.
  • Duration, result, retry, transition, and optional token fields.
  • Relative-effort estimates against all-HIGH and all-EXTRA_HIGH baselines.
  • No daemon, service, database, or background process.
  • No raw prompts, source code, or credentials in the log.

Preliminary Pilot / 初步試行

An internal two-project pilot on 2026-07-18 produced:

  • 17 work orders started, 14 completed.
  • 14 completed results were PASS.
  • 14 HIGH, 3 EXTRA_HIGH, and 0 MEDIUM starts.
  • Estimated 30.88% lower relative effort than an all-EXTRA_HIGH baseline.
  • Estimated 10.59% higher relative effort than an all-HIGH baseline.
  • No measured token data.

These are preliminary counterfactual estimates, not measured token savings. The absence of MEDIUM samples means downgrade savings have not yet been demonstrated.

以上是初步反事實估計,不是實測 token 節省。由於尚無 MEDIUM 樣本,自動降級效益 仍未獲得證明。

Install / 安裝

Clone the repository, then copy the skill into your personal Codex skill directory.

Windows PowerShell:

$dest = Join-Path $HOME '.codex\skills\adaptive-reasoning-router'
New-Item -ItemType Directory -Force $dest | Out-Null
Copy-Item -Recurse -Force '.\skills\adaptive-reasoning-router\*' $dest

macOS or Linux:

mkdir -p ~/.codex/skills/adaptive-reasoning-router
cp -R skills/adaptive-reasoning-router/. ~/.codex/skills/adaptive-reasoning-router/

Start a new Codex task or reload the app. The skill allows implicit invocation and can also be called explicitly with $adaptive-reasoning-router.

Decision Log / 決策歷程

The default log is:

~/.codex/state/adaptive-reasoning-router/decisions.jsonl

Record a work order:

python skills/adaptive-reasoning-router/scripts/reasoning_log.py log \
  --project-id example-project \
  --task-id TASK-001 \
  --event START \
  --level HIGH \
  --reason "Normal engineering task" \
  --validation-scope FOCUSED

python skills/adaptive-reasoning-router/scripts/reasoning_log.py log \
  --project-id example-project \
  --task-id TASK-001 \
  --event END \
  --level HIGH \
  --reason "Focused validation passed" \
  --result PASS \
  --retries 0

Inspect the history:

python skills/adaptive-reasoning-router/scripts/reasoning_log.py verify
python skills/adaptive-reasoning-router/scripts/reasoning_log.py summary --json
python skills/adaptive-reasoning-router/scripts/reasoning_log.py history --limit 20

Estimation Model / 估計模型

Default relative weights:

MEDIUM      0.65
HIGH        1.00
EXTRA_HIGH  1.60

The weights are assumptions and can be overridden. Summaries explicitly mark the counterfactual as unmeasured. Confidence becomes PRELIMINARY at 10 work orders and OBSERVATIONAL at 30; neither label turns an estimate into measured usage.

Privacy / 隱私

Do not publish raw decision logs. They may contain project names and task descriptions. Share anonymized summary --json output after reviewing it. The repository ignores decisions.jsonl, lock files, caches, and virtual environments.

不要公開原始決策 log。分享前請審查並匿名化摘要,避免洩漏專案名稱與工作內容。

Test / 測試

python -m unittest discover -s tests -v

The tests cover hash-chain integrity, tamper detection, two-project aggregation, and savings calculations using temporary files only.

Community / 社群

Feedback is especially useful from software, hardware, EDA, research, and content production workflows. Please open an issue with anonymized aggregate results, routing failures, or a better calibrated cost model. Never attach proprietary prompts or logs.

歡迎軟體、硬體、EDA、研究與內容製作工作流提供匿名統計、錯誤路由案例或更好的成本 校正模型。請勿附上機密 prompt、原始碼或未匿名化 log。

License

MIT License. See LICENSE.

About

Stable reasoning-effort routing and privacy-safe decision metrics for Codex skills

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages