Repository navigation
fix(agent-runtime): keep the context budget reminder out of the prefix - #2464
Merged
Merged
Conversation
pi-ai folds every system message into the leading system message for adapters without mid-conversation system support, which is the default for custom OpenAI-compatible endpoints. The context_budget section therefore rewrote the request head, so a 72-token reminder discarded a 200k-token prefix cache (TTFT 5 s -> 184 s on a local endpoint). Such models now receive the reminder as a request-only user message at the tail; models that keep system messages in place keep the existing section. The legacy systemPrompt append is dropped: the agent loop has ignored context.systemPrompt since the transcript-based pi 1.5 core. fixes #2458
Deploying pi-desktop with
|
| Latest commit: |
f985f41
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e59b5a5b.pi-desktop.pages.dev |
| Branch Preview URL: | https://fix-context-budget-prefix-ca.pi-desktop.pages.dev |
The source contract still expected the reminder to be a system section unconditionally. It now asserts the split by mid-conversation support and that the systemPrompt append is gone. refs #2458
2 tasks done
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 #2458
Root cause
On pi 1.5.2 the agent loop builds each request from
normalizeContext({ messages });context.systemPromptis no longer read, so thesystemPromptappend the issue points at is dead code. The real prefix rewrite is the trailingcontext_budgetsystem section: every adapter withoutsupportsMidConvoSystemMessages(the default for custom OpenAI-compatible endpoints, e.g. Strata / llama-server) runscollapseSystemMessages, which folds all system messages into the leading system message. The 72-token reminder therefore lands at token 0 and invalidates the whole prefix cache.Fix
context_budgetsection that expires at the next checkpoint.usermessage at the tail (same path as steering); it is not persisted and not carried into the next run.systemPromptappend.Tests
packages/agent-runtime:tsc --noEmitpasses,vitest run2062/2062 passes.Not changed: the
SILENT_TURN_NUDGErerun still rewrites the runtime section; it is a rare one-shot recovery path and is left for a separate change.