Skip to content

Add support for thought signatures and thought tokens#216

Merged
felixarntz merged 4 commits intotrunkfrom
thought-signatures-and-tokens-support
Mar 10, 2026
Merged

Add support for thought signatures and thought tokens#216
felixarntz merged 4 commits intotrunkfrom
thought-signatures-and-tokens-support

Conversation

@felixarntz
Copy link
Member

This PR does two decoupled but related things:

  1. Add support for thought signatures in message parts
    • This is technically more of a bug fix than an enhancement - it's a critical must-have. All of Anthropic, Google, and OpenAI rely heavily in thought signatures nowadays to validate that thought information passed back in a multi-turn chat was actually produced by their own APIs (rather than "made up" by the caller).
    • Contrary to what one might think, this is not only important for thought channel message parts. Several models will include thought signatures on actual content parts that (I suppose) involved thinking behind the scenes. For example, function calls commonly include them, but even images in multimodal output models can include them.
    • The rule is basically: If the API returns a thought signature with a message part, it must be passed when using the same content part in a response. Otherwise, the API call may result in an error.
  2. Add support for thought tokens in token usage data

Both changes are fully optional and therefore backward compatible. However, once this is launched, we should update the provider implementations to support both where applicable - especially critical for point 1.

@felixarntz felixarntz added this to the 1.3.0 milestone Mar 8, 2026
@felixarntz felixarntz requested a review from JasonTheAdams March 8, 2026 18:42
@felixarntz felixarntz added the [Type] Bug An existing feature does not function as intended label Mar 8, 2026
@github-actions
Copy link

github-actions bot commented Mar 8, 2026

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: felixarntz <flixos90@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>

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

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 89.18919% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.61%. Comparing base (30a1506) to head (7352d45).
⚠️ Report is 19 commits behind head on trunk.

Files with missing lines Patch % Lines
src/Messages/DTO/MessagePart.php 81.81% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #216      +/-   ##
============================================
+ Coverage     87.45%   87.61%   +0.16%     
- Complexity     1194     1209      +15     
============================================
  Files            60       60              
  Lines          3858     3924      +66     
============================================
+ Hits           3374     3438      +64     
- Misses          484      486       +2     
Flag Coverage Δ
unit 87.61% <89.18%> (+0.16%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Looks good — clean, backward compatible, well-tested. All checks pass locally (tests, PHPCS clean, PHPStan clean). Left a minor nit on test values.

@gziolo
Copy link
Member

gziolo commented Mar 10, 2026

Minor nit on tests/unit/Results/DTO/TokenUsageTest.php line 320 and a few other places:

$tokenUsage = new TokenUsage(100, 50, 250, 100);

thoughtTokens (100) exceeds completionTokens (50), which doesn't match the class docs stating thought tokens are "a subset of completion tokens." Might be worth adjusting for clarity — e.g. new TokenUsage(100, 150, 250, 100) — so the test values reinforce the documented invariant. Not blocking.

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

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants