Skip to content

feat(provider): add Anthropic-specific context overflow markers - #627

Closed
bukeeastrey wants to merge 1 commit into
use-agent-os:mainfrom
bukeeastrey:feat/anthropic-context-markers
Closed

feat(provider): add Anthropic-specific context overflow markers#627
bukeeastrey wants to merge 1 commit into
use-agent-os:mainfrom
bukeeastrey:feat/anthropic-context-markers

Conversation

@bukeeastrey

Copy link
Copy Markdown
Contributor

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 to ProviderFailureKind.BAD_REQUEST (via invalid_request_error), bypassing the COMPACT_AND_RETRY recovery 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-overflow invalid_request_error stays BAD_REQUEST.

Verification

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
@andreapn

andreapn commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Issue #613 has been resolved by #615, which landed on main with the same four Anthropic markers (prompt_too_long, exceed context limit, request_too_large, request size exceeds).

Closing this as superseded. Thanks for the contribution — the negative test in this PR (invalid_request_error without overflow markers stays BAD_REQUEST) is a nice addition and would be welcome as a small follow-up PR against current main if you'd like to open one.

@andreapn andreapn closed this Sep 1, 2026
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.

[Feature]: Add Anthropic-specific markers to _is_context_overflow for context overflow classification

2 participants