WordPress / WordPress/php-ai-client
Add a function call resolution loop and a way to append messages to PromptBuilder
@gziolo is already working on this.
Since Aug 5, 2026.
- Dominant language
- PHP
- Stars
- 308
- Forks
- 84
- Avg merge
- 7d 21h
- Merged PRs (30d)
- 2
Description
Background
I am working on an automatic ability resolution loop for the WP AI Client in WordPress core (Trac ticket 64865, wordpress-develop PR #12658). It works, but I had to work around two gaps in the PHP AI Client.
@JasonTheAdams suggested in the PR that this logic could live in the PHP AI Client instead:
I wonder if it would be better to introduce agentic looping on function declarations in the PHP AI Client. We could add an event, overloadable function, or some such thing to make it possible for WP to handle Abilities.
The gaps
-
There is no way to append messages to
PromptBuilder.withHistory()only prepends. So there is no public way to continue a conversation after a model response. In the WordPress PR, I had to capture the messages and the model fromBeforeGenerateResultEventand call the model directly. -
There is no built-in loop for function calls. When a model responds with a function call, every consumer has to write the same loop by hand: run the calls, send the results back, and ask the model again. Only the execution of one function call is WordPress-specific. The loop itself is generic and could live in the SDK.
Proposal
A. Add PromptBuilder::withMessages(Message ...$messages) to append full messages, as a counterpart to withHistory().
B. Add a small interface for resolving function calls, and fluent methods to turn the loop on:
$text = AiClient::prompt('What is this site about?')
->usingFunctionDeclarations(...$declarations)
->usingFunctionCallResolver($resolver)
->usingMaxFunctionCallIterations(3) // default 5
->generateText();
The loop runs the requested function calls through the resolver, adds the results to the conversation, and asks the model again. It stops when the model answers without function calls, when the resolver cannot handle a call, or after a maximum number of rounds.
I have a working implementation with unit tests and will open a PR with the full details next.
Open questions
docs/REQUIREMENTS.mdsays the client must not include agents. Is a small, bounded loop like this in scope? It builds only on the existing function calling feature.- Is an interface the right extension point, or would you prefer an event or an overloadable method?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.