fix(agent): restore temporary system_prompt override for invocations#1844
Closed
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Closed
fix(agent): restore temporary system_prompt override for invocations#1844giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Re-add system_prompt parameter to __call__, invoke_async, and stream_async. The override is applied only for the duration of the invocation and the original system prompt is restored in a finally block, even if the invocation raises. Uses a sentinel object to distinguish 'not provided' from explicit None, allowing callers to explicitly clear the system prompt for a single call. Fixes strands-agents#344 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Closing to reduce PR volume. Happy to resubmit individually if the team finds this fix useful. |
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.
Bug
After #289 removed kwargs spreading, there is no way to temporarily override the system prompt for a single agent invocation. Setting
agent.system_promptpermanently changes it, losing the original.Reported in: #344
Root cause
The
system_promptparameter was removed from__call__,invoke_async, andstream_asyncas part of the kwargs deprecation. Previously it flowed through kwargs into invocation_state, but it was never properly consumed as a temporary override — it just happened to be accessible.Fix
system_promptas a proper keyword parameter to__call__,invoke_async, andstream_async_UNSETsentinel to distinguish "not provided" from explicitNonetry/finallyblock around the invocationUsage
Testing
test_agent__call__passes_invocation_stateto verify system_prompt is now a proper parametertest_agent__call__temporary_system_prompt_override: verifies the override is active during the call and the original is restored afterFixes #344