Skip to content

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

@saarnilauri

Description

@saarnilauri

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 TokenLimitReachedException when 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

  1. Configure wp-ai-client with a token limit
  2. Use a tool/ability that requires multiple parameters (e.g., title, post_type, content)
  3. Generate content that approaches or exceeds the token limit (e.g., long markup for content)
  4. Observe that the AI calls the ability with only partial parameters (e.g., only title and post_type, missing content)

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-client and php-ai-client

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions