Skip to content

Add: AI-assisted payload generation to the Ability Explorer - Test Ability Screen - #695

Open
Arkenon wants to merge 17 commits into
WordPress:developfrom
Arkenon:develop
Open

Add: AI-assisted payload generation to the Ability Explorer - Test Ability Screen#695
Arkenon wants to merge 17 commits into
WordPress:developfrom
Arkenon:develop

Conversation

@Arkenon

@Arkenon Arkenon commented Jun 10, 2026

Copy link
Copy Markdown

What?

Adds AI-assisted payload generation to the Ability Test Runner. Users can describe a test scenario in natural language and automatically generate a valid JSON payload based on the selected ability's input schema.

Why?

Some abilities expose complex or deeply nested input schemas that are difficult to populate manually. Creating valid test payloads often requires understanding schema structures, enum values, nested objects, and validation constraints.

This makes testing abilities slower and more error-prone, especially for contributors who are unfamiliar with a specific ability's schema.

How?

ability_test_generate_with_ai.mp4

This PR introduces a new Generate with AI workflow in the Ability Test Runner:

  • Added a Generate with AI button to the test interface.
  • Added a modal that accepts a natural-language description of the desired test input.
  • Sends the ability's input schema and the user's description to the configured AI provider using wp_ai_client_prompt().
  • Parses the AI response, removes markdown code fencing if present, validates the JSON, and inserts the generated payload into the test input field.
  • The feature is only available when:
    • An AI provider is configured.
    • The selected ability exposes an input schema.

Implementation Details

  • Admin_Page.php
    • Added ajax_generate_payload() AJAX handler.
    • Retrieves the ability schema and user prompt.
    • Calls the configured AI provider via wp_ai_client_prompt().
    • Sanitizes and parses the response before returning JSON.
  • Abilities_Explorer.php
    • Added generateNonce (ai_ability_explorer_generate_payload) for AJAX authentication.
  • GeneratePayloadModal.jsx
    • New modal component for collecting user instructions and displaying errors.
  • index.js
    • Added modal mounting/unmounting logic and integration with the Ability Test Runner UI.
  • index.scss
    • Added styling for the modal footer and error notice area.

Use of AI Tools

AI assistance: Yes

Tool(s): ChatGPT

Model(s): GPT-5.5

Used for: Brainstorming the feature design, refining prompts, and drafting portions of documentation. Final implementation, review, testing, and code decisions were completed by me.

Testing Instructions

  1. Navigate to Tools → Abilities Explorer.
  2. Open an ability that exposes a non-trivial input schema.
  3. Click Test Ability.
  4. Click Generate with AI.
  5. Enter a natural-language instruction such as:
    • "Use the default values"
    • "Search for posts with the title 'Hello'"
    • "Query only the site URL information"
  6. Click Generate.
  7. Verify that the payload textarea is populated with valid JSON matching the schema.
  8. Click Invoke Ability.
  9. Verify that the ability executes successfully with the generated payload.

Note: An AI provider must be connected in the plugin settings for this feature to be available.

Screenshots or screencast

Before | After -- | -- N/A | Generate with AI button and payload generation modal

Changelog Entry

Added - AI-assisted payload generation for the Ability Test Runner.

Open WordPress Playground Preview

@github-actions

github-actions Bot commented Jun 10, 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: Arkenon <arkenon@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>

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

@Arkenon

Arkenon commented Jun 19, 2026

Copy link
Copy Markdown
Author

Any feedback or suggestions on this PR?

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 1.35135% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.14%. Comparing base (abcd7c9) to head (bff25bb).

Files with missing lines Patch % Lines
...udes/Experiments/Abilities_Explorer/Admin_Page.php 1.44% 68 Missing ⚠️
...eriments/Abilities_Explorer/Abilities_Explorer.php 0.00% 5 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #695      +/-   ##
=============================================
- Coverage      79.68%   79.14%   -0.55%     
- Complexity      2460     2478      +18     
=============================================
  Files            104      104              
  Lines           9955    10025      +70     
=============================================
+ Hits            7933     7934       +1     
- Misses          2022     2091      +69     
Flag Coverage Δ
unit 79.14% <1.35%> (-0.55%) ⬇️

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.

@dkotter dkotter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not tested yet but a number of things that need cleaned up here. In addition, would be great to get test coverage here, unit tests potentially but definitely E2E tests.

While the overall idea is neat here, the overall flow I think could be improved a bit. For instance, the modal itself has a title of Generate Payload with AI but then in the textarea, you add a prompt that says Generate payload for ....

We've been trying to remove the use of with AI, so I think just Generate Payload both in the modal and the button that triggers the modal will be better. I'm also not sure about requiring a user to enter details about their desired payload. Could the generate function not just generate it's own payload without user input? I understand that gets trickier if a post is required, for example, but seems solvable. Just seems to make it less user friendly to click a generate button but then be required to manually enter in a bunch of information first

Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Abilities_Explorer.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
Comment thread includes/Experiments/Abilities_Explorer/Admin_Page.php Outdated
onClose: close,
onSuccess: handleSuccess,
abilitySlug,
strings: aiAbilityExplorer.strings,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the client-side __ functions instead of passing in strings from the server-side

@dkotter dkotter added this to the Future Release milestone Jun 23, 2026
@Arkenon

Arkenon commented Jun 26, 2026

Copy link
Copy Markdown
Author

@dkotter Thanks for your review.

I just linted the PHP files, and I'm not sure why that extra spacing was added, but I'll fix it throughout the codebase.

I'm currently working on the feature. I'll also look into generating the payload automatically instead of using a prompt.

I'll submit an updated PR as soon as possible.

@jeffpaul
jeffpaul marked this pull request as draft June 26, 2026 17:32
@jeffpaul jeffpaul moved this from Triage to In progress in WordPress AI Roadmap Jun 26, 2026
@Arkenon
Arkenon marked this pull request as ready for review July 21, 2026 05:33
@Arkenon
Arkenon requested a review from a team July 21, 2026 05:33
@Arkenon

Arkenon commented Jul 21, 2026

Copy link
Copy Markdown
Author

I have completed the changes. The Test Ability screen now only has a Generate Payload button. The AI agent generates the payload based on the input schema.

ScreenRecorderProject3.mp4

@dkotter dkotter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking better but still have a few things that need addressed before we proceed.

In addition to the things flagged, we need to ensure we get some E2E tests added and ideally let's get the PR description updated to match latest changes

"Ability description: %s\n" .
"The payload must be a JSON object that conforms to the following JSON schema:\n%s\n" .
'Use plausible, realistic example values for every required property. If post id needed set id as 1.' .
'Include optional properties only when they help demonstrate the ability.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instruction here around optional properties contradicts what we do in normalize_schema_for_response, which forces all properties to be required. Ideally we should determine which approach we want to take and ensure we aren't providing conflicting instructions

"Generate a realistic example test payload for the WordPress ability \"%s\".\n" .
"Ability description: %s\n" .
"The payload must be a JSON object that conforms to the following JSON schema:\n%s\n" .
'Use plausible, realistic example values for every required property. If post id needed set id as 1.' .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a couple issues here:

  1. Some sites may not have a post ID of 1. We could find a real post and pass the ID in
  2. What if the input schema wants a post ID but doesn't want it in an id field? For instance, if it asks for post_id instead? I think we need to be a little more generic on this instruction

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need a newline break after this line otherwise it runs into the next line

<button type="button" id="ability-test-clear" class="button">
<?php esc_html_e( 'Clear Result', 'ai' ); ?>
</button>
<?php if ( ! empty( $ability['input_schema'] ) ) : ?>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want a check here to ensure we have an AI connector in place before we output this button? Or if not, we should ensure we output a better error message in that situation so users know what went wrong

if ( ! button.dataset.originalText ) {
button.dataset.originalText = originalText;
}
button.innerHTML =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid using innerHTML here? We should be able to build the span node and assign textContent to it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a bunch of unnecessary reformatting on this file. Ideally we revert that to keep the changes here focused

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

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

3 participants