Skip to content

Prompt template extension points#770

Open
the-hercules wants to merge 4 commits into
WordPress:developfrom
the-hercules:feature/prompt-template-extension-points
Open

Prompt template extension points#770
the-hercules wants to merge 4 commits into
WordPress:developfrom
the-hercules:feature/prompt-template-extension-points

Conversation

@the-hercules

@the-hercules the-hercules commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Add prompt template extension points

Summary

Introduces consistent, scoped extension points so developers can customize the prompts
and model configuration of AI abilities without forking the plugin. Adds three
per-ability filter hooks plus a developer guide.

Closes #192

What changed

A single slug helper on Abstract_Ability derives a hook-safe slug from each ability
name (ai/title-generationtitle_generation), and three filters are wired through
every AI ability:

  • wpai_{slug}_system_instruction — override/extend the system instruction for one
    ability. Added once in Abstract_Ability::get_system_instruction(), running after
    the existing global wpai_system_instruction filter.
  • wpai_{slug}_prompt — modify the assembled user prompt before it is sent. Added to
    the 10 abilities that did not already expose one.
  • wpai_{slug}_prompt_builder — adjust temperature, model/provider preference, request
    options, etc. Added to all 12 prompt-building abilities, after the default model
    preference is applied and before generation support is verified.

Abilities covered: Title, Excerpt, Summarization, Content Resizing, Meta Description,
Editorial Updates, Editorial Notes, Alt Text, Image Prompt Generation, Image Generation,
Comment Analysis, Content Classification.

Where abilities carry extra context, it is passed as additional filter arguments
(e.g. $length for summarization, $block_type for editorial notes, $action for content
resizing).

Backward compatibility

  • The global wpai_system_instruction filter is unchanged; the new scoped filter runs after it.
  • meta_description and content_classification already shipped a wpai_{slug}_prompt
    filter with richer signatures ($content/$title, taxonomy args). Those are left exactly
    as-is
    — no duplicate hook is registered — so existing integrations keep working. They are
    documented alongside the new hooks.
  • wpai_meta_description_result_temperature still applies; the new meta-description builder
    filter runs after it.
  • Every new hook is additive and a no-op unless a callback is attached, so default behavior is
    byte-for-byte unchanged.

Design notes / decisions

A few decisions were made in the absence of issue feedback (happy to adjust):

  1. Scoped system-instruction hook included. The issue asks for per-ability system
    instruction control; the global filter alone would require name-branching.
  2. Image Generation included for symmetry. Its _prompt is the image prompt (not post
    content), and editorial guidelines are appended after the filter — documented as such.
  3. Builder filter fires after set_provider_model_preference() so it can intentionally
    override the developer-mode model choice without breaking the default path.
  4. Structured-output abilities (comment_analysis, content_classification,
    editorial_notes) document that the builder should be extended, not replaced, to preserve
    JSON response schemas.
Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: the-hercules <thehercules@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 48.38710% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.51%. Comparing base (77f64fa) to head (d909fc1).

Files with missing lines Patch % Lines
includes/Abilities/Image/Alt_Text_Generation.php 0.00% 4 Missing ⚠️
.../Abilities/Comment_Moderation/Comment_Analysis.php 0.00% 2 Missing ⚠️
.../Abilities/Editorial_Updates/Editorial_Updates.php 33.33% 2 Missing ⚠️
...bilities/Excerpt_Generation/Excerpt_Generation.php 0.00% 2 Missing ⚠️
includes/Abilities/Image/Generate_Image_Prompt.php 0.00% 2 Missing ⚠️
includes/Abilities/Summarization/Summarization.php 0.00% 2 Missing ⚠️
...udes/Abilities/Editorial_Notes/Editorial_Notes.php 50.00% 1 Missing ⚠️
includes/Abilities/Image/Generate_Image.php 50.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #770      +/-   ##
=============================================
+ Coverage      76.41%   76.51%   +0.09%     
- Complexity      1828     1829       +1     
=============================================
  Files             87       87              
  Lines           7764     7792      +28     
=============================================
+ Hits            5933     5962      +29     
+ Misses          1831     1830       -1     
Flag Coverage Δ
unit 76.51% <48.38%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add extension points for custom prompt templates

1 participant