-
Notifications
You must be signed in to change notification settings - Fork 569
feat(bedrock): add guardrail_last_turn_only option #1224
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
base: main
Are you sure you want to change the base?
Conversation
|
Related: #999 |
|
@aiancheruk Thank you for raising this PR! Could you refine the helper function a bit? Once that's done, I'll be happy to merge it. |
cb166a6 to
8cda99f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
src/strands/models/bedrock.py
Outdated
| and self.config.get("guardrail_id") | ||
| and self.config.get("guardrail_version") | ||
| ): | ||
| messages_for_request = self._get_last_turn_messages(messages) |
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.
In #999, it is suggested to wrap the latest user message in guardrailConverseContent to reduce cost and latency. What is implemented here though is a different approach that could affect response quality as the model is given less context.
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.
I see, thanks for pointing this out. Updated
…en feature flag is true
Description
This PR adds a new guardrail_last_turn_only parameter to the BedrockModel that allows users to send only the last conversation turn (the most recent user message and assistant response) to AWS Bedrock Guardrails for evaluation, instead of the entire conversation history.
Key changes:
guardrail_last_turn_only: bool = Falseparameter toBedrockConfig_get_last_turn_messages()helper method to extract the last turn from conversation history_format_request()to use filtered messages whenguardrail_last_turn_only=TrueBenefits:
Related Issues
#999
Documentation PR
strands-agents/docs#340
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.