@myagentroam/agent 0.13.33 → 0.13.35
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/cli/subagent/control.d.ts +2 -2
- package/dist/cli/subagent/control.js +11 -8
- package/dist/cli/subagent/index.js +5 -0
- package/dist/cli/subagent/model-contract.d.ts +8 -0
- package/dist/cli/subagent/model-contract.js +68 -0
- package/dist/cli/subagent/native.js +1 -1
- package/dist/cli/subagent/query.js +2 -2
- package/dist/cli/subagent/start.js +18 -5
- package/dist/cli/subagent/wait-output.d.ts +11 -0
- package/dist/cli/subagent/wait-output.js +11 -0
- package/dist/cli/subagent/wait.js +29 -12
- package/package.json +1 -1
|
@@ -21,11 +21,11 @@ export declare function sendChild(context: SessionExtensionContext, agent: Agent
|
|
|
21
21
|
delivery: string;
|
|
22
22
|
clientMessageId: `${string}-${string}-${string}-${string}-${string}`;
|
|
23
23
|
}>;
|
|
24
|
-
/** Stop through the Session owner; native
|
|
24
|
+
/** Stop through the Session owner; only native receipts consume their returned observations. */
|
|
25
25
|
export declare function stopChild(context: SessionExtensionContext, agent: Agent, observations: SessionObservations, input: {
|
|
26
26
|
agentId: string;
|
|
27
27
|
executionId?: string;
|
|
28
|
-
}, call: ExtensionOperationContext): Promise<{
|
|
28
|
+
}, call: ExtensionOperationContext, mode: 'model' | 'native'): Promise<{
|
|
29
29
|
updates?: {
|
|
30
30
|
permissionStop?: import("@myagentroam/agent").PermissionStop;
|
|
31
31
|
errorMessage?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { AgentError } from '@myagentroam/agent';
|
|
3
|
+
import { modelReceipt } from './model-contract.js';
|
|
3
4
|
import { publicChildSnapshot } from './snapshot.js';
|
|
4
5
|
import { historicalExecutionStatus } from './history.js';
|
|
5
6
|
async function relation(agent, actorId, id) {
|
|
@@ -63,7 +64,8 @@ export function registerControlTools(context, agent, observations, warmObservati
|
|
|
63
64
|
async execute(value, call) {
|
|
64
65
|
const input = value;
|
|
65
66
|
const data = await sendChild(context, agent, observations, warmObservations, admission, input, call, 'model');
|
|
66
|
-
|
|
67
|
+
const projected = modelReceipt('send', data);
|
|
68
|
+
return { data: projected, content: JSON.stringify(projected) };
|
|
67
69
|
}
|
|
68
70
|
});
|
|
69
71
|
context.tools.register({
|
|
@@ -74,16 +76,16 @@ export function registerControlTools(context, agent, observations, warmObservati
|
|
|
74
76
|
inputSchema: {
|
|
75
77
|
type: 'object',
|
|
76
78
|
properties: {
|
|
77
|
-
agentId: { type: 'string', minLength: 1 }
|
|
78
|
-
executionId: { type: 'string', minLength: 1 }
|
|
79
|
+
agentId: { type: 'string', minLength: 1 }
|
|
79
80
|
},
|
|
80
81
|
required: ['agentId'],
|
|
81
82
|
additionalProperties: false
|
|
82
83
|
},
|
|
83
84
|
async execute(value, call) {
|
|
84
85
|
const input = value;
|
|
85
|
-
const data = await stopChild(context, agent, observations, input, call);
|
|
86
|
-
|
|
86
|
+
const data = await stopChild(context, agent, observations, input, call, 'model');
|
|
87
|
+
const projected = modelReceipt('stop', data);
|
|
88
|
+
return { data: projected, content: JSON.stringify(projected) };
|
|
87
89
|
}
|
|
88
90
|
});
|
|
89
91
|
}
|
|
@@ -186,8 +188,8 @@ export async function sendChild(context, agent, observations, warmObservations,
|
|
|
186
188
|
};
|
|
187
189
|
return data;
|
|
188
190
|
}
|
|
189
|
-
/** Stop through the Session owner; native
|
|
190
|
-
export async function stopChild(context, agent, observations, input, call) {
|
|
191
|
+
/** Stop through the Session owner; only native receipts consume their returned observations. */
|
|
192
|
+
export async function stopChild(context, agent, observations, input, call, mode) {
|
|
191
193
|
const { child, session } = await target(agent, context.sessionId, input.agentId);
|
|
192
194
|
if (!child)
|
|
193
195
|
throw new AgentError('MAR_AGENT_SUBAGENT_NOT_FOUND', 'Session is not available.');
|
|
@@ -216,6 +218,7 @@ export async function stopChild(context, agent, observations, input, call) {
|
|
|
216
218
|
...publicChildSnapshot(observations.snapshot(session.id, current.activeExecutionId)),
|
|
217
219
|
...(observation?.updates.length ? { updates: observation.updates } : {})
|
|
218
220
|
};
|
|
219
|
-
|
|
221
|
+
if (mode === 'native')
|
|
222
|
+
observation?.acknowledge();
|
|
220
223
|
return data;
|
|
221
224
|
}
|
|
@@ -4,6 +4,7 @@ import { registerStart, StartAdmission } from './start.js';
|
|
|
4
4
|
import { registerControlTools } from './control.js';
|
|
5
5
|
import { registerWait } from './wait.js';
|
|
6
6
|
import { registerQueryTools } from './query.js';
|
|
7
|
+
import { assertModelArguments } from './model-contract.js';
|
|
7
8
|
import { nativeSubagentService, SUBAGENT_NATIVE_SERVICE } from './native.js';
|
|
8
9
|
import { childResources } from './resources.js';
|
|
9
10
|
import { sharedSessionHistory } from './history.js';
|
|
@@ -83,6 +84,10 @@ export function createSubagentExtension(options) {
|
|
|
83
84
|
registerControlTools(context, agent, observations, warmObservations, admission);
|
|
84
85
|
registerWait(context, agent, observations, history);
|
|
85
86
|
registerQueryTools(context, agent);
|
|
87
|
+
context.hooks.intercept('tool.invoke', (input, _call, next) => {
|
|
88
|
+
assertModelArguments(input);
|
|
89
|
+
return next(input);
|
|
90
|
+
}, { reentry: 'allow' });
|
|
86
91
|
context.hooks.intercept('prompt.sections', (input, _call, next) => next({
|
|
87
92
|
...input,
|
|
88
93
|
sections: [
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Reject retired arguments before compatibility normalization can discard them. */
|
|
2
|
+
export declare function assertModelArguments(call: {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly arguments: unknown;
|
|
5
|
+
}): void;
|
|
6
|
+
/** Model adapters share receipt vocabulary without changing Session or native SDK contracts. */
|
|
7
|
+
export declare function modelStatus(status: string): string;
|
|
8
|
+
export declare function modelReceipt(action: 'start' | 'send' | 'stop', input: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AgentError } from '@myagentroam/agent';
|
|
2
|
+
import { boundedUtf8 } from './snapshot.js';
|
|
3
|
+
/** Reject retired arguments before compatibility normalization can discard them. */
|
|
4
|
+
export function assertModelArguments(call) {
|
|
5
|
+
const retired = call.name === 'agent_start'
|
|
6
|
+
? ['prompt', 'reasoningEffort']
|
|
7
|
+
: call.name === 'agent_wait'
|
|
8
|
+
? ['agentId']
|
|
9
|
+
: call.name === 'agent_stop'
|
|
10
|
+
? ['executionId']
|
|
11
|
+
: [];
|
|
12
|
+
if (!call.arguments || typeof call.arguments !== 'object')
|
|
13
|
+
return;
|
|
14
|
+
for (const key of retired)
|
|
15
|
+
if (Object.hasOwn(call.arguments, key))
|
|
16
|
+
throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', `Unsupported argument '${key}' for ${call.name}.`);
|
|
17
|
+
}
|
|
18
|
+
/** Model adapters share receipt vocabulary without changing Session or native SDK contracts. */
|
|
19
|
+
export function modelStatus(status) {
|
|
20
|
+
switch (status) {
|
|
21
|
+
case 'completed':
|
|
22
|
+
return 'SUCCEEDED';
|
|
23
|
+
case 'failed':
|
|
24
|
+
return 'FAILED';
|
|
25
|
+
case 'cancelled':
|
|
26
|
+
return 'CANCELLED';
|
|
27
|
+
case 'interrupted':
|
|
28
|
+
return 'INTERRUPTED';
|
|
29
|
+
case 'running':
|
|
30
|
+
return 'RUNNING';
|
|
31
|
+
case 'idle':
|
|
32
|
+
return 'IDLE';
|
|
33
|
+
default:
|
|
34
|
+
return status;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function modelReceipt(action, input) {
|
|
38
|
+
const result = { agentId: input.agentId };
|
|
39
|
+
const errors = {
|
|
40
|
+
...(input.errorCode === undefined ? {} : { code: input.errorCode }),
|
|
41
|
+
...(typeof input.errorMessage === 'string'
|
|
42
|
+
? { message: boundedUtf8(input.errorMessage, 1000).value }
|
|
43
|
+
: {})
|
|
44
|
+
};
|
|
45
|
+
if (action === 'start') {
|
|
46
|
+
result.start = {
|
|
47
|
+
status: input.status === 'not-started' ? 'failed' : 'accepted',
|
|
48
|
+
...(input.status === 'not-started'
|
|
49
|
+
? {}
|
|
50
|
+
: { executionStatus: modelStatus(String(input.status)) }),
|
|
51
|
+
...errors
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
else if (action === 'send') {
|
|
55
|
+
result.message = {
|
|
56
|
+
status: input.delivery === 'notAccepted' ? 'notAccepted' : 'accepted',
|
|
57
|
+
...(input.delivery === 'duplicate' ? { idempotent: true } : {})
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
result.cancel = {
|
|
62
|
+
executionStatus: modelStatus(String(input.status)),
|
|
63
|
+
...errors,
|
|
64
|
+
...(input.permissionStop === undefined ? {} : { permissionStop: input.permissionStop })
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
@@ -336,7 +336,7 @@ export function nativeSubagentService(context, agent, admission, warmObservation
|
|
|
336
336
|
if (!input || typeof input.agentId !== 'string' || !input.agentId)
|
|
337
337
|
throw new AgentError('MAR_AGENT_EXTENSION_AGENT_INPUT_INVALID', 'Agent target is invalid.');
|
|
338
338
|
return run(async (call) => {
|
|
339
|
-
const result = await stopChild(context, agent, observations, input, call);
|
|
339
|
+
const result = await stopChild(context, agent, observations, input, call, 'native');
|
|
340
340
|
const child = await agent.getSession(input.agentId);
|
|
341
341
|
return {
|
|
342
342
|
...result,
|
|
@@ -25,7 +25,7 @@ export function registerQueryTools(context, agent) {
|
|
|
25
25
|
: await agent
|
|
26
26
|
.listSessions({
|
|
27
27
|
parentSessionId: context.sessionId,
|
|
28
|
-
|
|
28
|
+
limit: input.limit ?? 10,
|
|
29
29
|
...(input.cursor === undefined ? {} : { cursor: input.cursor })
|
|
30
30
|
})
|
|
31
31
|
.then((page) => ({
|
|
@@ -85,7 +85,7 @@ export function registerQueryTools(context, agent) {
|
|
|
85
85
|
title: session.title,
|
|
86
86
|
parentSessionId: session.source.parentSessionId ?? null,
|
|
87
87
|
modelId: session.modelId,
|
|
88
|
-
|
|
88
|
+
effort: session.reasoningEffort,
|
|
89
89
|
lastActivityAt: session.lastActivityAt,
|
|
90
90
|
...(history
|
|
91
91
|
? {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AgentError } from '@myagentroam/agent';
|
|
2
|
+
import { modelReceipt } from './model-contract.js';
|
|
2
3
|
/** Admission reservations are bounded quota accounting, not Execution state. */
|
|
3
4
|
export class StartAdmission {
|
|
4
5
|
#pending = new Map();
|
|
@@ -50,21 +51,33 @@ export function registerStart(context, agent, admission) {
|
|
|
50
51
|
properties: {
|
|
51
52
|
title: { type: 'string', minLength: 1, maxLength: 80 },
|
|
52
53
|
description: { type: 'string', minLength: 1, maxLength: 80 },
|
|
53
|
-
|
|
54
|
+
content: { type: 'string', minLength: 1 },
|
|
54
55
|
role: { type: 'string', enum: ['general-purpose', 'explore'] },
|
|
55
56
|
modelId: { type: 'string', minLength: 1 },
|
|
56
|
-
|
|
57
|
+
effort: {
|
|
57
58
|
type: 'string',
|
|
58
59
|
enum: ['low', 'medium', 'high', 'xhigh', 'max', 'ultra']
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
|
-
required: ['title', '
|
|
62
|
+
required: ['title', 'content'],
|
|
62
63
|
additionalProperties: false
|
|
63
64
|
},
|
|
64
65
|
async execute(raw, call) {
|
|
65
66
|
const input = raw;
|
|
66
|
-
const { data } = await startChild(context, agent, admission, {
|
|
67
|
-
|
|
67
|
+
const { data } = await startChild(context, agent, admission, {
|
|
68
|
+
title: input.title,
|
|
69
|
+
description: input.description ?? input.title,
|
|
70
|
+
prompt: input.content,
|
|
71
|
+
role: input.role ?? 'general-purpose',
|
|
72
|
+
...(input.modelId === undefined ? {} : { modelId: input.modelId }),
|
|
73
|
+
...(input.effort === undefined ? {} : { reasoningEffort: input.effort })
|
|
74
|
+
}, call, 'model');
|
|
75
|
+
const projected = modelReceipt('start', data);
|
|
76
|
+
return {
|
|
77
|
+
content: JSON.stringify(projected),
|
|
78
|
+
data: projected,
|
|
79
|
+
eventData: { agentId: data.agentId }
|
|
80
|
+
};
|
|
68
81
|
}
|
|
69
82
|
});
|
|
70
83
|
}
|
|
@@ -3,6 +3,15 @@ type WaitAgent = {
|
|
|
3
3
|
executionId?: string;
|
|
4
4
|
status: string;
|
|
5
5
|
waitOutcome: string;
|
|
6
|
+
errorCode?: string;
|
|
7
|
+
errorMessage?: string;
|
|
8
|
+
receipt?: {
|
|
9
|
+
readonly status: string;
|
|
10
|
+
};
|
|
11
|
+
permissionStop?: {
|
|
12
|
+
readonly action: string;
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
};
|
|
6
15
|
summary?: string;
|
|
7
16
|
summaryTruncated?: boolean;
|
|
8
17
|
changedFiles?: string[];
|
|
@@ -15,5 +24,7 @@ type WaitAgent = {
|
|
|
15
24
|
/** Keep the model's JSON parseable without modifying the native result. */
|
|
16
25
|
export declare function modelWaitAgent<T extends WaitAgent>(agent: T, maximumBytes: number): T & {
|
|
17
26
|
detailsTruncated?: boolean;
|
|
27
|
+
summaryTruncated?: boolean;
|
|
28
|
+
changedFilesTruncated?: boolean;
|
|
18
29
|
};
|
|
19
30
|
export {};
|
|
@@ -51,6 +51,17 @@ export function modelWaitAgent(agent, maximumBytes) {
|
|
|
51
51
|
...(agent.executionId ? { executionId: agent.executionId } : {}),
|
|
52
52
|
status: agent.status,
|
|
53
53
|
waitOutcome: agent.waitOutcome,
|
|
54
|
+
...(agent.errorCode ? { errorCode: boundedUtf8(agent.errorCode, 512).value } : {}),
|
|
55
|
+
...(agent.errorMessage ? { errorMessage: boundedUtf8(agent.errorMessage, 1000).value } : {}),
|
|
56
|
+
...(agent.receipt ? { receipt: { status: agent.receipt.status } } : {}),
|
|
57
|
+
...(agent.permissionStop
|
|
58
|
+
? {
|
|
59
|
+
permissionStop: {
|
|
60
|
+
action: agent.permissionStop.action,
|
|
61
|
+
reason: boundedUtf8(agent.permissionStop.reason, 1000).value
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
: {}),
|
|
54
65
|
detailsTruncated: true
|
|
55
66
|
};
|
|
56
67
|
}
|
|
@@ -3,6 +3,7 @@ import { waitForToolCondition } from '@myagentroam/agent/extensions';
|
|
|
3
3
|
import { target } from './control.js';
|
|
4
4
|
import { boundedUtf8, nativeChildSnapshot, projectChildEvent, publicChildSnapshot } from './snapshot.js';
|
|
5
5
|
import { modelWaitAgent } from './wait-output.js';
|
|
6
|
+
import { modelStatus } from './model-contract.js';
|
|
6
7
|
function terminalStatus(type) {
|
|
7
8
|
if (type === 'execution.completed')
|
|
8
9
|
return 'completed';
|
|
@@ -143,7 +144,6 @@ export function registerWait(context, agent, observations, history = agent) {
|
|
|
143
144
|
inputSchema: {
|
|
144
145
|
type: 'object',
|
|
145
146
|
properties: {
|
|
146
|
-
agentId: { type: ['string', 'null'], minLength: 1 },
|
|
147
147
|
agentIds: {
|
|
148
148
|
type: ['array', 'null'],
|
|
149
149
|
minItems: 1,
|
|
@@ -160,13 +160,16 @@ export function registerWait(context, agent, observations, history = agent) {
|
|
|
160
160
|
async execute(raw, call) {
|
|
161
161
|
const value = raw;
|
|
162
162
|
const input = {
|
|
163
|
-
agentId: value.agentId ?? undefined,
|
|
164
163
|
agentIds: value.agentIds ?? undefined,
|
|
165
164
|
mode: value.mode ?? undefined,
|
|
166
165
|
waitFor: value.waitFor ?? undefined,
|
|
167
166
|
waitMs: value.waitMs ?? undefined
|
|
168
167
|
};
|
|
169
|
-
|
|
168
|
+
const result = await waitForChild(context, agent, observations, input, call, 'model', observations, history);
|
|
169
|
+
return {
|
|
170
|
+
content: result.content,
|
|
171
|
+
data: JSON.parse(result.content)
|
|
172
|
+
};
|
|
170
173
|
}
|
|
171
174
|
});
|
|
172
175
|
}
|
|
@@ -335,7 +338,7 @@ export async function waitForChild(context, agent, observations, input, call, mo
|
|
|
335
338
|
release();
|
|
336
339
|
};
|
|
337
340
|
},
|
|
338
|
-
waitMs:
|
|
341
|
+
waitMs: duration,
|
|
339
342
|
signal: call.signal,
|
|
340
343
|
...(mode === 'model' ? { interrupt: call.waitInterrupt } : {})
|
|
341
344
|
});
|
|
@@ -437,14 +440,28 @@ export async function waitForChild(context, agent, observations, input, call, mo
|
|
|
437
440
|
};
|
|
438
441
|
if (mode === 'native')
|
|
439
442
|
return { data, content: JSON.stringify(data) };
|
|
440
|
-
const modelAgents = agents.map((item) =>
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
...
|
|
444
|
-
|
|
445
|
-
...(
|
|
446
|
-
}
|
|
447
|
-
|
|
443
|
+
const modelAgents = agents.map((item) => {
|
|
444
|
+
const { executionId: _executionId, description: _description, role: _role, modelId: _modelId, modelName: _modelName, reasoningEffort: _effort, extensionId: _extensionId, turnId: _turnId, receipt: fact, ...snapshot } = { turnId: undefined, ...item };
|
|
445
|
+
return modelWaitAgent({
|
|
446
|
+
...snapshot,
|
|
447
|
+
status: modelStatus(item.status),
|
|
448
|
+
...(fact ? { receipt: { status: fact.status } } : {})
|
|
449
|
+
}, Math.floor(34000 / agents.length));
|
|
450
|
+
});
|
|
451
|
+
const modelData = {
|
|
452
|
+
waitFor,
|
|
453
|
+
waitOutcome: groupOutcome,
|
|
454
|
+
...(groupOutcome === 'interrupted' ? { reason: 'steer' } : {}),
|
|
455
|
+
...(!single
|
|
456
|
+
? {
|
|
457
|
+
mode: input.mode ?? 'any',
|
|
458
|
+
pendingAgentIds: values
|
|
459
|
+
.filter((value) => !value.ready)
|
|
460
|
+
.map((value) => value.item.session.id)
|
|
461
|
+
}
|
|
462
|
+
: {}),
|
|
463
|
+
agents: modelAgents
|
|
464
|
+
};
|
|
448
465
|
return { data, content: JSON.stringify(modelData) };
|
|
449
466
|
}
|
|
450
467
|
finally {
|