Skip to content

Conversation

@saarnilauri
Copy link
Contributor

This PR adds explicit token-limit handling for Anthropic so truncated outputs are surfaced as exceptions instead of normal results.

What changed

  • Added TokenLimitReachedException (src/Common/Exception/TokenLimitReachedException.php) with structured metadata:

    • maxTokens
    • providerStopReason
    • optional functionName
    • optional missingRequiredParameters
  • Updated Anthropic response parsing (src/ProviderImplementations/Anthropic/AnthropicTextGenerationModel.php) to throw TokenLimitReachedException when stop_reason is:

    • max_tokens
    • model_context_window_exceeded
  • Added tool-call diagnostics for partial argument payloads by comparing returned args with required schema fields.

  • Added Anthropic unit test scaffolding and initial coverage:

    • tests/unit/ProviderImplementations/Anthropic/MockAnthropicTextGenerationModel.php
    • tests/unit/ProviderImplementations/Anthropic/AnthropicTextGenerationModelTest.php
  • Added Anthropic integration tests for max-token scenarios (plain text + tool-calling):

    • tests/integration/Anthropic/TextGenerationIntegrationTest.php
    • tests/integration/Anthropic/FunctionCallingIntegrationTest.php

    This relates to Missing Required Parameters in Tool Calls When Token Limit Reached #193

I know that the providers will be moved to their own repositories. But as this change is still in very early stage. I decided to do this PR to the client repository, so that discussion on how this should be implemented can start.

The PR is co-authored with OpenAIs Codex 5.3 model.

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: saarnilauri <laurisaarni@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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.

1 participant