← Belső rendszer fejlesztők adatlapja

Skill · 1.0.0 verzió

AI-token-, cache- és költségkezelés

Csökkenti a felesleges modellkontextust és fizetős használatot a feladat, elszámolás és keret tisztázásával.

token-cache-cost

Ezt a skillt használó csapattagok

Nézd meg, miben segít

Mikor hasznos?

Akkor használd, ha ügynökfutás nagy kontextust vagy eszközeredményt ismételten küld.

Miben segít neked?

  • Újrahasználhatóan tartja a stabil promptkezdetet, külön kezeli a változó tartalmat.
  • Korlátozza az eszközeredményt, csak szükséges eszközleírást tölt.
  • Rögzített használattal és érvényesíthető kerettel veti össze a modellválasztást.

Például ezt kérheted

Elemezz drága kódolási futást, csökkentve az ismételt naplót a szükséges tények megőrzésével. Ugyanazt a vizsgálatot teljes naplóval és korlátos kivonattal vesd össze. Maradjanak hibaazonosítók és nyitott döntések, majd közöld a mért költség- és minőségeltérést.

Részletes dokumentáció

Itt a skill eredeti útmutatóját, példáit és ellenőrzési szempontjait olvashatod az eredeti nyelven.

Részletek…Összecsukás

Token, Cache & Cost Optimization

In multi-turn agent loops, input tokens grow quadratically ($O(T^2)$) with turn count $T$ because the full conversation history and tool definitions are re-sent on every step. Controlling agent cost and latency requires high prompt-cache hit rates, disciplined tool-output shaping, and right-sized model routing.

Maximizing Prompt Cache Hit Rates

Provider KV-cache reuse (Anthropic cache_control, OpenAI automatic prefix caching, Gemini context caching) cuts input token cost by 75–90% and drastically reduces Time-To-First-Token (TTFT), but a single mutated token near the top of the prompt invalidates the entire downstream cache prefix:

Common Cache-Busting Anti-Pattern Fix
Injecting Current time: 2026-10-20T04:01:12Z or per-turn counters in the system prompt Keep the system prompt 100% static; pass dynamic timestamps or turn metadata in the final user/tool turn (or round dates to the day if needed globally).
Non-deterministic Object.keys() or dynamic registration order of tools Sort tool definitions and JSON Schema properties deterministically by name before serialization.
Toggling tools on/off inside the tools array on every turn Keep the core tools array stable across a phase, or place volatile deferred tools after explicit cache breakpoints.
Rewriting or re-summarizing the entire message history on every turn Append-only during normal turns; compact only when crossing a high-water threshold (e.g., 75% window) so the prefix stays cached for many consecutive turns.

Tool Output & Schema Token Discipline

  1. Bound tool outputs at the source: A single unfiltered grep, DOM dump, or log file read can inject 50,000 tokens that get re-billed on every subsequent turn of the run. Enforce strict maxLines / maxBytes, return structured summaries with line numbers, and let the agent fetch targeted slices on demand.
  2. Lazy / deferred tool schemas: When an agent has access to dozens of MCP or domain tools, avoid injecting 20,000 tokens of JSON Schema on turn 1 if only 5 core tools are routinely used. Provide a compact catalog or search/discovery tool (defer_loading: true / schema lookup) and load full schemas only when needed.
  3. Concise structured intermediate turns: Instruct subagents and internal classification steps to emit compact JSON or terse bulleted findings rather than verbose conversational boilerplate.

Tiered Model Routing & Reasoning Effort

Match model capability and reasoning effort (low | medium | high) to the cognitive complexity of each step:

  • Frontier / High-Effort Model: Architecture design, multi-file root-cause diagnosis, subtle concurrency/security review, and complex orchestration planning.
  • Mid-Tier / Standard-Effort Model: Routine code implementation following an approved plan, standard tool-calling workflows, and structured test generation.
  • Fast / Lightweight Model: Context compaction summaries, query expansion, log/file triage, classification, and schema formatting.

Cost Accounting & Budget Circuit Breakers

Compute exact cost per turn from the provider's normalized usage object: $$\text{Cost}{\text{turn}} = I{\text{uncached}} \cdot P_{\text{in}} + I_{\text{cache_write}} \cdot P_{\text{cw}} + I_{\text{cache_read}} \cdot P_{\text{cr}} + O_{\text{total}} \cdot P_{\text{out}}$$ Track cache_hit_ratio = cache_read_input_tokens / (input_tokens + cache_read_input_tokens + cache_creation_input_tokens) in telemetry. Alert when cache hit ratio drops below expected baselines (typically $> 75%$ on multi-turn agent loops) and enforce hard per-run token and USD ceilings.

Csomagban lévő fájlok 1

  • SKILL.md