ai-gateway-loop-optimization
Skill17 starsChanged 6 days agoMITView on GitHub
Optimize AI Gateway provider-loop latency, retries, tool amplification, or cache cost using before/after evidence from the same live workload. Not for general API features or UI-only diagnosis.
In this repository13 other files it gives its agents.
- .changelog.d/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- clean-codeSkill
- console-e2eSkill
- console-handoffSkill
- console-performanceSkill
- design-sweepSkill
- git-worktreeSkill
- learning-harvestSkill
- product-proposalSkill
- pr-workflowSkill
- rebase-on-canarySkill
- release-version-updateSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use observe → one optimization → controlled remeasurement → falsification.
- Distinctive: line 20
Before baseline, read Measurement.
- Very specific: line 22
Before editing, read Optimization and verification.
- Distinctive: line 24
Run relevant package tests, typecheck, build, and git diff --check.
- Distinctive: line 30
Read Reporting and gotchas when interpreting results.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AI Gateway Loop Optimization
Use observe → one optimization → controlled remeasurement → falsification. Deliver more than a patch: reproducible evidence of which layer changed and whether the caller contract survived.
Inputs and experiment contract
Choose the exact provider/model and effort, a short workload (usually 3–5 logical operations), a symptom hypothesis, and trial count. Default to 5 successful trials before and after. Report changed sample sizes and excluded fixture failures.
Read Execution surface and use the smallest suitable path. For router/provider-loop behavior alone, use the standalone runner or built adapter without Console. When caller transcripts matter but Console does not, use the headless launcher path in console-e2e's live-agent reference; use a real Objective only when auxiliary turns or host lifecycle matter.
The live runner's confirmation flag consents to real quota use. Never add live calls to default test/CI paths. Raw wire contains sensitive prompt/tool payloads; collect it in scratchpad only with explicit authorization. Never record credentials.
Execution decisions
- Before baseline, read Measurement. Freeze literal model/effort, prompt, tool catalog/permissions, model-visible cwd/revision, turn-dispatch policy, logging, trial count, and success criteria. A changed condition or model mutation of the frozen tree invalidates that controlled comparison.
- Observe only existing layers. Separate caller executions, provider requests/retries, replay history, and host auxiliary turns. Do not report nonexistent standalone transcripts/lifecycle as zero. Record counts with denominators.
- Before editing, read Optimization and verification. State candidates as
observed symptom → smallest change → expected delta → failure mode; change one thing per round. Wire size alone does not prove waste. Preserve provider stateless/retry/permission/tool contracts. - Implement at the owning layer. Test positive and near-match negative cases, affected retry/cancellation/correlation behavior, and privacy boundaries. Repeat the baseline and challenge attribution with relevant failures, auxiliary turns, and repeated/concurrent cases. Use direct-adapter probes or focused tests for shapes the runner cannot express.
- Run relevant package tests, typecheck, build, and
git diff --check. Add dependent Console build/restart only for Console wiring or real Objective changes. Repair task-induced regressions and reverify under the same conditions.
Completion
Finish when the target improves, caller calls/results/errors, permissions, and final result are preserved, and falsification checks pass. Also stop when evidence proves remaining cost belongs to a required upstream/host contract; report why it is not removable. Do not continue merely because a number is large.
Read Reporting and gotchas when interpreting results. Report before/after metrics, request ownership, frozen conditions, sample/exclusions, stable invariants, verification, and unknowns. Verify router/server cleanup for standalone runs; clean up only owned Console/agent processes for real Objectives.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

