You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(prompt): split static system prompt from dynamic env reminder for cache hits
Pi-ai applies Anthropic-style cache_control to our entire system prompt,
but it was one block — date / cwd / git status all baked in. Every git
edit or day rollover blew the cache, costing full input tokens on every
turn.
Move the dynamic environment block out of the system prompt entirely:
- buildSystemPrompt() now produces only static content (identity, tone,
anti-patterns, verification, conversation conventions, task checklist,
available tools). Byte-stable across sessions for the same tool set.
- buildEnvironmentReminder() produces a <system-reminder> block with
cwd, platform, host, date, and git branch + dirty file summary.
- App.tsx prepends the env reminder to the user's text on the first
agent turn of each session (detected by zero assistant messages in the
transcript). Subsequent turns inherit it via cached conversation
history. Resumed sessions skip injection — the saved env from the
previous session is already in the loaded transcript.
- runPlanFlow accepts an optional envReminderForFirstTurn that gets
glued onto the buildAgentPrompt() output before bundle.agent.prompt(),
same shape as the direct path.
Cache impact: on a long coding session the system prompt was rebuilt
into the request every turn but cache-broken whenever git status
changed. Now it stays in cache for the full 5-minute ephemeral TTL
across every turn AND across sessions if the user reopens within the
window. Estimated 30-50% reduction in billed input tokens on long
sessions per our cost projections.
0 commit comments