Skip to content

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

Description

@bukeeastrey

Duplicate check

  • I searched the existing open and closed issues and this is not a duplicate.

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_OVERFLOWCOMPACT_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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: providerLLM provider clients and provider compatibilitypriority: p2Medium priority: important but has a workaround or limited impactstatus: needs reviewImplementation exists and needs maintainer reviewtype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions