-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: Add Anthropic Thinking and Streaming Support #3070
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
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @damithsenanayake, 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 significantly enhances the ADK Python SDK's integration with Anthropic's Claude models by introducing support for the Extended Thinking feature and substantially improving streaming capabilities. The changes allow for more sophisticated reasoning processes within Claude models and optimize performance for long-running or thought-intensive requests through intelligent streaming management, all while maintaining full backward compatibility. Highlights
Using Gemini Code AssistThe 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
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 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
|
Response from ADK Triaging Agent Hello @damithsenanayake, thank you for your contribution! Before we can review this PR, you'll need to sign our Contributor License Agreement (CLA). You can find instructions on how to do that here: https://cla.developers.google.com/ Also, our contribution guidelines require that new features have an associated GitHub issue to track the work. Could you please create an issue for this feature and link it in the PR description? These steps will help us move forward with the review process. Thanks! |
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.
Code Review
This pull request introduces support for Anthropic's Extended Thinking and enhances streaming capabilities for Claude models. The changes are well-structured and include comprehensive tests for the new features. My review focuses on improving code clarity, consistency, and maintainability. I've identified a misleading comment and log message regarding the thinking budget, which should be corrected. Additionally, I've suggested several minor refactorings to simplify conditional logic and reduce redundant code, making the implementation cleaner and easier to follow.
Summary
This PR adds support for Anthropic's Extended Thinking feature and Interleaved Thinking (beta) for Claude models in the ADK Python SDK. The implementation enables developers to use Claude's reasoning capabilities with thinking block signatures and multi-step tool reasoning, while maintaining full compatibility with existing code.
Key Features
Extended Thinking Support
ThinkingConfig
to Anthropic API formatValueError
for unlimited budget (-1) as it's not supported by ClaudePart(thought=True, thought_signature=...)
in standard GenAI formatBeta Features Support (e.g., Interleaved Thinking)
extra_headers
parameterextra_headers={"anthropic-beta": "interleaved-thinking-2025-05-14"}
Improved Streaming
AsyncAnthropicVertex
for async streaming supportstream
parameterLlmResponse
formatBackward Compatibility
extra_headers
parameterImplementation Details
Core Changes
File:
src/google/adk/models/anthropic_llm.py
Import AsyncAnthropicVertex (line 33)
Enhanced
content_to_message_param()
(lines 142-179)Enhanced
content_block_to_part()
(lines 182-219)thinking
attribute ortype='thinking'
Part(thought=True, thought_signature=signature)
for thinking contentNew
streaming_event_to_llm_response()
(lines 222-278)LlmResponse
with properpartial=True
flagRewritten
generate_content_async()
(lines 366-508)ValueError
forbudget=-1
(unlimited not supported)self.extra_headers or NOT_GIVEN
for API callsstream
parameterfinal_message.content
to preserve signaturesthinking
andextra_headers
parameters to both streaming and non-streaming API callsAdded
extra_headers
field (line 360)None
(no extra headers)Updated
_anthropic_client
property (lines 510-524)AnthropicVertex
toAsyncAnthropicVertex
Test Coverage
Test Files (50 tests total):
test_anthropic_thinking.py
(26 tests)test_anthropic_streaming.py
(8 tests)test_anthropic_llm.py
(16 tests)Code Quality
isort
andpyink
formattingTesting Results
No regressions - all existing tests continue to pass.
Breaking Changes
None. This PR is 100% backward compatible.
Usage Examples
Basic Extended Thinking
Beta Features with Tool Use (e.g., Interleaved Thinking)
Accessing Thinking Blocks
Streaming Decision Logic
Streaming is controlled exclusively by the
stream
parameter:stream=True
: Uses streaming mode viamessages.stream()
stream=False
: Uses non-streaming mode viamessages.create()
Both modes support thinking blocks when
thinking
parameter is provided.Beta Features Details
Interleaved Thinking
When to Use:
How It Works:
extra_headers={"anthropic-beta": "interleaved-thinking-2025-05-14"}
to enableRequirements:
thinking_budget > 0
)tool_choice: auto
)