Repository navigation
Write agent guidance as a prompt section to keep the prompt cache - #118
Merged
Merged
Conversation
A returned systemPrompt makes Pi resend the whole leading prompt on every run. When another prompt section changes mid-session, the leading prompt changes too, and the provider re-writes the whole conversation to its prompt cache. A prompt section lets Pi append a small delta instead. Fixes mavam#117
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #117.
Change
before_agent_startnow writes the agent guidance toevent.systemPromptOptions.sections["pi-agents"]instead of returning a fullsystemPrompt.A returned
systemPromptforces Pi to resend the whole leading system prompt on every run. When any other section changes in the middle of a session (for example, MCP servers that finish connecting), the leading prompt changes, and Anthropic re-writes the system block and the full conversation history to the prompt cache. With a section, Pi keeps the leading prompt and appends a small transcript delta.Verification
bun run check: typecheck passes, 254 pass / 0 fail. Biome reports the same 2 warnings asmain.claude-opus-5-5, RPC session that spawns one subagent and gets its result). I logged a hash of each system block per request:<pi-agents>guidance is still in the prompt.A changelog entry is in
changelog/unreleased/.