Skip to content

Commit f057aca

Browse files
committed
better var names...
1 parent 765a5b8 commit f057aca

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/mcp-client/src/Agent.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export class Agent extends McpClient {
7979
});
8080

8181
let numOfTurns = 0;
82-
let nextShouldCallTools = true;
82+
let nextTurnShouldCallTools = true;
8383
while (true) {
8484
yield* this.processSingleTurnWithTools(this.messages, {
8585
exitLoopTools,
86-
exitIfNoTool: numOfTurns > 0 && nextShouldCallTools,
86+
exitIfFirstChunkNoTool: numOfTurns > 0 && nextTurnShouldCallTools,
8787
});
8888
numOfTurns++;
8989
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -99,10 +99,14 @@ export class Agent extends McpClient {
9999
if (currentLast.role !== "tool" && numOfTurns > MAX_NUM_TURNS) {
100100
return;
101101
}
102-
if (currentLast.role !== "tool" && nextShouldCallTools) {
102+
if (currentLast.role !== "tool" && nextTurnShouldCallTools) {
103103
return;
104104
}
105-
nextShouldCallTools = currentLast.role !== "tool";
105+
if (currentLast.role === "tool") {
106+
nextTurnShouldCallTools = false;
107+
} else {
108+
nextTurnShouldCallTools = true;
109+
}
106110
}
107111
}
108112
}

packages/mcp-client/src/McpClient.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class McpClient {
7272

7373
async *processSingleTurnWithTools(
7474
messages: ChatCompletionInputMessage[],
75-
opts: { exitLoopTools?: ChatCompletionInputTool[]; exitIfNoTool?: boolean } = {}
75+
opts: { exitLoopTools?: ChatCompletionInputTool[]; exitIfFirstChunkNoTool?: boolean } = {}
7676
): AsyncGenerator<ChatCompletionStreamOutput | ChatCompletionInputMessageTool> {
7777
debug("start of single turn");
7878

@@ -90,7 +90,7 @@ export class McpClient {
9090
}
9191
const firstChunk = firstChunkResult.value;
9292
const firstToolCalls = firstChunk.choices[0]?.delta.tool_calls;
93-
if ((!firstToolCalls || firstToolCalls.length === 0) && opts.exitIfNoTool) {
93+
if ((!firstToolCalls || firstToolCalls.length === 0) && opts.exitIfFirstChunkNoTool) {
9494
return;
9595
}
9696
yield firstChunk;
@@ -120,7 +120,9 @@ export class McpClient {
120120
if (finalToolCalls[toolCall.index].function.arguments === undefined) {
121121
finalToolCalls[toolCall.index].function.arguments = "";
122122
}
123-
finalToolCalls[toolCall.index].function.arguments += toolCall.function.arguments;
123+
if (toolCall.function.arguments) {
124+
finalToolCalls[toolCall.index].function.arguments += toolCall.function.arguments;
125+
}
124126
}
125127
}
126128

0 commit comments

Comments
 (0)