-
Notifications
You must be signed in to change notification settings - Fork 154
feat: Add dynamic system prompt override functionality #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Modified Agent._execute_event_loop_cycle() to support system_prompt parameter override - Enables per-call system prompt customization via agent('Hello', system_prompt='Custom prompt') - Maintains backward compatibility with existing agent configurations - Added comprehensive test suite with 8 test cases covering all scenarios - Resolves GitHub issue strands-agents#103
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Shubhamraut01, thank you for your contribution!
A couple of comments on the changes. Please also use the pull request template as it includes some extra useful details about clarifying how the changes have been tested, along with some other information.
…ide.py into a single comprehensive test function test_agent_system_prompt_overrides_all_cases() in test_agent.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
Thanks for reviewing my PR.
I have done the needful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates @Shubhamraut01.
A couple of small comments and then we'll get this merged 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great to me!
Thank you for your contribution and making your first contribution! 🚀
You're welcome — glad to be part of it! Excited for more contributions ahead! 🚀 |
…cution_handler, event_loop_metrics, callback_handler, tool_handler, messages, tool_config)
@awsarron I think it looks good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last couple of nits and then we'll merge this. Thank you so much @Shubhamraut01 !
Works great, I gave it a test locally as well
Welcome @awsarron, Sounds Good. I have done the final changes. |
Awesome, thank you @Shubhamraut01. We'll get these improvements published in the next SDK release 🚀 |
Thank you so much @awsarron and @cagataycali ! 🎉 I'm thrilled to have contributed to the Strands SDK and excited to see these system prompt override improvements help developers build more flexible and dynamic AI agents. |
* models - openai - argument none (#97) * docs(readme): add open PRs badge + link to samples repo + change 'Docs' to 'Documentation' (#100) * docs(readme): add logo (#101) * docs(readme): add logo, title, badges, links to other repos, standardize headings (#102) * style(readme): use dark logo for clearer visibility when system is using light color scheme (#104) * fix(readme): use logo that changes color automatically depending on user's color preference scheme (#105) * feat(handlers): add reasoning text to callback handler and related tests (#109) * feat(handlers): add reasoning text to callback handler and related tests * feat(handlers): removed redundant comment in .gitignore file * feat(handlers): Updated reasoningText type as (Optional[str] * feat: Add dynamic system prompt override functionality (#108) * Modularizing Event Loop (#106) * fix(telemetry): fix agent span start and end when using Agent.stream_async() (#119) * feat: Update SlidingWindowConversationManager (#120) * v0.1.5 --------- Co-authored-by: Patrick Gray <pgrayy@amazon.com> Co-authored-by: Gokhan (Joe) Gultekin <joseph.gueltekin@gmail.com> Co-authored-by: Shubham Raut <shubhamrao12321@gmail.com> Co-authored-by: fede-dash <fede.kamelhar@doordash.com> Co-authored-by: Nick Clegg <nac542@gmail.com>
System Prompt Override Implementation - Resolves Issue #103
Description
This PR implements the system prompt override functionality requested in issue #103, allowing users to dynamically override the system prompt on a per-call basis when invoking an agent. The implementation preserves backward compatibility while enabling powerful new use cases for dynamic prompt management.
Key Changes:
Agent._execute_event_loop_cycle()
to extractsystem_prompt
from kwargs with fallback to instance valuekwargs.pop("system_prompt", None)
behavior that ignored user overridesBefore:
After:
Related Issues
Fixes #103 - [BUG] Agent.call() removes kwargs preventing dynamic system_prompt override
Documentation PR
N/A - This is a bug fix with enhanced functionality, no separate documentation changes required.
Type of Change
This change is both a bug fix (resolving the ignored kwargs) and a new feature (enabling dynamic system prompt override functionality).
Testing
Automated Testing
hatch fmt --linter
- ✅ All linting checks passhatch fmt --formatter
- ✅ Code formatting verifiedhatch test --all
- ✅ Full test suite passesImplementation Testing
Test Coverage includes:
system_prompt=None
parametersystem_prompt=""
parameterTest Results:
Manual Testing Examples
Real-World Use Cases Enabled
Checklist
Technical Implementation Details
Core Changes in
src/strands/agent/agent.py
Before (Problematic):
After (Fixed):
Test Implementation
Added comprehensive test function
test_agent_system_prompt_overrides_all_cases()
intests/strands/agent/test_agent.py
:Backward Compatibility
This change is 100% backward compatible:
Performance Impact
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.