feat(provider): add Anthropic-specific context overflow markers - #627
Closed
bukeeastrey wants to merge 1 commit into
Closed
feat(provider): add Anthropic-specific context overflow markers#627bukeeastrey wants to merge 1 commit into
bukeeastrey wants to merge 1 commit into
Conversation
Add four markers to _is_context_overflow() that match Anthropic's error phrasing: 'prompt_too_long', 'exceed context limit' (canonical 400 message), 'request_too_large' (413 error type), and 'request size exceeds' (413 variant). Without these, Anthropic context overflows fell through to BAD_REQUEST, bypassing the COMPACT_AND_RETRY recovery path. Refs use-agent-os#605
1 task
Contributor
|
Issue #613 has been resolved by #615, which landed on Closing this as superseded. Thanks for the contribution — the negative test in this PR ( |
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.
Summary
Anthropic's API returns context overflow errors using distinct phrasing and error types compared to OpenAI-compatible providers. Without matching markers in
_is_context_overflow(), Anthropic overflow errors fell through toProviderFailureKind.BAD_REQUEST(viainvalid_request_error), bypassing theCOMPACT_AND_RETRYrecovery action and immediately failing out to the user.This PR adds dedicated markers to
_is_context_overflow()to properly classify Anthropic context overflows:"prompt_too_long"— matches raw error code / proxy responses"exceed context limit"— matches Anthropic's canonical 400 error message ("input length and max_tokens exceed context limit: ...")"request_too_large"— matches Anthropic's 413 error type"request size exceeds"— matches the 413 payload message variant(Note:
"max_tokens"was intentionally omitted as a standalone marker to avoid false positives on valid requests mentioning parameter names).Changes
src/agentos/provider/failures.py: Added Anthropic-specific markers to_is_context_overflow().tests/test_provider_failure_classification.py: Added unit tests covering canonical Anthropic 400 messages, 413 error types, and negative cases ensuring non-overflowinvalid_request_errorstaysBAD_REQUEST.Verification
uv run ruff check src/agentos/provider/failures.py tests/test_provider_failure_classification.py(Passed)uv run mypy src/agentos/provider/failures.py --show-error-codes(Passed)uv run pytest tests/test_provider_failure_classification.py -q(93/93 tests passed)closes [Feature]: Add Anthropic-specific markers to _is_context_overflow for context overflow classification #613