open-agents-ai 0.181.0 → 0.182.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 +103 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25840,6 +25840,38 @@ Now call file_write with YOUR skeleton for this task.`
|
|
|
25840
25840
|
});
|
|
25841
25841
|
}
|
|
25842
25842
|
}
|
|
25843
|
+
if (turn === 0 && (turnTier === "small" || turnTier === "medium")) {
|
|
25844
|
+
const taskGoal = this._taskState.goal || "";
|
|
25845
|
+
const taskLower = taskGoal.toLowerCase();
|
|
25846
|
+
const taskTokens = new Set(taskLower.split(/\s+/).filter((w) => w.length > 2));
|
|
25847
|
+
const CORE = /* @__PURE__ */ new Set(["file_read", "file_write", "file_edit", "shell", "task_complete", "grep_search", "find_files", "list_directory", "file_explore"]);
|
|
25848
|
+
const toolHints = [];
|
|
25849
|
+
for (const tool of this.tools.values()) {
|
|
25850
|
+
if (CORE.has(tool.name))
|
|
25851
|
+
continue;
|
|
25852
|
+
const toolWords = `${tool.name.replace(/_/g, " ")} ${tool.description}`.toLowerCase().split(/\s+/);
|
|
25853
|
+
let score = 0;
|
|
25854
|
+
for (const tw of toolWords) {
|
|
25855
|
+
if (taskTokens.has(tw))
|
|
25856
|
+
score += 2;
|
|
25857
|
+
for (const qt of taskTokens) {
|
|
25858
|
+
if (tw.length > 3 && qt.length > 3 && (tw.includes(qt) || qt.includes(tw)))
|
|
25859
|
+
score += 1;
|
|
25860
|
+
}
|
|
25861
|
+
}
|
|
25862
|
+
if (score > 2)
|
|
25863
|
+
toolHints.push({ name: tool.name, desc: tool.description.slice(0, 80), score });
|
|
25864
|
+
}
|
|
25865
|
+
if (toolHints.length > 0) {
|
|
25866
|
+
toolHints.sort((a, b) => b.score - a.score);
|
|
25867
|
+
const top = toolHints.slice(0, 5);
|
|
25868
|
+
messages.push({
|
|
25869
|
+
role: "system",
|
|
25870
|
+
content: `[Relevant tools for this task]
|
|
25871
|
+
${top.map((t) => `- ${t.name}: ${t.desc}`).join("\n")}`
|
|
25872
|
+
});
|
|
25873
|
+
}
|
|
25874
|
+
}
|
|
25843
25875
|
const turnBudget = turnTier === "small" ? 5 : turnTier === "medium" ? 8 : 0;
|
|
25844
25876
|
if (turnBudget > 0 && turn > 0 && turn % turnBudget === 0) {
|
|
25845
25877
|
const repetitionRatio = this.detectRepetition(toolCallLog);
|
|
@@ -27833,14 +27865,79 @@ ${transcript}`
|
|
|
27833
27865
|
// -------------------------------------------------------------------------
|
|
27834
27866
|
// Tool definition builder
|
|
27835
27867
|
// -------------------------------------------------------------------------
|
|
27868
|
+
/**
|
|
27869
|
+
* Build tool definitions with task-aware filtering for small models.
|
|
27870
|
+
*
|
|
27871
|
+
* Research basis:
|
|
27872
|
+
* - Gorilla (arXiv:2305.15334): RAG-for-tools, 7B outperforms GPT-4 with tool retrieval
|
|
27873
|
+
* - EASYTOOL (arXiv:2401.06201): Minimal tool descriptions reduce tokens 40-70%
|
|
27874
|
+
* - ToolLLM (arXiv:2307.16789): Progressive tool discovery improves small model accuracy
|
|
27875
|
+
*
|
|
27876
|
+
* For small/medium models: only include core tools + task-relevant tools.
|
|
27877
|
+
* For large models: include everything (they can handle the context).
|
|
27878
|
+
*/
|
|
27836
27879
|
buildToolDefinitions() {
|
|
27837
|
-
|
|
27838
|
-
|
|
27839
|
-
|
|
27840
|
-
|
|
27841
|
-
|
|
27842
|
-
parameters: tool.parameters
|
|
27880
|
+
const allTools = Array.from(this.tools.values());
|
|
27881
|
+
const tier = this.options.modelTier;
|
|
27882
|
+
if (tier === "large") {
|
|
27883
|
+
return allTools.map((tool) => ({
|
|
27884
|
+
type: "function",
|
|
27885
|
+
function: { name: tool.name, description: tool.description, parameters: tool.parameters }
|
|
27886
|
+
}));
|
|
27887
|
+
}
|
|
27888
|
+
const CORE_TOOLS = /* @__PURE__ */ new Set([
|
|
27889
|
+
"file_read",
|
|
27890
|
+
"file_write",
|
|
27891
|
+
"file_edit",
|
|
27892
|
+
"shell",
|
|
27893
|
+
"task_complete",
|
|
27894
|
+
"grep_search",
|
|
27895
|
+
"find_files",
|
|
27896
|
+
"list_directory",
|
|
27897
|
+
"file_explore"
|
|
27898
|
+
]);
|
|
27899
|
+
const taskText = (this._taskState.goal || "").toLowerCase();
|
|
27900
|
+
const taskWords = new Set(taskText.split(/\s+/).filter((w) => w.length > 2));
|
|
27901
|
+
const scored = [];
|
|
27902
|
+
for (const tool of allTools) {
|
|
27903
|
+
if (CORE_TOOLS.has(tool.name))
|
|
27904
|
+
continue;
|
|
27905
|
+
const toolText = `${tool.name} ${tool.description}`.toLowerCase();
|
|
27906
|
+
const toolWords = toolText.split(/\s+/).filter((w) => w.length > 2);
|
|
27907
|
+
let score = 0;
|
|
27908
|
+
for (const tw of toolWords) {
|
|
27909
|
+
if (taskWords.has(tw))
|
|
27910
|
+
score += 2;
|
|
27911
|
+
for (const qw of taskWords) {
|
|
27912
|
+
if (tw.includes(qw) || qw.includes(tw))
|
|
27913
|
+
score += 1;
|
|
27914
|
+
}
|
|
27843
27915
|
}
|
|
27916
|
+
if (taskText.includes(tool.name.replace(/_/g, " ")) || taskText.includes(tool.name)) {
|
|
27917
|
+
score += 10;
|
|
27918
|
+
}
|
|
27919
|
+
if (["web_search", "web_fetch", "memory_read", "memory_write", "memory_search"].includes(tool.name)) {
|
|
27920
|
+
score += 1;
|
|
27921
|
+
}
|
|
27922
|
+
scored.push({ tool, score });
|
|
27923
|
+
}
|
|
27924
|
+
scored.sort((a, b) => b.score - a.score);
|
|
27925
|
+
const maxExtra = tier === "small" ? 6 : 12;
|
|
27926
|
+
const relevantTools = scored.slice(0, maxExtra).filter((s) => s.score > 0);
|
|
27927
|
+
const selectedTools = [
|
|
27928
|
+
...allTools.filter((t) => CORE_TOOLS.has(t.name)),
|
|
27929
|
+
...relevantTools.map((s) => s.tool)
|
|
27930
|
+
];
|
|
27931
|
+
const seen = /* @__PURE__ */ new Set();
|
|
27932
|
+
const deduped = selectedTools.filter((t) => {
|
|
27933
|
+
if (seen.has(t.name))
|
|
27934
|
+
return false;
|
|
27935
|
+
seen.add(t.name);
|
|
27936
|
+
return true;
|
|
27937
|
+
});
|
|
27938
|
+
return deduped.map((tool) => ({
|
|
27939
|
+
type: "function",
|
|
27940
|
+
function: { name: tool.name, description: tool.description, parameters: tool.parameters }
|
|
27844
27941
|
}));
|
|
27845
27942
|
}
|
|
27846
27943
|
// -------------------------------------------------------------------------
|
package/package.json
CHANGED