@ouro.bot/cli 0.1.0-alpha.1224 → 0.1.0-alpha.1225
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/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1225",
|
|
6
|
+
"changes": [
|
|
7
|
+
"A trial switch (off by default) can send the agent a small core set of tools and let it look the rest up on demand, cutting about 12,500 to 15,500 estimated tokens from each request; nothing changes unless it is turned on."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1224",
|
|
6
12
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1225</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
package/dist/heart/core.js
CHANGED
|
@@ -27,6 +27,7 @@ const model_limits_1 = require("./model-limits");
|
|
|
27
27
|
const source_grounding_1 = require("./source-grounding");
|
|
28
28
|
const shelf_claims_1 = require("./shelf-claims");
|
|
29
29
|
const reply_style_1 = require("./reply-style");
|
|
30
|
+
const deferred_tools_1 = require("../repertoire/deferred-tools");
|
|
30
31
|
const tools_1 = require("../repertoire/tools");
|
|
31
32
|
const tool_images_1 = require("./tool-images");
|
|
32
33
|
const tool_arguments_1 = require("../repertoire/tool-arguments");
|
|
@@ -1522,6 +1523,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
1522
1523
|
// Rebase provider-owned turn state from canonical messages at user-turn start.
|
|
1523
1524
|
// This prevents stale provider caches from replaying prior-turn context.
|
|
1524
1525
|
providerRuntime.resetTurnState(messages);
|
|
1526
|
+
const loadedDeferredTools = [];
|
|
1525
1527
|
while (!done) {
|
|
1526
1528
|
// Channel-based tool filtering:
|
|
1527
1529
|
// - Private runtime: exclude send_message (delivery via surface), observe (no one to observe)
|
|
@@ -1536,9 +1538,19 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
1536
1538
|
...baseTools,
|
|
1537
1539
|
...toolSelection.engine,
|
|
1538
1540
|
];
|
|
1539
|
-
const
|
|
1541
|
+
const scopedOrdinaryActiveTools = relationshipToolNames
|
|
1540
1542
|
? unscopedOrdinaryActiveTools.filter((tool) => relationshipToolNames.includes(tool.function.name))
|
|
1541
1543
|
: unscopedOrdinaryActiveTools;
|
|
1544
|
+
// Deferred loading narrows only what is advertised; the scoped list above is still the authority on what may exist.
|
|
1545
|
+
const deferralPossible = (0, deferred_tools_1.deferredToolLoadingEnabled)() && !options?.hardDisableTools && options?.toolProfile !== "sanctuary-health-private";
|
|
1546
|
+
const deferralKeep = new Set(requiredToolCallNames);
|
|
1547
|
+
for (const effect of unresolvedHistoricalEffects)
|
|
1548
|
+
deferralKeep.add(effect.name);
|
|
1549
|
+
const deferralPool = deferralPossible ? (0, deferred_tools_1.partitionTools)(scopedOrdinaryActiveTools, [], deferralKeep).deferred : [];
|
|
1550
|
+
const deferralHistory = deferralPossible ? (0, deferred_tools_1.deferredNamesCalledInHistory)(messages, deferralPool) : [];
|
|
1551
|
+
const ordinaryActiveTools = deferralPossible
|
|
1552
|
+
? (0, deferred_tools_1.partitionTools)(scopedOrdinaryActiveTools, [...new Set([...loadedDeferredTools, ...deferralHistory])], deferralKeep).active
|
|
1553
|
+
: scopedOrdinaryActiveTools;
|
|
1542
1554
|
const candidateActiveTools = options?.hardDisableTools
|
|
1543
1555
|
? []
|
|
1544
1556
|
: options?.toolProfile === "sanctuary-health-private"
|
|
@@ -2075,6 +2087,8 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2075
2087
|
]));
|
|
2076
2088
|
const preflightRejections = new Map();
|
|
2077
2089
|
for (const entry of validCalls) {
|
|
2090
|
+
if (entry.call.name === deferred_tools_1.FIND_TOOLS_NAME)
|
|
2091
|
+
continue;
|
|
2078
2092
|
if (!relationship && !toolSelection.engine.some((tool) => tool.function.name === entry.call.name))
|
|
2079
2093
|
continue;
|
|
2080
2094
|
const prepared = await (0, tools_1.preflightToolCall)(entry.call.name, validatedCallArguments.get(entry.call), augmentedToolContext);
|
|
@@ -2499,6 +2513,23 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2499
2513
|
if (tc.name === "send_message" && args.friendId === "self") {
|
|
2500
2514
|
sawSendMessageSelf = true;
|
|
2501
2515
|
}
|
|
2516
|
+
if (tc.name === deferred_tools_1.FIND_TOOLS_NAME) {
|
|
2517
|
+
// The pre-batch schema gate guarantees a string query.
|
|
2518
|
+
const query = args.query;
|
|
2519
|
+
callbacks.onToolStart(deferred_tools_1.FIND_TOOLS_NAME, { query });
|
|
2520
|
+
const matched = (0, deferred_tools_1.searchDeferredTools)(deferralPool, query);
|
|
2521
|
+
for (const tool of matched)
|
|
2522
|
+
if (!loadedDeferredTools.includes(tool.function.name))
|
|
2523
|
+
loadedDeferredTools.push(tool.function.name);
|
|
2524
|
+
const found = (0, deferred_tools_1.formatFindToolsResult)(matched);
|
|
2525
|
+
pushGenerated({ role: "tool", tool_call_id: tc.id, content: found });
|
|
2526
|
+
providerRuntime.appendToolOutput(tc.id, found);
|
|
2527
|
+
if (matched.length > 0)
|
|
2528
|
+
lastIterationMadeProgress = true;
|
|
2529
|
+
callbacks.onToolEnd(deferred_tools_1.FIND_TOOLS_NAME, query, matched.length > 0);
|
|
2530
|
+
(0, deferred_tools_1.recordDeferredToolsLoaded)(query, matched);
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2502
2533
|
if (tc.name === "speak") {
|
|
2503
2534
|
// The canonical pre-batch schema gate guarantees a required string.
|
|
2504
2535
|
const speakArgs = JSON.parse(tc.arguments);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CORE_TOOL_NAMES = exports.FIND_TOOLS_NAME = exports.DEFERRED_TOOLS_FLAG = void 0;
|
|
4
|
+
exports.deferredToolLoadingEnabled = deferredToolLoadingEnabled;
|
|
5
|
+
exports.partitionTools = partitionTools;
|
|
6
|
+
exports.buildFindToolsSchema = buildFindToolsSchema;
|
|
7
|
+
exports.searchDeferredTools = searchDeferredTools;
|
|
8
|
+
exports.formatFindToolsResult = formatFindToolsResult;
|
|
9
|
+
exports.deferredNamesCalledInHistory = deferredNamesCalledInHistory;
|
|
10
|
+
exports.recordDeferredToolsLoaded = recordDeferredToolsLoaded;
|
|
11
|
+
const runtime_1 = require("../nerves/runtime");
|
|
12
|
+
/**
|
|
13
|
+
* Deferred tool loading (trial, off by default). When OURO_DEFERRED_TOOLS is set, each request carries the core
|
|
14
|
+
* tools plus `find_tools`; the rest are advertised only after the model asks for them. Selection, relationship
|
|
15
|
+
* filtering, guards and approvals are untouched: this only narrows which already-selected schemas are sent.
|
|
16
|
+
*/
|
|
17
|
+
exports.DEFERRED_TOOLS_FLAG = "OURO_DEFERRED_TOOLS";
|
|
18
|
+
exports.FIND_TOOLS_NAME = "find_tools";
|
|
19
|
+
const MAX_RESULTS = 8;
|
|
20
|
+
function deferredToolLoadingEnabled(env = process.env) {
|
|
21
|
+
return ["1", "true", "on"].includes((env[exports.DEFERRED_TOOLS_FLAG] ?? "").trim().toLowerCase());
|
|
22
|
+
}
|
|
23
|
+
/** Always sent. Engine tools are listed so the offline measurement keeps them; the engine adds them separately. */
|
|
24
|
+
exports.CORE_TOOL_NAMES = new Set([
|
|
25
|
+
"settle", "ponder", "observe", "rest", "speak", "surface", "send_message",
|
|
26
|
+
"load_skill", "list_skills",
|
|
27
|
+
"read_file", "write_file", "edit_file", "glob", "grep", "ls",
|
|
28
|
+
"shell", "shell_status", "shell_tail",
|
|
29
|
+
"web_search", "fetch_url",
|
|
30
|
+
"note", "diary_write", "consult_diary", "consult_notes", "search_facts", "get_friend_note", "save_friend_note",
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* Core tools keep their canonical order; loaded tools follow in the order they were loaded, so the cached prefix
|
|
34
|
+
* only grows at the end. `find_tools` is added only when something is deferred.
|
|
35
|
+
*/
|
|
36
|
+
function partitionTools(tools, loaded = [], alwaysKeep = new Set()) {
|
|
37
|
+
const keep = (name) => exports.CORE_TOOL_NAMES.has(name) || alwaysKeep.has(name);
|
|
38
|
+
const core = tools.filter((tool) => keep(tool.function.name));
|
|
39
|
+
const deferred = tools.filter((tool) => !keep(tool.function.name));
|
|
40
|
+
if (deferred.length === 0)
|
|
41
|
+
return { active: [...core], deferred };
|
|
42
|
+
const loadedTools = loaded.flatMap((name) => deferred.filter((tool) => tool.function.name === name));
|
|
43
|
+
return { active: [...core, buildFindToolsSchema(deferred), ...loadedTools], deferred };
|
|
44
|
+
}
|
|
45
|
+
function groupCatalogue(deferred) {
|
|
46
|
+
const groups = new Map();
|
|
47
|
+
for (const tool of deferred) {
|
|
48
|
+
const name = tool.function.name;
|
|
49
|
+
const prefix = name.includes("_") ? name.slice(0, name.indexOf("_")) : name;
|
|
50
|
+
groups.set(prefix, [...(groups.get(prefix) ?? []), name]);
|
|
51
|
+
}
|
|
52
|
+
return [...groups.entries()].map(([prefix, names]) => (names.length === 1 ? names[0] : `${prefix}_*(${names.map((n) => n.slice(prefix.length + 1)).join(",")})`)).join(" ");
|
|
53
|
+
}
|
|
54
|
+
function buildFindToolsSchema(deferred) {
|
|
55
|
+
return {
|
|
56
|
+
type: "function",
|
|
57
|
+
function: {
|
|
58
|
+
name: exports.FIND_TOOLS_NAME,
|
|
59
|
+
description: `more tools exist than are listed. call find_tools with a short query (what you need to do) or select:name1,name2 to load them; they become callable on your next step this turn. not loaded now: ${groupCatalogue(deferred)}`,
|
|
60
|
+
parameters: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: { query: { type: "string", description: "what you need, or select:name1,name2" } },
|
|
63
|
+
required: ["query"],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const STOPWORDS = new Set(["the", "and", "for", "with", "that", "this", "from", "into", "again", "please", "need", "use", "can", "you", "tool", "tools"]);
|
|
69
|
+
const words = (text) => text.toLowerCase().split(/[^a-z0-9]+/).filter((word) => word.length > 2 && !STOPWORDS.has(word)).map((word) => (word.length > 3 && word.endsWith("s") ? word.slice(0, -1) : word));
|
|
70
|
+
function searchDeferredTools(deferred, query) {
|
|
71
|
+
const trimmed = query.trim();
|
|
72
|
+
if (trimmed.toLowerCase().startsWith("select:")) {
|
|
73
|
+
const names = new Set(trimmed.slice(7).split(",").map((name) => name.trim()).filter(Boolean));
|
|
74
|
+
return deferred.filter((tool) => names.has(tool.function.name));
|
|
75
|
+
}
|
|
76
|
+
const terms = words(trimmed);
|
|
77
|
+
const scored = deferred
|
|
78
|
+
.map((tool, index) => {
|
|
79
|
+
const name = tool.function.name.toLowerCase();
|
|
80
|
+
const nameWords = words(name);
|
|
81
|
+
const description = new Set(words(tool.function.description ?? ""));
|
|
82
|
+
const score = terms.reduce((sum, term) => sum + (name === term ? 6 : nameWords.includes(term) ? 4 : name.includes(term) ? 2 : 0) + (description.has(term) ? 1 : 0), 0);
|
|
83
|
+
return { tool, score, index };
|
|
84
|
+
})
|
|
85
|
+
.filter((entry) => entry.score > 0)
|
|
86
|
+
.sort((a, b) => b.score - a.score || a.index - b.index);
|
|
87
|
+
// Drop weak description-only hits when something matches strongly, so the result stays short.
|
|
88
|
+
const floor = scored.length > 0 ? Math.ceil(scored[0].score / 3) : 0;
|
|
89
|
+
return scored.filter((entry) => entry.score >= floor).slice(0, MAX_RESULTS).map((entry) => entry.tool);
|
|
90
|
+
}
|
|
91
|
+
function signature(tool) {
|
|
92
|
+
const parameters = tool.function.parameters;
|
|
93
|
+
const required = new Set(parameters?.required ?? []);
|
|
94
|
+
return Object.keys(parameters?.properties ?? {}).map((key) => (required.has(key) ? key : `${key}?`)).join(", ");
|
|
95
|
+
}
|
|
96
|
+
function formatFindToolsResult(matched) {
|
|
97
|
+
if (matched.length === 0)
|
|
98
|
+
return "no matching tools. try different words, or select:name1,name2 using a name from the list in find_tools.";
|
|
99
|
+
return `loaded; callable on your next step:\n${matched.map((tool) => `- ${tool.function.name}(${signature(tool)}): ${tool.function.description ?? ""}`).join("\n")}`;
|
|
100
|
+
}
|
|
101
|
+
/** Deferred tools the conversation already called, so a follow-up turn does not have to find them again. */
|
|
102
|
+
function deferredNamesCalledInHistory(messages, deferred) {
|
|
103
|
+
const deferredNames = new Set(deferred.map((tool) => tool.function.name));
|
|
104
|
+
const called = [];
|
|
105
|
+
for (const message of messages) {
|
|
106
|
+
if (message.role !== "assistant")
|
|
107
|
+
continue;
|
|
108
|
+
for (const call of message.tool_calls ?? []) {
|
|
109
|
+
if (call.type === "function" && deferredNames.has(call.function.name) && !called.includes(call.function.name))
|
|
110
|
+
called.push(call.function.name);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return called;
|
|
114
|
+
}
|
|
115
|
+
function recordDeferredToolsLoaded(query, matched) {
|
|
116
|
+
(0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.deferred_tools_loaded", message: "deferred tools loaded for this turn", meta: { query, loaded: matched.map((tool) => tool.function.name).join(",") } });
|
|
117
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1225",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1225",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|