powertools-lambda-python icon indicating copy to clipboard operation
powertools-lambda-python copied to clipboard

feat(bedrock_agents): add optional fields to response payload

Open anafalcao opened this issue 9 months ago • 2 comments

Issue number:

Summary

Changes

This PR introduces the new BedrockResponse class to support custom Amazon Bedrock Agent responses.

  1. BedrockResponse class with support for:
    • Session attributes
    • Prompt session attributes
    • Knowledge base configurations
  2. Type-safe implementation with proper validation
  3. Example showing how to use BedrockResponse with Bedrock Agents in the documentation

User experience

response = BedrockResponse(
    body={"message": "Hello from Bedrock!"},
    session_attributes={"user_id": "123"},
    prompt_session_attributes={"context": "testing"},
    knowledge_bases_configuration=[
        {
            "knowledgeBaseId": "kb-123",
            "retrievalConfiguration": {
                "vectorSearchConfiguration": {"numberOfResults": 3, "overrideSearchType": "HYBRID"},
            },
        },
    ],
)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • [ ] Migration process documented
  • [ ] Implement warnings (if it can live side by side)

Acknowledgment

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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

anafalcao avatar Mar 24 '25 19:03 anafalcao

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.12%. Comparing base (8883b1e) to head (0d2921b). Report is 18 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #6336   +/-   ##
========================================
  Coverage    96.11%   96.12%           
========================================
  Files          253      253           
  Lines        12086    12104   +18     
  Branches       898      902    +4     
========================================
+ Hits         11617    11635   +18     
  Misses         369      369           
  Partials       100      100           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Mar 24 '25 19:03 codecov[bot]

Hey @dreamorosi, can you check this PR?

anafalcao avatar Apr 30 '25 14:04 anafalcao