feat: add ProviderTokenCountError for native token counting failures#2211
Merged
opieter-aws merged 2 commits intostrands-agents:mainfrom Apr 28, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Assessment: Approve Clean, well-scoped PR that introduces a typed exception for null token count responses, replacing a generic Review Details
Solid incremental improvement to the token counting robustness. 👍 |
|
Assessment: Approve Clean, well-scoped PR that introduces a typed internal exception for null token count responses — replacing a generic Review Details
|
lizradway
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
ProviderTokenCountErrorto the Python SDK, matching the typed error introduced in the TypeScript SDK (sdk-typescript#886). This error is thrown when a model provider's native token counting API returns an unexpected null result, and is used as internal control flow within providercount_tokens()overrides.TypeScript port of
Related Issues
#2179
Documentation PR
Will update as part of proactive compression doc updated
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 prepareTestCountTokenstests for Bedrock and Gemini (includingtest_fallback_on_none_total_tokens,test_fallback_on_api_error,test_fallback_on_generic_exception) continue to pass — 188tests, 0 failures
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.