Feature/token limit reached exception #194
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.