Skip to content

feat(models): add BedrockModel — Amazon Bedrock integration via Converse API#94

Open
kevmyung wants to merge 2 commits intogoogle:mainfrom
kevmyung:feat/bedrock-model
Open

feat(models): add BedrockModel — Amazon Bedrock integration via Converse API#94
kevmyung wants to merge 2 commits intogoogle:mainfrom
kevmyung:feat/bedrock-model

Conversation

@kevmyung
Copy link

Summary

  • Add BedrockModel, a native Amazon Bedrock integration for ADK via the Converse API
  • Supports all Amazon Bedrock-hosted models and cross-region inference profiles (us.*, eu.*, ap.*)
  • Streaming and non-streaming modes, tool/function calling, image input, and Guardrails support
  • Automatic LLMRegistry registration on import — model ID strings work out of the box
  • Sample agent added at contributing/samples/bedrock_wikipedia_agent/

Test plan

Unit tests

  • All unit tests pass locally
tests/unittests/models/test_bedrock_model.py  51 passed

Manual E2E tests

Model: us.anthropic.claude-haiku-4-5-20251001-v1:0, region: us-east-1

Non-streaming

Q: What is Python?
  [tool] wikipedia_search({'query': 'Python programming language'})
  [result] status=success
A: Python is a high-level, general-purpose programming language ...

Streaming

Q: What is Artificial Intelligence?
  [tool] wikipedia_search({'query': 'Artificial Intelligence'})
  [result] status=success
A: Artificial Intelligence (AI) is the capability of computational systems ...

Closes #17

…rse API

Supports all Bedrock-hosted models with streaming, tool calling, and image input.
Registers automatically with LLMRegistry on import.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kevmyung, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant new capability to the ADK by integrating Amazon Bedrock via its Converse API. This BedrockModel allows ADK agents to seamlessly utilize a wide range of Bedrock-hosted large language models, including those with cross-region inference profiles. The integration supports essential features such as streaming, tool calling, and image input, enhancing the versatility and power of ADK agents. A new sample agent is also provided to showcase this new functionality in a practical application.

Highlights

  • Amazon Bedrock Integration: Introduced BedrockModel for native Amazon Bedrock integration using the Converse API, enabling ADK agents to interact with Bedrock-hosted models.
  • Broad Model Support: Enabled support for all Amazon Bedrock-hosted models and cross-region inference profiles (e.g., us.*, eu.*, ap.*).
  • Feature Parity: Implemented support for streaming and non-streaming modes, tool/function calling, image input, and Bedrock Guardrails.
  • Automatic Registration: Ensured automatic LLMRegistry registration for BedrockModel on import, allowing model ID strings to work out of the box.
  • Sample Agent: Added a new sample Wikipedia research agent (contributing/samples/bedrock_wikipedia_agent/) to demonstrate BedrockModel usage.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • contributing/samples/bedrock_wikipedia_agent/README.md
    • Added a new README providing an overview, prerequisites, usage instructions, and sample output for the Bedrock Wikipedia agent.
  • contributing/samples/bedrock_wikipedia_agent/agent.py
    • Added a new Python script implementing a Wikipedia research agent powered by Amazon Bedrock and ADK.
  • pyproject.toml
    • Added boto3 as a required dependency for the new bedrock optional extra.
    • Included boto3 in the test optional dependencies.
  • src/google/adk_community/init.py
    • Imported the new models subpackage to expose its contents.
  • src/google/adk_community/models/README.md
    • Added a new README detailing the google.adk_community.models package, specifically documenting the BedrockModel with installation, quick start, AWS authentication, configuration, Guardrails, streaming, and error handling information.
  • src/google/adk_community/models/init.py
    • Created a new __init__.py file for the models subpackage.
    • Imported and registered BedrockModel with the LLMRegistry.
  • src/google/adk_community/models/bedrock_model.py
    • Added the BedrockModel class, implementing the BaseLlm interface for Amazon Bedrock integration.
    • Included logic for converting ADK Part and Content objects to Bedrock-compatible formats.
    • Implemented non-streaming and streaming content generation using Bedrock's Converse API.
    • Added comprehensive error handling for botocore.exceptions.ClientError.
    • Managed boto3 client creation and AWS region resolution.
  • tests/unittests/models/init.py
    • Added an empty __init__.py file to mark the models directory as a Python package for unit tests.
  • tests/unittests/models/test_bedrock_model.py
    • Added extensive unit tests for the BedrockModel class, covering request building, non-streaming and streaming responses, error handling, and boto3 client initialization.
Activity
  • Unit tests were run locally and passed, as confirmed by the 51 passed output.
  • Manual end-to-end tests were performed for both non-streaming and streaming modes using us.anthropic.claude-haiku-4-5-20251001-v1:0 in us-east-1, demonstrating successful tool calling with wikipedia_search.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant new feature: integration with Amazon Bedrock models via the Converse API. The implementation in BedrockModel is robust, well-structured, and includes thoughtful features like streaming support, error handling, and custom boto3 session support. The accompanying documentation is excellent, and the unit tests are comprehensive, covering many edge cases. I have a couple of suggestions for the sample agent to improve its robustness and efficiency, but overall this is a high-quality contribution.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native Integration Support for Amazon Bedrock in Google ADK

1 participant