Skip to content

Commit 54f25d7

Browse files
authored
LangGraph (TypeScript) engine: a call with no name is never started (#2707)
On OpenBot Cloud a Bot on this engine had a call named "" kept in its conversation, and every later turn in it was refused, by Claude ("tool_use.name: String should have at least 1 character") and by Gemini ("function_response.name: Name cannot be empty"). streamStep started any call the stream left without a name under "" (slot.name ??= ... ?? "", then start(slot)). Now a call with no name is left out: never started, never handed back, and its tool_use block is taken out of the step's content so the next step of the run is not refused either. Logged as nameless-tool-call-dropped, counts only. The server drops such a call for every Bot as well (openbot-backend #1004); this stops the engine making one.
1 parent ea7b5a3 commit 54f25d7

2 files changed

Lines changed: 124 additions & 12 deletions

File tree

‎agent-langgraph-ts/src/run.ts‎

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ async function streamStep(
320320
continue;
321321
}
322322
slot.args += piece.args ?? "";
323-
if (slot.id && slot.name) start(slot);
323+
if (slot.id && slot.name?.trim()) start(slot);
324324
}
325325
// Gemini's OpenAI-compatible API puts the call's thought signature on its streamed delta,
326326
// which @langchain/openai keeps only in the raw calls (thought-signatures.ts).
@@ -340,9 +340,22 @@ async function streamStep(
340340

341341
const ordered = [...slots.values()].sort((a, b) => a.index - b.index);
342342
const parsed = whole.tool_calls ?? [];
343-
const calls = ordered.map((slot, position) => {
343+
/*
344+
* A CALL WITH NO NAME IS NO CALL. FOUND LIVE ON OPENBOT CLOUD, 1 December 2026: a call this engine
345+
* started with the name `""` was kept in the conversation, and every later turn in it was refused,
346+
* by Claude (`tool_use.name: String should have at least 1 character`) and by Gemini
347+
* (`function_response.name: Name cannot be empty`). No provider takes a call without a name and no
348+
* tool answers to one, so it is left out: never started, never run, never sent back to the model.
349+
* The server drops one too (openbot-backend `toolkit/src/nameless-calls.ts`), for every Bot.
350+
*/
351+
const nameless = new Set<string>();
352+
const calls = ordered.flatMap((slot, position) => {
344353
slot.id ??= parsed[position]?.id ?? randomUUID();
345354
slot.name ??= parsed[position]?.name ?? "";
355+
if (!slot.name.trim()) {
356+
nameless.add(slot.id);
357+
return [];
358+
}
346359
if (!slot.started) start(slot);
347360
run.emit({ type: "TOOL_CALL_END", toolCallId: slot.id } as BaseEvent);
348361
const sealed = signatureOf(parsed[position]) ?? slot.signature;
@@ -363,29 +376,55 @@ async function streamStep(
363376
(parsed[position]?.args as Record<string, unknown> | undefined) ?? {};
364377
}
365378
// What else the provider put on the call (Gemini's thought signature) stays with it.
366-
return {
367-
...(parsed[position] ?? {}),
368-
id: slot.id,
369-
name: slot.name,
370-
args,
371-
type: "tool_call" as const,
372-
...(sealed ? { thoughtSignature: sealed } : {}),
373-
};
379+
return [
380+
{
381+
...(parsed[position] ?? {}),
382+
id: slot.id,
383+
name: slot.name,
384+
args,
385+
type: "tool_call" as const,
386+
...(sealed ? { thoughtSignature: sealed } : {}),
387+
},
388+
];
374389
});
390+
if (nameless.size > 0)
391+
console.warn(
392+
JSON.stringify({
393+
type: "nameless-tool-call-dropped",
394+
where: "engine",
395+
count: nameless.size,
396+
}),
397+
);
375398

376399
// The provider's own content is kept for the rest of this run (Anthropic's thinking and tool_use
377400
// blocks, progress updates among them, signed and unchanged; the Responses API's reasoning
378-
// items), so a tool step continues the way it began.
401+
// items), so a tool step continues the way it began. All but a nameless call's own block, which
402+
// the provider would refuse on the next step of this run.
379403
return new AIMessage({
380404
id: messageId,
381-
content: whole.content as never,
405+
content: withoutNamelessBlocks(whole.content, nameless) as never,
382406
tool_calls: calls,
383407
additional_kwargs: whole.additional_kwargs,
384408
response_metadata: whole.response_metadata,
385409
...(whole.usage_metadata ? { usage_metadata: whole.usage_metadata } : {}),
386410
});
387411
}
388412

413+
/** A step's content without the `tool_use` blocks of calls left out for having no name. */
414+
function withoutNamelessBlocks(
415+
content: AIMessageChunk["content"],
416+
nameless: ReadonlySet<string>,
417+
): AIMessageChunk["content"] {
418+
if (!Array.isArray(content)) return content;
419+
const kept = content.filter((block) => {
420+
const part = block as { type?: unknown; id?: unknown; name?: unknown };
421+
if (part.type !== "tool_use") return true;
422+
if (typeof part.id === "string" && nameless.has(part.id)) return false;
423+
return typeof part.name === "string" && part.name.trim().length > 0;
424+
});
425+
return kept.length === content.length ? content : kept;
426+
}
427+
389428
/** Whether a step said a line to the person: its words, Claude's progress updates included. */
390429
function saidLine(message: AIMessage, progressUpdates: boolean): boolean {
391430
const words = progressUpdates ? progressWords(message.content) : message.text;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* A call the model streams with no name is never started.
3+
*
4+
* FOUND LIVE ON OPENBOT CLOUD, 1 December 2026: a Bot on this engine had a call named `""` kept in
5+
* its conversation, and every later turn in it was refused, by Claude (`messages.29.content.0.
6+
* tool_use.name: String should have at least 1 character`) and by Gemini (`function_response.name:
7+
* Name cannot be empty`). The engine started any call the stream left without a name under `""`.
8+
*
9+
* Driven through the real AG-UI endpoint against a provider that speaks each API's real streaming
10+
* format, with a step that makes a named call beside one with no name: only the named call is
11+
* started and handed back.
12+
*/
13+
import assert from "node:assert/strict";
14+
import { test } from "node:test";
15+
import { always, fakeProvider } from "./fake-provider.ts";
16+
import { conversation, pendingOf, run, withEngine } from "./helpers.ts";
17+
18+
const LOOKUP = {
19+
name: "lookup",
20+
description: "Look something up.",
21+
parameters: { type: "object", properties: { q: { type: "string" } } },
22+
};
23+
24+
const STEP = {
25+
text: "Looking it up.",
26+
calls: [
27+
{ id: "call_named", name: "lookup", args: { q: "Q3" } },
28+
{ id: "call_nameless", name: "", args: { title: "Q3" } },
29+
],
30+
};
31+
32+
const providers = {
33+
"Anthropic Messages": (base: string) => ({
34+
BOT_PROVIDER: "anthropic",
35+
ANTHROPIC_API_KEY: "sk-ant-test",
36+
ANTHROPIC_BASE_URL: base,
37+
}),
38+
"OpenAI Chat Completions": (base: string) => ({
39+
BOT_PROVIDER: "openai",
40+
BOT_MODEL: "gpt-5.2",
41+
OPENAI_API_KEY: "sk-test",
42+
OPENAI_BASE_URL: `${base}/v1`,
43+
}),
44+
};
45+
46+
for (const [wire, envFor] of Object.entries(providers)) {
47+
test(`${wire}: a call streamed with no name is not started; the named one beside it is`, async () => {
48+
const provider = await fakeProvider(always(STEP));
49+
try {
50+
const result = await withEngine({ env: envFor(provider.base) }, (base) =>
51+
run(base, conversation({ tools: [LOOKUP] })),
52+
);
53+
const starts = result.events.filter(
54+
(event) => event.type === "TOOL_CALL_START",
55+
);
56+
assert.deepEqual(
57+
starts.map((event) => event.toolCallName),
58+
["lookup"],
59+
"only the named call is started",
60+
);
61+
assert.equal(result.events.at(-1)?.type, "RUN_FINISHED");
62+
assert.deepEqual(pendingOf(result.events), [
63+
String(starts[0]?.toolCallId),
64+
]);
65+
assert.ok(
66+
!JSON.stringify(result.events).includes("call_nameless"),
67+
"nothing about the nameless call leaves the engine",
68+
);
69+
} finally {
70+
await provider.close();
71+
}
72+
});
73+
}

0 commit comments

Comments
 (0)