Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(agent-runtime): execute no-param tool calls whose arguments were omitted (#21013)

Arvin Xu7abd33e37148
diff --git a/packages/agent-runtime/src/agents/GeneralChatAgent.ts b/packages/agent-runtime/src/agents/GeneralChatAgent.ts
index 556ec950999..9f152ebce2f 100644
--- a/packages/agent-runtime/src/agents/GeneralChatAgent.ts
+++ b/packages/agent-runtime/src/agents/GeneralChatAgent.ts
@@ -26,7 +26,12 @@ import {
type SubAgentResultPayload,
type SubAgentsBatchResultPayload,
} from '../types';
-import { selectRunTools, selectToolManifestMap } from '../utils/operationToolSet';
+import {
+ EMPTY_ARGS_TOOL_CONTENT,
+ EMPTY_ARGS_TOOL_REASON,
+ partitionEmptyArgumentsCalls,
+} from '../utils/emptyArgumentsCalls';
+import { selectEffectiveToolManifestMap, selectRunTools } from '../utils/operationToolSet';
import { selectSecurityBlacklist, selectUserInterventionConfig } from '../utils/stateSlots';
import { shouldCompress } from '../utils/tokenCounter';
@@ -41,23 +46,6 @@ const TOOL_NOT_ALLOWED_REASON = 'tool_not_allowed';
const unresolvedToolContent = (names: string) =>
`Tool call rejected: no available tool is named ${names}. Copy a name exactly as declared in the tools schema and call it again.`;
-/**
- * Splits a batch into calls the executor can attempt and calls that arrived
- * with no `arguments` at all. `{}` stays executable β€” it is a legal
- * no-argument call and JSON-parses fine; only a missing arguments string is
- * the serialization-loss shape, and it cannot survive `JSON.parse` in the
- * executor anyway.
- */
-const partitionEmptyArgumentsCalls = (toolsCalling: ChatToolPayload[]) => {
- const emptyArgsCalls: ChatToolPayload[] = [];
- const executableCalls: ChatToolPayload[] = [];
- for (const toolCalling of toolsCalling) {
- if (toolCalling.arguments && toolCalling.arguments.trim().length > 0)
- executableCalls.push(toolCalling);
- else emptyArgsCalls.push(toolCalling);
- }
- return { emptyArgsCalls, executableCalls };
-};
/** The remote-device picker; walled off on device-locked runs. */
const REMOTE_DEVICE_IDENTIFIER = 'lobe-remote-device';
const UNRESOLVED_TOOL_REASON = 'tool_name_unresolved';
@@ -68,20 +56,6 @@ const UNRESOLVED_TOOL_REASON = 'tool_name_unresolved';
* broken, and failing loudly beats burning the step budget on it.
*/
const UNRESOLVED_TOOL_FEEDBACK_LIMIT = 2;
-const EMPTY_ARGS_TOOL_REASON = 'tool_arguments_empty';
-/**
- * What the model reads back when a call arrives with an empty `arguments`
- * string. Parallel tool-call batches from some model/gateway pairs lose the
- * per-call arguments during streaming serialization: the batch reaches the
- * platform as fully-formed calls whose `arguments` is `''` (vent T-673 β€”
- * 5/7/12 identical retries because the executor only answers with per-call
- * schema errors). Executing them just burns one validation error per call,
- * so the agent rejects them here with one actionable signal instead; the
- * escape that works is re-issuing the calls one at a time with complete
- * arguments.
- */
-const EMPTY_ARGS_TOOL_CONTENT =
- 'Tool call rejected: the arguments of this call arrived empty β€” the parameters were lost before execution, a known failure mode when several tool calls are emitted in parallel. The call was not executed. Call the tool again one call at a time and include the complete arguments JSON for the call.';
const PLUGIN_SCHEMA_SEPARATOR = '____';
// Leave 35% of the model window for server-side context engineering (system
// role, knowledge, memories, skills, etc.) and the model's completion. The
@@ -145,7 +119,7 @@ export class GeneralChatAgent implements Agent {
state: AgentState,
): ExtendedHumanInterventionConfig | undefined {
const { identifier, apiName } = toolCalling;
- const manifest = selectToolManifestMap(state)[identifier];
+ const manifest = selectEffectiveToolManifestMap(state)[identifier];
if (!manifest) return undefined;
@@ -254,7 +228,7 @@ export class GeneralChatAgent implements Agent {
}
// Phase 2.5: Get manifest for later use
- const manifest = selectToolManifestMap(state)[identifier];
+ const manifest = selectEffectiveToolManifestMap(state)[identifier];
// Phase 3: Per-tool dynamic resolver
const config = this.getToolInterventionConfig(toolCalling, state);
@@ -309,7 +283,7 @@ export class GeneralChatAgent implements Agent {
// Only applies to manual/allow-list modes; auto-run users accept the risk
if (!manifest) {
console.warn(
- `[InterventionGuard] Unknown tool "${identifier}/${apiName}" not found in toolManifestMap (keys: ${Object.keys(selectToolManifestMap(state)).join(', ')}), requiring intervention`,
+ `[InterventionGuard] Unknown tool "${identifier}/${apiName}" not found in effective toolManifestMap (keys: ${Object.keys(selectEffectiveToolManifestMap(state)).join(', ')}), requiring intervention`,
);
toolsNeedingIntervention.push(toolCalling);
continue;
@@ -769,7 +743,10 @@ export class GeneralChatAgent implements Agent {
// (see EMPTY_ARGS_TOOL_CONTENT). Executable calls in the same batch
// still run, and the feedback rides the resolve_blocked_tools path
// so the model sees one rejected tool row per lost call.
- const { emptyArgsCalls, executableCalls } = partitionEmptyArgumentsCalls(toolsCalling);
+ const { emptyArgsCalls, executableCalls } = partitionEmptyArgumentsCalls(
+ toolsCalling,
+ state,
+ );
const instructions: AgentInstruction[] = [];
diff --git a/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.emptyArguments.test.ts b/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.emptyArguments.test.ts
new file mode 100644
index 00000000000..819c48e42e7
--- /dev/null
+++ b/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.emptyArguments.test.ts
@@ -0,0 +1,245 @@
+import { type ChatToolPayload } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { type AgentRuntimeContext, type AgentState } from '../../types';
+import { GeneralChatAgent } from '../GeneralChatAgent';
+
+/**
+ * Scenario tests for the empty-arguments pre-check on the llm_result phase:
+ * which calls get normalized to a legal no-argument `{}` call and which get
+ * rejected as the T-673 serialization-loss shape (vent T-800). Pure-helper
+ * unit tests live beside the module in `utils/emptyArgumentsCalls.test.ts`.
+ */
+describe('GeneralChatAgent empty-arguments handling (llm_result phase)', () => {
+ const mockModelRuntimeConfig = {
+ model: 'gpt-4o-mini',
+ provider: 'openai',
+ };
+
+ const createMockState = (overrides?: Partial<AgentState>): AgentState => ({
+ operationId: 'test-session',
+ status: 'running',
+ messages: [],
+ toolManifestMap: {},
+ stepCount: 0,
+ usage: {
+ llm: { apiCalls: 0, processingTimeMs: 0, tokens: { input: 0, output: 0, total: 0 } },
+ tools: { totalCalls: 0, totalTimeMs: 0, byTool: [] },
+ humanInteraction: {
+ approvalRequests: 0,
+ promptRequests: 0,
+ selectRequests: 0,
+ totalWaitingTimeMs: 0,
+ },
+ },
+ cost: {
+ calculatedAt: new Date().toISOString(),
+ currency: 'USD',
+ llm: { byModel: [], currency: 'USD', total: 0 },
+ tools: { byTool: [], currency: 'USD', total: 0 },
+ total: 0,
+ },
+ createdAt: new Date().toISOString(),
+ lastModified: new Date().toISOString(),
+ ...overrides,
+ });
+
+ const createMockContext = (
+ phase: AgentRuntimeContext['phase'],
+ payload?: any,
+ ): AgentRuntimeContext => ({
+ phase,
+ payload,
+ session: {
+ // Note: AgentRuntimeContext.session uses sessionId for backward compatibility
+ sessionId: 'test-session',
+ messageCount: 0,
+ status: 'running',
+ stepCount: 0,
+ },
+ });
+
+ it('keeps a legal no-argument call executable (arguments "{}" is not the loss shape)', async () => {
+ const agent = new GeneralChatAgent({
+ agentConfig: { maxSteps: 100 },
+ operationId: 'test-session',
+ modelRuntimeConfig: mockModelRuntimeConfig,
+ });
+
+ const noArgsCall = {
+ apiName: 'listCriteria',
+ arguments: '{}',
+ id: 'call-1',
+ identifier: 'lobe-acceptance-evidence',
+ type: 'builtin',
+ } as unknown as ChatToolPayload;
+
+ const result = await agent.runner(
+ createMockContext('llm_result', {
+ hasToolsCalling: true,
+ parentMessageId: 'msg-1',
+ toolsCalling: [noArgsCall],
+ }),
+ createMockState({
+ toolManifestMap: {
+ 'lobe-acceptance-evidence': { identifier: 'lobe-acceptance-evidence' },
+ },
+ }),
+ );
+
+ expect(result).toEqual([
+ {
+ type: 'call_tool',
+ payload: {
+ parentMessageId: 'msg-1',
+ toolCalling: noArgsCall,
+ },
+ },
+ ]);
+ });
+
+ it('executes a no-required-parameter tool whose arguments field was omitted (vent T-800)', async () => {
+ const agent = new GeneralChatAgent({
+ agentConfig: { maxSteps: 100 },
+ operationId: 'test-session',
+ modelRuntimeConfig: mockModelRuntimeConfig,
+ });
+
+ // The T-800 shape: several provider/gateway serialization paths drop an
+ // empty arguments string entirely, so the call arrives with no
+ // `arguments` field at all. For a tool whose schema has no required
+ // properties this is a legal no-argument call, not the T-673 loss shape.
+ const omittedArgsCall = {
+ apiName: 'listCriteria',
+ id: 'call-1',
+ identifier: 'lobe-acceptance-evidence',
+ type: 'builtin',
+ } as unknown as ChatToolPayload;
+
+ const result = await agent.runner(
+ createMockContext('llm_result', {
+ hasToolsCalling: true,
+ parentMessageId: 'msg-1',
+ toolsCalling: [omittedArgsCall],
+ }),
+ createMockState({
+ toolManifestMap: {
+ 'lobe-acceptance-evidence': {
+ api: [{ name: 'listCriteria', parameters: { properties: {}, type: 'object' } }],
+ identifier: 'lobe-acceptance-evidence',
+ },
+ },
+ }),
+ );
+
+ expect(result).toEqual([
+ {
+ type: 'call_tool',
+ payload: {
+ parentMessageId: 'msg-1',
+ toolCalling: { ...omittedArgsCall, arguments: '{}' },
+ },
+ },
+ ]);
+ });
+
+ it('resolves a no-required-parameter tool manifest only exposed via activatedStepTools (Codex P2 on PR #21013)', async () => {
+ const agent = new GeneralChatAgent({
+ agentConfig: { maxSteps: 100 },
+ operationId: 'test-session',
+ modelRuntimeConfig: mockModelRuntimeConfig,
+ });
+
+ // Regression for the Codex P2 gap fix: the static map has no entry for
+ // this tool β€” it is only exposed through step-activated manifests, the
+ // same lookup shape `executors/tool.ts` uses at execution time.
+ const omittedArgsCall = {
+ apiName: 'listCriteria',
+ id: 'call-1',
+ identifier: 'lobe-acceptance-evidence',
+ type: 'builtin',
+ } as unknown as ChatToolPayload;
+
+ const result = await agent.runner(
+ createMockContext('llm_result', {
+ hasToolsCalling: true,
+ parentMessageId: 'msg-1',
+ toolsCalling: [omittedArgsCall],
+ }),
+ createMockState({
+ activatedStepTools: [
+ {
+ id: 'lobe-acceptance-evidence',
+ manifest: {
+ api: [{ name: 'listCriteria', parameters: { properties: {}, type: 'object' } }],
+ identifier: 'lobe-acceptance-evidence',
+ },
+ },
+ ],
+ } as unknown as Partial<AgentState>),
+ );
+
+ expect(result).toEqual([
+ {
+ type: 'call_tool',
+ payload: {
+ parentMessageId: 'msg-1',
+ toolCalling: { ...omittedArgsCall, arguments: '{}' },
+ },
+ },
+ ]);
+ });
+
+ it('still rejects an empty-arguments call to a tool with required parameters', async () => {
+ const agent = new GeneralChatAgent({
+ agentConfig: { maxSteps: 100 },
+ operationId: 'test-session',
+ modelRuntimeConfig: mockModelRuntimeConfig,
+ });
+
+ const requiredArgsCall = {
+ apiName: 'submitEvidence',
+ arguments: '',
+ id: 'call-1',
+ identifier: 'lobe-acceptance-evidence',
+ type: 'builtin',
+ } as unknown as ChatToolPayload;
+
+ const result = await agent.runner(
+ createMockContext('llm_result', {
+ hasToolsCalling: true,
+ parentMessageId: 'msg-1',
+ toolsCalling: [requiredArgsCall],
+ }),
+ createMockState({
+ toolManifestMap: {
+ 'lobe-acceptance-evidence': {
+ api: [
+ {
+ name: 'submitEvidence',
+ parameters: {
+ properties: { content: { type: 'string' } },
+ required: ['content'],
+ type: 'object',
+ },
+ },
+ ],
+ identifier: 'lobe-acceptance-evidence',
+ },
+ },
+ }),
+ );
+
+ expect(result).toEqual([
+ {
+ payload: {
+ blockedContent: expect.stringContaining('arguments of this call arrived empty'),
+ blockedReason: 'tool_arguments_empty',
+ parentMessageId: 'msg-1',
+ toolsCalling: [requiredArgsCall],
+ },
+ type: 'resolve_blocked_tools',
+ },
+ ]);
+ });
+});
diff --git a/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts b/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts
index 7acf22ccea2..8cc403034a6 100644
--- a/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts
+++ b/packages/agent-runtime/src/agents/__tests__/GeneralChatAgent.test.ts
@@ -1085,43 +1085,6 @@ describe('GeneralChatAgent', () => {
},
]);
});
-
- it('keeps a legal no-argument call executable (arguments "{}" is not the loss shape)', async () => {
- const agent = new GeneralChatAgent({
- agentConfig: { maxSteps: 100 },
- operationId: 'test-session',
- modelRuntimeConfig: mockModelRuntimeConfig,
- });
-
- const noArgsCall: ChatToolPayload = {
- apiName: 'listOnlineDevices',
- arguments: '{}',
- id: 'call-1',
- identifier: 'lobe-remote-device',
- type: 'builtin',
- };
-
- const result = await agent.runner(
- createMockContext('llm_result', {
- hasToolsCalling: true,
- parentMessageId: 'msg-1',
- toolsCalling: [noArgsCall],
- }),
- createMockState({
- toolManifestMap: { 'lobe-remote-device': { identifier: 'lobe-remote-device' } },
- }),
- );
-
- expect(result).toEqual([
- {
- type: 'call_tool',
- payload: {
- parentMessageId: 'msg-1',
- toolCalling: noArgsCall,
- },
- },
- ]);
- });
});
describe('tool_result phase', () => {
diff --git a/packages/agent-runtime/src/executors/tool.ts b/packages/agent-runtime/src/executors/tool.ts
index bf343bf4bc5..db216f82a9c 100644
--- a/packages/agent-runtime/src/executors/tool.ts
+++ b/packages/agent-runtime/src/executors/tool.ts
@@ -19,7 +19,7 @@ import {
extractTodosFromMessages,
redactResultForEvents,
} from '../utils';
-import { selectToolManifestMap, selectToolSourceMap } from '../utils/operationToolSet';
+import { selectEffectiveToolManifestMap, selectToolSourceMap } from '../utils/operationToolSet';
import { settleAbortedToolRows } from './abortedToolRows';
const TOOL_EXECUTION_PHASE = 'tool_execution';
@@ -114,15 +114,8 @@ const parseToolArgs = (tool: ChatToolPayload): Record<string, unknown> => {
}
};
-const buildEffectiveManifestMap = (state: AgentState): Record<string, any> => ({
- ...selectToolManifestMap(state),
- ...Object.fromEntries(
- (state.activatedStepTools ?? [])
- .filter((activation) => activation.manifest)
- .map((activation) => [activation.id, activation.manifest!]),
- ),
-});
-
+const buildEffectiveManifestMap = (state: AgentState): Record<string, any> =>
+ selectEffectiveToolManifestMap(state);
/**
* Resource an API call mutates, read from the argument its manifest names in
* `serializeBy`. Undefined when the API declares none or the argument is not a
diff --git a/packages/agent-runtime/src/utils/emptyArgumentsCalls.test.ts b/packages/agent-runtime/src/utils/emptyArgumentsCalls.test.ts
new file mode 100644
index 00000000000..240d68b1485
--- /dev/null
+++ b/packages/agent-runtime/src/utils/emptyArgumentsCalls.test.ts
@@ -0,0 +1,194 @@
+import type { ChatToolPayload } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import type { AgentState } from '../types';
+import {
+ EMPTY_ARGS_TOOL_CONTENT,
+ EMPTY_ARGS_TOOL_REASON,
+ partitionEmptyArgumentsCalls,
+ toolExpectsNoArguments,
+} from './emptyArgumentsCalls';
+
+const makeState = (manifestMap: Record<string, unknown> = {}): AgentState =>
+ ({ toolManifestMap: manifestMap }) as unknown as AgentState;
+
+const call = (overrides: Record<string, unknown>): ChatToolPayload =>
+ ({
+ id: 'call-1',
+ identifier: 'tool-a',
+ type: 'builtin',
+ ...overrides,
+ }) as unknown as ChatToolPayload;
+
+describe('toolExpectsNoArguments', () => {
+ it('returns true when the tool-level schema has no required array', () => {
+ const state = makeState({
+ 'tool-a': { identifier: 'tool-a', parameters: { properties: {}, type: 'object' } },
+ });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(true);
+ });
+
+ it('returns true when required is an empty array', () => {
+ const state = makeState({
+ 'tool-a': {
+ identifier: 'tool-a',
+ parameters: { properties: {}, required: [], type: 'object' },
+ },
+ });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(true);
+ });
+
+ it('returns false when the schema requires parameters', () => {
+ const state = makeState({
+ 'tool-a': {
+ identifier: 'tool-a',
+ parameters: {
+ properties: { target: { type: 'string' } },
+ required: ['target'],
+ type: 'object',
+ },
+ },
+ });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(false);
+ });
+
+ it('prefers the api-level schema over the tool-level schema', () => {
+ const state = makeState({
+ 'tool-a': {
+ api: [
+ { name: 'run', parameters: { required: ['x'], type: 'object' } },
+ { name: 'runAll', parameters: { properties: {}, type: 'object' } },
+ ],
+ identifier: 'tool-a',
+ parameters: { required: ['x'], type: 'object' },
+ },
+ });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(false);
+ expect(toolExpectsNoArguments(call({ apiName: 'runAll' }), state)).toBe(true);
+ });
+
+ it('falls back to the step-activated manifest when the static map misses the tool', () => {
+ const state = {
+ activatedStepTools: [
+ {
+ id: 'tool-a',
+ manifest: { identifier: 'tool-a', parameters: { properties: {}, type: 'object' } },
+ },
+ ],
+ operationId: 'test-session',
+ toolManifestMap: {},
+ } as unknown as AgentState;
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(true);
+ });
+
+ it('returns false when the manifest is missing or has no parameters schema', () => {
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), makeState({}))).toBe(false);
+ const state = makeState({ 'tool-a': { identifier: 'tool-a' } });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(false);
+ });
+
+ it('rejects oneOf combinator schemas that accept no empty object (Codex P2 on PR #21013)', () => {
+ const state = makeState({
+ 'tool-a': {
+ identifier: 'tool-a',
+ parameters: {
+ oneOf: [
+ { required: ['path'], type: 'object' },
+ { required: ['url'], type: 'object' },
+ ],
+ type: 'object',
+ },
+ },
+ });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(false);
+ });
+
+ it('rejects allOf/anyOf/not/if combinators and minProperties', () => {
+ const variants = [
+ { allOf: [{ required: ['x'] }] },
+ { anyOf: [{ required: ['x'] }] },
+ { not: { required: ['x'] } },
+ { unevaluatedProperties: false, type: 'object' },
+ { minProperties: 1, type: 'object' },
+ { enum: [{}, { a: 1 }] },
+ { dependentRequired: { a: ['b'] }, properties: { a: { type: 'string' } }, type: 'object' },
+ ];
+ for (const parameters of variants) {
+ const state = makeState({ 'tool-a': { identifier: 'tool-a', parameters } });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(false);
+ }
+ });
+
+ it('rejects a non-object type and a non-array required', () => {
+ const state = makeState({
+ 'tool-a': { identifier: 'tool-a', parameters: { type: 'string' } },
+ 'tool-b': { identifier: 'tool-b', parameters: { required: 'x', type: 'object' } },
+ });
+ expect(toolExpectsNoArguments(call({ apiName: 'run' }), state)).toBe(false);
+ expect(toolExpectsNoArguments(call({ apiName: 'run', identifier: 'tool-b' }), state)).toBe(
+ false,
+ );
+ });
+});
+
+describe('partitionEmptyArgumentsCalls', () => {
+ const state = makeState({
+ 'tool-a': { identifier: 'tool-a', parameters: { properties: {}, type: 'object' } },
+ 'tool-b': {
+ identifier: 'tool-b',
+ parameters: { required: ['x'], type: 'object' },
+ },
+ });
+
+ it('keeps non-empty arguments executable without touching them', () => {
+ const ok = call({ apiName: 'run', arguments: '{"x":1}' });
+ const result = partitionEmptyArgumentsCalls([ok], state);
+ expect(result).toEqual({ emptyArgsCalls: [], executableCalls: [ok] });
+ });
+
+ it('normalizes a missing arguments field on a no-param tool to "{}"', () => {
+ const omitted = call({ apiName: 'run' });
+ const result = partitionEmptyArgumentsCalls([omitted], state);
+ expect(result.emptyArgsCalls).toEqual([]);
+ expect(result.executableCalls).toEqual([{ ...omitted, arguments: '{}' }]);
+ });
+
+ it('normalizes an empty-string arguments field on a no-param tool to "{}"', () => {
+ const blank = call({ apiName: 'run', arguments: ' ' });
+ const result = partitionEmptyArgumentsCalls([blank], state);
+ expect(result.emptyArgsCalls).toEqual([]);
+ expect(result.executableCalls).toEqual([{ ...blank, arguments: '{}' }]);
+ });
+
+ it('rejects an empty-arguments call to a tool with required parameters', () => {
+ const blank = call({ apiName: 'run', arguments: '' });
+ // Same lookup shape, but the manifest requires parameters.
+ const required = call({ identifier: 'tool-b', apiName: 'run', arguments: '' });
+ const result = partitionEmptyArgumentsCalls([blank, required], {
+ ...state,
+ toolManifestMap: {
+ 'tool-a': { identifier: 'tool-a', parameters: { properties: {}, type: 'object' } },
+ 'tool-b': {
+ identifier: 'tool-b',
+ parameters: { required: ['x'], type: 'object' },
+ },
+ },
+ } as AgentState);
+ expect(result.executableCalls).toEqual([{ ...blank, arguments: '{}' }]);
+ expect(result.emptyArgsCalls).toEqual([required]);
+ });
+
+ it('rejects a missing-arguments call when no manifest exists', () => {
+ const unknown = call({ apiName: 'run' });
+ const result = partitionEmptyArgumentsCalls([unknown], makeState({}));
+ expect(result.executableCalls).toEqual([]);
+ expect(result.emptyArgsCalls).toEqual([unknown]);
+ });
+});
+
+describe('rejection feedback constants', () => {
+ it('keeps the actionable single-call escape hint in the blocked content', () => {
+ expect(EMPTY_ARGS_TOOL_CONTENT).toContain('Call the tool again one call at a time');
+ expect(EMPTY_ARGS_TOOL_REASON).toBe('tool_arguments_empty');
+ });
+});
diff --git a/packages/agent-runtime/src/utils/emptyArgumentsCalls.ts b/packages/agent-runtime/src/utils/emptyArgumentsCalls.ts
new file mode 100644
index 00000000000..b344e256fb9
--- /dev/null
+++ b/packages/agent-runtime/src/utils/emptyArgumentsCalls.ts
@@ -0,0 +1,121 @@
+import type { ChatToolPayload } from '@lobechat/types';
+
+import type { AgentState } from '../types';
+import { selectEffectiveToolManifestMap } from './operationToolSet';
+
+/**
+ * What the model reads back when a call arrives with an empty `arguments`
+ * string and its tool cannot legally be called without arguments. Parallel
+ * tool-call batches from some model/gateway pairs lose the per-call arguments
+ * during streaming serialization: the batch reaches the platform as
+ * fully-formed calls whose `arguments` is `''` (vent T-673 β€” 5/7/12 identical
+ * retries because the executor only answers with per-call schema errors).
+ * Executing them just burns one validation error per call, so the agent
+ * rejects them here with one actionable signal instead; the escape that works
+ * is re-issuing the calls one at a time with complete arguments.
+ */
+export const EMPTY_ARGS_TOOL_CONTENT =
+ 'Tool call rejected: the arguments of this call arrived empty β€” the parameters were lost before execution, a known failure mode when several tool calls are emitted in parallel. The call was not executed. Call the tool again one call at a time and include the complete arguments JSON for the call.';
+export const EMPTY_ARGS_TOOL_REASON = 'tool_arguments_empty';
+
+/**
+ * JSON Schema keywords that cannot make an object with no properties
+ * invalid, and are therefore safe to ignore when proving that `{}` is a
+ * valid input. Any keyword outside this set β€” combinators (`oneOf` /
+ * `allOf` / `anyOf` / `not`), `minProperties`, `enum` / `const`,
+ * `if` / `then`, `dependent*`, … β€” can constrain the shape in ways a
+ * missing top-level `required` does not reveal (e.g. connector/MCP schemas
+ * like `{ oneOf: [{ required: ['path'] }, { required: ['url'] }] }` accept
+ * no empty object even though `required` is absent), so such schemas stay
+ * loss-shaped and take the rejection path.
+ */
+const EMPTY_OBJECT_SAFE_KEYWORDS = new Set([
+ 'type',
+ 'properties',
+ 'required',
+ 'additionalProperties',
+ 'patternProperties',
+ 'propertyNames',
+ '$schema',
+ '$id',
+ '$defs',
+ 'definitions',
+ 'title',
+ 'description',
+ 'default',
+ 'examples',
+]);
+
+/**
+ * Conservative JSON Schema proof that an empty object is a valid input.
+ * Only schemas proven to accept `{}` normalize an omitted-arguments call;
+ * anything unrecognized or combinator-shaped is not proven.
+ */
+const schemaProvesEmptyObjectValid = (parameters: object): boolean => {
+ const schema = parameters as Record<string, unknown>;
+ for (const key of Object.keys(schema)) {
+ if (!EMPTY_OBJECT_SAFE_KEYWORDS.has(key)) return false;
+ }
+ // A non-object type (string, array, number, …) rejects `{}`.
+ if (schema.type !== undefined && schema.type !== 'object') return false;
+ const required = schema.required;
+ if (required !== undefined && (!Array.isArray(required) || required.length > 0)) return false;
+ return true;
+};
+
+/**
+ * Whether the tool's declared parameter schema makes this a legal no-argument
+ * call. A tool whose schema is proven to accept `{}` can also be invoked
+ * with the `arguments` field omitted entirely β€” several provider/gateway
+ * serialization paths drop an empty arguments string when streaming a tool
+ * call β€” so an empty `arguments` there is not the T-673 serialization-loss
+ * shape and must not be rejected. Schemas that are missing, combinator-
+ * shaped, or otherwise not proven to accept an empty object stay loss-shaped
+ * and take the rejection path.
+ */
+export const toolExpectsNoArguments = (
+ toolCalling: ChatToolPayload,
+ state: AgentState,
+): boolean => {
+ // Effective lookup (static map + step-activated manifests): a tool exposed
+ // only through `state.activatedStepTools` has no static entry, and a lookup
+ // that misses it degrades a legal no-argument call to the rejection path.
+ const manifest = selectEffectiveToolManifestMap(state)[toolCalling.identifier];
+ if (!manifest) return false;
+
+ const api = manifest.api?.find((a: any) => a.name === toolCalling.apiName);
+ // API-level schema takes precedence over tool-level, mirroring getToolInterventionConfig.
+ const parameters = api?.parameters ?? manifest.parameters;
+ if (!parameters || typeof parameters !== 'object' || Array.isArray(parameters)) return false;
+
+ return schemaProvesEmptyObjectValid(parameters);
+};
+
+/**
+ * Splits a batch into calls the executor can attempt and calls that arrived
+ * with no `arguments` at all. `{}` stays executable β€” it is a legal
+ * no-argument call and JSON-parses fine; only a missing arguments string is
+ * the serialization-loss shape, and it cannot survive `JSON.parse` in the
+ * executor anyway. Exception: a tool whose schema is proven to accept an
+ * empty object accepts an empty `arguments` β€” providers may omit the field
+ * for no-parameter calls, and rejecting it blocks legal listCriteria-style
+ * calls (vent T-800), so those calls are normalized to `{}` and executed.
+ * Combinator schemas (oneOf/allOf/anyOf) are not proven and stay rejected.
+ */
+export const partitionEmptyArgumentsCalls = (
+ toolsCalling: ChatToolPayload[],
+ state: AgentState,
+) => {
+ const emptyArgsCalls: ChatToolPayload[] = [];
+ const executableCalls: ChatToolPayload[] = [];
+ for (const toolCalling of toolsCalling) {
+ if (toolCalling.arguments && toolCalling.arguments.trim().length > 0) {
+ executableCalls.push(toolCalling);
+ } else if (toolExpectsNoArguments(toolCalling, state)) {
+ executableCalls.push({ ...toolCalling, arguments: '{}' });
+ } else {
+ emptyArgsCalls.push(toolCalling);
+ }
+ }
+ return { emptyArgsCalls, executableCalls };
+};
diff --git a/packages/agent-runtime/src/utils/operationToolSet.ts b/packages/agent-runtime/src/utils/operationToolSet.ts
index 993c6dfa458..9b0b1949158 100644
--- a/packages/agent-runtime/src/utils/operationToolSet.ts
+++ b/packages/agent-runtime/src/utils/operationToolSet.ts
@@ -5,7 +5,12 @@ import type { AgentState } from '../types';
/** Every place a run's tool set can be found on the state. */
type ToolSetCarrier = Pick<
AgentState,
- 'operationToolSet' | 'toolExecutorMap' | 'toolManifestMap' | 'toolSourceMap' | 'tools'
+ | 'activatedStepTools'
+ | 'operationToolSet'
+ | 'toolExecutorMap'
+ | 'toolManifestMap'
+ | 'toolSourceMap'
+ | 'tools'
>;
/**
@@ -27,6 +32,30 @@ export const selectRunTools = (state: Partial<ToolSetCarrier>): any[] | undefine
export const selectToolManifestMap = (state: Partial<ToolSetCarrier>): Record<string, any> =>
state.operationToolSet?.manifestMap ?? state.toolManifestMap ?? {};
+/**
+ * The run's full manifest lookup: the static manifest map plus manifests of
+ * tools activated at step level (`state.activatedStepTools`). Executors and
+ * LLM-result pre-checks must resolve step-activated tools the same way β€” a
+ * tool exposed only through `activatedStepTools` has no entry in the static
+ * map, and reading the static map alone silently degrades a pre-check to the
+ * wrong branch.
+ */
+export const selectEffectiveToolManifestMap = (
+ state: Partial<ToolSetCarrier>,
+): Record<string, any> => {
+ const staticMap = selectToolManifestMap(state);
+ const activated = state.activatedStepTools ?? [];
+ if (activated.length === 0) return staticMap;
+ return {
+ ...staticMap,
+ ...Object.fromEntries(
+ activated
+ .filter((activation) => activation.manifest)
+ .map((activation) => [activation.id, activation.manifest!]),
+ ),
+ };
+};
+
export const selectToolSourceMap = (
state: Partial<ToolSetCarrier>,
): NonNullable<AgentState['toolSourceMap']> =>