@unieai/rabi-tool-subagent-control 0.0.0-stage → 0.2.2-rc.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/LICENSE +21 -0
- package/README.md +7 -2
- package/lib/index.js +319 -0
- package/lib/types/index.d.ts +27 -0
- package/lib/types/list-agents.d.ts +10 -0
- package/lib/types/wait-agent.d.ts +8 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +41 -4
- package/src/index.ts +158 -0
- package/src/list-agents.ts +97 -0
- package/src/wait-agent.ts +118 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @unieai/rabi-tool-subagent-control
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared messaging, interruption, and child discovery tools for subagents
|
|
4
|
+
|
|
5
|
+
Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
|
|
6
|
+
not meant to be used on its own.
|
|
7
|
+
|
|
8
|
+
See LICENSE for the license and copyright of this package.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import z from "@unieai/schemastery";
|
|
2
|
+
import { defineTool } from "@unieai/rabi-tools";
|
|
3
|
+
import { ROOT_AGENT_NAME } from "@unieai/rabi-subagent";
|
|
4
|
+
import { HarnessError } from "@unieai/rabi-llm";
|
|
5
|
+
//#region lib/types/list-agents.js
|
|
6
|
+
/** Discover the caller's entire subagent tree; the control plugin owns registration. */
|
|
7
|
+
/** Report turn activity without exposing whether the child is loaded. */
|
|
8
|
+
function statusOf(agents, id) {
|
|
9
|
+
return agents.get(id)?.status === "running" ? "running" : "inactive";
|
|
10
|
+
}
|
|
11
|
+
/** Project one service row into the model-facing entry, or omit a one-shot or external child. */
|
|
12
|
+
function project(agents, entry) {
|
|
13
|
+
const name = entry.path ?? entry.id;
|
|
14
|
+
if (entry.kind === "diagnostic") return {
|
|
15
|
+
name,
|
|
16
|
+
status: entry.reason
|
|
17
|
+
};
|
|
18
|
+
if (entry.mode !== "continuable") return void 0;
|
|
19
|
+
return {
|
|
20
|
+
name,
|
|
21
|
+
status: statusOf(agents, entry.id),
|
|
22
|
+
description: entry.label
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Register the `list_agents` tool.
|
|
27
|
+
* @param ctx - context carrying the tool registry, subagent service, and live Agent registry.
|
|
28
|
+
* @returns the registered definition for scoped availability checks.
|
|
29
|
+
*/
|
|
30
|
+
function registerListAgents(ctx) {
|
|
31
|
+
const definition = defineTool({
|
|
32
|
+
name: "list_agents",
|
|
33
|
+
description: "List your entire subagent tree: the root agent and all reachable continuable descendants, including yourself. Rows carry names, descriptions, and status. A descendant's name is its path from the root, such as reviewer/checker. You can message any other agent in the subagent tree. running means it is working; inactive means no turn is executing; it does not indicate task completion, success, or failure. corrupt, unsupported, or unavailable means this row's own descendants could not be read; the row itself is still a member you can message. While you remain active, you will be notified when a direct child finishes; there is no need to keep checking its status. Use send_message to continue the conversation.",
|
|
34
|
+
parameters: {},
|
|
35
|
+
isConcurrencySafe: () => true,
|
|
36
|
+
output: {
|
|
37
|
+
schema: {
|
|
38
|
+
type: "array",
|
|
39
|
+
items: {
|
|
40
|
+
type: "object",
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
properties: {
|
|
43
|
+
name: {
|
|
44
|
+
type: "string",
|
|
45
|
+
required: true
|
|
46
|
+
},
|
|
47
|
+
status: {
|
|
48
|
+
type: "string",
|
|
49
|
+
required: true,
|
|
50
|
+
enum: [
|
|
51
|
+
"running",
|
|
52
|
+
"inactive",
|
|
53
|
+
"corrupt",
|
|
54
|
+
"unsupported",
|
|
55
|
+
"unavailable"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
description: { type: "string" }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
render: (_args, entries) => [{
|
|
63
|
+
type: "text",
|
|
64
|
+
text: entries.map((entry) => `${entry.name} [${entry.status}]${entry.description === void 0 ? "" : ` — ${entry.description}`}`).join("\n")
|
|
65
|
+
}]
|
|
66
|
+
},
|
|
67
|
+
async execute(_args, exec) {
|
|
68
|
+
const parent = exec.agent;
|
|
69
|
+
if (!parent) throw new Error("list_agents requires a calling agent (exec.agent was undefined)");
|
|
70
|
+
const root = ctx.subagents.rootOf(parent);
|
|
71
|
+
const entries = await ctx.subagents.listDescendants(root.id, exec.signal);
|
|
72
|
+
return [{
|
|
73
|
+
name: ROOT_AGENT_NAME,
|
|
74
|
+
status: statusOf(ctx.agents, root.id),
|
|
75
|
+
description: "root agent"
|
|
76
|
+
}, ...entries.map((entry) => project(ctx.agents, entry)).filter((entry) => entry !== void 0)];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
ctx.tools.register(definition);
|
|
80
|
+
return definition;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region lib/types/wait-agent.js
|
|
84
|
+
/** Input waiting owned by the subagent control plugin. */
|
|
85
|
+
/** Wait failures retain a stable machine-readable reason through tool execution. */
|
|
86
|
+
var AgentWaitError = class extends HarnessError {
|
|
87
|
+
constructor(message, code) {
|
|
88
|
+
super(message, code);
|
|
89
|
+
this.name = "AgentWaitError";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Wait without consuming input; every settlement removes its live resources.
|
|
94
|
+
* Within one model tool call, such as a `run_code` program, pending input that
|
|
95
|
+
* an earlier wait already reported does not end this wait: that input reaches
|
|
96
|
+
* the model only after the call finishes, so a waiting loop cannot spin on it.
|
|
97
|
+
*/
|
|
98
|
+
function waitForInput(ctx, agent, timeoutMs, signal, lifetime, reported, rootCallId) {
|
|
99
|
+
lifetime.throwIfAborted();
|
|
100
|
+
if (ctx.agents.get(agent.id) !== agent) throw new AgentWaitError("wait_agent requires the exact live calling agent", "WAIT_UNAVAILABLE");
|
|
101
|
+
const previous = reported.get(agent);
|
|
102
|
+
const seen = previous?.rootCallId === rootCallId ? previous.ids : void 0;
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
const finish = (settle) => {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
offInbox();
|
|
107
|
+
offDisposed();
|
|
108
|
+
signal.removeEventListener("abort", onAbort);
|
|
109
|
+
lifetime.removeEventListener("abort", onUnload);
|
|
110
|
+
settle();
|
|
111
|
+
};
|
|
112
|
+
const onInput = () => {
|
|
113
|
+
const pending = agent.inbox.nextStep;
|
|
114
|
+
if (pending.some((message) => seen?.has(message.id) !== true)) {
|
|
115
|
+
reported.set(agent, {
|
|
116
|
+
rootCallId,
|
|
117
|
+
ids: new Set(pending.map((message) => message.id))
|
|
118
|
+
});
|
|
119
|
+
finish(() => {
|
|
120
|
+
resolve({ timedOut: false });
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const onAbort = () => {
|
|
125
|
+
finish(() => {
|
|
126
|
+
reject(signal.reason);
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const onUnload = () => {
|
|
130
|
+
finish(() => {
|
|
131
|
+
reject(lifetime.reason);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const offInbox = ctx.on("agent/inbox/inserted", ({ agent: recipient }) => {
|
|
135
|
+
if (recipient === agent) onInput();
|
|
136
|
+
});
|
|
137
|
+
const offDisposed = ctx.on("agent/disposed", ({ agent: disposed }) => {
|
|
138
|
+
if (disposed === agent) finish(() => {
|
|
139
|
+
reject(new AgentWaitError("wait_agent ended because the calling agent was disposed", "WAIT_UNAVAILABLE"));
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
143
|
+
lifetime.addEventListener("abort", onUnload, { once: true });
|
|
144
|
+
const timer = setTimeout(() => {
|
|
145
|
+
finish(() => {
|
|
146
|
+
resolve({ timedOut: true });
|
|
147
|
+
});
|
|
148
|
+
}, timeoutMs);
|
|
149
|
+
if (signal.aborted) onAbort();
|
|
150
|
+
else onInput();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Register one inbox wait tool and cancel its waits when the plugin unloads.
|
|
155
|
+
* @param ctx - plugin context owning the tool, event listeners, and wait lifetime.
|
|
156
|
+
*/
|
|
157
|
+
function registerWaitAgent(ctx) {
|
|
158
|
+
const lifetime = new AbortController();
|
|
159
|
+
const reported = /* @__PURE__ */ new WeakMap();
|
|
160
|
+
ctx.effect(() => () => {
|
|
161
|
+
lifetime.abort(new AgentWaitError("wait_agent ended because its plugin was unloaded", "WAIT_UNAVAILABLE"));
|
|
162
|
+
}, "subagent-control.waits()");
|
|
163
|
+
ctx.tools.register(defineTool({
|
|
164
|
+
name: "wait_agent",
|
|
165
|
+
description: "Wait for input at your next step, including agent messages, completion notifications, and user steering. Returns immediately if new input is pending. `timedOut: false` means new input is pending. Pending input is delivered to the model after code execution finishes.",
|
|
166
|
+
parameters: { timeout_ms: {
|
|
167
|
+
type: "integer",
|
|
168
|
+
description: "Wait duration in milliseconds, from 10000 through 3600000. Defaults to 30000."
|
|
169
|
+
} },
|
|
170
|
+
output: {
|
|
171
|
+
schema: {
|
|
172
|
+
type: "object",
|
|
173
|
+
additionalProperties: false,
|
|
174
|
+
properties: { timedOut: {
|
|
175
|
+
type: "boolean",
|
|
176
|
+
required: true
|
|
177
|
+
} }
|
|
178
|
+
},
|
|
179
|
+
render: (_args, value) => [{
|
|
180
|
+
type: "text",
|
|
181
|
+
text: JSON.stringify(value)
|
|
182
|
+
}]
|
|
183
|
+
},
|
|
184
|
+
async execute(args, exec) {
|
|
185
|
+
const timeoutMs = args.timeout_ms ?? 3e4;
|
|
186
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1e4 || timeoutMs > 36e5) throw new AgentWaitError("timeout_ms must be an integer from 10000 through 3600000", "WAIT_INVALID_TIMEOUT");
|
|
187
|
+
if (exec.agent === void 0) throw new AgentWaitError("wait_agent requires a calling agent", "WAIT_UNAVAILABLE");
|
|
188
|
+
return await waitForInput(ctx, exec.agent, timeoutMs, exec.signal, lifetime.signal, reported, exec.rootCallId);
|
|
189
|
+
}
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region lib/types/index.js
|
|
194
|
+
/**
|
|
195
|
+
* Shared messaging, inbox waiting, interruption, and child discovery tools.
|
|
196
|
+
* They perform no lifecycle routing of their own —
|
|
197
|
+
* residency, cold resume, and interrupt authorization belong to the subagent
|
|
198
|
+
* service — and they live apart from the provider-bound
|
|
199
|
+
* `@unieai/rabi-tool-subagent` instances so multiple delegation tools share
|
|
200
|
+
* one control API.
|
|
201
|
+
* @module @unieai/rabi-tool-subagent-control
|
|
202
|
+
*/
|
|
203
|
+
const name = "tool-subagent-control";
|
|
204
|
+
const inject = [
|
|
205
|
+
"tools",
|
|
206
|
+
"subagents",
|
|
207
|
+
"agents",
|
|
208
|
+
"systemPrompt"
|
|
209
|
+
];
|
|
210
|
+
/** Loader schema for optional subagent control tools. */
|
|
211
|
+
const Config = z.object({ interrupt: z.boolean().default(true) });
|
|
212
|
+
/**
|
|
213
|
+
* Register the shared subagent control and discovery tools.
|
|
214
|
+
* @param ctx - context carrying tools, subagents, live Agents, and prompt assembly.
|
|
215
|
+
* @param config - optional tool registration settings.
|
|
216
|
+
*/
|
|
217
|
+
function apply(ctx, config = {}) {
|
|
218
|
+
const interrupt = config.interrupt !== false;
|
|
219
|
+
const listAgents = registerListAgents(ctx);
|
|
220
|
+
registerWaitAgent(ctx);
|
|
221
|
+
const sendMessage = defineTool({
|
|
222
|
+
name: "send_message",
|
|
223
|
+
description: "Send a message to an agent. A working agent receives it at its next step; an idle agent starts a new turn with it. Returns delivery confirmation.",
|
|
224
|
+
parameters: {
|
|
225
|
+
agent: {
|
|
226
|
+
type: "string",
|
|
227
|
+
required: true,
|
|
228
|
+
description: "The name of another agent in your subagent tree, as shown by list_agents."
|
|
229
|
+
},
|
|
230
|
+
message: {
|
|
231
|
+
type: "string",
|
|
232
|
+
required: true,
|
|
233
|
+
description: "The message to deliver to the agent."
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
output: {
|
|
237
|
+
schema: {
|
|
238
|
+
type: "object",
|
|
239
|
+
additionalProperties: false,
|
|
240
|
+
properties: { messageId: {
|
|
241
|
+
type: "string",
|
|
242
|
+
required: true
|
|
243
|
+
} }
|
|
244
|
+
},
|
|
245
|
+
render: (args, _value) => [{
|
|
246
|
+
type: "text",
|
|
247
|
+
text: `message delivered to agent ${args.agent}`
|
|
248
|
+
}]
|
|
249
|
+
},
|
|
250
|
+
async execute(args, exec) {
|
|
251
|
+
const sender = exec.agent;
|
|
252
|
+
if (!sender) throw new Error("send_message requires a calling agent (exec.agent was undefined)");
|
|
253
|
+
const message = [{
|
|
254
|
+
type: "text",
|
|
255
|
+
text: args.message
|
|
256
|
+
}];
|
|
257
|
+
const targetId = await ctx.subagents.resolveName(sender, args.agent, exec.signal);
|
|
258
|
+
return { messageId: await ctx.subagents.sendMessage(sender, targetId, message, { signal: exec.signal }) };
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
ctx.tools.register(sendMessage);
|
|
262
|
+
ctx.systemPrompt.context({
|
|
263
|
+
name: "subagent:identity",
|
|
264
|
+
order: ctx.systemPrompt.getContextOrder("SUBAGENT_DELEGATION"),
|
|
265
|
+
required: true,
|
|
266
|
+
interpolate: false,
|
|
267
|
+
text: ({ agent, scope, toolSet }) => {
|
|
268
|
+
if (agent === void 0) return "";
|
|
269
|
+
try {
|
|
270
|
+
const names = ctx.subagents.namesOf(agent);
|
|
271
|
+
let identity = names.parent === void 0 ? `You are the root agent. Your name is ${JSON.stringify(names.self)}.` : `You are a subagent delegated by agent ${JSON.stringify(names.parent)}.\nYour name is ${JSON.stringify(names.self)}.\nThe root agent of your collaboration tree is ${JSON.stringify(ROOT_AGENT_NAME)}.`;
|
|
272
|
+
const guidance = [];
|
|
273
|
+
if (ctx.tools.get(sendMessage.name, scope, toolSet) === sendMessage) guidance.push("To message other agents, use send_message({ agent: \"<agent-name>\", message: \"...\" }).");
|
|
274
|
+
if (ctx.tools.get(listAgents.name, scope, toolSet) === listAgents) guidance.push("Use list_agents({}) to find your collaborator agents and their names.");
|
|
275
|
+
if (guidance.length > 0) identity += "\n\n" + guidance.join("\n");
|
|
276
|
+
return identity;
|
|
277
|
+
} catch (error) {
|
|
278
|
+
if (!(typeof error === "object" && error !== null && "name" in error && error.name === "SubagentError" && "code" in error && error.code === "UNAUTHORIZED")) throw error;
|
|
279
|
+
return `Your agent id is ${JSON.stringify(agent.id)}. Your subagent tree root is unavailable. Continue independent work; subagent discovery and messaging require an active root.`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
if (!interrupt) return;
|
|
284
|
+
ctx.tools.register(defineTool({
|
|
285
|
+
name: "interrupt_agent",
|
|
286
|
+
description: "Ask a subagent to stop its current work. This call returns without waiting for it to stop. You can continue a local subagent's conversation later with send_message. External executions stop permanently and cannot receive follow-ups. Subagents it started will keep running.",
|
|
287
|
+
parameters: { agent: {
|
|
288
|
+
type: "string",
|
|
289
|
+
required: true,
|
|
290
|
+
description: "The name of an agent created under you: your direct child or a deeper descendant."
|
|
291
|
+
} },
|
|
292
|
+
output: {
|
|
293
|
+
schema: {
|
|
294
|
+
type: "object",
|
|
295
|
+
additionalProperties: false,
|
|
296
|
+
properties: { accepted: {
|
|
297
|
+
type: "boolean",
|
|
298
|
+
required: true
|
|
299
|
+
} }
|
|
300
|
+
},
|
|
301
|
+
render: (args, _value) => [{
|
|
302
|
+
type: "text",
|
|
303
|
+
text: `interrupt requested for agent ${args.agent}`
|
|
304
|
+
}]
|
|
305
|
+
},
|
|
306
|
+
async execute(args, exec) {
|
|
307
|
+
const caller = exec.agent;
|
|
308
|
+
if (!caller) throw new Error("interrupt_agent requires a calling agent (exec.agent was undefined)");
|
|
309
|
+
const targetId = await ctx.subagents.resolveName(caller, args.agent, exec.signal);
|
|
310
|
+
ctx.subagents.interrupt(targetId, {
|
|
311
|
+
kind: "ancestor",
|
|
312
|
+
agent: caller
|
|
313
|
+
});
|
|
314
|
+
return { accepted: true };
|
|
315
|
+
}
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
export { Config, apply, inject, name };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared messaging, inbox waiting, interruption, and child discovery tools.
|
|
3
|
+
* They perform no lifecycle routing of their own —
|
|
4
|
+
* residency, cold resume, and interrupt authorization belong to the subagent
|
|
5
|
+
* service — and they live apart from the provider-bound
|
|
6
|
+
* `@unieai/rabi-tool-subagent` instances so multiple delegation tools share
|
|
7
|
+
* one control API.
|
|
8
|
+
* @module @unieai/rabi-tool-subagent-control
|
|
9
|
+
*/
|
|
10
|
+
import type { Context } from '@unieai/cordis';
|
|
11
|
+
import z from '@unieai/schemastery';
|
|
12
|
+
export declare const name = "tool-subagent-control";
|
|
13
|
+
export declare const inject: string[];
|
|
14
|
+
/** Optional subagent control tools. */
|
|
15
|
+
export interface Config {
|
|
16
|
+
/** Register `interrupt_agent`. Defaults to true; false leaves the service API available. */
|
|
17
|
+
interrupt?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Loader schema for optional subagent control tools. */
|
|
20
|
+
export declare const Config: z<Config>;
|
|
21
|
+
/**
|
|
22
|
+
* Register the shared subagent control and discovery tools.
|
|
23
|
+
* @param ctx - context carrying tools, subagents, live Agents, and prompt assembly.
|
|
24
|
+
* @param config - optional tool registration settings.
|
|
25
|
+
*/
|
|
26
|
+
export declare function apply(ctx: Context, config?: Config): void;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Discover the caller's entire subagent tree; the control plugin owns registration. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
import type { ToolDefinition } from '@unieai/rabi-tools';
|
|
4
|
+
/**
|
|
5
|
+
* Register the `list_agents` tool.
|
|
6
|
+
* @param ctx - context carrying the tool registry, subagent service, and live Agent registry.
|
|
7
|
+
* @returns the registered definition for scoped availability checks.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerListAgents(ctx: Context): ToolDefinition;
|
|
10
|
+
//# sourceMappingURL=list-agents.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Input waiting owned by the subagent control plugin. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
/**
|
|
4
|
+
* Register one inbox wait tool and cancel its waits when the plugin unloads.
|
|
5
|
+
* @param ctx - plugin context owning the tool, event listeners, and wait lifetime.
|
|
6
|
+
*/
|
|
7
|
+
export declare function registerWaitAgent(ctx: Context): void;
|
|
8
|
+
//# sourceMappingURL=wait-agent.d.ts.map
|
package/locale/de.json
ADDED
package/locale/en.json
ADDED
package/locale/es.json
ADDED
package/locale/fr.json
ADDED
package/locale/ja.json
ADDED
package/locale/pt.json
ADDED
package/locale/ru.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-tool-subagent-control",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Shared messaging, interruption, and child discovery tools for subagents",
|
|
4
|
+
"version": "0.2.2-rc.5",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./locale/*.json": "./locale/*.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"locale/*.json",
|
|
22
|
+
"lib/index.js",
|
|
23
|
+
"lib/types/**/*.d.ts",
|
|
24
|
+
"lib/types/**/*.d.ts.map",
|
|
25
|
+
"lib/**/*.js.map",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@unieai/cordis": "4.1.0",
|
|
32
|
+
"@unieai/rabi-llm": "0.2.2-rc.5",
|
|
33
|
+
"@unieai/rabi-session": "0.2.2-rc.5",
|
|
34
|
+
"@unieai/rabi-subagent": "0.2.2-rc.5",
|
|
35
|
+
"@unieai/rabi-tools": "0.2.2-rc.5",
|
|
36
|
+
"@unieai/rabi-agent": "0.2.2-rc.5",
|
|
37
|
+
"@unieai/rabi-system-prompt": "0.2.2-rc.5"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@unieai/schemastery": "3.19.0",
|
|
41
|
+
"@unieai/rabi-util-values": "0.2.2-rc.5"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared messaging, inbox waiting, interruption, and child discovery tools.
|
|
3
|
+
* They perform no lifecycle routing of their own —
|
|
4
|
+
* residency, cold resume, and interrupt authorization belong to the subagent
|
|
5
|
+
* service — and they live apart from the provider-bound
|
|
6
|
+
* `@unieai/rabi-tool-subagent` instances so multiple delegation tools share
|
|
7
|
+
* one control API.
|
|
8
|
+
* @module @unieai/rabi-tool-subagent-control
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Context } from '@unieai/cordis'
|
|
12
|
+
import z from '@unieai/schemastery'
|
|
13
|
+
import { defineTool } from '@unieai/rabi-tools'
|
|
14
|
+
import type { ContentBlock } from '@unieai/rabi-llm'
|
|
15
|
+
import { ROOT_AGENT_NAME } from '@unieai/rabi-subagent'
|
|
16
|
+
import type {} from '@unieai/rabi-system-prompt'
|
|
17
|
+
import { registerListAgents } from './list-agents.ts'
|
|
18
|
+
import { registerWaitAgent } from './wait-agent.ts'
|
|
19
|
+
|
|
20
|
+
export const name = 'tool-subagent-control'
|
|
21
|
+
export const inject = ['tools', 'subagents', 'agents', 'systemPrompt']
|
|
22
|
+
|
|
23
|
+
/** Optional subagent control tools. */
|
|
24
|
+
export interface Config {
|
|
25
|
+
/** Register `interrupt_agent`. Defaults to true; false leaves the service API available. */
|
|
26
|
+
interrupt?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Loader schema for optional subagent control tools. */
|
|
30
|
+
export const Config: z<Config> = z.object({
|
|
31
|
+
interrupt: z.boolean().default(true),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Register the shared subagent control and discovery tools.
|
|
36
|
+
* @param ctx - context carrying tools, subagents, live Agents, and prompt assembly.
|
|
37
|
+
* @param config - optional tool registration settings.
|
|
38
|
+
*/
|
|
39
|
+
export function apply(ctx: Context, config: Config = {}): void {
|
|
40
|
+
const interrupt = config.interrupt !== false
|
|
41
|
+
const listAgents = registerListAgents(ctx)
|
|
42
|
+
registerWaitAgent(ctx)
|
|
43
|
+
const sendMessage = defineTool({
|
|
44
|
+
name: 'send_message',
|
|
45
|
+
description:
|
|
46
|
+
'Send a message to an agent. A working agent receives it at its next step; an idle agent starts a new turn with it. '
|
|
47
|
+
+ 'Returns delivery confirmation.',
|
|
48
|
+
parameters: {
|
|
49
|
+
agent: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
required: true,
|
|
52
|
+
description: 'The name of another agent in your subagent tree, as shown by list_agents.',
|
|
53
|
+
},
|
|
54
|
+
message: {
|
|
55
|
+
type: 'string',
|
|
56
|
+
required: true,
|
|
57
|
+
description: 'The message to deliver to the agent.',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
output: {
|
|
61
|
+
schema: {
|
|
62
|
+
type: 'object',
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
properties: {
|
|
65
|
+
messageId: { type: 'string', required: true },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
render: (args, _value) => [{
|
|
69
|
+
type: 'text',
|
|
70
|
+
text: `message delivered to agent ${args.agent}`,
|
|
71
|
+
}],
|
|
72
|
+
},
|
|
73
|
+
async execute(args, exec) {
|
|
74
|
+
const sender = exec.agent
|
|
75
|
+
if (!sender) {
|
|
76
|
+
throw new Error('send_message requires a calling agent (exec.agent was undefined)')
|
|
77
|
+
}
|
|
78
|
+
const message: ContentBlock[] = [{ type: 'text', text: args.message }]
|
|
79
|
+
const targetId = await ctx.subagents.resolveName(sender, args.agent, exec.signal)
|
|
80
|
+
const messageId = await ctx.subagents.sendMessage(sender, targetId, message, { signal: exec.signal })
|
|
81
|
+
return { messageId }
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
ctx.tools.register(sendMessage)
|
|
85
|
+
ctx.systemPrompt.context({
|
|
86
|
+
name: 'subagent:identity',
|
|
87
|
+
order: ctx.systemPrompt.getContextOrder('SUBAGENT_DELEGATION'),
|
|
88
|
+
required: true,
|
|
89
|
+
interpolate: false,
|
|
90
|
+
text: ({ agent, scope, toolSet }) => {
|
|
91
|
+
if (agent === undefined) return ''
|
|
92
|
+
try {
|
|
93
|
+
const names = ctx.subagents.namesOf(agent)
|
|
94
|
+
let identity = names.parent === undefined
|
|
95
|
+
? `You are the root agent. Your name is ${JSON.stringify(names.self)}.`
|
|
96
|
+
: `You are a subagent delegated by agent ${JSON.stringify(names.parent)}.\n`
|
|
97
|
+
+ `Your name is ${JSON.stringify(names.self)}.\n`
|
|
98
|
+
+ `The root agent of your collaboration tree is ${JSON.stringify(ROOT_AGENT_NAME)}.`
|
|
99
|
+
const guidance: string[] = []
|
|
100
|
+
if (ctx.tools.get(sendMessage.name, scope, toolSet) === sendMessage) {
|
|
101
|
+
guidance.push('To message other agents, use send_message({ agent: "<agent-name>", message: "..." }).')
|
|
102
|
+
}
|
|
103
|
+
if (ctx.tools.get(listAgents.name, scope, toolSet) === listAgents) {
|
|
104
|
+
guidance.push('Use list_agents({}) to find your collaborator agents and their names.')
|
|
105
|
+
}
|
|
106
|
+
if (guidance.length > 0) identity += '\n\n' + guidance.join('\n')
|
|
107
|
+
return identity
|
|
108
|
+
} catch (error: unknown) {
|
|
109
|
+
const rootUnavailable = typeof error === 'object' && error !== null
|
|
110
|
+
&& 'name' in error && error.name === 'SubagentError'
|
|
111
|
+
&& 'code' in error && error.code === 'UNAUTHORIZED'
|
|
112
|
+
if (!rootUnavailable) throw error
|
|
113
|
+
return `Your agent id is ${JSON.stringify(agent.id)}. Your subagent tree root is unavailable. `
|
|
114
|
+
+ 'Continue independent work; subagent discovery and messaging require an active root.'
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
if (!interrupt) return
|
|
119
|
+
ctx.tools.register(defineTool({
|
|
120
|
+
name: 'interrupt_agent',
|
|
121
|
+
description:
|
|
122
|
+
'Ask a subagent to stop its current work. This call returns without waiting for it to stop. '
|
|
123
|
+
+ 'You can continue a local subagent\'s conversation later with send_message. '
|
|
124
|
+
+ 'External executions stop permanently and cannot receive follow-ups. Subagents it started will keep running.',
|
|
125
|
+
parameters: {
|
|
126
|
+
agent: {
|
|
127
|
+
type: 'string',
|
|
128
|
+
required: true,
|
|
129
|
+
description: 'The name of an agent created under you: your direct child or a deeper descendant.',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
output: {
|
|
133
|
+
schema: {
|
|
134
|
+
type: 'object',
|
|
135
|
+
additionalProperties: false,
|
|
136
|
+
properties: {
|
|
137
|
+
accepted: { type: 'boolean', required: true },
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
render: (args, _value) => [{
|
|
141
|
+
type: 'text',
|
|
142
|
+
text: `interrupt requested for agent ${args.agent}`,
|
|
143
|
+
}],
|
|
144
|
+
},
|
|
145
|
+
async execute(args, exec) {
|
|
146
|
+
const caller = exec.agent
|
|
147
|
+
if (!caller) {
|
|
148
|
+
// Ancestor authority requires an exact live calling agent.
|
|
149
|
+
throw new Error('interrupt_agent requires a calling agent (exec.agent was undefined)')
|
|
150
|
+
}
|
|
151
|
+
const targetId = await ctx.subagents.resolveName(caller, args.agent, exec.signal)
|
|
152
|
+
// The service authorizes the exact live caller against the target's
|
|
153
|
+
// recorded lineage; the tool adds no authority of its own.
|
|
154
|
+
ctx.subagents.interrupt(targetId, { kind: 'ancestor', agent: caller })
|
|
155
|
+
return { accepted: true }
|
|
156
|
+
},
|
|
157
|
+
}))
|
|
158
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** Discover the caller's entire subagent tree; the control plugin owns registration. */
|
|
2
|
+
|
|
3
|
+
import type { Context } from '@unieai/cordis'
|
|
4
|
+
import { defineTool } from '@unieai/rabi-tools'
|
|
5
|
+
import type { ToolDefinition } from '@unieai/rabi-tools'
|
|
6
|
+
import type { Agent } from '@unieai/rabi-agent'
|
|
7
|
+
import type { SessionId } from '@unieai/rabi-session'
|
|
8
|
+
import { ROOT_AGENT_NAME } from '@unieai/rabi-subagent'
|
|
9
|
+
import type { SubagentDescendantListEntry } from '@unieai/rabi-subagent'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
type ListAgentsStatus = 'running' | 'inactive' | 'corrupt' | 'unsupported' | 'unavailable'
|
|
13
|
+
|
|
14
|
+
/** One model-facing tree member; unreadable branches report their failure as status. */
|
|
15
|
+
interface ListAgentsEntry {
|
|
16
|
+
readonly name: string
|
|
17
|
+
readonly status: ListAgentsStatus
|
|
18
|
+
readonly description?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Report turn activity without exposing whether the child is loaded. */
|
|
22
|
+
function statusOf(agents: { get(id: SessionId): Agent | undefined }, id: SessionId): 'running' | 'inactive' {
|
|
23
|
+
return agents.get(id)?.status === 'running' ? 'running' : 'inactive'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Project one service row into the model-facing entry, or omit a one-shot or external child. */
|
|
27
|
+
function project(
|
|
28
|
+
agents: { get(id: SessionId): Agent | undefined },
|
|
29
|
+
entry: SubagentDescendantListEntry,
|
|
30
|
+
): ListAgentsEntry | undefined {
|
|
31
|
+
const name = entry.path ?? entry.id
|
|
32
|
+
if (entry.kind === 'diagnostic') return { name, status: entry.reason }
|
|
33
|
+
// One-shot children cannot be continued by send_message, so the model
|
|
34
|
+
// never selects them; discovery still traversed them for descendants.
|
|
35
|
+
if (entry.mode !== 'continuable') return undefined
|
|
36
|
+
return { name, status: statusOf(agents, entry.id), description: entry.label }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Register the `list_agents` tool.
|
|
41
|
+
* @param ctx - context carrying the tool registry, subagent service, and live Agent registry.
|
|
42
|
+
* @returns the registered definition for scoped availability checks.
|
|
43
|
+
*/
|
|
44
|
+
export function registerListAgents(ctx: Context): ToolDefinition {
|
|
45
|
+
const definition = defineTool({
|
|
46
|
+
name: 'list_agents',
|
|
47
|
+
description:
|
|
48
|
+
'List your entire subagent tree: the root agent and all reachable continuable descendants, including yourself. '
|
|
49
|
+
+ 'Rows carry names, descriptions, and status. A descendant\'s name is its path from the root, such as reviewer/checker. '
|
|
50
|
+
+ 'You can message any other agent in the subagent tree. '
|
|
51
|
+
+ 'running means it is working; inactive means no turn is executing; it does not indicate task completion, success, or failure. '
|
|
52
|
+
+ 'corrupt, unsupported, or unavailable means this row\'s own descendants could not be read; the row itself is '
|
|
53
|
+
+ 'still a member you can message. '
|
|
54
|
+
+ 'While you remain active, you will be notified when a direct child finishes; there is no need to keep checking its status. '
|
|
55
|
+
+ 'Use send_message to continue the conversation.',
|
|
56
|
+
parameters: {},
|
|
57
|
+
// Catalog observations are read-only and release their Session handles.
|
|
58
|
+
isConcurrencySafe: () => true,
|
|
59
|
+
output: {
|
|
60
|
+
schema: {
|
|
61
|
+
type: 'array',
|
|
62
|
+
items: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
properties: {
|
|
66
|
+
name: { type: 'string', required: true },
|
|
67
|
+
status: { type: 'string', required: true, enum: ['running', 'inactive', 'corrupt', 'unsupported', 'unavailable'] },
|
|
68
|
+
description: { type: 'string' },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
render: (_args, entries) => [{
|
|
73
|
+
type: 'text',
|
|
74
|
+
text: entries.map(entry =>
|
|
75
|
+
`${entry.name} [${entry.status}]${entry.description === undefined ? '' : ` — ${entry.description}`}`,
|
|
76
|
+
).join('\n'),
|
|
77
|
+
}],
|
|
78
|
+
},
|
|
79
|
+
async execute(_args, exec) {
|
|
80
|
+
const parent = exec.agent
|
|
81
|
+
if (!parent) {
|
|
82
|
+
// Non-agent callers have no session whose children could be listed.
|
|
83
|
+
throw new Error('list_agents requires a calling agent (exec.agent was undefined)')
|
|
84
|
+
}
|
|
85
|
+
const root = ctx.subagents.rootOf(parent)
|
|
86
|
+
const entries = await ctx.subagents.listDescendants(root.id, exec.signal)
|
|
87
|
+
return [
|
|
88
|
+
{ name: ROOT_AGENT_NAME, status: statusOf(ctx.agents, root.id), description: 'root agent' },
|
|
89
|
+
...entries
|
|
90
|
+
.map(entry => project(ctx.agents, entry))
|
|
91
|
+
.filter(entry => entry !== undefined),
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
ctx.tools.register(definition)
|
|
96
|
+
return definition
|
|
97
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** Input waiting owned by the subagent control plugin. */
|
|
2
|
+
|
|
3
|
+
import type { Context } from '@unieai/cordis'
|
|
4
|
+
import type { Agent } from '@unieai/rabi-agent'
|
|
5
|
+
import type { MessageId, ToolCallId } from '@unieai/rabi-llm'
|
|
6
|
+
import { HarnessError } from '@unieai/rabi-llm'
|
|
7
|
+
import { defineTool } from '@unieai/rabi-tools'
|
|
8
|
+
|
|
9
|
+
/** Wait failures retain a stable machine-readable reason through tool execution. */
|
|
10
|
+
class AgentWaitError extends HarnessError {
|
|
11
|
+
constructor(message: string, code: 'WAIT_INVALID_TIMEOUT' | 'WAIT_UNAVAILABLE') {
|
|
12
|
+
super(message, code)
|
|
13
|
+
this.name = 'AgentWaitError'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Pending input ids that the latest successful wait of one model tool call reported. */
|
|
18
|
+
type ReportedInput = WeakMap<Agent, { readonly rootCallId: ToolCallId; readonly ids: ReadonlySet<MessageId> }>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Wait without consuming input; every settlement removes its live resources.
|
|
22
|
+
* Within one model tool call, such as a `run_code` program, pending input that
|
|
23
|
+
* an earlier wait already reported does not end this wait: that input reaches
|
|
24
|
+
* the model only after the call finishes, so a waiting loop cannot spin on it.
|
|
25
|
+
*/
|
|
26
|
+
function waitForInput(
|
|
27
|
+
ctx: Context,
|
|
28
|
+
agent: Agent,
|
|
29
|
+
timeoutMs: number,
|
|
30
|
+
signal: AbortSignal,
|
|
31
|
+
lifetime: AbortSignal,
|
|
32
|
+
reported: ReportedInput,
|
|
33
|
+
rootCallId: ToolCallId,
|
|
34
|
+
): Promise<{ timedOut: boolean }> {
|
|
35
|
+
lifetime.throwIfAborted()
|
|
36
|
+
if (ctx.agents.get(agent.id) !== agent) {
|
|
37
|
+
throw new AgentWaitError('wait_agent requires the exact live calling agent', 'WAIT_UNAVAILABLE')
|
|
38
|
+
}
|
|
39
|
+
const previous = reported.get(agent)
|
|
40
|
+
const seen = previous?.rootCallId === rootCallId ? previous.ids : undefined
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const finish = (settle: () => void): void => {
|
|
43
|
+
clearTimeout(timer)
|
|
44
|
+
offInbox()
|
|
45
|
+
offDisposed()
|
|
46
|
+
signal.removeEventListener('abort', onAbort)
|
|
47
|
+
lifetime.removeEventListener('abort', onUnload)
|
|
48
|
+
settle()
|
|
49
|
+
}
|
|
50
|
+
const onInput = (): void => {
|
|
51
|
+
const pending = agent.inbox.nextStep
|
|
52
|
+
if (pending.some(message => seen?.has(message.id) !== true)) {
|
|
53
|
+
reported.set(agent, { rootCallId, ids: new Set(pending.map(message => message.id)) })
|
|
54
|
+
finish(() => { resolve({ timedOut: false }) })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// oxlint-disable-next-line typescript/prefer-promise-reject-errors -- Cancellation preserves the caller's exact AbortSignal reason.
|
|
58
|
+
const onAbort = (): void => { finish(() => { reject(signal.reason) }) }
|
|
59
|
+
// oxlint-disable-next-line typescript/prefer-promise-reject-errors -- This plugin aborts its lifetime only with AgentWaitError.
|
|
60
|
+
const onUnload = (): void => { finish(() => { reject(lifetime.reason) }) }
|
|
61
|
+
const offInbox = ctx.on('agent/inbox/inserted', ({ agent: recipient }) => {
|
|
62
|
+
if (recipient === agent) onInput()
|
|
63
|
+
})
|
|
64
|
+
const offDisposed = ctx.on('agent/disposed', ({ agent: disposed }) => {
|
|
65
|
+
if (disposed === agent) {
|
|
66
|
+
finish(() => {
|
|
67
|
+
reject(new AgentWaitError('wait_agent ended because the calling agent was disposed', 'WAIT_UNAVAILABLE'))
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
72
|
+
lifetime.addEventListener('abort', onUnload, { once: true })
|
|
73
|
+
const timer = setTimeout(() => { finish(() => { resolve({ timedOut: true }) }) }, timeoutMs)
|
|
74
|
+
// Subscribe before reading pending input so an arrival cannot fall between them.
|
|
75
|
+
if (signal.aborted) onAbort()
|
|
76
|
+
else onInput()
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Register one inbox wait tool and cancel its waits when the plugin unloads.
|
|
82
|
+
* @param ctx - plugin context owning the tool, event listeners, and wait lifetime.
|
|
83
|
+
*/
|
|
84
|
+
export function registerWaitAgent(ctx: Context): void {
|
|
85
|
+
const lifetime = new AbortController()
|
|
86
|
+
const reported: ReportedInput = new WeakMap()
|
|
87
|
+
ctx.effect(() => () => {
|
|
88
|
+
lifetime.abort(new AgentWaitError('wait_agent ended because its plugin was unloaded', 'WAIT_UNAVAILABLE'))
|
|
89
|
+
}, 'subagent-control.waits()')
|
|
90
|
+
ctx.tools.register(defineTool({
|
|
91
|
+
name: 'wait_agent',
|
|
92
|
+
description: 'Wait for input at your next step, including agent messages, completion notifications, and user steering. Returns immediately if new input is pending. `timedOut: false` means new input is pending. Pending input is delivered to the model after code execution finishes.',
|
|
93
|
+
parameters: {
|
|
94
|
+
timeout_ms: {
|
|
95
|
+
type: 'integer',
|
|
96
|
+
description: 'Wait duration in milliseconds, from 10000 through 3600000. Defaults to 30000.',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
output: {
|
|
100
|
+
schema: {
|
|
101
|
+
type: 'object',
|
|
102
|
+
additionalProperties: false,
|
|
103
|
+
properties: { timedOut: { type: 'boolean', required: true } },
|
|
104
|
+
},
|
|
105
|
+
render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }],
|
|
106
|
+
},
|
|
107
|
+
async execute(args, exec) {
|
|
108
|
+
const timeoutMs = args.timeout_ms ?? 30_000
|
|
109
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 10_000 || timeoutMs > 3_600_000) {
|
|
110
|
+
throw new AgentWaitError('timeout_ms must be an integer from 10000 through 3600000', 'WAIT_INVALID_TIMEOUT')
|
|
111
|
+
}
|
|
112
|
+
if (exec.agent === undefined) {
|
|
113
|
+
throw new AgentWaitError('wait_agent requires a calling agent', 'WAIT_UNAVAILABLE')
|
|
114
|
+
}
|
|
115
|
+
return await waitForInput(ctx, exec.agent, timeoutMs, exec.signal, lifetime.signal, reported, exec.rootCallId)
|
|
116
|
+
},
|
|
117
|
+
}))
|
|
118
|
+
}
|