Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Might any of these 3p libraries potentially be used outside of the AI client in the future? ie. they might benefit from being in the higher level Extenders might refer to that 3p code as soon as it's in, so we can't change the namespace at a later date. |
479ebb4 to
a5bd792
Compare
|
FYI there are 50+ |
|
I was fixing that as you posted the comment, @swissspidy. 😄 |
dkotter
left a comment
There was a problem hiding this comment.
Did a fairly quick review here (mostly ignoring everything in the php-ai-client directory as I know that's already been reviewed and tested upstream) and have left a few minor comments.
I was mostly curious to see what, if any, changes would need to be made for those that have already been building on top of the WP AI Client (like we're doing in the AI Experiments plugin). Or if there's anything here that's missing that we'd need to ensure those integrations work (beyond the obvious exclusions in this PR like the provider credentials settings screen).
Not surprisingly, seems there's only super minimal changes we'd make, namely:
- Removing the inclusion of the WP AI Client
- Remove the loading and initialization of the client
- Changing from
AI_Client::prompt_with_wp_errortowp_ai_client_prompt
But looks like everything else we're doing will continue to work, which is great.
We've built many features on top of the (WP) AI Client now in AI Experiments and it's all been working great, so would love to see this merged into core to make it even easier to build on.
There was a problem hiding this comment.
I'm assuming this is probably due to the scoping tool we run here but noticing all the extra line breaks are removed from the php-ai-client files. This may be expected/desired, just makes it a bit harder to read through the code
There was a problem hiding this comment.
Yes, it's due to the tool indeed. Potentially something we can fix in the future, though this code should never be edited in Core anyway, similar to e.g. the Requests library or all the block PHP files that are controlled via Gutenberg.
src/wp-includes/class-wp-ai-client-ability-function-resolver.php
Outdated
Show resolved
Hide resolved
src/wp-includes/ai-client-utils/class-wp-ai-client-http-client.php
Outdated
Show resolved
Hide resolved
I'm certainly open to this! What libraries are you thinking of, specifically? |
|
Thanks for looking over this, @dkotter! I've resolved most of what you raised. I'm temporarily shifting to get the settings screen PR in place so we can start testing! |
This adjusts the test coverage workflow to run for any change to a PHP file in a pull request. This is not meant to be included in the final merge, but aims to help gauge the test coverage changes this merge would result in.
|
So I updated the test coverage workflow to run every time this PR is updated (please revert this before a final commit to SVN. In the status checks, you'll find two Surprisingly, it seems that 96%+ of this PR is actually covered by tests (which excludes the bundled library parts of this PR based on the PHPUnit configuration file changes), and this PR actually increases overall test coverages by roughly 2-tenths of a percent. For easier reference, you can view the coverage report for the PR here. Chatting it through with @aaronjorbin, @jeffpaul, and @felixarntz just now, this seems to make sense. The I do feel a bit better about the test coverage part of this. I think this will need to be a blended approach. There should be a high level of coverage for the non-bundled library code here combined with the test coverage within the PHP SDK library. @aaronjorbin has created an issue to follow up with adding test coverage reporting to the |
|
@JasonTheAdams Are you able to add some testing notes to the PR description. I'm having trouble finguring out what needs to be done to add providers to the settings screen with the AI Experiments plugin installed. The menu page is available but without any form fields.
|
Sorry it was just the note you left #10881 (comment), I should have linked. |
It said: TODO: Revert before commit (just leaving this here as a reminder and was on file github/workflows/test-coverage.yml. |
|
Based on some of the feedback so far, @JasonTheAdams and I found a way to simplify the WordPress-owned code in terms of those PSR7 and PSR-17 classes - they are boilerplate code needed to work with PSR-7 and PSR-17 standards, but they can be part of This is being handled in WordPress/php-ai-client#208. We'll publish a new release after and pull that in here. |
felixarntz
left a comment
There was a problem hiding this comment.
@JasonTheAdams Awesome work on this - and extra thanks for going through this with me to push it over the finish line!
|
Awesome work. I'm catching up after a longer break and I would like to offer my help to bring the remaining work to the finish line. I see that this PR was committed by @felixarntz in 52e3c30 (svn changeset https://core.trac.wordpress.org/changeset/61700). |
|
I have minor additional feedback from my reviews sessions with Claude Code:
|
|
Really like how On the response side, my understanding from studying the code is that $result = $builder->using_abilities( 'core/get-site-info' )->generate_text_result();
while ( WP_AI_Client_Ability_Function_Resolver::has_ability_calls( $result->getMessage() ) ) {
$response = WP_AI_Client_Ability_Function_Resolver::execute_abilities( $result->getMessage() );
$result = $builder->with_history( $result->getMessage(), $response )->generate_text_result();
}Or is there a plan to provide a higher-level helper that handles this loop automatically? Would be great to understand the design vision here. |
|
One more minor finding for consideration. The // This throws InvalidArgumentException instead of returning a WP_Error from generate_text().
wp_ai_client_prompt( ' ' )->generate_text();The same applies to other invalid constructor inputs like A possible fix would be wrapping the new prompt builder call in the constructor with a try/catch, storing the exception as a Here's a test case that documents the current behavior: /**
* Test that wp_ai_client_prompt() with an empty string throws an InvalidArgumentException.
*
* The SDK's PromptBuilder constructor throws immediately for empty strings,
* bypassing the WP_Error wrapping provided by __call(). This means invalid
* input to wp_ai_client_prompt() surfaces as an uncaught exception rather
* than a WP_Error from a generating method.
*
* @ticket 64591
*/
public function test_empty_string_throws_exception() {
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( 'Cannot create a message from an empty string' );
wp_ai_client_prompt( ' ' );
} |
|
Awesome work moving this big project forward @JasonTheAdams and @felixarntz! Thank you for the way you iterated fast and addressed the comments during the review process. |
Yeah, wrong link. I was referring to Mainly posting this for logging purposes, even though the PR has been merged. |
|
Thanks, @gziolo!
To start we decided not to get too deep into agent-like behavior, as we'd tossed around an
That's a fair point! Typically, I'd say this is appropriate behavior, but given that all the constructor's parameter does is the same as |

Trac ticket: https://core.trac.wordpress.org/ticket/64591
Merge Proposal: https://make.wordpress.org/core/2026/02/03/proposal-for-merging-wp-ai-client-into-wordpress-7-0
Summary
Adds a provider-agnostic AI Client, enabling developers to interact with generative AI services through a single, fluent API — without needing to know which provider is configured.
This PR includes three layers:
PHP AI Client SDK (
php-ai-client): The upstream SDK fromWordPress/php-ai-client, bundled intowp-includes/php-ai-client/with all third-party dependencies (PSR interfaces, HTTPlug) scoped toWordPress\AiClientDependencies\*to avoid conflicts with plugins shipping their own versions.Import tooling (
tools/php-ai-client/): An installer script and PHP-Scoper configuration that fetches, scopes, and reorganizes the SDK for bundling. Runningbash tools/php-ai-client/installer.shreproduces the bundled output deterministically.WP AI Client (
ai-client-utils/,ai-client.php): The WordPress integration layer. This provides minimal PSR-7/PSR-17 implementations backed by string buffers andwp_parse_url(), an HTTP client adapter that routes requests throughwp_remote_request(), a discovery strategy so the SDK automatically finds these implementations, and an event dispatcher that bridges PSR-14 events to WordPress hooks.The public API is a single function:
WP_AI_Client_Prompt_Builderwraps the SDK's fluent builder with WordPress conventions — snake_case methods,WP_Errorreturns instead of exceptions, andusing_abilities()for connecting the Abilities API to AI function calling.The
wp_ai_client_prevent_promptfilter gives site owners and plugins centralized control over AI availability. When a prompt is prevented, generating methods returnWP_Errorwhileis_supported_*methods returnfalse— giving plugin developers a graceful way to hide AI features entirely when AI is not available.This gives plugin and theme developers a stable, provider-neutral way to add AI features without bundling their own HTTP clients or managing provider-specific SDKs.
Testing Instructions
This is strictly the core work and doesn't include a built-in UI for setting up provider credentials. While it is possible to add a provider and set up the credentials, the easiest way to test this is using the stacked settings PR: #10904. That PR has testing instructions and links to provider plugins you can install.
Use of AI Tools
This is a compilation of work from the PHP AI Client and WP AI Client repositories, with some changes made in porting to core. Claude Code was used in both the original development of those packages as well as the porting over and creation of the tooling. All code was generated by Claude Code and reviewed by myself and @felixarntz.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.