@unieai/rabi-tool-subagent-control 0.0.0-stage → 0.2.1-rc.3

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 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
- # Temporary Holding Version
1
+ # @unieai/rabi-tool-subagent-control
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Globally named send_message, interrupt_agent, and list_agents tools over ctx.subagents continuations
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,95 @@
1
+ import { brandString } from "@unieai/rabi-brand";
2
+ import { defineTool } from "@unieai/rabi-tools";
3
+ import { markAdjacentAgentSendMessageTool } from "@unieai/rabi-subagent/internal";
4
+ //#region lib/types/index.js
5
+ /**
6
+ * The globally named `send_message` and `interrupt_agent` tools: thin
7
+ * model-facing adapters over `ctx.subagents.sendMessage()` and
8
+ * `ctx.subagents.interrupt()`. They perform no lifecycle routing of their own —
9
+ * residency, cold resume, and interrupt authorization belong to the subagent
10
+ * service — and they live apart from the provider-bound
11
+ * `@unieai/rabi-tool-subagent` instances so multiple delegation tools share
12
+ * one control API.
13
+ * @module @unieai/rabi-tool-subagent-control
14
+ */
15
+ const name = "tool-subagent-control";
16
+ const inject = ["tools", "subagents"];
17
+ /**
18
+ * Register the `send_message` and `interrupt_agent` tools.
19
+ * @param ctx - context carrying the tool registry and subagent service.
20
+ */
21
+ function apply(ctx) {
22
+ ctx.tools.register(markAdjacentAgentSendMessageTool(defineTool({
23
+ name: "send_message",
24
+ 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, not the agent's answer.",
25
+ parameters: {
26
+ agent_id: {
27
+ type: "string",
28
+ required: true,
29
+ description: "The agent id of your direct continuable child, or your direct parent when you are a resident continuable child."
30
+ },
31
+ message: {
32
+ type: "string",
33
+ required: true,
34
+ description: "The message to deliver to the agent."
35
+ }
36
+ },
37
+ output: {
38
+ schema: {
39
+ type: "object",
40
+ additionalProperties: false,
41
+ properties: { messageId: {
42
+ type: "string",
43
+ required: true
44
+ } }
45
+ },
46
+ render: (args, _value) => [{
47
+ type: "text",
48
+ text: `message delivered to agent ${args.agent_id}`
49
+ }]
50
+ },
51
+ async execute(args, exec) {
52
+ const sender = exec.agent;
53
+ if (!sender) throw new Error("send_message requires a calling agent (exec.agent was undefined)");
54
+ const message = [{
55
+ type: "text",
56
+ text: args.message
57
+ }];
58
+ return { messageId: await ctx.subagents.sendMessage(sender, brandString(args.agent_id), message, { signal: exec.signal }) };
59
+ }
60
+ })));
61
+ ctx.tools.register(defineTool({
62
+ name: "interrupt_agent",
63
+ description: "Ask a subagent to stop its current work. This call returns without waiting for it to stop. You can continue a local direct child's conversation later with send_message. External executions stop permanently and cannot receive follow-ups. Subagents it started will keep running.",
64
+ parameters: { agent_id: {
65
+ type: "string",
66
+ required: true,
67
+ description: "The id of an agent created under you: your direct child or a deeper descendant."
68
+ } },
69
+ output: {
70
+ schema: {
71
+ type: "object",
72
+ additionalProperties: false,
73
+ properties: { accepted: {
74
+ type: "boolean",
75
+ required: true
76
+ } }
77
+ },
78
+ render: (args, _value) => [{
79
+ type: "text",
80
+ text: `interrupt requested for agent ${args.agent_id}`
81
+ }]
82
+ },
83
+ execute(args, exec) {
84
+ const caller = exec.agent;
85
+ if (!caller) throw new Error("interrupt_agent requires a calling agent (exec.agent was undefined)");
86
+ ctx.subagents.interrupt(brandString(args.agent_id), {
87
+ kind: "ancestor",
88
+ agent: caller
89
+ });
90
+ return Promise.resolve({ accepted: true });
91
+ }
92
+ }));
93
+ }
94
+ //#endregion
95
+ export { apply, inject, name };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The globally named `send_message` and `interrupt_agent` tools: thin
3
+ * model-facing adapters over `ctx.subagents.sendMessage()` and
4
+ * `ctx.subagents.interrupt()`. They perform no lifecycle routing of their own —
5
+ * residency, cold resume, and interrupt authorization belong to the subagent
6
+ * service — and they live apart from the provider-bound
7
+ * `@unieai/rabi-tool-subagent` instances so multiple delegation tools share
8
+ * one control API.
9
+ * @module @unieai/rabi-tool-subagent-control
10
+ */
11
+ import type { Context } from '@unieai/cordis';
12
+ export declare const name = "tool-subagent-control";
13
+ export declare const inject: string[];
14
+ /**
15
+ * Register the `send_message` and `interrupt_agent` tools.
16
+ * @param ctx - context carrying the tool registry and subagent service.
17
+ */
18
+ export declare function apply(ctx: Context): void;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The globally named `send_message` and `interrupt_agent` tools: thin
3
+ * model-facing adapters over `ctx.subagents.sendMessage()` and
4
+ * `ctx.subagents.interrupt()`. They perform no lifecycle routing of their own —
5
+ * residency, cold resume, and interrupt authorization belong to the subagent
6
+ * service — and they live apart from the provider-bound
7
+ * `@unieai/rabi-tool-subagent` instances so multiple delegation tools share
8
+ * one control API.
9
+ * @module @unieai/rabi-tool-subagent-control
10
+ */
11
+ import { brandString } from '@unieai/rabi-brand';
12
+ import { defineTool } from '@unieai/rabi-tools';
13
+ import { markAdjacentAgentSendMessageTool } from '@unieai/rabi-subagent/internal';
14
+ export const name = 'tool-subagent-control';
15
+ export const inject = ['tools', 'subagents'];
16
+ /**
17
+ * Register the `send_message` and `interrupt_agent` tools.
18
+ * @param ctx - context carrying the tool registry and subagent service.
19
+ */
20
+ export function apply(ctx) {
21
+ ctx.tools.register(markAdjacentAgentSendMessageTool(defineTool({
22
+ name: 'send_message',
23
+ 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. '
24
+ + 'Returns delivery confirmation, not the agent\'s answer.',
25
+ parameters: {
26
+ agent_id: {
27
+ type: 'string',
28
+ required: true,
29
+ description: 'The agent id of your direct continuable child, or your direct parent when you are a resident continuable child.',
30
+ },
31
+ message: {
32
+ type: 'string',
33
+ required: true,
34
+ description: 'The message to deliver to the agent.',
35
+ },
36
+ },
37
+ output: {
38
+ schema: {
39
+ type: 'object',
40
+ additionalProperties: false,
41
+ properties: {
42
+ messageId: { type: 'string', required: true },
43
+ },
44
+ },
45
+ render: (args, _value) => [{
46
+ type: 'text',
47
+ text: `message delivered to agent ${args.agent_id}`,
48
+ }],
49
+ },
50
+ async execute(args, exec) {
51
+ const sender = exec.agent;
52
+ if (!sender) {
53
+ throw new Error('send_message requires a calling agent (exec.agent was undefined)');
54
+ }
55
+ const message = [{ type: 'text', text: args.message }];
56
+ const messageId = await ctx.subagents.sendMessage(sender, brandString(args.agent_id), message, { signal: exec.signal });
57
+ return { messageId };
58
+ },
59
+ })));
60
+ ctx.tools.register(defineTool({
61
+ name: 'interrupt_agent',
62
+ description: 'Ask a subagent to stop its current work. This call returns without waiting for it to stop. '
63
+ + 'You can continue a local direct child\'s conversation later with send_message. '
64
+ + 'External executions stop permanently and cannot receive follow-ups. Subagents it started will keep running.',
65
+ parameters: {
66
+ agent_id: {
67
+ type: 'string',
68
+ required: true,
69
+ description: 'The id of an agent created under you: your direct child or a deeper descendant.',
70
+ },
71
+ },
72
+ output: {
73
+ schema: {
74
+ type: 'object',
75
+ additionalProperties: false,
76
+ properties: {
77
+ accepted: { type: 'boolean', required: true },
78
+ },
79
+ },
80
+ render: (args, _value) => [{
81
+ type: 'text',
82
+ text: `interrupt requested for agent ${args.agent_id}`,
83
+ }],
84
+ },
85
+ execute(args, exec) {
86
+ const caller = exec.agent;
87
+ if (!caller) {
88
+ // Ancestor authority requires an exact live calling agent.
89
+ throw new Error('interrupt_agent requires a calling agent (exec.agent was undefined)');
90
+ }
91
+ // The service authorizes the exact live caller against the target's
92
+ // recorded lineage; the tool adds no authority of its own.
93
+ ctx.subagents.interrupt(brandString(args.agent_id), { kind: 'ancestor', agent: caller });
94
+ return Promise.resolve({ accepted: true });
95
+ },
96
+ }));
97
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The globally named `list_agents` tool: a thin model-facing adapter over
3
+ * the continuable projection of `ctx.subagents.listChildren()` and, for the
4
+ * `descendants` scope, `ctx.subagents.listDescendants()`. It stays separately
5
+ * loadable from the root `send_message` plugin so a deployment can register
6
+ * continuation delivery without exposing discovery.
7
+ * @module @unieai/rabi-tool-subagent-control/list-agents
8
+ */
9
+ import type { Context } from '@unieai/cordis';
10
+ export declare const name = "tool-subagent-list-agents";
11
+ export declare const inject: string[];
12
+ /**
13
+ * Register the `list_agents` tool.
14
+ * @param ctx - context carrying the tool registry, subagent service, and live Agent registry.
15
+ */
16
+ export declare function apply(ctx: Context): void;
17
+ //# sourceMappingURL=list-agents.d.ts.map
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The globally named `list_agents` tool: a thin model-facing adapter over
3
+ * the continuable projection of `ctx.subagents.listChildren()` and, for the
4
+ * `descendants` scope, `ctx.subagents.listDescendants()`. It stays separately
5
+ * loadable from the root `send_message` plugin so a deployment can register
6
+ * continuation delivery without exposing discovery.
7
+ * @module @unieai/rabi-tool-subagent-control/list-agents
8
+ */
9
+ import { defineTool } from '@unieai/rabi-tools';
10
+ import { assertNever } from '@unieai/rabi-util-values';
11
+ export const name = 'tool-subagent-list-agents';
12
+ export const inject = ['tools', 'subagents', 'agents'];
13
+ /** Resolve the optional model request into an internal required-scope spec. */
14
+ function resolveListAgentsRequest(request) {
15
+ return { scope: request.scope ?? 'children' };
16
+ }
17
+ /** Report turn activity without exposing whether the child is loaded. */
18
+ function statusOf(agents, id) {
19
+ return agents.get(id)?.status === 'running' ? 'running' : 'inactive';
20
+ }
21
+ /** Project one service row into the model-facing entry, or omit a one-shot child. */
22
+ function project(agents, entry, position) {
23
+ const at = position === undefined ? {} : { parent: position.parentId, depth: position.depth };
24
+ if ('kind' in entry && entry.kind === 'diagnostic') {
25
+ return { kind: 'diagnostic', id: entry.id, reason: entry.reason, ...at };
26
+ }
27
+ // One-shot children cannot be continued by send_message, so the model
28
+ // never selects them; discovery still traversed them for descendants.
29
+ if (entry.mode !== 'continuable')
30
+ return undefined;
31
+ return {
32
+ kind: 'child',
33
+ id: entry.id,
34
+ label: entry.label,
35
+ status: statusOf(agents, entry.id),
36
+ ...at,
37
+ };
38
+ }
39
+ /**
40
+ * Register the `list_agents` tool.
41
+ * @param ctx - context carrying the tool registry, subagent service, and live Agent registry.
42
+ */
43
+ export function apply(ctx) {
44
+ ctx.tools.register(defineTool({
45
+ name: 'list_agents',
46
+ description: 'List subagents you started, with their ids, labels, and status. '
47
+ + 'running means it is working; inactive means it is not currently working. '
48
+ + 'You will be notified when a subagent finishes; there is no need to keep checking its status. '
49
+ + 'Use send_message to continue the conversation.',
50
+ parameters: {
51
+ scope: {
52
+ type: 'string',
53
+ enum: ['children', 'descendants'],
54
+ description: 'children (default) lists direct children, which accept send_message in any status. '
55
+ + 'descendants lists the whole tree below you with each entry\'s parent session id and depth; entries deeper than 1 accept only interrupt_agent.',
56
+ },
57
+ },
58
+ output: {
59
+ schema: {
60
+ type: 'array',
61
+ items: {
62
+ oneOf: [
63
+ {
64
+ type: 'object',
65
+ additionalProperties: false,
66
+ properties: {
67
+ kind: { type: 'string', required: true, enum: ['child'] },
68
+ id: { type: 'string', required: true },
69
+ label: { type: 'string', required: true },
70
+ status: { type: 'string', required: true, enum: ['running', 'inactive'] },
71
+ parent: { type: 'string' },
72
+ depth: { type: 'number' },
73
+ },
74
+ },
75
+ {
76
+ type: 'object',
77
+ additionalProperties: false,
78
+ properties: {
79
+ kind: { type: 'string', required: true, enum: ['diagnostic'] },
80
+ id: { type: 'string', required: true },
81
+ reason: { type: 'string', required: true, enum: ['corrupt', 'unsupported', 'unavailable'] },
82
+ parent: { type: 'string' },
83
+ depth: { type: 'number' },
84
+ },
85
+ },
86
+ ],
87
+ },
88
+ },
89
+ render: (args, entries) => {
90
+ const request = resolveListAgentsRequest(args);
91
+ return [{
92
+ type: 'text',
93
+ text: entries.length === 0
94
+ ? '(no subagents)'
95
+ : entries.map((entry) => {
96
+ // A descendants row always carries its position; children rows
97
+ // never render it. String() spans the schema-optional shape
98
+ // without a dead fallback branch.
99
+ const at = request.scope === 'descendants'
100
+ ? ` parent=${String(entry.parent)} depth=${String(entry.depth)}`
101
+ : '';
102
+ return entry.kind === 'child'
103
+ ? `${entry.id} [${entry.status}]${at} — ${entry.label}`
104
+ : `${entry.id} [diagnostic: ${entry.reason}]${at}`;
105
+ }).join('\n'),
106
+ }];
107
+ },
108
+ },
109
+ async execute(args, exec) {
110
+ const parent = exec.agent;
111
+ if (!parent) {
112
+ // Non-agent callers have no session whose children could be listed.
113
+ throw new Error('list_agents requires a calling agent (exec.agent was undefined)');
114
+ }
115
+ const request = resolveListAgentsRequest(args);
116
+ switch (request.scope) {
117
+ case 'children': {
118
+ const entries = await ctx.subagents.listChildren(parent.id, exec.signal);
119
+ return entries
120
+ .map(entry => project(ctx.agents, entry))
121
+ .filter(entry => entry !== undefined);
122
+ }
123
+ case 'descendants': {
124
+ const entries = await ctx.subagents.listDescendants(parent.id, exec.signal);
125
+ return entries
126
+ .map(entry => project(ctx.agents, entry, entry))
127
+ .filter(entry => entry !== undefined);
128
+ }
129
+ /* v8 ignore next 2 -- the resolver normalizes the schema-validated closed scope before dispatch. */
130
+ default:
131
+ return assertNever(request.scope, 'list_agents scope');
132
+ }
133
+ },
134
+ }));
135
+ }
package/locale/en.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "meta": {
3
+ "title": "tool-subagent-control"
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "meta": {
3
+ "title": "tool-subagent-control/list-agents"
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "meta": {
3
+ "title": "子智能体列表工具"
4
+ }
5
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "子智能体控制工具",
4
+ "description": "让 AI 向子智能体发送消息或中断其运行。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@unieai/rabi-tool-subagent-control",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Globally named send_message, interrupt_agent, and list_agents tools over ctx.subagents continuations",
4
+ "version": "0.2.1-rc.3",
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
+ "./list-agents": {
17
+ "types": "./lib/types/list-agents.d.ts",
18
+ "default": "./lib/types/list-agents.js"
19
+ },
20
+ "./src/*": "./src/*",
21
+ "./package.json": "./package.json",
22
+ "./locale/*.json": "./locale/*.json",
23
+ "./list-agents/locale/*.json": "./locale/list-agents/*.json"
24
+ },
25
+ "files": [
26
+ "locale/*.json",
27
+ "locale/list-agents/*.json",
28
+ "lib/index.js",
29
+ "lib/types/**/*.js",
30
+ "lib/types/**/*.d.ts",
31
+ "README.md"
32
+ ],
33
+ "license": "MIT",
34
+ "peerDependencies": {
35
+ "@unieai/cordis": "4.0.5",
36
+ "@unieai/rabi-llm": "0.2.1-rc.3",
37
+ "@unieai/rabi-session": "0.2.1-rc.3",
38
+ "@unieai/rabi-subagent": "0.2.1-rc.3",
39
+ "@unieai/rabi-tools": "0.2.1-rc.3"
40
+ },
41
+ "dependencies": {
42
+ "@unieai/rabi-brand": "0.2.1-rc.3",
43
+ "@unieai/rabi-util-values": "0.2.1-rc.3"
44
+ }
45
+ }