Add extensibility hooks for system instructions, ability results, and post context#304
Add extensibility hooks for system instructions, ability results, and post context#304Ryujiyasu wants to merge 4 commits intoWordPress:developfrom
Conversation
… post context Adds filters agreed upon in WordPress#34 hook audit discussion: - `ai_experiments_system_instruction` in Abstract_Ability::get_system_instruction() - `ai_experiments_ability_result` and `ai_experiments_ability_result_{$name}` for filtering ability execution results - `ai_experiments_get_post_details` in get-post-details ability - `ai_experiments_get_post_terms` in get-post-terms ability
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Tests cover:
- ai_experiments_system_instruction filter modifies instructions
- ai_experiments_system_instruction filter receives correct ability name
- ai_experiments_ability_result filter modifies results
- ai_experiments_ability_result_{$name} dynamic filter works
- WP_Error results bypass filtering
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #304 +/- ##
=============================================
- Coverage 58.03% 57.89% -0.15%
- Complexity 576 615 +39
=============================================
Files 37 46 +9
Lines 2955 3168 +213
=============================================
+ Hits 1715 1834 +119
- Misses 1240 1334 +94
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The plugin is being renamed in #287 by @dkotter. There is a related feedback #287 (review) from @jeffpaul, which makes perfect sense here as well:
This applies to the names of the proposed hooks. Let's finalize the naming conventions here. Also note that in WP core, all AI related hooks are prefixed with |
|
Thanks for working on this, @Ryujiyasu! I'm very much in favor of adding extensibility filters — this is exactly the kind of developer control the plugin needs. However, after reviewing this alongside prior work on the Abilities API, I think some of these filters would be better suited for WP core rather than the plugin. Here's my analysis: Filters that should go to WP coreWP core already fires
These are generic "filter the result of any ability execution" hooks — not AI-specific. The same concept was proposed in the Abilities API repo in the early phase of development:
Placing result filtering in core (inside
Now that Abilities API development has moved to core, these filters should be proposed there. I'd be happy to help with that. Filters that belong in this plugin
|
| /** | ||
| * Filters the post details returned by the get-post-details ability. | ||
| * | ||
| * @since 0.5.0 |
There was a problem hiding this comment.
Let's replace all @since statements with x.x.x as we're not sure of the actual version until we prep a release (and we have a step in our release process to find and replace all of those)
Note we've settled on |
…_result filters - Rename all hook prefixes from ai_experiments_ to wpai_ per WordPress#315 decision - Replace @SInCE 0.5.0 with @SInCE x.x.x for release-time replacement - Remove ability_result and ability_result_{$name} filters (to be proposed for WP core per @gziolo's feedback) - Replace filtered_execute_callback with simple do_execute wrapper - Remove related tests and Test_Error_Ability class
I will have to open a WordPress Trac ticket so it's lined up for WP 7.1. I will see if we can find a way to include it in the AI plugin faster, conditionally. Maybe, through some feature detection or PHP version check. |
|
I opened Abilities API: Add execution lifecycle filters to WP_Ability methods to track the functionality needed directly in WordPress core. I appreciate all the feedback as well! I also included there a related note:
It's worth looking at the same angle as the MCP adapter and figuring out whether additional filters in the execution flow are needed, or if it is fine to wait until WP 7.1 for what WP core will implement. |
|
I think it's fine to wait for WP 7.1 for the execution lifecycle filters in core (Trac #64989). This PR is already scoped to plugin-specific hooks only, and adding interim ability result filters here would create backcompat overhead once core ships them. The MCP Adapter has different needs (caching, validation toggling) that justify their own hooks, but for this plugin, relying on core seems cleaner. Happy to help with the core implementation when the time comes. |
|
Regarding |
The do_execute method was originally added to support ability_result filters, which were removed in the previous commit. Revert to directly registering execute_callback as it was before.
gziolo
left a comment
There was a problem hiding this comment.
It would be nice to add test coverage for wpai_get_post_terms and wpai_get_post_details, following wpai_system_instruction case. Otherwise, we are good to go.
Summary
Implements the extensibility hooks agreed upon in the #34 hook audit discussion with @dkotter.
New Filters
1. System Instruction Filter (
Abstract_Ability)ai_experiments_system_instruction— Filters the system instruction text before it's passed to the AI model. Receives the instruction string, ability name, and data array.2. Ability Result Filters (
Abstract_Ability)ai_experiments_ability_result— Generic filter applied to the result of any ability execution. Receives the result, ability name, and input.ai_experiments_ability_result_{$name}— Dynamic filter for a specific ability (e.g.,ai_experiments_ability_result_ai/title-generation). Receives the result and input.3. Post Context Filters (in the Abilities, per discussion)
ai_experiments_get_post_details— Filters post details returned by theai/get-post-detailsability. Receives details array, post ID, and requested fields.ai_experiments_get_post_terms— Filters terms returned by theai/get-post-termsability. Receives terms array, post ID, and allowed taxonomies.Design Decisions
filtered_execute_callbackwrapper inAbstract_Abilitythat wraps the abstractexecute_callback. This avoids requiring changes to every concrete ability class while ensuring all abilities get consistent filtering.get_post_contexthelper), as agreed with @dkotter.Example Usage
Closes #34
Test Plan
ai_experiments_system_instructionfilter modifies system instructionsai_experiments_ability_resultfilter modifies ability resultsai_experiments_get_post_detailsfilter modifies post detailsai_experiments_get_post_termsfilter modifies post terms