-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Summary
When using wp-ai-client, and it uses php-ai-client if the AI reaches the token limit while generating a tool call with input parameters, it returns the tool call without all required parameters. This can cause multiple retries in the agent loop instead of properly handling the token limit condition.
Current Behavior
- AI generates a tool call that requires input parameters
- Token limit is reached during parameter generation (e.g., while generating long content)
- Tool call is returned with incomplete parameters (missing required fields)
- Agent loop retries multiple times attempting to complete the request ( the agent loop is NOT part of the package)
Expected Behavior
- Providers should throw a
TokenLimitReachedExceptionwhen the token limit is reached - Exception should contain information about the current max tokens set for the provider
- This allows the plugin developpers agent to handle the exception gracefully instead of entering a retry loop
Steps to Reproduce
- Configure
wp-ai-clientwith a token limit - Use a tool/ability that requires multiple parameters (e.g.,
title,post_type,content) - Generate content that approaches or exceeds the token limit (e.g., long markup for
content) - Observe that the AI calls the ability with only partial parameters (e.g., only
titleandpost_type, missingcontent)
Example Case
Tool: WordPress ability for creating posts
Required Parameters:
title(string)post_type(string)content(string)
Scenario:
When AI generates long markup for the content parameter and reaches the token limit, the tool call is made with only title and post_type, omitting the required content parameter.
Proposed Solution
Implement proper exception handling at the provider level.
The provider shoulds detect when the token limit is reached during tool call generation and throw this exception instead of returning incomplete tool calls.
Consideration of the client and provider separation
As the code for the providers will be moved to seperate repositories, there should be guideline to implement this error handling for the providers.
Impact
- Severity: Medium-High
- Affected Component: Provider layer, tool/ability system
- User Impact: Poor user experience due to multiple retries, wasted API calls, and potentially incomplete operations
Environment
- Packages:
wp-ai-clientandphp-ai-client