Skip to content

fix: Support Agent Skills (ignore code execution results, merge custom tools) - #26

Merged
saarnilauri merged 1 commit into
WordPress:trunkfrom
drywall:feat/skills-container-beta-header
Nov 20, 2026
Merged

saarnilauri merged 1 commit into
WordPress:trunkfrom
drywall:feat/skills-container-beta-header

Conversation

@drywall

@drywall drywall commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Agent Skills need a container with skills and the code execution tool. Neither could be used through this provider:

  • The response contains bash_code_execution_tool_result / text_editor_code_execution_tool_result blocks, which made parsing fail with "Part has an unexpected type".
  • Passing the code execution tool via customOptions['tools'] threw "conflicts with an existing parameter" whenever the prompt also had function declarations or web search.

Changes

  • Ignore code execution result blocks in parseResponseContentMessagePart(), as already done for web_search_tool_result.
  • Append a tools list from custom options to the generated tools instead of rejecting it.
  • When continuing a pause_turn, add the container ID to an array container option instead of replacing it, so the skills are kept.

The Skills API is GA, so no beta headers are needed.

Usage

add_action( 'wp_ai_client_before_generate_result', function( $event ) {
    $model = $event->getModel();
    if ( 'anthropic' !== $model->providerMetadata()->getId() ) {
        return;
    }
    $config = $model->getConfig();
    $config->setCustomOptions( array_merge( $config->getCustomOptions() ?? [], [
        'container' => [
            'skills' => [
                [ 'type' => 'anthropic', 'skill_id' => 'xlsx', 'version' => 'latest' ],
            ],
        ],
        'tools' => [
            [ 'type' => 'code_execution_20250825', 'name' => 'code_execution' ],
        ],
    ] ) );
} );

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jul 9, 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.

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: drywall <bbyrne@git.wordpress.org>
Co-authored-by: saarnilauri <laurisaarni@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.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@jeffpaul
jeffpaul requested a review from superdav42 August 17, 2026 18:29
@jeffpaul jeffpaul added this to the 1.1.0 milestone Aug 17, 2026
@drywall
drywall requested a review from a team August 21, 2026 15:56
@jeffpaul
jeffpaul requested a review from saarnilauri October 1, 2026 17:12
@jeffpaul jeffpaul modified the milestones: 1.0.5, 1.1.0 Oct 1, 2026

@saarnilauri saarnilauri 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.

Thanks for picking this up. Skills support would be useful.

I rebased the change onto current trunk locally and ran it against the live API. The live tests revealed drift in the beta status and secondly as the PR stands, it doesn't make Skills usable:

  1. Skills need the code execution tool. Without it the API returns 400, so the example in the description fails.
  2. The response parser is the real blocker. With the tool added, the API returns 200, but the provider throws on the code-execution result blocks. Adding those block types to the ignored cases in parseResponseContentMessagePart() fixed it for both an Anthropic skill and a custom skill, with no beta headers. The Skills API is generally available and needs no beta header.
  3. Adding the tool collides with other tools. Passing it through customOptions['tools'] throws "conflicts with an existing parameter" whenever the prompt also has function declarations or web search. Since the example hook runs for every prompt, that would break tool-using features site-wide. It should also only act on the Anthropic provider.

Could you rescope the PR to the parser fix, plus a way to add the code execution tool alongside the other tools, and drop the beta headers? The branch also needs a rebase (it conflicts after #32).

$headers['anthropic-beta'] = 'structured-outputs-2025-11-13';
}

// Add beta headers required for Skills (container parameter) if present in custom options.

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.

Tested against the live API (2026-10-09). These headers aren't what blocks Skills. The Skills guide now says "The Skills API is out of beta and needs no beta header." With Anthropic's xlsx skill and a throwaway custom skill:

  • Without the code_execution tool, the request is rejected with 400 "container: skills can only be used when a code execution tool is enabled", with or without these headers. That's the PR description's example as written.
  • With tools: [{type: code_execution_20250825, name: code_execution}] and no anthropic-beta header at all, the request returns 200. That held for xlsx on Haiku 4.5 and Sonnet 5, and for an uploaded custom skill.
  • Through this model class, that 200 then fails in the provider with ResponseException: … Part has an unexpected type. That happens with or without this PR. The response contains bash_code_execution_tool_result and, for the custom skill, text_editor_code_execution_tool_result blocks, and parseResponseContentMessagePart() rejects both.

I added bash_code_execution_tool_result, code_execution_tool_result and text_editor_code_execution_tool_result to the existing "ignore" cases next to web_search_tool_result. With that change, both calls worked end to end with no beta headers. The custom skill's answer came through correctly.

@jeffpaul

Copy link
Copy Markdown
Member

@drywall thanks for the contribution! Any chance you can respond to the code review feedback here to unblock getting this into the provider plugin?

…m tools)

Agent Skills need a `container` with `skills` and the code execution tool.

- Ignore `code_execution_tool_result`, `bash_code_execution_tool_result` and
  `text_editor_code_execution_tool_result` blocks when parsing the response,
  as already done for `web_search_tool_result`.
- Append a `tools` list from custom options to the generated tools instead of
  throwing a conflict when function declarations or web search are also set.
- When continuing a `pause_turn`, add the container ID to an array `container`
  option instead of replacing it, so the skills are kept.

The Skills API is GA, so no beta headers are needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@drywall
drywall force-pushed the feat/skills-container-beta-header branch from 9016e9b to e339409 Compare November 17, 2026 17:21
@drywall drywall changed the title feat: add anthropic-beta headers automatically when Skills container is used fix: Support Agent Skills (ignore code execution results, merge custom tools) Nov 17, 2026
@drywall

drywall commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

@jeffpaul Thanks for the nudge!

@saarnilauri Thanks for testing this against the live API. I've rescoped the PR as you suggested and rebuilt it on current trunk: the beta headers are gone, the code execution result blocks are now ignored by the parser, and customOptions['tools'] is appended to the other tools instead of conflicting. The example now checks for the Anthropic provider. I also changed pause_turn continuation so an array container keeps its skills when the container ID is added. Could you check that part live?

@drywall
drywall requested a review from saarnilauri November 17, 2026 17:23

@saarnilauri saarnilauri 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.

Thanks for rebuilding this. It now covers everything from my earlier review.

On the pause_turn change, I checked it live (Haiku 4.5, xlsx skill, no beta header). I couldn't trigger a real pause_turn, even with 15 tool calls in one turn, so I reused a container across two calls instead:

  • With container: {skills, id}, the same container came back with its files and the skill still attached.
  • With the bare ID, which is what trunk sends, the files were still there, but the response no longer listed the skill and the input was ~1,200 tokens smaller. So the continuation ran without the skill.

That matches Anthropic's Skills guide, which sends {id, skills} on each pause_turn continuation, so this change is needed.

End to end through the model with a function declaration plus the code execution tool, the request went out with both tools and no beta header, and the result came back fine.

Checked locally: the full suite passes, PHPCS and PHPStan are clean, and reverting each of the three source changes fails its new test.

@jeffpaul One note for the release changelog: a list-shaped tools custom option is now added to the generated tools instead of throwing a conflict error. Nothing that worked before changes, but it's worth mentioning alongside the Skills support.

@jeffpaul

Copy link
Copy Markdown
Member

@saarnilauri want to confirm what those changelog entries would be an include them in the squash merge commit description then?

@saarnilauri

Copy link
Copy Markdown
Contributor

@saarnilauri want to confirm what those changelog entries would be an include them in the squash merge commit description then?

@jeffpaul I will check again tomorrow and include them into the squash merge commit description.

@saarnilauri
saarnilauri merged commit 0380600 into WordPress:trunk Nov 20, 2026
14 checks passed
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.

3 participants