open-agents-ai 0.137.0 → 0.138.0
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/dist/index.js +49 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21583,8 +21583,55 @@ If you're stuck, try a completely different approach. Do NOT repeat what failed
|
|
|
21583
21583
|
break;
|
|
21584
21584
|
}
|
|
21585
21585
|
if (/does not support tools|HTTP 400.*tools/i.test(errMsg)) {
|
|
21586
|
-
this.emit({
|
|
21587
|
-
|
|
21586
|
+
this.emit({
|
|
21587
|
+
type: "status",
|
|
21588
|
+
content: `Model lacks native tool support \u2014 switching to prompt-injected tool mode`,
|
|
21589
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
21590
|
+
});
|
|
21591
|
+
const toolDescriptions = Array.from(this.tools.values()).map((t) => `- ${t.name}: ${t.description}`).join("\n");
|
|
21592
|
+
const toolInjectMsg = [
|
|
21593
|
+
"\n\n[TOOL MODE \u2014 PROMPT INJECTION]",
|
|
21594
|
+
"This model does not have native tool-calling. To use tools, output a JSON block:",
|
|
21595
|
+
"```json",
|
|
21596
|
+
'{"tool": "tool_name", "args": {"param": "value"}}',
|
|
21597
|
+
"```",
|
|
21598
|
+
"\nAvailable tools:",
|
|
21599
|
+
toolDescriptions,
|
|
21600
|
+
"\nOutput EXACTLY ONE tool call per response in the JSON format above.",
|
|
21601
|
+
"After seeing the tool result, continue or call another tool.",
|
|
21602
|
+
'When done, output: {"tool": "task_complete", "args": {"summary": "what you did"}}'
|
|
21603
|
+
].join("\n");
|
|
21604
|
+
messages.push({ role: "system", content: toolInjectMsg });
|
|
21605
|
+
chatRequest.tools = [];
|
|
21606
|
+
try {
|
|
21607
|
+
response = this.options.streamEnabled && this.hasStreamingSupport() ? await this.streamingRequest(chatRequest, turn) : await this.backend.chatCompletion(chatRequest);
|
|
21608
|
+
const content = response.choices?.[0]?.message?.content ?? "";
|
|
21609
|
+
const jsonMatch = content.match(/```json\s*\n?([\s\S]*?)```/);
|
|
21610
|
+
if (jsonMatch) {
|
|
21611
|
+
try {
|
|
21612
|
+
const parsed = JSON.parse(jsonMatch[1]);
|
|
21613
|
+
if (parsed.tool && this.tools.has(parsed.tool)) {
|
|
21614
|
+
const tool = this.tools.get(parsed.tool);
|
|
21615
|
+
const result = await tool.execute(parsed.args ?? {});
|
|
21616
|
+
messages.push({ role: "assistant", content });
|
|
21617
|
+
messages.push({ role: "user", content: `Tool result (${parsed.tool}): ${result.output.slice(0, 2e3)}` });
|
|
21618
|
+
if (parsed.tool === "task_complete") {
|
|
21619
|
+
completed = true;
|
|
21620
|
+
summary = String(parsed.args?.summary ?? content);
|
|
21621
|
+
}
|
|
21622
|
+
toolCallCount++;
|
|
21623
|
+
continue;
|
|
21624
|
+
}
|
|
21625
|
+
} catch {
|
|
21626
|
+
}
|
|
21627
|
+
}
|
|
21628
|
+
messages.push({ role: "assistant", content });
|
|
21629
|
+
continue;
|
|
21630
|
+
} catch (retryErr2) {
|
|
21631
|
+
const msg2 = retryErr2 instanceof Error ? retryErr2.message : String(retryErr2);
|
|
21632
|
+
this.emit({ type: "error", content: `Prompt-injected tool mode also failed: ${msg2}`, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
21633
|
+
break;
|
|
21634
|
+
}
|
|
21588
21635
|
}
|
|
21589
21636
|
messages.push({ role: "user", content: "[System: backend request failed, retrying on next turn. The previous request was lost.]" });
|
|
21590
21637
|
continue;
|
package/package.json
CHANGED