Skip to content

Commit f158ec5

Browse files
author
Xiaomi
committed
fix(tool-search): normalize dotted call arguments (#119418)
1 parent b3aab44 commit f158ec5

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎src/agents/tool-search-runtime.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ describe("Tool Search flattened call arguments", () => {
6363
arguments: { id: "inspect_resource", command: "list", timeout_ms: 5_000 },
6464
expected: { command: "list", timeout_ms: 5_000 },
6565
},
66+
{
67+
label: "dotted args from compatibility providers",
68+
arguments: {
69+
id: "inspect_resource",
70+
"args.path": "projects/example.md",
71+
"args.limit": 20,
72+
},
73+
expected: { path: "projects/example.md", limit: 20 },
74+
},
75+
{
76+
label: "ordinary flattened args precedence over dotted args",
77+
arguments: {
78+
id: "inspect_resource",
79+
"args.path": "projects/dotted.md",
80+
path: "projects/flattened.md",
81+
},
82+
expected: { path: "projects/flattened.md" },
83+
},
6684
{
6785
label: "toolId selector with a target id",
6886
arguments: { toolId: "inspect_resource", id: "record-7" },
@@ -84,8 +102,10 @@ describe("Tool Search flattened call arguments", () => {
84102
id: "inspect_resource",
85103
args: { command: "nested" },
86104
command: "flattened",
105+
"args.command": "dotted",
106+
"args.path": "projects/dotted.md",
87107
},
88-
expected: { command: "nested" },
108+
expected: { command: "nested", path: "projects/dotted.md" },
89109
},
90110
{
91111
label: "explicit input precedence",

‎src/agents/tool-search-runtime.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,17 @@ export function readToolSearchCallArgs(
241241
catalog?: ToolSearchCatalogSession,
242242
): { id: string; input: unknown } {
243243
const params = asToolParamsRecord(args);
244+
const dottedInput = Object.fromEntries(
245+
Object.entries(params)
246+
.filter(([key]) => key.startsWith("args.") && key.length > 5)
247+
.map(([key, value]) => [key.slice(5), value]),
248+
);
244249
const nestedInput = params.args ?? params.input;
245250
if (nestedInput != null) {
246-
return { id: readToolSearchId(params), input: nestedInput };
251+
return {
252+
id: readToolSearchId(params),
253+
input: isRecord(nestedInput) ? { ...dottedInput, ...nestedInput } : nestedInput,
254+
};
247255
}
248256

249257
const selectorKeys = ["id", "toolId", "name"] as const;
@@ -279,10 +287,11 @@ export function readToolSearchCallArgs(
279287
...matchingSelectors.map(({ key }) => key),
280288
...(matchingSelector ? [] : [selector ?? "id"]),
281289
]);
290+
const targetInputEntries = Object.entries(params).filter(([key]) => !wrapperKeys.has(key));
282291
const flattenedInput = Object.fromEntries(
283-
Object.entries(params).filter(([key]) => !wrapperKeys.has(key)),
292+
targetInputEntries.filter(([key]) => !(key.startsWith("args.") && key.length > 5)),
284293
);
285-
return { id, input: flattenedInput };
294+
return { id, input: { ...dottedInput, ...flattenedInput } };
286295
}
287296

288297
function getTelemetry(catalog: ToolSearchCatalogSession) {

0 commit comments

Comments
 (0)