Skip to content

packages/ai: adapt Anthropic thinking payloads#49

Merged
masnwilliams merged 3 commits into
mainfrom
hypeship/cua-sonnet-5-adaptive-thinking
Jun 30, 2026
Merged

packages/ai: adapt Anthropic thinking payloads#49
masnwilliams merged 3 commits into
mainfrom
hypeship/cua-sonnet-5-adaptive-thinking

Conversation

@masnwilliams

@masnwilliams masnwilliams commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Convert legacy Anthropic thinking.type=enabled payloads to adaptive thinking for models that require or recommend the new format.
  • Cover newer/adaptive Anthropic CUA families: Sonnet 5, Sonnet 4.6, Opus 4.8, Opus 4.7, Opus 4.6, Fable 5, and Mythos-style models.
  • Preserve caller output_config while setting output_config.effort from the existing budget-token levels.
  • Add unit coverage for adaptive conversion and older manual-thinking models that should remain unchanged.

Test plan

  • npm run build --workspace @onkernel/cua-ai
  • npm test --workspace @onkernel/cua-ai
  • npm test --workspace @onkernel/cua-agent -- --exclude "**/*.live.test.ts"
  • npm pack --workspace @onkernel/cua-ai --dry-run

Note

Medium Risk
Changes outbound Anthropic API payload shape for a defined set of newer models; behavior is gated by model ID and only applies when legacy thinking is enabled, but incorrect mapping could affect model reasoning/cost.

Overview
@onkernel/cua-ai 0.3.4 adds Anthropic request payload middleware so callers can keep sending legacy thinking: { type: "enabled", budget_tokens } while newer CUA models get the adaptive format.

For matching models (Sonnet 5/4.6, Opus 4.8/4.7/4.6, Fable 5, Mythos families), anthropicAdaptiveThinkingOnPayload rewrites thinking to { type: "adaptive" }, merges existing output_config, and sets output_config.effort from the old budget tiers (low through xhigh). Older models like Sonnet 4.5 are left untouched when the hook returns undefined. The hook is registered on the Anthropic providerModule, so resolveCuaRuntimeSpec now exposes onPayload for Anthropic like Yutori/Tzafon.

Unit tests cover conversion, model coverage, effort mapping, and runtime-spec expectations. The agent payload-hook test is relaxed to toMatchObject so composed payloads with extra fields still pass.

Reviewed by Cursor Bugbot for commit dac33b8. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5b7ea25. Configure here.

outputConfig.effort = effortFromBudgetTokens(thinking.budget_tokens);
next.output_config = outputConfig;
return next;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing TSDoc on payload hook

Low Severity

The new exported anthropicAdaptiveThinkingOnPayload hook has no TSDoc describing when it rewrites thinking for Sonnet 5, how output_config.effort is derived, or that it returns undefined to leave other models and payloads unchanged.

Fix in Cursor Fix in Web

Triggered by learned rule: Exported types, interfaces, and classes require TSDoc

Reviewed by Cursor Bugbot for commit 5b7ea25. Configure here.

Co-authored-by: Cursor <cursoragent@cursor.com>
@masnwilliams masnwilliams changed the title packages/ai: adapt Sonnet 5 thinking payload packages/ai: adapt Anthropic thinking payloads Jun 30, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@masnwilliams masnwilliams merged commit ba6d43c into main Jun 30, 2026
9 of 11 checks passed
@masnwilliams masnwilliams deleted the hypeship/cua-sonnet-5-adaptive-thinking branch June 30, 2026 19:07
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.

1 participant