Skip to content

Commit a692f44

Browse files
authored
fix: fix faulty tool calling in long context window (#92)
Fixes two whitespace bugs in tool calling: - Remove erroneous space in template literal that caused models to echo the literal string at large context sizes - Remove trailing spaces from tool_call_id that caused ID mismatches in frameworks like LangChain Co-authored-by: jeromevde <jeromevde@users.noreply.github.com>
1 parent fccb3ec commit a692f44

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/CopilotApiGateway.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,7 +3674,7 @@ export class CopilotApiGateway implements vscode.Disposable {
36743674
role: 'assistant',
36753675
content: result.content || null,
36763676
tool_calls: result.toolCalls.map((tc: any) => ({
3677-
id: `call_${randomUUID().slice(0, 24)} `,
3677+
id: `call_${randomUUID().slice(0, 24)}`,
36783678
type: 'function',
36793679
function: {
36803680
name: tc.name,
@@ -3697,13 +3697,13 @@ export class CopilotApiGateway implements vscode.Disposable {
36973697
const toolResult = await mcp.callTool(serverName, toolName, tc.arguments);
36983698
messages.push({
36993699
role: 'tool',
3700-
tool_call_id: `call_${randomUUID().slice(0, 24)} `, // Best effort ID mapping
3700+
tool_call_id: `call_${randomUUID().slice(0, 24)}`, // Best effort ID mapping
37013701
content: JSON.stringify(toolResult)
37023702
});
37033703
} catch (error: any) {
37043704
messages.push({
37053705
role: 'tool',
3706-
tool_call_id: `call_${randomUUID().slice(0, 24)} `,
3706+
tool_call_id: `call_${randomUUID().slice(0, 24)}`,
37073707
content: `Error executing MCP tool: ${error.message} `
37083708
});
37093709
}
@@ -3756,7 +3756,7 @@ export class CopilotApiGateway implements vscode.Disposable {
37563756
role: 'assistant',
37573757
content: result.content || null,
37583758
tool_calls: result.toolCalls.map((tc: any, idx: number) => ({
3759-
id: `call_${randomUUID().slice(0, 24)} `,
3759+
id: `call_${randomUUID().slice(0, 24)}`,
37603760
type: 'function',
37613761
function: {
37623762
name: tc.name,
@@ -3866,7 +3866,7 @@ export class CopilotApiGateway implements vscode.Disposable {
38663866
if (msg.tool_calls && msg.tool_calls.length > 0) {
38673867
// Assistant message with tool calls - include tool call info
38683868
const toolCallInfo = msg.tool_calls.map((tc: any) =>
3869-
`[Called function: $ { tc.function?.name || tc.name } (${tc.function?.arguments || JSON.stringify(tc.arguments)})]`
3869+
`[Called function: ${tc.function?.name || tc.name} (${tc.function?.arguments || JSON.stringify(tc.arguments)})]`
38703870
).join('\n');
38713871
lmMessages.push(vscode.LanguageModelChatMessage.Assistant(toolCallInfo));
38723872
} else {

0 commit comments

Comments
 (0)