🚀 Quick Start
- Install:
omp plugin install omp-cache-optimizer. - Reload: Run
/reloadin OMP to refresh extension hooks. - Verify: Run
/cache-optimizer doctorto confirm model/provider/compat status. - Check Stats: Run
/cache-optimizer statsfor session-scoped hit rates after a few turns.
🔧 Configuration
- Environment Variables: Opt-out via
PI_CACHE_OPTIMIZER_NO_PROMPT_REWRITE=1,PI_CACHE_OPTIMIZER_NO_SKILL_COMPRESSION=1, orPI_CACHE_OPTIMIZER_NO_OPENAI_CACHE_KEY=1. - Models YAML (
~/.omp/agent/models.yml):providers: your-provider: compat: supportsLongPromptCacheRetention: true # Only if endpoint explicitly supports OpenAI long retention - Commands: Use
/cache-optimizer fixto generate copyable YAML compat snippets. Useenable/disablefor process-level toggles.
📦 Dependencies
- Designed for Oh My Pi (OMP) runtime.
- Forked from
pi-cache-optimizer(adapted from JSONC to YAML, shifted state directories).
💡 Best Practices
- Prompt Stabilization: The optimizer automatically moves stable system prompt content ahead of dynamic contexts. It also compresses verbose skill XMLs to maximize static token prefix matching.
- OpenAI Cache Keys: Rely on the automatic
prompt_cache_keyfallback injection (using session id) for OpenAI-compatible APIs missing explicit keys. - Router Integration: Extension authors should pass real upstream identity via assistant message metadata (
provider,responseModel,usage.cacheRead/cacheWrite). This avoids importing the optimizer while gaining accurate footer stats. - Session Affinity: Rely on OMP’s multi-credential auth and
agent.dbfor session stickiness instead of legacy headers.
🚨 Gotchas / Anti-patterns
- Proxy Splitting: Proxies like LiteLLM/OneAPI often route identical sessions to different backend nodes. This shatters provider-side prompt caching.
- 400 Errors: If you see
400 Unsupported parameter: prompt_cache_retention, instantly removesupportsLongPromptCacheRetention: truefrom your models config. - Obsolete Fields: NEVER use
sendSessionAffinityHeaders,sendSessionIdHeader, orforceAdaptiveThinking. OMP natively handles session affinity and adaptive thinking detection. - DeepSeek Formatting: Do NOT manually configure
thinkingFormat: "deepseek". OMP automatically detects the reasoning format. - Manual Fixes Required: The
/cache-optimizer fixcommand currently lacks automatic YAML writing. You must manually copy and paste the suggested overrides.
🔍 Research / References
- Source: npm package
omp-cache-optimizer(v1.0.7). - Stats Location:
~/.omp/agent/omp-cache-optimizer-stats.json.