feat: add staticInstructions for multi-block Anthropic prompt cache o… - #52
realjimhamilton wants to merge 1 commit into
Conversation
…ptimization Adds optional staticInstructions field to AgentInputs that enables separating static system instructions from dynamic content for Anthropic prompt caching. When staticInstructions is provided and promptCache is true, buildSystemRunnable() creates two content blocks: the static portion with cache_control (cached and shared across users) and the dynamic-only remainder without cache_control (sent fresh each request). This dramatically improves cache hit rates in multi-user deployments where agents have large static base prompts (~90K tokens) but small per-user dynamic context (~5-15K tokens). Changes: - Add staticInstructions to AgentInputs interface (types/graph.ts) - Add staticInstructions property, constructor param, and fromConfig() (AgentContext.ts) - Add multi-block cache logic in buildSystemRunnable() with dynamic content extraction - Fully backwards compatible: field is optional, single-block behavior unchanged when not provided Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks for the contribution here. We ended up implementing this path more broadly in #128, so I am going to close this PR as superseded. This PR introduced a new So the idea is appreciated, but #128 is the more complete implementation we will review and carry forward. |
…ptimization
Adds optional staticInstructions field to AgentInputs that enables separating static system instructions from dynamic content for Anthropic prompt caching.
When staticInstructions is provided and promptCache is true, buildSystemRunnable() creates two content blocks: the static portion with cache_control (cached and shared across users) and the dynamic-only remainder without cache_control (sent fresh each request).
This dramatically improves cache hit rates in multi-user deployments where agents have large static base prompts (~90K tokens) but small per-user dynamic context (~5-15K tokens).
Changes:
Add staticInstructions to AgentInputs interface (types/graph.ts)
Add staticInstructions property, constructor param, and fromConfig() (AgentContext.ts)
Add multi-block cache logic in buildSystemRunnable() with dynamic content extraction
Fully backwards compatible: field is optional, single-block behavior unchanged when not provided