Duplicate check
Problem
When using the anthropic provider, context overflow errors are misclassified as BAD_REQUEST instead of CONTEXT_OVERFLOW. This prevents the COMPACT_AND_RETRY recovery path from activating — the error is surfaced directly to the user instead of automatically compacting the conversation and retrying.
The root cause is that _is_context_overflow() in failures.py only contains OpenAI-centric markers ("context length", "context window", "too many tokens", etc.) and doesn't recognize Anthropic's specific error phrasing:
"exceed context limit" (from "input length and max_tokens exceed context limit: ...")
"request_too_large" (413 error type)
"request size exceeds" (413 message variant)
"prompt_too_long" (error code)
Proposed behavior
Add Anthropic-specific markers to _is_context_overflow() in src/agentos/provider/failures.py:
"prompt_too_long" — matches the error code
"exceed context limit" — matches Anthropic's canonical 400 message
"request_too_large" — matches Anthropic's 413 error type
"request size exceeds" — matches the 413 message variant
This ensures Anthropic context overflows classify as CONTEXT_OVERFLOW → COMPACT_AND_RETRY, consistent with how OpenAI-compatible providers already behave.
Area
Provider integration
Alternatives considered
- Adding
"max_tokens" as a marker was considered but rejected — it appears in nearly every Anthropic error message as a parameter name and would cause widespread false positives.
- Matching on
status_code == 413 alone was considered, but a 413 can indicate a payload-size issue unrelated to token count, so text-based markers are more precise.
Duplicate check
Problem
When using the
anthropicprovider, context overflow errors are misclassified asBAD_REQUESTinstead ofCONTEXT_OVERFLOW. This prevents theCOMPACT_AND_RETRYrecovery path from activating — the error is surfaced directly to the user instead of automatically compacting the conversation and retrying.The root cause is that
_is_context_overflow()infailures.pyonly contains OpenAI-centric markers ("context length","context window","too many tokens", etc.) and doesn't recognize Anthropic's specific error phrasing:"exceed context limit"(from"input length and max_tokens exceed context limit: ...")"request_too_large"(413 error type)"request size exceeds"(413 message variant)"prompt_too_long"(error code)Proposed behavior
Add Anthropic-specific markers to
_is_context_overflow()insrc/agentos/provider/failures.py:"prompt_too_long"— matches the error code"exceed context limit"— matches Anthropic's canonical 400 message"request_too_large"— matches Anthropic's 413 error type"request size exceeds"— matches the 413 message variantThis ensures Anthropic context overflows classify as
CONTEXT_OVERFLOW→COMPACT_AND_RETRY, consistent with how OpenAI-compatible providers already behave.Area
Provider integration
Alternatives considered
"max_tokens"as a marker was considered but rejected — it appears in nearly every Anthropic error message as a parameter name and would cause widespread false positives.status_code == 413alone was considered, but a 413 can indicate a payload-size issue unrelated to token count, so text-based markers are more precise.