Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

ACP: match tool-call tails as models write them, and an open parameter tag only while unclosed

milind-soni712b7a455431
diff --git a/server/drivers/acp/turn-state.test.ts b/server/drivers/acp/turn-state.test.ts
index 587e57037a..1b0ac743dc 100644
--- a/server/drivers/acp/turn-state.test.ts
+++ b/server/drivers/acp/turn-state.test.ts
@@ -137,6 +137,12 @@ describe("endTurn on a reply that ends on tool-call markup", () => {
expect(replies).toEqual(['The answer is:\n{"ok":true}']);
});
+ it("leaves prose that ends on a type or a closed tag in other words alone", () => {
+ for (const text of ["It returns a Promise<Parameter>", "The method returns Promise<parameter>", "Wrap it in a <Parameter> element"]) {
+ expect(endTurn(turnWith(text).current, true, null, "Grok"), text).toEqual({ ok: true, stopReason: null });
+ }
+ });
+
it("leaves an ordinary announcement alone", () => {
const { current } = turnWith("I'll keep that in mind.");
expect(endTurn(current, true, null, "Grok")).toEqual({ ok: true, stopReason: null });
diff --git a/server/drivers/acp/turn-state.ts b/server/drivers/acp/turn-state.ts
index 52a08804d9..6fa0d07e46 100644
--- a/server/drivers/acp/turn-state.ts
+++ b/server/drivers/acp/turn-state.ts
@@ -139,12 +139,12 @@ export interface AcpTurnEnd {
const TOOL_CALL_TAIL = ["</parameter>", "</invoke>", "<tool_call>"];
/** A reply whose tail is tool-call markup no tool ran: the model wrote the call as text. A tag inside an unclosed ```
- * example block is a cut-off sample, not a leak. */
+ * example block is a cut-off sample, not a leak. The tags are matched as models write them (lower case), and an open
+ * `<parameter` only while it is still unclosed, so prose ending on a type such as `Promise<Parameter>` is a reply. */
export function endsOnToolCallMarkup(text: string): boolean {
const trimmed = text.trimEnd();
if (!trimmed || (trimmed.match(/```/g)?.length ?? 0) % 2 === 1) return false;
- const tail = trimmed.slice(-64).toLowerCase();
- return TOOL_CALL_TAIL.some((tag) => tail.endsWith(tag)) || /<parameter(?:\s[^<>]*)?>?$/i.test(trimmed);
+ return TOOL_CALL_TAIL.some((tag) => trimmed.endsWith(tag)) || /<parameter(?:\s+name=[^<>]*)?$/.test(trimmed);
}
/** How a settling turn ends, once its last text is out. A Stop the agent answers with end_turn (OpenCode does) is the