Repository navigation
Conversation
The sanitizer from lanl#339 removes unanswered trailing prompts by keeping only the last human message after the last reply. With no reply yet the whole history is the tail, so the first request of every ChatAgent conversation, and any caller-supplied leading system message, reaches the model without its system prompt, and a history holding only a system prompt becomes an empty request. Red first: four cases fail on main; three guards pin the cleanups lanl#339 intended.
…tory _sanitize_history treats everything after the last reply as unanswered trailing prompts and keeps only the last human message. A history with no reply yet made the whole list the tail, so the leading system prompt was dropped from the first request of every conversation (ChatAgent, and any caller-supplied system message) since lanl#339. The leading system message is now held out of the tail computation; duplicate trailing prompts still collapse and mid-list system messages are still dropped.
Contributor
Author
|
CI note: the Windows job's single failure is |
This branch has not been deployed
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.
Summary
Fixes #372. Since #339,
_sanitize_historydrops the leading system prompt from any history that has no reply yet, so the first request of everyChatAgentconversation started throughformat_query(the TUI path for its default agent) and any caller-supplied leadingSystemMessagereach the model without it. The "unanswered trailing prompts" step computes the tail from the lastAIMessageorToolMessage; with no reply the tail is the whole list and only the lastHumanMessagesurvives. Present in v0.17.1 and v0.17.2; absent in v0.17.0.The change
A leading
SystemMessageis held out of the tail computation and put back in front:head + body[:last_reply + 1] + kept prompt. Everything #339 intended is preserved: duplicate trailing prompts still collapse to the last one, now also on a first turn when a caller holding its own state retries, and mid-list system messages are still dropped. A history holding only a system prompt is returned as is instead of becoming an empty request. The hunk inbase.pyis six insertions and three deletions, with no signature change and no change to any caller.Tests
tests/agents/test_sanitize_history.py, committed red first and flipped by the fix with no test edits. Four fail on main: the firstChatAgentrequest keeps its system prompt (it washumanonly), a caller-supplied leadingSystemMessagesurvives the first call, a first-turn duplicate prompt collapses while the prompt stays, and a system-only history is left alone (it became empty). Three guards pass throughout: trailing duplicates after a reply still collapse, mid-list system messages are still dropped, and a history without a system prompt keeps only its last prompt. Running the test commit without the fix commit gives exactly 4 failed / 3 passed. Full suite locally with the dev dependencies installed: 1124 passed, 6 skipped, 1 xfailed (the pinned #295 case).