2d543ac999
* feat(agent): move every model call to Sonnet 5
Sonnet 5 is verified enabled on our Bedrock account already: a live probe of
eu.anthropic.claude-sonnet-5 in eu-north-1 answered normally, so no model-access
request was needed. The bare anthropic.claude-sonnet-5 is rejected (on-demand
throughput needs the cross-region inference profile), so the eu. prefix we
already use stays.
This is not a model-string swap. Sonnet 5 REJECTS the fixed thinking budget
outright: thinking {type:'enabled', budget_tokens} returns 400 "not supported
for this model. Use thinking.type.adaptive and output_config.effort". Every
chat intent set a budget, so the assistant would have failed on the first turn
after a bare ID change. Reasoning depth is now an effort level (STANDARD high,
DEEP xhigh), and max_tokens is explicit per tier rather than derived from a
budget that no longer exists.
display:'summarized' is load-bearing, not cosmetic. The default is 'omitted',
which still emits thinking blocks but with empty text. Measured on our own
account at xhigh effort: summarized returned ~1k characters of reasoning, the
default returned none. Without it the collapsible "Tänker ..." block in the
chat would have gone silently empty, which no mocked test would have caught.
Ceilings are raised (16k standard, 24k deep) because Sonnet 5's tokenizer
produces roughly 30% more tokens for the same text and max_tokens now caps
thinking and the visible reply together.
Also resolves the Opus 4.7 landmine recorded in the readiness doc: the composer
comment told ops to flip BEDROCK_OPUS_MODEL_ID to Opus 4.7, which would have
400d every thinking intent against the legacy budget shape. Both model
constants now point at Sonnet 5 and the stale instruction is gone.
Checked but deliberately unchanged: forced tool_choice in atom-selection. The
Sonnet 5 docs require thinking:{type:'disabled'} alongside a forced tool_choice
on Bedrock; probed against our account, the forced call succeeds without it, so
no change was made rather than adding a guard we cannot show is needed.
Other call sites moved too: invoice-inbox extraction, document extraction, the
compliance config, and the CI/CD workflows (pr-agent MODEL and MODEL_WEAK,
swedish-compliance-review, compliance-swarm).
Verified: 11315 tests pass, lint and tsc clean on every touched file, guards
pass.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* fix(agent): review triage: keep the no-thinking output ceiling, finish the model sweep
max_tokens now caps thinking and the visible reply together, so collapsing the
two tiers into one made every non-thinking intent inherit a 16000 ceiling where
it used to have 4096. Give it its own MAX_TOKENS_NO_THINKING instead, set to the
old 4096 scaled ~30% for Sonnet 5's tokenizer so the effective reply length is
unchanged rather than quietly cut.
scripts/swedish-compliance-review.mjs still fell back to Sonnet 4.6 when
REVIEW_MODEL was unset, so a manual run silently used the old model. The initial
sweep only covered .ts and .yml.
pr-agent's FALLBACK_MODELS listed the primary model as its own fallback, which is
not a fallback; dropped it and rewrote the surrounding comments, which still
described Opus 4.8 and a 200k window.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
155 lines
5.1 KiB
TypeScript
155 lines
5.1 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import type { AgentIntent } from '@/lib/agent/intents/types'
|
|
|
|
// Verifies the extended-thinking ("tänka längre") wiring: an opted-in intent
|
|
// gets a thinking config + bumped max_tokens on the model call, an intent
|
|
// without it gets neither; and thinking blocks are stripped before persistence.
|
|
//
|
|
// The Anthropic client mock mirrors run-turn-memory.test.ts: stream().on() is a
|
|
// chainable no-op and finalMessage() delegates to a queued mock that records
|
|
// the args the stream was called with.
|
|
const messagesCreate = vi.fn()
|
|
vi.mock('@/lib/agent/composer/client', () => ({
|
|
getAnthropic: () => ({
|
|
messages: {
|
|
stream: (args: unknown) => {
|
|
const stream = { on: () => stream, finalMessage: () => messagesCreate(args) }
|
|
return stream
|
|
},
|
|
},
|
|
}),
|
|
SONNET_MODEL: 'claude-sonnet-5',
|
|
MAX_TOKENS_NO_THINKING: 5400,
|
|
MAX_TOKENS_STANDARD: 16000,
|
|
MAX_TOKENS_DEEP: 24000,
|
|
}))
|
|
|
|
const MAX_TOKENS_NO_THINKING = 5400
|
|
const MAX_TOKENS_STANDARD = 16000
|
|
const MAX_TOKENS_DEEP = 24000
|
|
|
|
vi.mock('../system-prompt', () => ({
|
|
buildSystemPrompt: vi.fn().mockResolvedValue({
|
|
blocks: [],
|
|
promptHash: 'sha256:test',
|
|
atomsLoaded: [],
|
|
}),
|
|
}))
|
|
|
|
const getManyMock = vi.fn()
|
|
vi.mock('@/lib/agent/tools/registry', () => ({
|
|
agentToolRegistry: {
|
|
get: () => undefined,
|
|
getMany: (...args: unknown[]) => getManyMock(...args),
|
|
},
|
|
}))
|
|
|
|
import { runChatTurn, stripThinking } from '../run-turn'
|
|
|
|
function fakeSupabase() {
|
|
const passthrough: Record<string, unknown> = {}
|
|
const proxy: unknown = new Proxy(passthrough, {
|
|
get(_t, prop) {
|
|
if (prop === 'then') {
|
|
return (resolve: (v: unknown) => void) => resolve({ data: null, error: null })
|
|
}
|
|
return () => proxy
|
|
},
|
|
})
|
|
return proxy as unknown as Parameters<typeof runChatTurn>[0]['supabase']
|
|
}
|
|
|
|
function baseIntent(): AgentIntent {
|
|
return {
|
|
id: 'general.help',
|
|
buttonLabel: 'x',
|
|
sheetTitle: 'x',
|
|
atoms: { mode: 'progressive', horizontal: [], includeCompanyVertical: false, includeCompanyModifiers: false },
|
|
tools: [],
|
|
model: 'claude-sonnet-4-6',
|
|
capture: async () => ({}),
|
|
promptTemplate: () => '',
|
|
}
|
|
}
|
|
|
|
async function runWith(intent: AgentIntent) {
|
|
messagesCreate.mockResolvedValueOnce({
|
|
content: [{ type: 'text', text: 'ok' }],
|
|
stop_reason: 'end_turn',
|
|
})
|
|
getManyMock.mockResolvedValue([])
|
|
await runChatTurn({
|
|
supabase: fakeSupabase(),
|
|
userId: 'u',
|
|
companyId: 'c',
|
|
companyName: 'X',
|
|
firstName: 'A',
|
|
intent,
|
|
conversationId: 'conv',
|
|
userMessage: 'hej',
|
|
persist: false,
|
|
emit: () => true,
|
|
})
|
|
// The args object the stream was invoked with.
|
|
return messagesCreate.mock.calls[0][0] as {
|
|
thinking?: unknown
|
|
output_config?: unknown
|
|
max_tokens?: number
|
|
}
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('runChatTurn: extended thinking wiring', () => {
|
|
it('requests adaptive thinking with a summarized display when the intent opts in', async () => {
|
|
const args = await runWith({ ...baseIntent(), thinking: { effort: 'high' } })
|
|
// Sonnet 5 rejects { type: 'enabled', budget_tokens } outright.
|
|
expect(args.thinking).toEqual({ type: 'adaptive', display: 'summarized' })
|
|
// display:'summarized' is what makes reasoning text actually arrive; the
|
|
// default 'omitted' streams empty thinking blocks and the chat's
|
|
// "Tänker …" block would never populate.
|
|
expect(args.output_config).toEqual({ effort: 'high' })
|
|
expect(args.max_tokens).toBe(MAX_TOKENS_STANDARD)
|
|
})
|
|
|
|
it('raises the output ceiling for the deep-reasoning tier', async () => {
|
|
const args = await runWith({ ...baseIntent(), thinking: { effort: 'xhigh' } })
|
|
expect(args.output_config).toEqual({ effort: 'xhigh' })
|
|
// max_tokens now caps thinking AND the visible reply together.
|
|
expect(args.max_tokens).toBe(MAX_TOKENS_DEEP)
|
|
})
|
|
|
|
it('omits thinking and effort when the intent does not opt in', async () => {
|
|
const args = await runWith(baseIntent())
|
|
expect(args.thinking).toBeUndefined()
|
|
expect(args.output_config).toBeUndefined()
|
|
// A non-thinking intent keeps its own reply-sized ceiling: max_tokens now
|
|
// covers thinking too, so inheriting the reasoning tier's 16000 would let a
|
|
// plain answer run several times longer than it ever did before.
|
|
expect(args.max_tokens).toBe(MAX_TOKENS_NO_THINKING)
|
|
expect(args.max_tokens).toBeLessThan(MAX_TOKENS_STANDARD)
|
|
})
|
|
})
|
|
|
|
describe('stripThinking', () => {
|
|
it('drops thinking and redacted_thinking blocks but keeps text and tool_use', () => {
|
|
const blocks = [
|
|
{ type: 'thinking', thinking: 'raw chain of thought', signature: 'sig' },
|
|
{ type: 'redacted_thinking', data: 'xxx' },
|
|
{ type: 'text', text: 'svar' },
|
|
{ type: 'tool_use', id: 't1', name: 'gnubok_load_skill', input: {} },
|
|
]
|
|
expect(stripThinking(blocks)).toEqual([
|
|
{ type: 'text', text: 'svar' },
|
|
{ type: 'tool_use', id: 't1', name: 'gnubok_load_skill', input: {} },
|
|
])
|
|
})
|
|
|
|
it('is a no-op when there are no thinking blocks', () => {
|
|
const blocks = [{ type: 'text', text: 'x' }]
|
|
expect(stripThinking(blocks)).toEqual(blocks)
|
|
})
|
|
})
|