agentsclimarketplace

Cache identical fork prefix construction

Skill ychampion/cskill-agents/skills/cache-identical-fork-prefix-construction

Build forked conversation prefixes that stay identical across turns so prompt caching keeps working.From its SKILL.md

Install
npx -y skills add ychampion/cskill-agents --skill cache-identical-fork-prefix-construction

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

2.1 KB, 358 tokens by cl100k_base, as published. Nobody here has run it

SKILL: Cache Identical Fork Prefix Construction

Domain: caching Trigger: Use this when a forked agent must reuse the parent prompt cache and needs byte-identical prefixes for each invocation. Source Pattern: Distilled from reviewed subagent orchestration, isolation, and lifecycle implementations.

Core Method

Duplicate the parent assistant message wholesale, then generate a single user message containing standardized tool_result placeholders (all with the same text) followed by the directive text. Keeping every byte of the assistant message and placeholder deterministic ensures that identical tool_use sequences map to the same cache key. Build a child-specific directive message by wrapping it in <fork-boilerplate> and appending fork directive prefix before the per-worker instructions.

Key Rules

  • Never mutate the cached assistant message; copy it to a new object and only append the uniform tool_result blocks and directive text afterward.
  • Use identical placeholder text (Fork started — processing in background) for every tool_result so the child prefix byte stream stays constant across runs.
  • Append the directive text as the final block after the placeholders, ensuring fork children encode their own instructions without altering earlier bytes.
  • Provide the directive in the same build child message helper so the cached prefix always ends with the same sentinel.

Example Application

When the model triggers a fork from an inline agent, reuse this method to build the fork prompt so the fork shares the cache of the parent — future identical tasks reuse the same cached prefix and avoid redundant API calls.

Anti-Patterns (What NOT to do)

  • Do not recompute the assistant message or tool_result text differently per turn; any divergence breaks the cache key.
  • Avoid embedding random IDs or timestamps inside the prefix; keep only stable verbatim text before the directive block.

What ships with it: 1 file

883 B alongside SKILL.md

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.