mirror of
https://github.com/bitbaum/causius.git
synced 2026-12-04 05:07:50 +01:00
fix(agent): narration left after the correction is never stored
Agent check on 7decfe8: the final round offers no tools, so a text-protocol
model's TOOL lines there were never parsed and became the stored answer;
a bare '(called note_fact)' was stored likewise. Such an answer is now
stripped of TOOL lines, call notes and fenced JSON naming a tool; if
nothing remains, the existing 'could not finish' message is shown. The
live test logs which model served each turn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Lem7GyhyyjKhmwjG8G7Ud
This commit is contained in:
4 files changed
+32
-5
No files matched your search
@@ -44,7 +44,7 @@ import {
|
||||
import { workflowById } from "../workflows";
|
||||
import { localeEnglishNames, type Locale } from "../../i18n/routing";
|
||||
import { marketOf } from "../jurisdictions";
|
||||
import { answerProblems, repairPrompt } from "./answer-check";
|
||||
import { answerProblems, repairPrompt, withoutNarration } from "./answer-check";
|
||||
|
||||
/**
|
||||
* The agent that works a matter.
|
||||
@@ -655,7 +655,7 @@ async function runTurnLocked(input: {
|
||||
continue;
|
||||
}
|
||||
unverified = problems.includes("unsourced") || problems.includes("narrated");
|
||||
finalText = turn.text;
|
||||
finalText = problems.includes("narrated") ? withoutNarration(turn.text, TOOL_NAMES) : turn.text;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { answerProblems, repairPrompt } from "./answer-check";
|
||||
import { answerProblems, repairPrompt, withoutNarration } from "./answer-check";
|
||||
|
||||
const TOOLS = ["web_search", "read_page", "record_deadline", "update_matter", "draft_document"];
|
||||
const none = { toolNames: TOOLS, sources: 0 };
|
||||
@@ -56,6 +56,15 @@ describe("answer check", () => {
|
||||
expect(answerProblems("The assessment is dated 2 October 2026.", { ...none, deadlines: 0 })).toEqual([]);
|
||||
});
|
||||
|
||||
it("strips the narration an answer still carries after its correction", () => {
|
||||
expect(withoutNarration("(called note_fact)", TOOLS)).toBe("");
|
||||
expect(withoutNarration('TOOL: note_fact\nARGS: {"fact":"x"}', TOOLS)).toBe("");
|
||||
const json = 'Your deadline is 4 November.\n```json\n{ "action": "update_matter" }\n```';
|
||||
expect(withoutNarration(json, TOOLS)).toBe("Your deadline is 4 November.");
|
||||
const code = 'Example:\n```json\n{ "amount": 1 }\n```';
|
||||
expect(withoutNarration(code, TOOLS)).toBe(code);
|
||||
});
|
||||
|
||||
it("asks for each problem, plainly", () => {
|
||||
const p = repairPrompt(["narrated", "unsourced"]);
|
||||
expect(p).toMatch(/Call the tools now/);
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
* still failing is stored with a visible "not checked against a source" step,
|
||||
* never silently.
|
||||
*/
|
||||
import { stripToolCallLines } from "@bitbaum/ai-kit";
|
||||
|
||||
export type AnswerProblem = "narrated" | "unsourced" | "unrecorded";
|
||||
|
||||
/** A statement of law: an article, a paragraph sign, a Swiss/Liechtenstein code or collection number. */
|
||||
@@ -70,3 +72,19 @@ export function repairPrompt(problems: readonly AnswerProblem[]): string {
|
||||
);
|
||||
return `${lines.join("\n")}\nDo not apologise or mention this message; just do it.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* An answer that still narrates after its one correction is stored without
|
||||
* the narration: TOOL/ARGS lines, notes of calls, fenced JSON naming a tool.
|
||||
* The last round offers no tools, so nothing parses them there; left in, they
|
||||
* read as work done. What remains may be empty, and the caller says so.
|
||||
*/
|
||||
export function withoutNarration(text: string, toolNames: readonly string[]): string {
|
||||
const names = new Set(toolNames);
|
||||
return stripToolCallLines(text)
|
||||
.replace(/```[a-z]*\n([\s\S]*?)```/g, (block, body: string) =>
|
||||
[...body.matchAll(/"(\w+)"/g)].some((m) => names.has(m[1])) ? "" : block,
|
||||
)
|
||||
.replace(/^\s*\(called [\w, ]+\)\s*$/gm, "")
|
||||
.trim();
|
||||
}
|
||||
+2
-2
@@ -65,7 +65,7 @@ describe.skipIf(!available)("a real model works a matter", () => {
|
||||
for (const i of view.items) console.log(`[agent] item ${i.kind} ${i.due} ${i.label}`);
|
||||
console.log(`[agent] answer ${answer && answer.kind === "message" ? answer.text.slice(0, 600).replace(/\n/g, " ") : "-"}`);
|
||||
const sent = seen.join("\n");
|
||||
console.log(`[agent] model requests ${seen.length}; name sent: ${/Erika|Muster/.test(sent)}`);
|
||||
console.log(`[agent] model requests ${seen.length}; name sent: ${/Erika|Muster/.test(sent)}; served by ${outcome.ok ? outcome.servedBy : "-"}`);
|
||||
|
||||
expect(outcome.ok).toBe(true);
|
||||
expect(sent).not.toMatch(/Erika|Muster/);
|
||||
@@ -92,7 +92,7 @@ describe.skipIf(!available)("a real model works a matter", () => {
|
||||
const text = answer && answer.kind === "message" ? answer.text : "";
|
||||
const sources = answer && answer.kind === "message" ? (answer.sources ?? []) : [];
|
||||
console.log(`[agent] rent: outcome ${JSON.stringify(outcome)}`);
|
||||
console.log(`[agent] rent: steps ${steps.join(", ")}`);
|
||||
console.log(`[agent] rent: steps ${steps.join(", ")}; served by ${outcome.ok ? outcome.servedBy : "-"}`);
|
||||
for (const i of view.items) console.log(`[agent] rent: item ${i.kind} ${i.due} ${i.label}`);
|
||||
console.log(`[agent] rent: sources ${sources.map((s) => s.url).join(" ")}`);
|
||||
console.log(`[agent] rent: answer ${text.slice(0, 900).replace(/\n/g, " ")}`);
|
||||
|
||||
Reference in new issue
Block a user