@miphamai/cli 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/engine.ts +28 -5
package/package.json
CHANGED
package/src/core/engine.ts
CHANGED
|
@@ -300,7 +300,7 @@ export class QueryEngine {
|
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
private async *continueWithTools(signal?: AbortSignal): AsyncGenerator<StreamChunk> {
|
|
303
|
-
const MAX_TURNS =
|
|
303
|
+
const MAX_TURNS = 20
|
|
304
304
|
const toolDefs = this.getToolDefinitions()
|
|
305
305
|
|
|
306
306
|
for (let turn = 0; turn < MAX_TURNS; turn++) {
|
|
@@ -381,11 +381,34 @@ export class QueryEngine {
|
|
|
381
381
|
this.context.addMessage(msg)
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
// Safety:
|
|
384
|
+
// Safety: when max turns reached with pending tools, ask model to summarize
|
|
385
385
|
if (turn === MAX_TURNS - 1 && toolUses.length > 0) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
386
|
+
this.context.addMessage({
|
|
387
|
+
role: 'user',
|
|
388
|
+
content:
|
|
389
|
+
`You've reached the maximum of ${MAX_TURNS} tool-calling rounds. ` +
|
|
390
|
+
`${toolUses.length} tool call(s) were not executed. ` +
|
|
391
|
+
'Please summarize what you found so far and any next steps the user should take.',
|
|
392
|
+
})
|
|
393
|
+
// Give model one final chance to respond with a summary
|
|
394
|
+
try {
|
|
395
|
+
const finalSystemPrompt = this.context.getSystemPrompt()
|
|
396
|
+
const finalMessages = this.context.getMessages()
|
|
397
|
+
for await (const chunk of this.registry.chat({
|
|
398
|
+
model: this.registry.getActiveModel(),
|
|
399
|
+
messages: finalMessages,
|
|
400
|
+
systemPrompt: finalSystemPrompt,
|
|
401
|
+
tools: undefined, // no tools — force text-only summary
|
|
402
|
+
signal,
|
|
403
|
+
})) {
|
|
404
|
+
yield chunk
|
|
405
|
+
if (chunk.type === 'error') return
|
|
406
|
+
}
|
|
407
|
+
} catch {
|
|
408
|
+
yield {
|
|
409
|
+
type: 'error',
|
|
410
|
+
error: `Max tool-calling turns (${MAX_TURNS}) reached. Some tool calls were not executed.`,
|
|
411
|
+
}
|
|
389
412
|
}
|
|
390
413
|
return
|
|
391
414
|
}
|