@myagentroam/agent 0.11.39 → 0.11.41
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/catalog-file.d.ts +2 -0
- package/dist/cli/main.js +11 -4
- package/dist/cli/subagent/control.d.ts +56 -0
- package/dist/cli/subagent/control.js +219 -0
- package/dist/cli/subagent/history.d.ts +17 -0
- package/dist/cli/subagent/history.js +85 -0
- package/dist/cli/subagent/index.d.ts +10 -0
- package/dist/cli/subagent/index.js +94 -0
- package/dist/cli/subagent/native.d.ts +91 -0
- package/dist/cli/subagent/native.js +359 -0
- package/dist/cli/subagent/observations.d.ts +57 -0
- package/dist/cli/subagent/observations.js +351 -0
- package/dist/cli/subagent/query.d.ts +4 -0
- package/dist/cli/subagent/query.js +114 -0
- package/dist/cli/subagent/resources.d.ts +3 -0
- package/dist/cli/subagent/resources.js +112 -0
- package/dist/cli/subagent/snapshot.d.ts +77 -0
- package/dist/cli/subagent/snapshot.js +127 -0
- package/dist/cli/subagent/start.d.ts +24 -0
- package/dist/cli/subagent/start.js +201 -0
- package/dist/cli/subagent/wait-output.d.ts +19 -0
- package/dist/cli/subagent/wait-output.js +56 -0
- package/dist/cli/subagent/wait.d.ts +175 -0
- package/dist/cli/subagent/wait.js +453 -0
- package/dist/extensions/contracts.d.ts +2 -5
- package/dist/extensions/manager.d.ts +0 -2
- package/dist/extensions/manager.js +1 -2
- package/dist/extensions/models.d.ts +3 -0
- package/dist/extensions/operation.d.ts +8 -0
- package/dist/extensions/operation.js +3 -0
- package/dist/extensions/services.d.ts +9 -1
- package/dist/extensions/services.js +26 -3
- package/dist/extensions/session-context.d.ts +18 -0
- package/dist/extensions/session-context.js +4 -0
- package/dist/extensions/session-input.d.ts +2 -2
- package/dist/extensions/session-input.js +3 -4
- package/dist/extensions/session-messages.d.ts +1 -1
- package/dist/extensions/session-tools.js +20 -3
- package/dist/extensions/session.d.ts +1 -4
- package/dist/extensions/session.js +2 -16
- package/dist/extensions/tools.js +21 -3
- package/dist/extensions.d.ts +5 -2
- package/dist/extensions.js +2 -1
- package/dist/host/local-agent-host.d.ts +2 -2
- package/dist/host/local-exec-tool.d.ts +1 -1
- package/dist/host/local-exec-tool.js +28 -3
- package/dist/host/local-tool-registry.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/model/configuration.d.ts +3 -1
- package/dist/model/configuration.js +1 -0
- package/dist/model/openai-responses.js +5 -0
- package/dist/model/responses-request.js +9 -0
- package/dist/prompts/index.js +1 -3
- package/dist/prompts/permissions.d.ts +1 -1
- package/dist/prompts/permissions.js +1 -0
- package/dist/prompts/resources.d.ts +1 -5
- package/dist/prompts/resources.js +3 -12
- package/dist/prompts/subagent.d.ts +1 -1
- package/dist/prompts/subagent.js +1 -1
- package/dist/runtime/context/gc-candidates-web.d.ts +6 -0
- package/dist/runtime/context/gc-candidates-web.js +53 -1
- package/dist/runtime/context/gc-candidates.js +1 -9
- package/dist/runtime/context/gc.js +19 -11
- package/dist/runtime/context/projection.js +1 -0
- package/dist/runtime/events.d.ts +4 -3
- package/dist/runtime/execution-handle.d.ts +2 -0
- package/dist/runtime/wait.js +12 -2
- package/dist/sdk/agent.js +94 -5
- package/dist/sdk/execution-context-coordinator.d.ts +2 -3
- package/dist/sdk/execution-context-coordinator.js +3 -3
- package/dist/sdk/execution-input.d.ts +3 -4
- package/dist/sdk/execution-input.js +31 -25
- package/dist/sdk/execution-round-preparation.d.ts +1 -1
- package/dist/sdk/execution-round-preparation.js +4 -4
- package/dist/sdk/execution-tool-catalog.js +2 -10
- package/dist/sdk/execution-tool-scope.d.ts +1 -3
- package/dist/sdk/execution-tool-scope.js +10 -12
- package/dist/sdk/extension-models.js +3 -0
- package/dist/sdk/extension-session-launch.d.ts +3 -2
- package/dist/sdk/extension-session-launch.js +2 -3
- package/dist/sdk/extension-tools.js +0 -2
- package/dist/sdk/native-steer.d.ts +2 -2
- package/dist/sdk/native-steer.js +2 -2
- package/dist/sdk/session-composition.d.ts +2 -17
- package/dist/sdk/session-execution-factory.d.ts +2 -3
- package/dist/sdk/session-execution-factory.js +20 -114
- package/dist/sdk/session-execution.d.ts +13 -7
- package/dist/sdk/session-execution.js +11 -3
- package/dist/sdk/session-extension-messages.d.ts +1 -3
- package/dist/sdk/session-extension-messages.js +14 -9
- package/dist/sdk/session-extension-prompt.js +1 -3
- package/dist/sdk/session-maintenance.d.ts +1 -0
- package/dist/sdk/session-maintenance.js +16 -7
- package/dist/sdk/session-open.d.ts +2 -3
- package/dist/sdk/session-open.js +5 -24
- package/dist/sdk/session-runtime.d.ts +19 -8
- package/dist/sdk/session-runtime.js +36 -30
- package/dist/sdk/session.d.ts +3 -2
- package/dist/sdk/session.js +22 -89
- package/dist/sdk/types.d.ts +36 -0
- package/dist/session/catalog.d.ts +22 -1
- package/dist/session/catalog.js +102 -0
- package/dist/session/context-gc-checkpoint.js +30 -1
- package/dist/session/context-gc-contract.d.ts +7 -0
- package/dist/session/context-gc-replacements.d.ts +3 -0
- package/dist/session/context-gc-replacements.js +26 -0
- package/dist/session/store/contracts.d.ts +2 -2
- package/dist/session/store/jsonl/directory-index.d.ts +1 -1
- package/dist/session/store/jsonl/directory-index.js +18 -17
- package/dist/session/store/jsonl/history.js +1 -1
- package/dist/session/store/jsonl/index-transaction.js +2 -8
- package/dist/session/store/jsonl/jsonl-store.d.ts +1 -1
- package/dist/session/store/jsonl/jsonl-store.js +24 -9
- package/dist/session/store/jsonl/resources.js +5 -1
- package/dist/session/types.d.ts +1 -0
- package/dist/tools/agent/sleep.js +1 -1
- package/dist/tools/callers.js +1 -12
- package/dist/tools/code-mode/dispatch.js +5 -2
- package/dist/tools/code-mode/index.d.ts +1 -1
- package/dist/tools/code-mode/index.js +4 -2
- package/dist/tools/contracts.d.ts +20 -0
- package/dist/tools/execution-limits.d.ts +5 -20
- package/dist/tools/execution-limits.js +0 -2
- package/dist/tools/execution.js +16 -4
- package/dist/tools/local/exec.js +8 -2
- package/dist/tools/output-projection.d.ts +5 -2
- package/dist/tools/output-projection.js +133 -92
- package/dist/tools/permissions.d.ts +0 -1
- package/dist/tools/permissions.js +1 -9
- package/dist/tools/registry.js +1 -13
- package/dist/tools/runtime-context.d.ts +1 -21
- package/package.json +2 -2
- package/dist/extensions/agents.d.ts +0 -100
- package/dist/extensions/agents.js +0 -121
- package/dist/runtime/context/gc-candidates-subagent.d.ts +0 -6
- package/dist/runtime/context/gc-candidates-subagent.js +0 -100
- package/dist/sdk/extension-agent-controller.d.ts +0 -3
- package/dist/sdk/extension-agent-controller.js +0 -69
- package/dist/sdk/extension-agents.d.ts +0 -9
- package/dist/sdk/extension-agents.js +0 -58
- package/dist/sdk/subagent-backend.d.ts +0 -3
- package/dist/sdk/subagent-backend.js +0 -49
- package/dist/subagent/contracts.d.ts +0 -107
- package/dist/subagent/contracts.js +0 -1
- package/dist/subagent/limits.d.ts +0 -17
- package/dist/subagent/limits.js +0 -17
- package/dist/subagent/model-update.d.ts +0 -2
- package/dist/subagent/model-update.js +0 -81
- package/dist/subagent/session-controller.d.ts +0 -87
- package/dist/subagent/session-controller.js +0 -1343
- package/dist/subagent/task.d.ts +0 -134
- package/dist/subagent/task.js +0 -436
- package/dist/subagent/turn-contracts.d.ts +0 -64
- package/dist/subagent/turn-contracts.js +0 -1
- package/dist/subagent/wait-targets.d.ts +0 -10
- package/dist/subagent/wait-targets.js +0 -26
- package/dist/subagent/wait.d.ts +0 -26
- package/dist/subagent/wait.js +0 -73
- package/dist/tools/agent/agent-cancel.d.ts +0 -7
- package/dist/tools/agent/agent-cancel.js +0 -29
- package/dist/tools/agent/agent-message.d.ts +0 -7
- package/dist/tools/agent/agent-message.js +0 -57
- package/dist/tools/agent/agent-start.d.ts +0 -12
- package/dist/tools/agent/agent-start.js +0 -106
- package/dist/tools/agent/agent-wait.d.ts +0 -7
- package/dist/tools/agent/agent-wait.js +0 -91
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { contextGcTargetKey } from '../../session/context-gc-checkpoint.js';
|
|
2
|
-
import { contextGcSubagentNeedsRetainedPriorFinal, contextGcSubagentOutputReplacement, contextGcSubagentPriorFinalIsRetained, contextGcSubagentSnapshotIsPreciselyCovered, contextGcSubagentSnapshotIsSuperseded, contextGcSubagentSnapshotTurnId, normalizeContextGcSubagentSnapshot } from '../../session/context-gc-subagent.js';
|
|
3
|
-
import { CONTEXT_GC_POLICY } from './gc-economics.js';
|
|
4
|
-
import { successfulRolloutsAfter, targetFor } from './gc-candidates.js';
|
|
5
|
-
export function collectSubagentCandidates(input, groups, existingTargets, candidateSavings) {
|
|
6
|
-
const eligible = [];
|
|
7
|
-
let protectedTokens = 0;
|
|
8
|
-
let retryAfterRollouts = Infinity;
|
|
9
|
-
const invocations = [...groups.values()]
|
|
10
|
-
.flatMap((group) => {
|
|
11
|
-
if (!isContextGcSubagentToolName(group.toolName) ||
|
|
12
|
-
!group.call ||
|
|
13
|
-
!group.result ||
|
|
14
|
-
group.failed ||
|
|
15
|
-
!group.completed ||
|
|
16
|
-
group.call.message.role !== 'tool_call' ||
|
|
17
|
-
group.result.message.role !== 'tool')
|
|
18
|
-
return [];
|
|
19
|
-
const snapshot = normalizeContextGcSubagentSnapshot(group.result.message.content, group.completed.payload, group.toolName);
|
|
20
|
-
const turnId = snapshot && contextGcSubagentSnapshotTurnId(snapshot);
|
|
21
|
-
return snapshot && turnId ? [{ group, snapshot, turnId }] : [];
|
|
22
|
-
})
|
|
23
|
-
.sort((left, right) => left.group.completed.sequence - right.group.completed.sequence);
|
|
24
|
-
for (const [index, source] of invocations.entries()) {
|
|
25
|
-
if (source.group.evidenceOnly)
|
|
26
|
-
continue;
|
|
27
|
-
if (source.group.toolName !== 'agent_wait' &&
|
|
28
|
-
source.group.toolName !== 'agent_message' &&
|
|
29
|
-
source.group.toolName !== 'agent_cancel')
|
|
30
|
-
continue;
|
|
31
|
-
const sourceTarget = targetFor(source.group.result.record, source.group.result.message);
|
|
32
|
-
if (!sourceTarget || existingTargets.has(contextGcTargetKey(sourceTarget)))
|
|
33
|
-
continue;
|
|
34
|
-
const needsRetainedPriorFinal = contextGcSubagentNeedsRetainedPriorFinal(source.snapshot);
|
|
35
|
-
const retainedPriorFinal = needsRetainedPriorFinal
|
|
36
|
-
? invocations
|
|
37
|
-
.slice(0, index)
|
|
38
|
-
.findLast((candidate) => contextGcSubagentPriorFinalIsRetained(source.snapshot, candidate.snapshot))
|
|
39
|
-
: undefined;
|
|
40
|
-
if (needsRetainedPriorFinal && retainedPriorFinal === undefined)
|
|
41
|
-
continue;
|
|
42
|
-
const terminal = invocations
|
|
43
|
-
.slice(index + 1)
|
|
44
|
-
.find((candidate) => candidate.snapshot.agentId === source.snapshot.agentId &&
|
|
45
|
-
candidate.turnId === source.turnId &&
|
|
46
|
-
(contextGcSubagentSnapshotIsSuperseded(source.snapshot, candidate.snapshot, retainedPriorFinal?.snapshot) ||
|
|
47
|
-
contextGcSubagentSnapshotIsPreciselyCovered(source.snapshot, candidate.snapshot)));
|
|
48
|
-
if (!terminal)
|
|
49
|
-
continue;
|
|
50
|
-
const sourceContent = source.group.result.message.content;
|
|
51
|
-
if (typeof sourceContent !== 'string')
|
|
52
|
-
continue;
|
|
53
|
-
const evidenceSequence = terminal.group.result.record.sequence;
|
|
54
|
-
const observedRollouts = successfulRolloutsAfter(input.records, evidenceSequence, input.modelId, input.contextWindowTokens);
|
|
55
|
-
const replacement = {
|
|
56
|
-
kind: 'SUBAGENT_OUTPUT',
|
|
57
|
-
toolName: source.group.toolName,
|
|
58
|
-
callId: source.group.callId,
|
|
59
|
-
target: sourceTarget,
|
|
60
|
-
replacementContent: contextGcSubagentOutputReplacement({
|
|
61
|
-
sourceContent,
|
|
62
|
-
source: source.snapshot,
|
|
63
|
-
terminal: terminal.snapshot
|
|
64
|
-
}),
|
|
65
|
-
terminalToolName: terminal.group.toolName,
|
|
66
|
-
terminalCallId: terminal.group.callId,
|
|
67
|
-
evidenceSequence,
|
|
68
|
-
...(retainedPriorFinal === undefined
|
|
69
|
-
? {}
|
|
70
|
-
: {
|
|
71
|
-
retainedPriorFinal: {
|
|
72
|
-
toolName: retainedPriorFinal.group.toolName,
|
|
73
|
-
callId: retainedPriorFinal.group.callId,
|
|
74
|
-
evidenceSequence: retainedPriorFinal.group.result.record.sequence
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
};
|
|
78
|
-
const candidate = {
|
|
79
|
-
replacements: [replacement],
|
|
80
|
-
observedRollouts,
|
|
81
|
-
evidenceSequence
|
|
82
|
-
};
|
|
83
|
-
const reclaimedTokens = candidateSavings(candidate);
|
|
84
|
-
if (reclaimedTokens <= 0)
|
|
85
|
-
continue;
|
|
86
|
-
if (observedRollouts >= CONTEXT_GC_POLICY.stageAProtectionRollouts)
|
|
87
|
-
eligible.push(candidate);
|
|
88
|
-
else {
|
|
89
|
-
protectedTokens += reclaimedTokens;
|
|
90
|
-
retryAfterRollouts = Math.min(retryAfterRollouts, CONTEXT_GC_POLICY.stageAProtectionRollouts - observedRollouts);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return { eligible, protectedTokens, retryAfterRollouts };
|
|
94
|
-
}
|
|
95
|
-
function isContextGcSubagentToolName(value) {
|
|
96
|
-
return (value === 'agent_start' ||
|
|
97
|
-
value === 'agent_wait' ||
|
|
98
|
-
value === 'agent_message' ||
|
|
99
|
-
value === 'agent_cancel');
|
|
100
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { parseAgentWaitTargets } from '../subagent/wait-targets.js';
|
|
2
|
-
import { resolveAgentSpawn } from '../extensions/agents.js';
|
|
3
|
-
export function bindAgentController(controller, action) {
|
|
4
|
-
const wait = (input, waitInterrupt) => action('agent.wait', input, (target, call) => {
|
|
5
|
-
const selection = parseAgentWaitTargets(target);
|
|
6
|
-
return selection.agentIds !== undefined
|
|
7
|
-
? controller.outputMany(selection.agentIds, {
|
|
8
|
-
...target,
|
|
9
|
-
waitInterrupt,
|
|
10
|
-
mode: selection.mode ?? 'any',
|
|
11
|
-
signal: call.signal
|
|
12
|
-
})
|
|
13
|
-
: target.agentId === undefined
|
|
14
|
-
? controller.outputAny({ ...target, waitInterrupt, signal: call.signal })
|
|
15
|
-
: controller.output(target.agentId, { ...target, waitInterrupt, signal: call.signal });
|
|
16
|
-
});
|
|
17
|
-
return {
|
|
18
|
-
run: (input, options) => {
|
|
19
|
-
return action('agent.spawn', {
|
|
20
|
-
...(options?.waitFor === undefined ? {} : { waitFor: options.waitFor }),
|
|
21
|
-
prompt: input.prompt,
|
|
22
|
-
description: input.description,
|
|
23
|
-
role: input.role,
|
|
24
|
-
background: input.background ?? false,
|
|
25
|
-
...(input.modelId === undefined ? {} : { modelId: input.modelId }),
|
|
26
|
-
...(input.reasoningEffort === undefined ? {} : { reasoningEffort: input.reasoningEffort })
|
|
27
|
-
}, async (target, call) => {
|
|
28
|
-
const task = resolveAgentSpawn(target);
|
|
29
|
-
return controller.run({
|
|
30
|
-
prompt: task.prompt,
|
|
31
|
-
description: task.description ?? input.description,
|
|
32
|
-
role: task.role ?? input.role,
|
|
33
|
-
background: task.background ?? false,
|
|
34
|
-
...(input.parentSubagentId === undefined
|
|
35
|
-
? {}
|
|
36
|
-
: { parentSubagentId: input.parentSubagentId }),
|
|
37
|
-
...(task.modelId === undefined ? {} : { modelId: task.modelId }),
|
|
38
|
-
...(task.reasoningEffort === undefined
|
|
39
|
-
? {}
|
|
40
|
-
: { reasoningEffort: task.reasoningEffort })
|
|
41
|
-
}, {
|
|
42
|
-
...options,
|
|
43
|
-
...(task.turnSignal === undefined ? {} : { turnSignal: task.turnSignal }),
|
|
44
|
-
...(task.waitFor === undefined ? {} : { waitFor: task.waitFor }),
|
|
45
|
-
signal: call.signal
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
output: (id, options) => {
|
|
50
|
-
const { waitInterrupt, ...input } = options ?? {};
|
|
51
|
-
return wait({ ...input, agentId: id }, waitInterrupt);
|
|
52
|
-
},
|
|
53
|
-
outputAny: (options) => {
|
|
54
|
-
const { waitInterrupt, ...input } = options ?? {};
|
|
55
|
-
return wait(input, waitInterrupt);
|
|
56
|
-
},
|
|
57
|
-
outputMany: (ids, options) => {
|
|
58
|
-
const { waitInterrupt, ...input } = options ?? {};
|
|
59
|
-
return wait({ ...input, agentIds: ids }, waitInterrupt);
|
|
60
|
-
},
|
|
61
|
-
message: (id, message, options) => action('agent.message', { ...options, agentId: id, message }, (target, call) => controller.message(target.agentId, target.message, {
|
|
62
|
-
...(target.delivery === undefined ? {} : { delivery: target.delivery }),
|
|
63
|
-
signal: call.signal
|
|
64
|
-
})),
|
|
65
|
-
cancel: (id) => action('agent.cancel', { agentId: id }, (target) => controller.cancel(target.agentId)),
|
|
66
|
-
listSessionResources: () => controller.listSessionResources(),
|
|
67
|
-
dispose: () => controller.dispose()
|
|
68
|
-
};
|
|
69
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAgentsBackend } from '../extensions/agents.js';
|
|
2
|
-
import type { ExtensionOperationContext } from '../extensions/operation.js';
|
|
3
|
-
import type { SubagentParentOperation, SubagentSessionController } from '../subagent/session-controller.js';
|
|
4
|
-
/** Uses the Session's sole task controller, including its durable children and queue. */
|
|
5
|
-
export declare function createExtensionAgentsBackend(input: {
|
|
6
|
-
readonly controller: () => Promise<SubagentSessionController>;
|
|
7
|
-
readonly existingController: () => SubagentSessionController | undefined;
|
|
8
|
-
readonly parent: (controller: SubagentSessionController, call: ExtensionOperationContext) => SubagentParentOperation;
|
|
9
|
-
}): ExtensionAgentsBackend;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { AgentError } from '../error.js';
|
|
2
|
-
import { parseAgentWaitTargets } from '../subagent/wait-targets.js';
|
|
3
|
-
/** Uses the Session's sole task controller, including its durable children and queue. */
|
|
4
|
-
export function createExtensionAgentsBackend(input) {
|
|
5
|
-
const withController = async (call, run) => {
|
|
6
|
-
call.signal.throwIfAborted();
|
|
7
|
-
const controller = await input.controller();
|
|
8
|
-
call.signal.throwIfAborted();
|
|
9
|
-
return controller.withOperation(input.parent(controller, call), () => run(controller));
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
own: (owner) => async () => {
|
|
13
|
-
await input.existingController()?.cancelOwned(owner);
|
|
14
|
-
},
|
|
15
|
-
spawn: (task, call) => withController(call, (controller) => controller.run({
|
|
16
|
-
description: task.description ?? 'Extension agent',
|
|
17
|
-
prompt: task.prompt,
|
|
18
|
-
role: task.role ?? 'general-purpose',
|
|
19
|
-
background: task.background ?? true,
|
|
20
|
-
...(task.modelId === undefined ? {} : { modelId: task.modelId }),
|
|
21
|
-
...(task.reasoningEffort === undefined ? {} : { reasoningEffort: task.reasoningEffort })
|
|
22
|
-
}, {
|
|
23
|
-
signal: call.signal,
|
|
24
|
-
...(task.turnSignal === undefined ? {} : { turnSignal: task.turnSignal }),
|
|
25
|
-
...(task.waitFor === undefined ? {} : { waitFor: task.waitFor }),
|
|
26
|
-
onCreated: (created) => {
|
|
27
|
-
if (created.status === 'failed')
|
|
28
|
-
throw new AgentError(created.errorCode ?? 'MAR_AGENT_SUBAGENT_FAILED', created.errorMessage ?? 'Agent could not start.');
|
|
29
|
-
}
|
|
30
|
-
})),
|
|
31
|
-
list: (call) => withController(call, (controller) => controller.list(call.signal)),
|
|
32
|
-
inspect: (target, call) => withController(call, (controller) => controller.inspect(target.agentId)),
|
|
33
|
-
wait: (target, call) => withController(call, (controller) => {
|
|
34
|
-
const selection = parseAgentWaitTargets(target);
|
|
35
|
-
const options = {
|
|
36
|
-
waitMs: target.waitMs ?? 30_000,
|
|
37
|
-
...(target.untilSettled === undefined ? {} : { untilSettled: target.untilSettled }),
|
|
38
|
-
...(target.waitFor === undefined ? {} : { waitFor: target.waitFor }),
|
|
39
|
-
signal: call.signal
|
|
40
|
-
};
|
|
41
|
-
if (selection.agentIds !== undefined)
|
|
42
|
-
return controller.outputMany(selection.agentIds, {
|
|
43
|
-
...options,
|
|
44
|
-
mode: selection.mode ?? 'any'
|
|
45
|
-
});
|
|
46
|
-
if (target.untilSettled && target.agentId === undefined)
|
|
47
|
-
throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'An unbounded wait requires an agent id.');
|
|
48
|
-
return target.agentId === undefined
|
|
49
|
-
? controller.outputAny(options)
|
|
50
|
-
: controller.output(target.agentId, options);
|
|
51
|
-
}),
|
|
52
|
-
message: (target, call) => withController(call, (controller) => controller.message(target.agentId, target.message, {
|
|
53
|
-
...(target.delivery === undefined ? {} : { delivery: target.delivery }),
|
|
54
|
-
signal: call.signal
|
|
55
|
-
})),
|
|
56
|
-
cancel: (target, call) => withController(call, (controller) => controller.cancel(target.agentId))
|
|
57
|
-
};
|
|
58
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { SessionStore } from '../session/store/contracts.js';
|
|
2
|
-
import type { SubagentSessionControllerBackend } from '../subagent/session-controller.js';
|
|
3
|
-
export declare function createSubagentBackend(store: Pick<SessionStore, 'createSession' | 'delete' | 'listSubagentChildren' | 'getSession' | 'read'>, workspace: string): SubagentSessionControllerBackend;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { AgentError } from '../error.js';
|
|
2
|
-
export function createSubagentBackend(store, workspace) {
|
|
3
|
-
return {
|
|
4
|
-
createSession: async (input) => {
|
|
5
|
-
const session = await store.createSession({
|
|
6
|
-
workspace,
|
|
7
|
-
title: input.title,
|
|
8
|
-
source: input.source
|
|
9
|
-
});
|
|
10
|
-
return { id: session.id };
|
|
11
|
-
},
|
|
12
|
-
deleteSession: async (sessionId) => {
|
|
13
|
-
await store.delete(sessionId);
|
|
14
|
-
},
|
|
15
|
-
listChildren: async (parentSessionId) => {
|
|
16
|
-
const sessions = await store.listSubagentChildren(parentSessionId);
|
|
17
|
-
return sessions.map((session) => ({
|
|
18
|
-
id: session.id,
|
|
19
|
-
createdAt: session.createdAt,
|
|
20
|
-
lastActivityAt: session.lastActivityAt,
|
|
21
|
-
source: session.source
|
|
22
|
-
}));
|
|
23
|
-
},
|
|
24
|
-
loadChild: async (parentSessionId, childSessionId) => {
|
|
25
|
-
try {
|
|
26
|
-
const session = await store.getSession(childSessionId);
|
|
27
|
-
if (session.source.type !== 'subagent' ||
|
|
28
|
-
session.source.parentSessionId !== parentSessionId)
|
|
29
|
-
return undefined;
|
|
30
|
-
return {
|
|
31
|
-
id: session.id,
|
|
32
|
-
createdAt: session.createdAt,
|
|
33
|
-
lastActivityAt: session.lastActivityAt,
|
|
34
|
-
source: session.source,
|
|
35
|
-
records: await store.read(session.id)
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
if (error instanceof AgentError && error.code === 'MAR_AGENT_SESSION_NOT_FOUND') {
|
|
40
|
-
// A history read failure is not proof that the child was deleted.
|
|
41
|
-
const children = await store.listSubagentChildren(parentSessionId);
|
|
42
|
-
if (!children.some((child) => child.id === childSessionId))
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import type { AgentReasoningEffort } from '../model/configuration.js';
|
|
2
|
-
import type { ExecutionResult } from '../runtime/contracts.js';
|
|
3
|
-
export interface SubagentTaskInput {
|
|
4
|
-
description: string;
|
|
5
|
-
prompt: string;
|
|
6
|
-
role: 'general-purpose' | 'explore';
|
|
7
|
-
modelId?: string;
|
|
8
|
-
reasoningEffort?: AgentReasoningEffort;
|
|
9
|
-
background?: boolean;
|
|
10
|
-
parentSubagentId?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface SubagentLatestMessage {
|
|
13
|
-
itemId: string;
|
|
14
|
-
turnId: string;
|
|
15
|
-
phase: 'commentary' | 'final_answer';
|
|
16
|
-
text: string;
|
|
17
|
-
timestamp: string;
|
|
18
|
-
truncated: boolean;
|
|
19
|
-
}
|
|
20
|
-
export type SubagentLatestActivity = {
|
|
21
|
-
kind: 'message';
|
|
22
|
-
timestamp: string;
|
|
23
|
-
phase: 'commentary' | 'final_answer';
|
|
24
|
-
} | {
|
|
25
|
-
kind: 'tool';
|
|
26
|
-
timestamp: string;
|
|
27
|
-
toolName: string;
|
|
28
|
-
status: 'started' | 'completed' | 'failed';
|
|
29
|
-
};
|
|
30
|
-
export interface SubagentTaskSnapshot extends Record<string, unknown> {
|
|
31
|
-
permissionStop?: ExecutionResult['permissionStop'];
|
|
32
|
-
agentId: string;
|
|
33
|
-
description: string;
|
|
34
|
-
role?: SubagentTaskInput['role'];
|
|
35
|
-
extensionId?: string;
|
|
36
|
-
status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled' | 'interrupted';
|
|
37
|
-
modelId?: string;
|
|
38
|
-
modelName?: string;
|
|
39
|
-
reasoningEffort?: AgentReasoningEffort;
|
|
40
|
-
latestMessage?: SubagentLatestMessage;
|
|
41
|
-
latestActivity?: SubagentLatestActivity;
|
|
42
|
-
summary?: string;
|
|
43
|
-
changedFiles?: string[];
|
|
44
|
-
verification?: string[];
|
|
45
|
-
evidence?: Array<{
|
|
46
|
-
path: string;
|
|
47
|
-
startLine?: number;
|
|
48
|
-
endLine?: number;
|
|
49
|
-
}>;
|
|
50
|
-
errorCode?: string;
|
|
51
|
-
errorMessage?: string;
|
|
52
|
-
messageId?: string;
|
|
53
|
-
turnId?: string;
|
|
54
|
-
deliveryStatus?: 'accepted' | 'applied' | 'cancelled' | 'failed';
|
|
55
|
-
waitOutcome?: SubagentWaitOutcome;
|
|
56
|
-
reason?: 'steer';
|
|
57
|
-
}
|
|
58
|
-
export type SubagentWaitFor = 'completion' | 'message';
|
|
59
|
-
export type SubagentWaitOutcome = Exclude<import('../runtime/wait.js').ToolWaitOutcome, 'yield'>;
|
|
60
|
-
export interface SubagentMessageOptions {
|
|
61
|
-
delivery?: 'append' | 'replace';
|
|
62
|
-
signal?: AbortSignal;
|
|
63
|
-
}
|
|
64
|
-
export interface SubagentRunOptions {
|
|
65
|
-
turnSignal?: AbortSignal;
|
|
66
|
-
waitFor?: 'start' | 'completion';
|
|
67
|
-
signal?: AbortSignal;
|
|
68
|
-
onCreated?: (task: SubagentTaskSnapshot) => Promise<void> | void;
|
|
69
|
-
}
|
|
70
|
-
export interface SubagentOutputOptions {
|
|
71
|
-
waitInterrupt?: import('../runtime/wait.js').ToolWaitInterrupt | undefined;
|
|
72
|
-
untilSettled?: true;
|
|
73
|
-
waitMs?: number;
|
|
74
|
-
waitFor?: SubagentWaitFor;
|
|
75
|
-
signal?: AbortSignal;
|
|
76
|
-
}
|
|
77
|
-
export type SubagentWaitMode = 'any' | 'all';
|
|
78
|
-
export interface SubagentManyOutputOptions extends Omit<SubagentOutputOptions, 'untilSettled'> {
|
|
79
|
-
mode?: SubagentWaitMode;
|
|
80
|
-
}
|
|
81
|
-
export interface SubagentManyOutput {
|
|
82
|
-
mode: SubagentWaitMode;
|
|
83
|
-
waitFor: SubagentWaitFor;
|
|
84
|
-
waitOutcome: SubagentWaitOutcome;
|
|
85
|
-
reason?: 'steer';
|
|
86
|
-
agents: SubagentTaskSnapshot[];
|
|
87
|
-
pendingAgentIds: string[];
|
|
88
|
-
}
|
|
89
|
-
export interface SubagentHandledResult {
|
|
90
|
-
readonly outcome: 'handled';
|
|
91
|
-
readonly value?: unknown;
|
|
92
|
-
}
|
|
93
|
-
export type SubagentRunResult = SubagentTaskSnapshot | SubagentHandledResult;
|
|
94
|
-
export interface SubagentController {
|
|
95
|
-
run(input: SubagentTaskInput, options?: SubagentRunOptions): Promise<SubagentRunResult>;
|
|
96
|
-
output(agentId: string, options?: SubagentOutputOptions): Promise<SubagentTaskSnapshot>;
|
|
97
|
-
outputAny(options?: SubagentOutputOptions): Promise<SubagentTaskSnapshot>;
|
|
98
|
-
outputMany(agentIds: readonly string[], options?: SubagentManyOutputOptions): Promise<SubagentManyOutput>;
|
|
99
|
-
message(agentId: string, message: string, options?: SubagentMessageOptions): Promise<SubagentTaskSnapshot>;
|
|
100
|
-
cancel(agentId: string): Promise<SubagentTaskSnapshot>;
|
|
101
|
-
listSessionResources(): readonly {
|
|
102
|
-
agentId: string;
|
|
103
|
-
status: SubagentTaskSnapshot['status'];
|
|
104
|
-
description: string;
|
|
105
|
-
}[];
|
|
106
|
-
dispose(): Promise<void>;
|
|
107
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const SUBAGENT_LIMITS: Readonly<{
|
|
2
|
-
agentWaitMinWaitMs: 0;
|
|
3
|
-
agentWaitWaitFloorMs: 10000;
|
|
4
|
-
agentWaitDefaultWaitMs: 30000;
|
|
5
|
-
agentWaitMaxWaitMs: 300000;
|
|
6
|
-
agentWaitMaxAgents: 8;
|
|
7
|
-
subagentDescriptionMaxCharacters: 80;
|
|
8
|
-
subagentPromptMaxBytes: 131072;
|
|
9
|
-
subagentMessageMaxBytes: 131072;
|
|
10
|
-
subagentReasoningEffortMaxCharacters: 64;
|
|
11
|
-
subagentSummaryMaxBytes: 16384;
|
|
12
|
-
subagentUpdateMaxBytes: 32768;
|
|
13
|
-
subagentRunningLatestMessageMaxCharacters: 2000;
|
|
14
|
-
subagentEvidenceMaxItems: 64;
|
|
15
|
-
subagentVerificationMaxItems: 16;
|
|
16
|
-
subagentChangedFilesMaxItems: 200;
|
|
17
|
-
}>;
|
package/dist/subagent/limits.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const SUBAGENT_LIMITS = Object.freeze({
|
|
2
|
-
agentWaitMinWaitMs: 0,
|
|
3
|
-
agentWaitWaitFloorMs: 10_000,
|
|
4
|
-
agentWaitDefaultWaitMs: 30_000,
|
|
5
|
-
agentWaitMaxWaitMs: 300_000,
|
|
6
|
-
agentWaitMaxAgents: 8,
|
|
7
|
-
subagentDescriptionMaxCharacters: 80,
|
|
8
|
-
subagentPromptMaxBytes: 131_072,
|
|
9
|
-
subagentMessageMaxBytes: 131_072,
|
|
10
|
-
subagentReasoningEffortMaxCharacters: 64,
|
|
11
|
-
subagentSummaryMaxBytes: 16_384,
|
|
12
|
-
subagentUpdateMaxBytes: 32_768,
|
|
13
|
-
subagentRunningLatestMessageMaxCharacters: 2_000,
|
|
14
|
-
subagentEvidenceMaxItems: 64,
|
|
15
|
-
subagentVerificationMaxItems: 16,
|
|
16
|
-
subagentChangedFilesMaxItems: 200
|
|
17
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { escapeMarkupText, markupAttributes } from '../prompts/markup.js';
|
|
2
|
-
import { SUBAGENT_LIMITS } from './limits.js';
|
|
3
|
-
export function renderSubagentUpdate(snapshot, truncated = false) {
|
|
4
|
-
const attributes = (values) => markupAttributes(Object.fromEntries(Object.entries(values).map(([key, value]) => {
|
|
5
|
-
if (value === undefined)
|
|
6
|
-
return [key, undefined];
|
|
7
|
-
let bounded = '';
|
|
8
|
-
let count = 0;
|
|
9
|
-
for (const point of String(value)) {
|
|
10
|
-
if (count++ === 256) {
|
|
11
|
-
truncated = true;
|
|
12
|
-
break;
|
|
13
|
-
}
|
|
14
|
-
bounded += point;
|
|
15
|
-
}
|
|
16
|
-
return [key, bounded];
|
|
17
|
-
})));
|
|
18
|
-
const root = '<mar_subagent_update' +
|
|
19
|
-
attributes({
|
|
20
|
-
agentId: snapshot.agentId,
|
|
21
|
-
status: snapshot.status,
|
|
22
|
-
modelId: snapshot.modelId,
|
|
23
|
-
modelName: snapshot.modelName,
|
|
24
|
-
reasoningEffort: snapshot.reasoningEffort,
|
|
25
|
-
messageId: snapshot.messageId,
|
|
26
|
-
turnId: snapshot.turnId,
|
|
27
|
-
deliveryStatus: snapshot.deliveryStatus
|
|
28
|
-
});
|
|
29
|
-
const close = '</mar_subagent_update>';
|
|
30
|
-
let remaining = SUBAGENT_LIMITS.subagentUpdateMaxBytes -
|
|
31
|
-
Buffer.byteLength(root + ' truncated="false">\n' + close);
|
|
32
|
-
const lines = [];
|
|
33
|
-
const field = (name, value, metadata = {}, limit = remaining) => {
|
|
34
|
-
let attrs = attributes(metadata);
|
|
35
|
-
const overhead = Buffer.byteLength(' <' + name + attrs + '></' + name + '>\n');
|
|
36
|
-
if (overhead > remaining) {
|
|
37
|
-
truncated = true;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
let budget = Math.min(limit, remaining - overhead);
|
|
41
|
-
let text = '';
|
|
42
|
-
let clipped = false;
|
|
43
|
-
for (const point of value) {
|
|
44
|
-
const encoded = escapeMarkupText(point);
|
|
45
|
-
const bytes = Buffer.byteLength(encoded);
|
|
46
|
-
if (bytes > budget) {
|
|
47
|
-
clipped = true;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
text += encoded;
|
|
51
|
-
budget -= bytes;
|
|
52
|
-
}
|
|
53
|
-
if (clipped) {
|
|
54
|
-
truncated = true;
|
|
55
|
-
if ('truncated' in metadata)
|
|
56
|
-
attrs = attributes({ ...metadata, truncated: true });
|
|
57
|
-
}
|
|
58
|
-
const opening = ' <' + name + attrs;
|
|
59
|
-
const line = text === '' ? opening + ' />\n' : opening + '>' + text + '</' + name + '>\n';
|
|
60
|
-
remaining -= Buffer.byteLength(line);
|
|
61
|
-
lines.push(line);
|
|
62
|
-
};
|
|
63
|
-
// Preserve failure/permission facts before spending the remaining budget on result text.
|
|
64
|
-
if (snapshot.errorCode !== undefined || snapshot.errorMessage !== undefined)
|
|
65
|
-
field('error', snapshot.errorMessage ?? '', { code: snapshot.errorCode }, 1024);
|
|
66
|
-
if (snapshot.permissionStop)
|
|
67
|
-
field('permission_stop', snapshot.permissionStop.reason, { action: snapshot.permissionStop.action, ...snapshot.permissionStop.source }, 1024);
|
|
68
|
-
field('description', snapshot.description, {}, 1024);
|
|
69
|
-
if (snapshot.latestMessage) {
|
|
70
|
-
const { text, ...metadata } = snapshot.latestMessage;
|
|
71
|
-
truncated ||= metadata.truncated;
|
|
72
|
-
field('message', text, metadata, SUBAGENT_LIMITS.subagentSummaryMaxBytes);
|
|
73
|
-
}
|
|
74
|
-
if (snapshot.summary !== undefined)
|
|
75
|
-
field('summary', snapshot.summary);
|
|
76
|
-
for (const path of snapshot.changedFiles ?? [])
|
|
77
|
-
field('changed_file', path);
|
|
78
|
-
if (snapshot.latestActivity)
|
|
79
|
-
field('activity', '', snapshot.latestActivity);
|
|
80
|
-
return root + ' truncated="' + String(truncated) + '">\n' + lines.join('') + close;
|
|
81
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { type ToolWaitInterrupt } from '../runtime/wait.js';
|
|
2
|
-
import type { SessionSource } from '../session/types.js';
|
|
3
|
-
import type { SubagentManyOutput, SubagentManyOutputOptions } from './contracts.js';
|
|
4
|
-
import type { SubagentController, SubagentMessageOptions, SubagentOutputOptions, SubagentRunOptions, SubagentTaskInput, SubagentTaskSnapshot } from './contracts.js';
|
|
5
|
-
import type { SubagentParentExecution, SubagentParentOperation } from './turn-contracts.js';
|
|
6
|
-
export type { SubagentModelOption, SubagentTurnHandle, SubagentOrigin, SubagentMessageDelivery, SubagentMailboxMessage, SubagentParentExecution, SubagentParentOperation } from './turn-contracts.js';
|
|
7
|
-
interface SubagentHistoryRecord {
|
|
8
|
-
readonly type: string;
|
|
9
|
-
readonly payload: unknown;
|
|
10
|
-
readonly turnId?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface PersistedSubagentSession {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly createdAt: string;
|
|
15
|
-
readonly lastActivityAt: string;
|
|
16
|
-
readonly source: Extract<SessionSource, {
|
|
17
|
-
type: 'subagent';
|
|
18
|
-
}>;
|
|
19
|
-
readonly records: readonly SubagentHistoryRecord[];
|
|
20
|
-
}
|
|
21
|
-
export interface SubagentSessionControllerBackend {
|
|
22
|
-
createSession(input: {
|
|
23
|
-
readonly title: string;
|
|
24
|
-
readonly source: Extract<SessionSource, {
|
|
25
|
-
type: 'subagent';
|
|
26
|
-
}>;
|
|
27
|
-
}): Promise<{
|
|
28
|
-
readonly id: string;
|
|
29
|
-
}>;
|
|
30
|
-
deleteSession(sessionId: string): Promise<void>;
|
|
31
|
-
/** Returns children in durable creation order. */
|
|
32
|
-
listChildren(parentSessionId: string): Promise<readonly Omit<PersistedSubagentSession, 'records'>[]>;
|
|
33
|
-
loadChild(parentSessionId: string, sessionId: string): Promise<PersistedSubagentSession | undefined>;
|
|
34
|
-
}
|
|
35
|
-
export declare class SubagentSessionController implements SubagentController {
|
|
36
|
-
#private;
|
|
37
|
-
private readonly parentSessionId;
|
|
38
|
-
private readonly rootSessionId;
|
|
39
|
-
private readonly backend;
|
|
40
|
-
readonly limits: {
|
|
41
|
-
maxTasks: number;
|
|
42
|
-
maxConcurrent: number;
|
|
43
|
-
};
|
|
44
|
-
readonly modelMessages: ToolWaitInterrupt;
|
|
45
|
-
private constructor();
|
|
46
|
-
static open(input: {
|
|
47
|
-
readonly parentSessionId: string;
|
|
48
|
-
readonly rootSessionId: string;
|
|
49
|
-
readonly backend: SubagentSessionControllerBackend;
|
|
50
|
-
readonly limits?: {
|
|
51
|
-
readonly maxTasks: number;
|
|
52
|
-
readonly maxConcurrent: number;
|
|
53
|
-
};
|
|
54
|
-
}): Promise<SubagentSessionController>;
|
|
55
|
-
beginParentExecution(execution: SubagentParentExecution): Promise<void>;
|
|
56
|
-
/** A retained cell must not borrow a later model Execution's identity or task budget. */
|
|
57
|
-
captureExecution(executionId?: string): SubagentController;
|
|
58
|
-
/** SDK physical tool ingress shares the same captured parent as its model controls. */
|
|
59
|
-
captureParentFrame(executionId?: string): <Value>(run: () => Value) => Value;
|
|
60
|
-
withOperation<T>(operation: SubagentParentOperation, run: () => T): T;
|
|
61
|
-
inspect(agentId: string): Promise<SubagentTaskSnapshot>;
|
|
62
|
-
inspectAll(): readonly SubagentTaskSnapshot[];
|
|
63
|
-
list(signal?: AbortSignal): Promise<readonly SubagentTaskSnapshot[]>;
|
|
64
|
-
/** Full listing is explicit; ordinary opens and executions never require it. */
|
|
65
|
-
prepareAll(signal?: AbortSignal): Promise<void>;
|
|
66
|
-
prepareSessionResources(signal?: AbortSignal): Promise<void>;
|
|
67
|
-
collectModelUpdates(): readonly {
|
|
68
|
-
snapshot: SubagentTaskSnapshot;
|
|
69
|
-
truncated: boolean;
|
|
70
|
-
acknowledge(): void;
|
|
71
|
-
}[];
|
|
72
|
-
cancelOwned(ownerInstanceId: string): Promise<void>;
|
|
73
|
-
endParentExecution(executionId: string): void;
|
|
74
|
-
parentExecution(executionId: string): SubagentParentExecution | undefined;
|
|
75
|
-
run(input: SubagentTaskInput, options?: SubagentRunOptions): Promise<SubagentTaskSnapshot>;
|
|
76
|
-
output(agentId: string, options?: SubagentOutputOptions): Promise<SubagentTaskSnapshot>;
|
|
77
|
-
outputAny(options?: SubagentOutputOptions): Promise<SubagentTaskSnapshot>;
|
|
78
|
-
outputMany(agentIds: readonly string[], options?: SubagentManyOutputOptions): Promise<SubagentManyOutput>;
|
|
79
|
-
message(agentId: string, message: string, options?: SubagentMessageOptions): Promise<SubagentTaskSnapshot>;
|
|
80
|
-
cancel(agentId: string): Promise<SubagentTaskSnapshot>;
|
|
81
|
-
listSessionResources(): {
|
|
82
|
-
agentId: string;
|
|
83
|
-
status: "completed" | "failed" | "cancelled" | "interrupted" | "queued" | "running";
|
|
84
|
-
description: string;
|
|
85
|
-
}[];
|
|
86
|
-
dispose(): Promise<void>;
|
|
87
|
-
}
|