Title: FunctionDeclaration
Published: May 20, 2026

---

# class FunctionDeclaration {}

## In this article

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

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

Represents a function declaration for AI models.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/?output_format=md#description)󠁿

This DTO describes a function that can be called by the AI model, including its 
name, description, and parameter schema.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/?output_format=md#methods)󠁿

| Name | Description | 
| [FunctionDeclaration::__construct](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/__construct/) | Constructor. | 
| [FunctionDeclaration::fromArray](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/fromarray/) | {@inheritDoc} | 
| [FunctionDeclaration::getDescription](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/getdescription/) | Gets the function description. | 
| [FunctionDeclaration::getJsonSchema](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/getjsonschema/) | {@inheritDoc} | 
| [FunctionDeclaration::getName](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/getname/) | Gets the function name. | 
| [FunctionDeclaration::getParameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/getparameters/) | Gets the function parameters schema. | 
| [FunctionDeclaration::toArray](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/toarray/) | {@inheritDoc} |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/?output_format=md#source)󠁿

    ```php
    class FunctionDeclaration extends AbstractDataTransferObject
    {
        public const KEY_NAME = 'name';
        public const KEY_DESCRIPTION = 'description';
        public const KEY_PARAMETERS = 'parameters';
        /**
         * @var string The name of the function.
         */
        private string $name;
        /**
         * @var string A description of what the function does.
         */
        private string $description;
        /**
         * @var array<string, mixed>|null The JSON schema for the function parameters.
         */
        private ?array $parameters;
        /**
         * Constructor.
         *
         * @since 0.1.0
         *
         * @param string $name The name of the function.
         * @param string $description A description of what the function does.
         * @param array<string, mixed>|null $parameters The JSON schema for the function parameters.
         */
        public function __construct(string $name, string $description, ?array $parameters = null)
        {
            $this->name = $name;
            $this->description = $description;
            $this->parameters = $parameters;
        }
        /**
         * Gets the function name.
         *
         * @since 0.1.0
         *
         * @return string The function name.
         */
        public function getName(): string
        {
            return $this->name;
        }
        /**
         * Gets the function description.
         *
         * @since 0.1.0
         *
         * @return string The function description.
         */
        public function getDescription(): string
        {
            return $this->description;
        }
        /**
         * Gets the function parameters schema.
         *
         * @since 0.1.0
         *
         * @return array<string, mixed>|null The parameters schema.
         */
        public function getParameters(): ?array
        {
            return $this->parameters;
        }
        /**
         * {@inheritDoc}
         *
         * @since 0.1.0
         */
        public static function getJsonSchema(): array
        {
            return ['type' => 'object', 'properties' => [self::KEY_NAME => ['type' => 'string', 'description' => 'The name of the function.'], self::KEY_DESCRIPTION => ['type' => 'string', 'description' => 'A description of what the function does.'], self::KEY_PARAMETERS => ['type' => 'object', 'description' => 'The JSON schema for the function parameters.', 'additionalProperties' => \true]], 'required' => [self::KEY_NAME, self::KEY_DESCRIPTION]];
        }
        /**
         * {@inheritDoc}
         *
         * @since 0.1.0
         *
         * @return FunctionDeclarationArrayShape
         */
        public function toArray(): array
        {
            $data = [self::KEY_NAME => $this->name, self::KEY_DESCRIPTION => $this->description];
            if ($this->parameters !== null) {
                $data[self::KEY_PARAMETERS] = $this->parameters;
            }
            return $data;
        }
        /**
         * {@inheritDoc}
         *
         * @since 0.1.0
         */
        public static function fromArray(array $array): self
        {
            static::validateFromArrayData($array, [self::KEY_NAME, self::KEY_DESCRIPTION]);
            return new self($array[self::KEY_NAME], $array[self::KEY_DESCRIPTION], $array[self::KEY_PARAMETERS] ?? null);
        }
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/tools/dto/functiondeclaration.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Tools/DTO/FunctionDeclaration.php#L23)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Tools/DTO/FunctionDeclaration.php#L23-L122)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/?output_format=md#changelog)󠁿

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

## User Contributed Notes

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