fix(agent): a deadline given in the answer must be recorded

The real-model Agent check saw the model compute the tax objection
deadline correctly (4 November 2026) and never call record_deadline, so
no reminder was set. An answer naming a deadline date while the matter
holds none now gets the one correction, like a narrated call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Lem7GyhyyjKhmwjG8G7Ud
This commit is contained in:
Claude committed 2026-10-22 07:47:54 +00:00
1 parent bc4535a348
commit b33cf5db8d
3 files changed
+36 -4

No files matched your search

+7 -1
View File
@@ -586,6 +586,7 @@ async function runTurnLocked(input: {
let finalText = "";
let repaired = false;
let unverified = false;
let recorded = 0;
for (let round = 0; round < MAX_ROUNDS; round++) {
const last = round === MAX_ROUNDS - 1;
@@ -626,7 +627,11 @@ async function runTurnLocked(input: {
if (turn.toolCalls.length === 0) {
// The server holds the answer to what the prompt asks (answer-check.ts):
// no tool calls written out instead of made, no law without a source.
const problems = answerProblems(turn.text, { toolNames: TOOL_NAMES, sources: sources.length });
const problems = answerProblems(turn.text, {
toolNames: TOOL_NAMES,
sources: sources.length,
deadlines: recorded + view.items.filter((i) => i.kind === "deadline").length,
});
if (problems.length && !repaired && round < MAX_ROUNDS - 2) {
repaired = true;
conversation.push(
@@ -746,6 +751,7 @@ async function runTurnLocked(input: {
label: args.label!,
quote: args.quote,
});
recorded++;
await appendStep(db, m, {
tool: "record_deadline",
summary: `${args.date}: ${args.label}`,
+10
View File
@@ -41,9 +41,19 @@ describe("answer check", () => {
expect(answerProblems("I will search the web for the cantonal rules.", none)).toEqual([]);
});
it("catches a deadline given but not recorded", () => {
const text = "## Your deadline: **4 November 2026**\nThe 30 days run from service.";
expect(answerProblems(text, { ...none, deadlines: 0 })).toEqual(["unrecorded"]);
expect(answerProblems("Die Frist läuft am 04.11.2026 ab.", { ...none, deadlines: 0 })).toEqual(["unrecorded"]);
expect(answerProblems(text, { ...none, deadlines: 1 })).toEqual([]);
// A date with no deadline in sight is not a deadline.
expect(answerProblems("The assessment is dated 2 October 2026.", { ...none, deadlines: 0 })).toEqual([]);
});
it("asks for each problem, plainly", () => {
const p = repairPrompt(["narrated", "unsourced"]);
expect(p).toMatch(/Call the tools now/);
expect(p).toMatch(/web_search/);
expect(repairPrompt(["unrecorded"])).toMatch(/record_deadline/);
});
});
+19 -3
View File
@@ -18,26 +18,40 @@
* natively) switched to text calls and then answered "(called note_fact)"; the
* real-model Agent check went from passing to failing. Without it, it passes.
* unsourced — a rule of law stated in a turn that consulted no source
* unrecorded — a deadline date given in the answer while the matter holds
* no deadline: the Agent check saw a model compute "4 November
* 2026" correctly and never call record_deadline, so the
* reminder the person relies on was never set
*
* The agent gets one precise correction per problem and tries again; an answer
* still failing is stored with a visible "not checked against a source" step,
* never silently.
*/
export type AnswerProblem = "narrated" | "unsourced";
export type AnswerProblem = "narrated" | "unsourced" | "unrecorded";
/** A statement of law: an article, a paragraph sign, a Swiss/Liechtenstein code or collection number. */
const CITES_LAW =
/(?:\b[Aa]rt(?:ikel|icle|icolo|ículo|\.)\s*\d|§\s*\d|\b(?:OR|ZGB|StGB|SchKG|ZPO|DBG|StHG|AIG|ATSG|CO|CC|CPC|LP|PGR|ABGB)\b\s*(?:Art\.?\s*)?\d|\bSR\s*\d{3}|\bLGBl\.?\s*\d)/;
const MONTHS =
"Jan(?:uary|uar)?|Feb(?:ruary|ruar)?|M(?:ar(?:ch)?|ärz)|Apr(?:il)?|Ma[iy]|June?|Juni|July?|Juli|Aug(?:ust)?|Sep(?:tember)?|O[ck]t(?:ober)?|Nov(?:ember)?|De[cz](?:ember)?|janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre|gennaio|febbraio|marzo|aprile|maggio|giugno|luglio|agosto|settembre|ottobre|novembre|dicembre";
/** A calendar date: "4 November 2026", "4. November 2026", "04.11.2026", "2026-11-04". */
const DATE = new RegExp(
`\\b\\d{1,2}\\.?\\s*(?:${MONTHS})\\.?\\s+\\d{4}\\b|\\b\\d{1,2}\\.\\d{1,2}\\.\\d{4}\\b|\\b\\d{4}-\\d{2}-\\d{2}\\b`,
"i",
);
const DEADLINE_WORD = /\b(?:deadline|Frist|délai|termine|scadenza)/i;
export function answerProblems(
text: string,
turn: { toolNames: readonly string[]; sources: number },
turn: { toolNames: readonly string[]; sources: number; deadlines?: number },
): AnswerProblem[] {
const problems: AnswerProblem[] = [];
const names = turn.toolNames.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
const narrated = new RegExp(`\\b(?:${names})\\s*\\(|^\\s*(?:\\*\\*)?TOOL(?:\\*\\*)?\\s*[:=]`, "m");
if ((names && narrated.test(text)) || /^\s*\(called [\w, ]+\)\s*$/.test(text)) problems.push("narrated");
if (turn.sources === 0 && CITES_LAW.test(text)) problems.push("unsourced");
if (turn.deadlines === 0 && DEADLINE_WORD.test(text) && DATE.test(text)) problems.push("unrecorded");
return problems;
}
@@ -46,7 +60,9 @@ export function repairPrompt(problems: readonly AnswerProblem[]): string {
const lines = problems.map((p) =>
p === "narrated"
? "Your answer describes tool calls instead of making them. Nothing you described has happened. Call the tools now (natively, or with the TOOL/ARGS lines), then answer."
: "Your answer states rules of law, but this turn consulted no source. Use web_search and read_page now to find the official text for each rule, cite it as [n], and drop or mark as unverified any rule you cannot source.",
: p === "unrecorded"
? "Your answer gives a deadline, but none is recorded in the matter. Call record_deadline now for each deadline, quoting the text it comes from, then answer."
: "Your answer states rules of law, but this turn consulted no source. Use web_search and read_page now to find the official text for each rule, cite it as [n], and drop or mark as unverified any rule you cannot source.",
);
return `${lines.join("\n")}\nDo not apologise or mention this message; just do it.`;
}