Repository navigation
feat: Thought signature support - #20
Takshil-Kunadia wants to merge 4 commits into
Conversation
|
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. |
|
@felixarntz separate question while you're looking at this - whats the plan on bumping It would let us drop the version compare and write the calls directly. PHPStan would also gain accurate type info instead of being bypassed. |
JasonTheAdams
left a comment
There was a problem hiding this comment.
Thanks, @Takshil-Kunadia! A couple of questions here. I'm also curious if we need the backwards-compatibility checks since thinking would fail otherwise in earlier versions. But maybe the old failure is better than an invalid method call?
| if (null !== $signature) { | ||
| $data['signature'] = $signature; | ||
| } |
There was a problem hiding this comment.
Is there a condition in which the signature for a thinking part could be null? For my understanding this is a requirement and this being null would mean the data is incomplete and Anthropic is going to throw an error.
There was a problem hiding this comment.
Yes Anthropic always returns signature on thinking blocks. The null check is defensive as getThoughtSignature() returns ?string, and omitting the field when null is the least-bad fallback (single-turn requests work fine without it). Happy to change to fail-fast if you prefer.
5b4e1df to
d39dd85
Compare
Thinking doesn't fail on 0.4.x. It works for single-turn. The guards ensure it continues to work (degraded) rather than crashing with a fatal error or TypeError. Extended thinking works on sdk 0.4.x for single-turn requests, the code path is reachable. Its the multi-turn tool-use continuations that need signatures (added in 1.3.0). So the guards prevent crashes when a 0.4.x user hits this path rather than relying on a different failure mode upstream. |
|
@JasonTheAdams @superdav42 back to you for review |
superdav42
left a comment
There was a problem hiding this comment.
Looks good we just need to remove the version check because we require the 1.3.1 version since this was shipped in WP 7.0
| ? $partData['signature'] | ||
| : null; | ||
| $messagePartArgs = [$partData['thinking'], MessagePartChannelEnum::thought()]; | ||
| if (null !== $signature && version_compare(AiClient::VERSION, '1.3.0', '>=')) { |
There was a problem hiding this comment.
| if (null !== $signature && version_compare(AiClient::VERSION, '1.3.0', '>=')) { | |
| if (null !== $signature) { |
| if (method_exists($part, 'getThoughtSignature')) { | ||
| $signature = $part->getThoughtSignature(); | ||
| if (null !== $signature) { | ||
| $data['signature'] = $signature; | ||
| } | ||
| } |
There was a problem hiding this comment.
We have php-ai-client 1.3.1 as the min required so we can remove this check now
| if (method_exists($part, 'getThoughtSignature')) { | |
| $signature = $part->getThoughtSignature(); | |
| if (null !== $signature) { | |
| $data['signature'] = $signature; | |
| } | |
| } | |
| $signature = $part->getThoughtSignature(); | |
| if (null !== $signature) { | |
| $data['signature'] = $signature; | |
| } |
|
|
||
| namespace WordPress\AnthropicAiProvider\Models; | ||
|
|
||
| use WordPress\AiClient\AiClient; |
There was a problem hiding this comment.
| use WordPress\AiClient\AiClient; |
|
Closing as superseded by #31. |
Closes #14
Summary
Round-trips
MessagePart::thoughtSignatureon the Anthropic adapter so multi-turn extended-thinking + tool-use exchanges work. Without it, Anthropic API rejects the request because thesignaturefield is missing.Test plan
Title_GenerationAbility in Abilities Explorer, with vendor temporarily upgraded tophp-ai-client 1.3.1and extended thinking. Captured a 384-char signature on the inboundMessagePart.thinking+tool_useresponse; turn 2 echoed the assistant message back (with the captured signature) together with atool_result. Anthropic accepted turn 2 and returned the final answer confirming thesignaturefield is correctly serialised in the outbound JSON.