* 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>
132 lines
5.1 KiB
TypeScript
132 lines
5.1 KiB
TypeScript
import { defineAgentIntent } from './types'
|
|
import { OPUS_MODEL, EFFORT_DEEP } from '@/lib/agent/composer/client'
|
|
import { renderAgentGroundRules } from './shared-rules'
|
|
|
|
// vat.review: "Fråga [namn]" from the VAT declaration preview.
|
|
//
|
|
// Highest-stakes regular intent: the user is about to submit a momsdeklaration
|
|
// and wants a sanity check. The agent reads the Rutor (05-62), spots
|
|
// anomalies vs. the prior period, validates that one-sided reverse-charge
|
|
// flags balance, and points out filing/payment deadlines.
|
|
//
|
|
// Declarative atoms: swedish-vat (essential), plus accounting-compliance and
|
|
// the company's vertical/modifier so industry-specific quirks fire
|
|
// (restaurang's 12/25 % split, bygg's omvänd skattskyldighet, e-handel OSS).
|
|
//
|
|
// Opus per plan §8 V1 #7: anomaly + cross-check reasoning rewards deeper
|
|
// reasoning than Sonnet.
|
|
|
|
interface VatReviewArgs {
|
|
period_type?: 'monthly' | 'quarterly' | 'yearly'
|
|
year?: number
|
|
period?: number
|
|
}
|
|
|
|
interface CapturedVatReview {
|
|
period: {
|
|
period_type: string | null
|
|
year: number | null
|
|
period: number | null
|
|
label: string | null
|
|
}
|
|
company_moms_period: string | null
|
|
filing_deadline: string | null
|
|
}
|
|
|
|
export const vatReview = defineAgentIntent<VatReviewArgs, CapturedVatReview>({
|
|
id: 'vat.review',
|
|
buttonLabel: 'Fråga om denna deklaration',
|
|
sheetTitle: 'Granska momsdeklaration',
|
|
|
|
atoms: {
|
|
mode: 'declarative',
|
|
horizontal: ['swedish-vat', 'swedish-accounting-compliance'],
|
|
includeCompanyVertical: true,
|
|
includeCompanyModifiers: true,
|
|
},
|
|
|
|
// Agent reads the actual Rutor via the tool; we don't capture them server-
|
|
// side because the report is large and version-sensitive.
|
|
tools: [
|
|
'gnubok_get_vat_report',
|
|
'gnubok_vat_close_check',
|
|
'gnubok_query_journal',
|
|
'gnubok_load_skill',
|
|
'gnubok_search_tools',
|
|
'gnubok_remember_fact',
|
|
'gnubok_forget_fact',
|
|
],
|
|
|
|
model: OPUS_MODEL,
|
|
|
|
// Reason over the period figures + Rutor in the thinking channel, so the
|
|
// visible reply is one conclusion, not a running commentary of each read
|
|
// followed by a restated summary. Parity with the other reasoning intents.
|
|
thinking: { effort: EFFORT_DEEP },
|
|
|
|
capture: async ({ period_type, year, period }, { supabase, companyId }) => {
|
|
const { data: settings } = await supabase
|
|
.from('company_settings')
|
|
.select('moms_period')
|
|
.eq('company_id', companyId)
|
|
.maybeSingle()
|
|
const momsPeriod = (settings as { moms_period?: string | null } | null)?.moms_period ?? null
|
|
|
|
// Period defaulting: if the caller didn't specify, use the company's
|
|
// declared period and the most recent applicable bucket.
|
|
const now = new Date()
|
|
const resolvedType =
|
|
period_type ??
|
|
(momsPeriod === 'yearly' ? 'yearly' : momsPeriod === 'monthly' ? 'monthly' : 'quarterly')
|
|
const resolvedYear = year ?? now.getFullYear()
|
|
let resolvedPeriod: number | undefined = period
|
|
if (resolvedPeriod == null) {
|
|
if (resolvedType === 'monthly') resolvedPeriod = now.getMonth() // previous month
|
|
else if (resolvedType === 'quarterly') resolvedPeriod = Math.floor(now.getMonth() / 3) || 4
|
|
else resolvedPeriod = 1
|
|
}
|
|
|
|
const label =
|
|
resolvedType === 'yearly'
|
|
? `${resolvedYear}`
|
|
: resolvedType === 'quarterly'
|
|
? `Q${resolvedPeriod} ${resolvedYear}`
|
|
: `${resolvedYear}-${String(resolvedPeriod).padStart(2, '0')}`
|
|
|
|
return {
|
|
period: {
|
|
period_type: resolvedType,
|
|
year: resolvedYear,
|
|
period: resolvedPeriod ?? null,
|
|
label,
|
|
},
|
|
company_moms_period: momsPeriod,
|
|
filing_deadline: null,
|
|
}
|
|
},
|
|
|
|
promptTemplate: ({ captured, profileSummary }) => {
|
|
const lines: string[] = []
|
|
if (profileSummary) lines.push(`Företagets profil: ${profileSummary}`, '')
|
|
|
|
lines.push('Användaren granskar en momsdeklaration innan inlämning.')
|
|
lines.push('')
|
|
lines.push(renderAgentGroundRules())
|
|
lines.push('')
|
|
lines.push(`Period: ${captured.period.label ?? '?'} (${captured.period.period_type ?? '?'})`)
|
|
if (captured.company_moms_period) {
|
|
lines.push(`Företagets momsperiod: ${captured.company_moms_period}`)
|
|
}
|
|
lines.push('')
|
|
lines.push('Arbetssätt:')
|
|
lines.push('1. Hämta declarationen med gnubok_get_vat_report (period_type, year, period).')
|
|
lines.push('2. Hämta gnubok_vat_close_check för pre-filing varningar (t.ex. ensidig reverse charge utan motpost).')
|
|
lines.push('3. Återrapportera Rutor 05-62 i ett kort format användaren kan ögna igenom: SE-försäljning, EU-tjänster, export, ingående/utgående moms per skattesats, reverse-charge-vyer, samt Ruta 49 (att betala / återfå).')
|
|
lines.push('4. Varna explicit för anomalier: stora avvikelser mot förra perioden, oväntade reverse-charge-belopp, saknad motpost.')
|
|
lines.push('5. Påminn om deadline (deklarationsdatum + betalningsdatum) och rekommendera fortsatta steg om allt ser bra ut.')
|
|
lines.push('')
|
|
lines.push('Svara på svenska, kort och konkret. Använd tabellform när det hjälper användaren skanna siffrorna. Ditt första svar är det första användaren ser.')
|
|
return lines.join('\n')
|
|
},
|
|
})
|