-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Anthropic CoT controls #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
odilitime
wants to merge
85
commits into
dev
Choose a base branch
from
odi-anthro
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
ad41bb9
fix(types): test project, split check-types, UI package, gateways
odilitime 1093dd0
fix(tests): stabilize Milady billing cron and MILADY_PRICING mocks
odilitime e306880
feat(providers): Anthropic thinking options and route wiring
odilitime e1f36be
docs: Milady test mocks, Anthropic COT, changelog, and WHYs
odilitime 42ab187
feat(agents): per-agent Anthropic thinking budget (MCP/A2A) + docs
odilitime 99924fb
Fix spread order to ensure deploy-wide thinking config cannot be over…
cursoragent 31a963e
Fix spread order to ensure deploy-wide thinking config cannot be over…
cursor[bot] 9b2bed4
packages: improve error handling (env-validator.ts)
odilitime d1ba7cb
packages: add tests for docker-ssh-cloud-deploy.test
odilitime fe10e6b
packages: add tests for rate-limit (rate-limit.ts)
odilitime aed9df8
misc: improve code quality
odilitime 2f7ad95
app: fix issues in app (route.ts)
odilitime 1fe79e7
docs: add review dismissal comments
odilitime 4d58eff
packages: add tests for setup-server (setup-server.ts)
odilitime 29ad666
packages: add tests for webhooks-e2e.test (webhooks-e2e.test.ts)
odilitime 9940a31
packages: add tests for field-encryption.test (field-encryption.test.ts)
odilitime 557b66e
packages: add tests for provisioning-jobs.test
odilitime 35f6784
packages: add tests for z-milady-billing-route.test
odilitime 2817993
packages: Temperature silently dropped when thinking is enabled (seo.ts)
odilitime cb1f343
app: Potential issue | 🟠 Major (route.ts)
odilitime 5470955
packages: add tests for oauth-cache-invalidation.test
odilitime 3ff2fc3
packages: add tests for facilitator-service.test
odilitime 1db5ad6
app: add tests for route (route.ts)
odilitime 705d40e
packages: 3. `env-validator` and parser disagree on whether `"0"` is ...
odilitime ecd95c3
packages: 1. Rate limit change breaks local dev workflows
odilitime bc0fe7e
packages: add tests for x402-topup.test (x402-topup.test.ts)
odilitime 97a014f
misc: improve code quality
odilitime e1a426b
packages: 2. Temperature silently dropped when COT enabled
odilitime 2ca3e28
packages: add type safety (runtime-factory.ts)
odilitime e973f7e
packages: add tests for anthropic-thinking.test
odilitime 5d56e57
app: add tests for route (route.ts)
odilitime ba7ff77
app: fix issues in app (route.ts)
odilitime 2f2aeeb
packages: Temperature silently dropped when thinking is enabled (seo.ts)
odilitime 3f00c01
packages: fix issues in packages (env-validator.ts)
odilitime 08c27ff
app: Extended thinking applied to image generation endpoints (route.ts)
odilitime b9c92c2
packages: 3. `env-validator` and parser disagree on whether `"0"` is ...
odilitime 7caa325
misc: improve code quality
odilitime 8c3e23b
packages: add type safety (app-promotion.ts)
odilitime 07813b4
packages: add tests for app-automation (app-automation.ts)
odilitime 0a81562
packages: fix lint or formatting (seo.ts)
odilitime d435a8c
packages: improve error handling (env-validator.ts)
odilitime dc61ad5
packages: Minor Issues (rate-limit.ts)
odilitime 0f7314c
packages: 2. Temperature silently dropped when COT enabled
odilitime 82e680e
packages: add tests for anthropic-thinking.test
odilitime a7bdea3
app: fix security issue (route.ts)
odilitime 90eaec3
packages: add type safety (runtime-factory.ts)
odilitime 96f3615
packages: fix issues in packages (anthropic-thinking.ts)
odilitime 9cc7cf5
packages: fix before merge (rate-limit.ts)
odilitime bcbc223
packages: add or fix tests (anthropic-thinking.ts)
odilitime b7e33a9
packages: fix like (anthropic-thinking.ts)
odilitime 18bfb11
packages: consolidate duplicate logic
odilitime 9b558af
packages: add type safety (runtime-factory.ts)
odilitime df1e49c
packages: add tests for anthropic-thinking.test
odilitime a73b0b1
packages: add tests for x402-topup.test (x402-topup.test.ts)
odilitime edf761f
packages: add tests for app-automation (app-automation.ts)
odilitime 602a0f1
app: A2A route omits thinking tokens from credit reservation (route.ts)
odilitime 022d426
packages: add tests for anthropic-thinking.test
odilitime 4d4037c
app: 6. MCP generation tools inherit `ANTHROPICCOTBUDGET`
odilitime 6455e14
misc: improve code quality
odilitime 7d3e6e7
packages: add tests for anthropic-thinking.test
odilitime a2b03cb
app: A2A route omits thinking tokens from credit reservation (route.ts)
odilitime 914ee8b
packages: 7. `check-types-split.ts` now checks `packages/lib` as a si...
odilitime c991a33
app: 💡 Minor / Suggestions (route.ts)
odilitime 63d0930
misc: improve code quality
odilitime 1e12524
app: improve a guard (route.ts)
odilitime 99b53bc
packages: 5. `app-builder-ai-sdk.ts` inherits CoT without a comment
odilitime b737e41
app: 6. MCP generation tools inherit `ANTHROPICCOTBUDGET`
odilitime 9516525
packages: add tests for anthropic-thinking.test
odilitime 8a872e8
packages: 6. `RATELIMITMULTIPLIER` is not validated in `env-validator...
odilitime 66e9b98
packages: 9. Import ordering in `runtime-factory.ts`
odilitime 8b14b89
app: consolidate duplicate logic (route.ts)
odilitime 421fda1
app: improve a guard (route.ts)
odilitime 718e962
packages: 5. `app-builder-ai-sdk.ts` inherits CoT without a comment
odilitime ddd4e20
app: 6. MCP generation tools inherit `ANTHROPICCOTBUDGET`
odilitime 3d6bd66
misc: add tests for anthropic-thinking (anthropic-thinking.ts)
odilitime d292214
packages: 7. `a2a/skills.ts` — no character context for CoT (skills.ts)
odilitime 8174ca9
packages: 9. Import ordering in `runtime-factory.ts`
odilitime 4807344
app: fix issues in app (route.ts)
odilitime 19f22c5
packages: 3. App-builder does not explicitly disable CoT
odilitime 3465972
app: improve a guard (route.ts)
odilitime e6bb1a8
packages: 5. `app-builder-ai-sdk.ts` inherits CoT without a comment
odilitime e093709
app: 6. MCP generation tools inherit `ANTHROPICCOTBUDGET`
odilitime 8d71533
packages: Cursor search/replace artifact left in production code
odilitime 67138cc
misc: improve code quality
odilitime 3b0b079
docs: add review dismissal comments
odilitime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Changelog | ||
|
|
||
| All notable engineering changes to this repository are recorded here. For **product-facing** release notes on the docs site, see `packages/content/changelog.mdx`. | ||
|
|
||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
|
|
||
| - **Per-agent Anthropic extended thinking** — `user_characters.settings.anthropicThinkingBudgetTokens` (integer ≥ 0) controls thinking for **MCP** and **A2A** agent chat when the model is Anthropic. **`ANTHROPIC_COT_BUDGET_MAX`** optionally caps any effective budget (character or env default). **Why:** Agent owners set policy in stored character data; request bodies must not carry budgets (untrusted MCP/A2A callers). Env still supplies defaults where no character field exists and caps worst-case cost. | ||
| - **`ANTHROPIC_COT_BUDGET`** (existing) — Clarified role as **default** when the character omits `anthropicThinkingBudgetTokens` (or value is invalid), plus baseline for routes without a resolved character. **Why:** One deploy-level knob for generic chat; per-agent overrides stay in JSON. | ||
| - **`parseThinkingBudgetFromCharacterSettings`**, **`resolveAnthropicThinkingBudgetTokens`**, **`parseAnthropicCotBudgetMaxFromEnv`**, **`ANTHROPIC_THINKING_BUDGET_CHARACTER_SETTINGS_KEY`** — See `packages/lib/providers/anthropic-thinking.ts`. **Why:** Single resolution path and a stable settings key for dashboards/APIs. | ||
| - **`packages/lib/providers/cloud-provider-options.ts`** — Shared type for merged `providerOptions`. **Why:** Type-safe merges without `any`. | ||
| - **`mockMiladyPricingMinimumDepositForRouteTests`** — Test helper in `packages/tests/helpers/mock-milady-pricing-for-route-tests.ts`. **Why:** Partial `MILADY_PRICING` mocks broke Milady billing cron under full `bun run test:unit`. | ||
|
|
||
| ### Changed | ||
|
|
||
| - **`POST /api/agents/{id}/mcp`** (`chat` tool) and **`POST /api/agents/{id}/a2a`** (`chat`) pass character `settings` into `mergeAnthropicCotProviderOptions`. **Why:** Those routes always resolve a `user_characters` row; other v1 routes remain env-only until a character is available on the request path. | ||
| - **Milady billing cron unit tests** — `z-milady-billing-route.test.ts`, queue-backed DB mocks, `package.json` script paths. **Why:** `mock.module` ordering and partial pricing objects caused flaky full-suite failures. | ||
|
|
||
| ### Documentation | ||
|
|
||
| - **`docs/anthropic-cot-budget.md`** — Per-agent settings, env default/max, operator checklist, MCP/A2A scope. | ||
| - **`docs/unit-testing-milady-mocks.md`** — Milady `mock.module` pitfalls. | ||
| - **`docs/ROADMAP.md`** — Done / near-term items. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { | ||
| validateBudgetTokens, | ||
| getThinkingConfig, | ||
| buildThinkingParam, | ||
| supportsExtendedThinking, | ||
| type ThinkingConfig, | ||
| type CharacterThinkingSettings, | ||
| // Note: imports are structured to unify testing across different modules consistently | ||
| } from "./anthropic-thinking"; | ||
|
|
||
| describe("anthropic-thinking", () => { | ||
| describe("validateBudgetTokens", () => { | ||
| it("returns default budget when undefined", () => { | ||
| expect(validateBudgetTokens(undefined)).toBe(10000); | ||
| }); | ||
|
|
||
| it("clamps to minimum budget", () => { | ||
| expect(validateBudgetTokens(500)).toBe(1000); | ||
| expect(validateBudgetTokens(0)).toBe(1000); | ||
| expect(validateBudgetTokens(-100)).toBe(1000); | ||
| }); | ||
|
|
||
| it("clamps to maximum budget", () => { | ||
| expect(validateBudgetTokens(150000)).toBe(100000); | ||
| expect(validateBudgetTokens(100001)).toBe(100000); | ||
| }); | ||
|
|
||
| it("returns valid values within range", () => { | ||
| expect(validateBudgetTokens(1000)).toBe(1000); | ||
| expect(validateBudgetTokens(50000)).toBe(50000); | ||
| expect(validateBudgetTokens(100000)).toBe(100000); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getThinkingConfig", () => { | ||
| it("returns disabled config when settings undefined", () => { | ||
| expect(getThinkingConfig(undefined)).toEqual({ enabled: false }); | ||
| }); | ||
|
|
||
| it("returns disabled config when anthropicThinking undefined", () => { | ||
| expect(getThinkingConfig({})).toEqual({ enabled: false }); | ||
| }); | ||
|
|
||
| it("returns disabled config when enabled is false", () => { | ||
| const settings: CharacterThinkingSettings = { | ||
| anthropicThinking: { enabled: false }, | ||
| }; | ||
| expect(getThinkingConfig(settings)).toEqual({ enabled: false }); | ||
| }); | ||
|
|
||
| it("returns enabled config with default budget", () => { | ||
| const settings: CharacterThinkingSettings = { | ||
| anthropicThinking: { enabled: true }, | ||
| }; | ||
| expect(getThinkingConfig(settings)).toEqual({ | ||
| enabled: true, | ||
| budgetTokens: 10000, | ||
| }); | ||
| }); | ||
|
|
||
| it("returns enabled config with custom budget", () => { | ||
| const settings: CharacterThinkingSettings = { | ||
| anthropicThinking: { enabled: true, budgetTokens: 25000 }, | ||
| }; | ||
| expect(getThinkingConfig(settings)).toEqual({ | ||
| enabled: true, | ||
| budgetTokens: 25000, | ||
| }); | ||
| }); | ||
|
|
||
| it("validates and clamps budget tokens", () => { | ||
| const settings: CharacterThinkingSettings = { | ||
| anthropicThinking: { enabled: true, budgetTokens: 500 }, | ||
| }; | ||
| expect(getThinkingConfig(settings)).toEqual({ | ||
| enabled: true, | ||
| budgetTokens: 1000, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("buildThinkingParam", () => { | ||
| it("returns undefined when disabled", () => { | ||
| const config: ThinkingConfig = { enabled: false }; | ||
| expect(buildThinkingParam(config)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("returns thinking param when enabled with budget", () => { | ||
| const config: ThinkingConfig = { enabled: true, budgetTokens: 15000 }; | ||
| expect(buildThinkingParam(config)).toEqual({ | ||
| type: "enabled", | ||
| budget_tokens: 15000, | ||
| }); | ||
| }); | ||
|
|
||
| it("uses default budget when budgetTokens undefined", () => { | ||
| const config: ThinkingConfig = { enabled: true }; | ||
| expect(buildThinkingParam(config)).toEqual({ | ||
| type: "enabled", | ||
| budget_tokens: 10000, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("supportsExtendedThinking", () => { | ||
| it("returns true for claude-3-5-sonnet models", () => { | ||
| expect(supportsExtendedThinking("claude-3-5-sonnet-20241022")).toBe(true); | ||
| expect(supportsExtendedThinking("claude-3-5-sonnet")).toBe(true); | ||
| expect(supportsExtendedThinking("Claude-3-5-Sonnet")).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true for claude-3.5-sonnet models", () => { | ||
| expect(supportsExtendedThinking("claude-3.5-sonnet")).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true for claude-3-opus models", () => { | ||
| expect(supportsExtendedThinking("claude-3-opus-20240229")).toBe(true); | ||
| expect(supportsExtendedThinking("claude-3-opus")).toBe(true); | ||
| expect(supportsExtendedThinking("Claude-3-Opus")).toBe(true); | ||
| }); | ||
|
|
||
| it("returns false for unsupported models", () => { | ||
| expect(supportsExtendedThinking("claude-3-haiku")).toBe(false); | ||
| expect(supportsExtendedThinking("claude-2")).toBe(false); | ||
| expect(supportsExtendedThinking("gpt-4")).toBe(false); | ||
| expect(supportsExtendedThinking("gemini-pro")).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Root test imports from nonexistent module path
Medium Severity
The root-level
anthropic-thinking.test.tsimportsvalidateBudgetTokens,getThinkingConfig,buildThinkingParam, andCharacterThinkingSettingsfrom./anthropic-thinking, but no such file exists at the repository root. The actual implementation lives atpackages/lib/providers/anthropic-thinking.tsand exports completely different functions. This test will fail at import time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissed: Comment targets line 9 but identifier
validateBudgetTokensnot found in file — code may have been removed or renamed