Skip to content

Commit 1fdff06

Browse files
sjhuclaude
andcommitted
perf(tool-calling): compress tool prompt from 730 to 611 chars
Shorten tool descriptions and instructions to reduce prompt overhead. Less tokens = faster response + lower ban risk. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e0666e4 commit 1fdff06

2 files changed

Lines changed: 18 additions & 36 deletions

File tree

src/zero-token/tool-calling/web-tool-defs.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@ export interface WebToolDef {
1010
}
1111

1212
export const WEB_CORE_TOOLS: WebToolDef[] = [
13-
{ name: "web_search", description: "Search the web", parameters: { query: "search query" } },
14-
{ name: "web_fetch", description: "Fetch URL content", parameters: { url: "URL to fetch" } },
15-
{ name: "exec", description: "Run shell command", parameters: { command: "shell command" } },
16-
{ name: "read", description: "Read file contents", parameters: { path: "file path" } },
17-
{
18-
name: "write",
19-
description: "Write to file",
20-
parameters: { path: "file path", content: "file content" },
21-
},
22-
{
23-
name: "message",
24-
description: "Send message",
25-
parameters: { text: "message text", channel: "channel name" },
26-
},
13+
{ name: "web_search", description: "Search web", parameters: { query: "string" } },
14+
{ name: "web_fetch", description: "Fetch URL", parameters: { url: "string" } },
15+
{ name: "exec", description: "Run command", parameters: { command: "string" } },
16+
{ name: "read", description: "Read file", parameters: { path: "string" } },
17+
{ name: "write", description: "Write file", parameters: { path: "string", content: "string" } },
18+
{ name: "message", description: "Send msg", parameters: { text: "string", channel: "string" } },
2719
];
2820

2921
/** Compact JSON string of tool definitions */

src/zero-token/tool-calling/web-tool-prompt.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,27 @@ import { toolDefsJson } from "./web-tool-defs.js";
1010

1111
const TOOL_DEFS = toolDefsJson();
1212

13-
const EN_TEMPLATE = `You have these tools:
14-
${TOOL_DEFS}
15-
16-
To use a tool, reply ONLY with:
17-
\`\`\`tool_json
18-
{"tool":"name","parameters":{"key":"value"}}
13+
const EN_TEMPLATE = `Tools: ${TOOL_DEFS}
14+
Use tool? Reply ONLY: \`\`\`tool_json
15+
{"tool":"name","parameters":{"k":"v"}}
1916
\`\`\`
20-
If no tool needed, answer directly.
17+
No tool? Answer directly.
2118
2219
`;
2320

24-
const EN_STRICT_TEMPLATE = `You have these tools:
25-
${TOOL_DEFS}
26-
27-
To use a tool, reply ONLY with:
28-
\`\`\`tool_json
29-
{"tool":"name","parameters":{"key":"value"}}
21+
const EN_STRICT_TEMPLATE = `Tools: ${TOOL_DEFS}
22+
Use tool? Reply ONLY: \`\`\`tool_json
23+
{"tool":"name","parameters":{"k":"v"}}
3024
\`\`\`
31-
Do not add any text before or after the JSON block when using a tool.
32-
If no tool needed, answer directly.
25+
No extra text. No tool? Answer directly.
3326
3427
`;
3528

36-
const CN_TEMPLATE = `你可以使用以下工具:
37-
${TOOL_DEFS}
38-
39-
需要使用工具时,只需回复:
40-
\`\`\`tool_json
41-
{"tool":"工具名","parameters":{"参数名":"参数值"}}
29+
const CN_TEMPLATE = `工具: ${TOOL_DEFS}
30+
用工具则只回复: \`\`\`tool_json
31+
{"tool":"名","parameters":{"键":"值"}}
4232
\`\`\`
43-
不需要工具则直接回答
33+
不用则直接答
4434
4535
`;
4636

0 commit comments

Comments
 (0)