Title: WP_AI_Client_Ability_Function_Resolver
Published: May 20, 2026

---

# class WP_AI_Client_Ability_Function_Resolver {}

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#description)
 * [Methods](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#wp--skip-link--target)

Resolves and executes WordPress Abilities API function calls from AI models.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#description)󠁿

This class must be instantiated with the specific abilities that the AI model is
allowed to execute, ensuring that only explicitly specified abilities can be called.
This prevents the model from executing arbitrary abilities.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_AI_Client_Ability_Function_Resolver::__construct](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/__construct/) | Constructor. | 
| [WP_AI_Client_Ability_Function_Resolver::ability_name_to_function_name](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/ability_name_to_function_name/) | Converts an ability name to a function name. | 
| [WP_AI_Client_Ability_Function_Resolver::execute_abilities](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/execute_abilities/) | Executes all ability function calls in a message. | 
| [WP_AI_Client_Ability_Function_Resolver::execute_ability](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/execute_ability/) | Executes a WordPress ability from a function call. | 
| [WP_AI_Client_Ability_Function_Resolver::function_name_to_ability_name](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/function_name_to_ability_name/) | Converts a function name to an ability name. | 
| [WP_AI_Client_Ability_Function_Resolver::has_ability_calls](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/has_ability_calls/) | Checks if a message contains any ability function calls. | 
| [WP_AI_Client_Ability_Function_Resolver::is_ability_call](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/is_ability_call/) | Checks if a function call is an ability call. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#source)󠁿

    ```php
    class WP_AI_Client_Ability_Function_Resolver {

    	/**
    	 * Prefix used to identify ability function calls.
    	 *
    	 * @since 7.0.0
    	 * @var string
    	 */
    	private const ABILITY_PREFIX = 'wpab__';

    	/**
    	 * Map of allowed ability names for this instance.
    	 *
    	 * Keys are ability name strings, values are `true` for O(1) lookup.
    	 *
    	 * @since 7.0.0
    	 * @var array<string, true>
    	 */
    	private array $allowed_abilities;

    	/**
    	 * Constructor.
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param WP_Ability|string ...$abilities The abilities that this resolver is allowed to execute.
    	 */
    	public function __construct( ...$abilities ) {
    		$this->allowed_abilities = array();

    		foreach ( $abilities as $ability ) {
    			if ( $ability instanceof WP_Ability ) {
    				$this->allowed_abilities[ $ability->get_name() ] = true;
    			} elseif ( is_string( $ability ) ) {
    				$this->allowed_abilities[ $ability ] = true;
    			}
    		}
    	}

    	/**
    	 * Checks if a function call is an ability call.
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param FunctionCall $call The function call to check.
    	 * @return bool True if the function call is an ability call, false otherwise.
    	 */
    	public function is_ability_call( FunctionCall $call ): bool {
    		$name = $call->getName();
    		if ( null === $name ) {
    			return false;
    		}

    		return str_starts_with( $name, self::ABILITY_PREFIX );
    	}

    	/**
    	 * Executes a WordPress ability from a function call.
    	 *
    	 * Only abilities that were specified in the constructor are allowed to be
    	 * executed. If the ability is not in the allowed list, an error response
    	 * with code `ability_not_allowed` is returned.
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param FunctionCall $call The function call to execute.
    	 * @return FunctionResponse The response from executing the ability.
    	 */
    	public function execute_ability( FunctionCall $call ): FunctionResponse {
    		$function_name = $call->getName() ?? 'unknown';
    		$function_id   = $call->getId() ?? 'unknown';

    		if ( ! $this->is_ability_call( $call ) ) {
    			return new FunctionResponse(
    				$function_id,
    				$function_name,
    				array(
    					'error' => __( 'Not an ability function call' ),
    					'code'  => 'invalid_ability_call',
    				)
    			);
    		}

    		$ability_name = self::function_name_to_ability_name( $function_name );

    		if ( ! isset( $this->allowed_abilities[ $ability_name ] ) ) {
    			return new FunctionResponse(
    				$function_id,
    				$function_name,
    				array(
    					/* translators: %s: ability name */
    					'error' => sprintf( __( 'Ability "%s" was not specified in the allowed abilities list.' ), $ability_name ),
    					'code'  => 'ability_not_allowed',
    				)
    			);
    		}

    		$ability = wp_get_ability( $ability_name );

    		if ( ! $ability instanceof WP_Ability ) {
    			return new FunctionResponse(
    				$function_id,
    				$function_name,
    				array(
    					/* translators: %s: ability name */
    					'error' => sprintf( __( 'Ability "%s" not found' ), $ability_name ),
    					'code'  => 'ability_not_found',
    				)
    			);
    		}

    		$args   = $call->getArgs();
    		$result = $ability->execute( ! empty( $args ) ? $args : null );

    		if ( is_wp_error( $result ) ) {
    			return new FunctionResponse(
    				$function_id,
    				$function_name,
    				array(
    					'error' => $result->get_error_message(),
    					'code'  => $result->get_error_code(),
    					'data'  => $result->get_error_data(),
    				)
    			);
    		}

    		return new FunctionResponse(
    			$function_id,
    			$function_name,
    			$result
    		);
    	}

    	/**
    	 * Checks if a message contains any ability function calls.
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param Message $message The message to check.
    	 * @return bool True if the message contains ability calls, false otherwise.
    	 */
    	public function has_ability_calls( Message $message ): bool {
    		foreach ( $message->getParts() as $part ) {
    			if ( $part->getType()->isFunctionCall() ) {
    				$function_call = $part->getFunctionCall();
    				if ( $function_call instanceof FunctionCall && $this->is_ability_call( $function_call ) ) {
    					return true;
    				}
    			}
    		}

    		return false;
    	}

    	/**
    	 * Executes all ability function calls in a message.
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param Message $message The message containing function calls.
    	 * @return Message A new message with function responses.
    	 */
    	public function execute_abilities( Message $message ): Message {
    		$response_parts = array();

    		foreach ( $message->getParts() as $part ) {
    			if ( $part->getType()->isFunctionCall() ) {
    				$function_call = $part->getFunctionCall();
    				if ( $function_call instanceof FunctionCall ) {
    					$function_response = $this->execute_ability( $function_call );
    					$response_parts[]  = new MessagePart( $function_response );
    				}
    			}
    		}

    		return new UserMessage( $response_parts );
    	}

    	/**
    	 * Converts an ability name to a function name.
    	 *
    	 * Transforms "tec/create_event" to "wpab__tec__create_event".
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param string $ability_name The ability name to convert.
    	 * @return string The function name.
    	 */
    	public static function ability_name_to_function_name( string $ability_name ): string {
    		return self::ABILITY_PREFIX . str_replace( '/', '__', $ability_name );
    	}

    	/**
    	 * Converts a function name to an ability name.
    	 *
    	 * Transforms "wpab__tec__create_event" to "tec/create_event".
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param string $function_name The function name to convert.
    	 * @return string The ability name.
    	 */
    	public static function function_name_to_ability_name( string $function_name ): string {
    		$without_prefix = substr( $function_name, strlen( self::ABILITY_PREFIX ) );

    		return str_replace( '__', '/', $without_prefix );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php#L25)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php#L25-L232)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_ai_client_ability_function_resolver%2F)
before being able to contribute a note or feedback.