Skip to content

Conversation

@aiancheruk
Copy link

@aiancheruk aiancheruk commented Nov 21, 2025

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:

  • Added guardrail_last_turn_only: bool = False parameter to BedrockConfig
  • Implemented _get_last_turn_messages() helper method to extract the last turn from conversation history
  • Modified _format_request() to use filtered messages when guardrail_last_turn_only=True
  • Added comprehensive unit tests for the helper method and request formatting
  • Added integration tests to verify the feature works end-to-end with AWS Bedrock Guardrails

Benefits:

  • Reduces token usage and costs when using guardrails
  • Enables conversation recovery after guardrail interventions (blocked content in history won't block future messages)

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

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aiancheruk
Copy link
Author

Related: #999

@JackYPCOnline JackYPCOnline self-requested a review December 17, 2025 17:12
@JackYPCOnline
Copy link
Contributor

JackYPCOnline commented Dec 17, 2025

@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.
Update: I'll update the PR based on your code to expedite the merge.

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants