Feature/token limit reached exception#194
Feature/token limit reached exception#194saarnilauri wants to merge 8 commits intoWordPress:trunkfrom
Conversation
…so diagnostics are deterministic and clean.
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@JasonTheAdams and @felixarntz Are you still considering adding the If so, as the providers have been removed from this repository, should the |
|
Hi @saarnilauri! I just opened up #203 as a reduced version of this in light of removing the providers. I'd appreciate it if you'd hop over there and give me some feedback. I didn't port over all the exception properties you have here because, even looking at the code, it wasn't clear to me what purpose all the properties had. Thanks for bringing up this idea! It's a good one! |
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:maxTokensproviderStopReasonfunctionNamemissingRequiredParametersUpdated Anthropic response parsing (
src/ProviderImplementations/Anthropic/AnthropicTextGenerationModel.php) to throwTokenLimitReachedExceptionwhenstop_reasonis:max_tokensmodel_context_window_exceededAdded 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.phptests/unit/ProviderImplementations/Anthropic/AnthropicTextGenerationModelTest.phpAdded Anthropic integration tests for max-token scenarios (plain text + tool-calling):
tests/integration/Anthropic/TextGenerationIntegrationTest.phptests/integration/Anthropic/FunctionCallingIntegrationTest.phpThis 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.