@simulacra-ai/orchestration 0.0.3 → 0.0.4
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/index.cjs +706 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +342 -0
- package/dist/index.d.ts +342 -8
- package/dist/index.js +669 -7
- package/dist/index.js.map +1 -1
- package/package.json +11 -5
- package/dist/background-agent-pool.d.ts +0 -59
- package/dist/background-agent-pool.d.ts.map +0 -1
- package/dist/background-agent-pool.js +0 -107
- package/dist/background-agent-pool.js.map +0 -1
- package/dist/background-agent.d.ts +0 -59
- package/dist/background-agent.d.ts.map +0 -1
- package/dist/background-agent.js +0 -143
- package/dist/background-agent.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/orchestrator.d.ts +0 -48
- package/dist/orchestrator.d.ts.map +0 -1
- package/dist/orchestrator.js +0 -134
- package/dist/orchestrator.js.map +0 -1
- package/dist/parallel-agent.d.ts +0 -17
- package/dist/parallel-agent.d.ts.map +0 -1
- package/dist/parallel-agent.js +0 -33
- package/dist/parallel-agent.js.map +0 -1
- package/dist/subagent.d.ts +0 -19
- package/dist/subagent.d.ts.map +0 -1
- package/dist/subagent.js +0 -20
- package/dist/subagent.js.map +0 -1
- package/dist/tools/background-task-pool.d.ts +0 -21
- package/dist/tools/background-task-pool.d.ts.map +0 -1
- package/dist/tools/background-task-pool.js +0 -133
- package/dist/tools/background-task-pool.js.map +0 -1
- package/dist/tools/index.d.ts +0 -9
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -15
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/parallel-agent-task.d.ts +0 -21
- package/dist/tools/parallel-agent-task.d.ts.map +0 -1
- package/dist/tools/parallel-agent-task.js +0 -75
- package/dist/tools/parallel-agent-task.js.map +0 -1
- package/dist/tools/subagent-task.d.ts +0 -19
- package/dist/tools/subagent-task.d.ts.map +0 -1
- package/dist/tools/subagent-task.js +0 -65
- package/dist/tools/subagent-task.js.map +0 -1
- package/dist/tools/utils.d.ts +0 -8
- package/dist/tools/utils.d.ts.map +0 -1
- package/dist/tools/utils.js +0 -25
- package/dist/tools/utils.js.map +0 -1
- package/dist/types.d.ts +0 -90
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,342 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ToolClass, Workflow, Message, WorkflowManager, Conversation, ToolSuccessResult } from '@simulacra-ai/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for spawning a subagent.
|
|
5
|
+
*/
|
|
6
|
+
interface SubagentOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The system prompt for the subagent's conversation.
|
|
9
|
+
*/
|
|
10
|
+
system?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The tools available to the subagent.
|
|
13
|
+
*/
|
|
14
|
+
toolkit?: ToolClass[];
|
|
15
|
+
/**
|
|
16
|
+
* Whether the subagent starts with a copy of the parent's conversation history.
|
|
17
|
+
*/
|
|
18
|
+
fork_session?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* A custom identifier for the subagent.
|
|
21
|
+
*/
|
|
22
|
+
id?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The result of a completed subagent execution.
|
|
26
|
+
*/
|
|
27
|
+
interface SubagentResult {
|
|
28
|
+
/**
|
|
29
|
+
* The unique identifier of the subagent.
|
|
30
|
+
*/
|
|
31
|
+
id: string;
|
|
32
|
+
/**
|
|
33
|
+
* The complete message history from the subagent's conversation.
|
|
34
|
+
*/
|
|
35
|
+
messages: readonly Readonly<Message>[];
|
|
36
|
+
/**
|
|
37
|
+
* The reason the subagent's execution ended.
|
|
38
|
+
*/
|
|
39
|
+
end_reason: "complete" | "cancel" | "error";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A handle for managing a background subagent task.
|
|
43
|
+
*/
|
|
44
|
+
interface BackgroundHandle {
|
|
45
|
+
/**
|
|
46
|
+
* The unique identifier of the background task.
|
|
47
|
+
*/
|
|
48
|
+
readonly id: string;
|
|
49
|
+
/**
|
|
50
|
+
* The workflow instance running the background task.
|
|
51
|
+
*/
|
|
52
|
+
readonly workflow: Workflow;
|
|
53
|
+
/**
|
|
54
|
+
* A promise that resolves when the background task completes.
|
|
55
|
+
*/
|
|
56
|
+
readonly promise: Promise<SubagentResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the background task has finished execution.
|
|
59
|
+
*/
|
|
60
|
+
readonly done: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Cancels the background task.
|
|
63
|
+
*/
|
|
64
|
+
cancel(): void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Status snapshot of a background worker.
|
|
68
|
+
*/
|
|
69
|
+
interface WorkerState {
|
|
70
|
+
/**
|
|
71
|
+
* The unique identifier of the worker.
|
|
72
|
+
*/
|
|
73
|
+
id: string;
|
|
74
|
+
/**
|
|
75
|
+
* The worker's current execution state.
|
|
76
|
+
*/
|
|
77
|
+
status: "idle" | "running" | "completed" | "cancelled";
|
|
78
|
+
/**
|
|
79
|
+
* Number of agentic turns (assistant messages) completed.
|
|
80
|
+
*/
|
|
81
|
+
rounds: number;
|
|
82
|
+
/**
|
|
83
|
+
* Total number of tool calls made across all rounds.
|
|
84
|
+
*/
|
|
85
|
+
tool_call_count: number;
|
|
86
|
+
/**
|
|
87
|
+
* The text content of the most recent assistant message, if any.
|
|
88
|
+
*/
|
|
89
|
+
latest_message?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Context key used to propagate the remaining orchestration depth to child agents.
|
|
94
|
+
*/
|
|
95
|
+
declare const ORCHESTRATION_DEPTH_KEY = "__orchestration_depth";
|
|
96
|
+
/**
|
|
97
|
+
* Base class for orchestration patterns.
|
|
98
|
+
*
|
|
99
|
+
* Accepts a `WorkflowManager` (for programmatic use) or a `Workflow`
|
|
100
|
+
* (for tool integration). Provides the shared child-spawning logic
|
|
101
|
+
* that all orchestration patterns build on.
|
|
102
|
+
*
|
|
103
|
+
* By default, `recursive_depth` is `0`, which strips orchestration tools
|
|
104
|
+
* from child agents to prevent nesting. Set to a positive number to allow
|
|
105
|
+
* that many levels of recursive orchestration, or `-1` for unlimited depth.
|
|
106
|
+
*/
|
|
107
|
+
declare abstract class Orchestrator {
|
|
108
|
+
#private;
|
|
109
|
+
/**
|
|
110
|
+
* @param source - A `WorkflowManager` or `Workflow` to spawn children from.
|
|
111
|
+
* @param options.recursive_depth - How many levels of recursive orchestration to allow. `0` (default) strips orchestration tools from children, `-1` allows unlimited nesting.
|
|
112
|
+
*/
|
|
113
|
+
constructor(source: WorkflowManager | Workflow, { recursive_depth }?: {
|
|
114
|
+
recursive_depth?: number | undefined;
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* The conversation associated with the orchestrator.
|
|
118
|
+
*/
|
|
119
|
+
protected get conversation(): Conversation;
|
|
120
|
+
/**
|
|
121
|
+
* The parent workflow, if available. Used to establish parent-child workflow relationships.
|
|
122
|
+
*/
|
|
123
|
+
protected get parent_workflow(): Workflow | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Spawn a child agent with its own conversation and workflow.
|
|
126
|
+
*
|
|
127
|
+
* Creates a child conversation, assigns tools (stripping orchestration
|
|
128
|
+
* tools when depth is exhausted), and starts the workflow. Returns a
|
|
129
|
+
* handle for awaiting, inspecting, or cancelling the child.
|
|
130
|
+
*
|
|
131
|
+
* @param prompt - The instruction to send to the child agent.
|
|
132
|
+
* @param options - Configuration for the child agent (system prompt, tools, session forking, custom ID).
|
|
133
|
+
*/
|
|
134
|
+
protected spawn(prompt: string, options?: SubagentOptions): BackgroundHandle;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Spawns a child agent and blocks until it completes.
|
|
139
|
+
*
|
|
140
|
+
* The child runs its own agentic loop with access to the parent's tools.
|
|
141
|
+
* Orchestration tools are excluded when `recursive_depth` is 0 (the default)
|
|
142
|
+
* and included when a positive depth is configured.
|
|
143
|
+
*/
|
|
144
|
+
declare class SubagentOrchestrator extends Orchestrator {
|
|
145
|
+
/**
|
|
146
|
+
* Run a prompt as an autonomous child agent and return when it completes.
|
|
147
|
+
*
|
|
148
|
+
* @param prompt - The instruction for the child agent.
|
|
149
|
+
* @param options - Configuration for the child agent (system prompt, tools, session forking, custom ID).
|
|
150
|
+
*/
|
|
151
|
+
execute(prompt: string, options?: SubagentOptions): Promise<SubagentResult>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A single background worker agent.
|
|
156
|
+
*
|
|
157
|
+
* Each instance represents one background task. Call `execute` once to
|
|
158
|
+
* start it, then use `status`, `done`, `collect`, and `cancel` to manage it.
|
|
159
|
+
*/
|
|
160
|
+
declare class BackgroundOrchestrator extends Orchestrator {
|
|
161
|
+
#private;
|
|
162
|
+
/**
|
|
163
|
+
* Start the background worker. Can only be called once.
|
|
164
|
+
*
|
|
165
|
+
* @param prompt - The instruction for the worker.
|
|
166
|
+
* @param options - Configuration for the worker (system prompt, tools, session forking, custom ID).
|
|
167
|
+
*/
|
|
168
|
+
execute(prompt: string, options?: SubagentOptions): void;
|
|
169
|
+
/**
|
|
170
|
+
* The unique identifier of this worker. Throws if not started.
|
|
171
|
+
*/
|
|
172
|
+
get id(): string;
|
|
173
|
+
/**
|
|
174
|
+
* Current state: `idle`, `running`, `completed`, or `cancelled`.
|
|
175
|
+
*/
|
|
176
|
+
get status(): "idle" | "running" | "completed" | "cancelled";
|
|
177
|
+
/**
|
|
178
|
+
* `true` when the worker has completed or been cancelled.
|
|
179
|
+
*/
|
|
180
|
+
get done(): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Number of agentic turns (assistant messages) so far.
|
|
183
|
+
*/
|
|
184
|
+
get rounds(): number;
|
|
185
|
+
/**
|
|
186
|
+
* Total number of tool calls made across all rounds.
|
|
187
|
+
*/
|
|
188
|
+
get tool_call_count(): number;
|
|
189
|
+
/**
|
|
190
|
+
* The text content of the most recent assistant message, if any.
|
|
191
|
+
*/
|
|
192
|
+
get latest_message(): string | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* Snapshot of the worker's current state.
|
|
195
|
+
*/
|
|
196
|
+
get_state(): WorkerState;
|
|
197
|
+
/**
|
|
198
|
+
* Await completion and return the full result.
|
|
199
|
+
*/
|
|
200
|
+
collect(): Promise<SubagentResult>;
|
|
201
|
+
/**
|
|
202
|
+
* Cancel the running worker. Throws if not running.
|
|
203
|
+
*/
|
|
204
|
+
cancel(): void;
|
|
205
|
+
/**
|
|
206
|
+
* Dispose the worker, cancelling it if still running.
|
|
207
|
+
*/
|
|
208
|
+
[Symbol.dispose](): void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Manages a pool of background worker agents.
|
|
213
|
+
*
|
|
214
|
+
* Provides a registry for starting, listing, inspecting, cancelling,
|
|
215
|
+
* and acknowledging (collecting + removing) completed workers.
|
|
216
|
+
*/
|
|
217
|
+
declare class BackgroundAgentPool {
|
|
218
|
+
#private;
|
|
219
|
+
/**
|
|
220
|
+
* @param source - A `WorkflowManager` or `Workflow` to spawn workers from.
|
|
221
|
+
* @param options.recursive_depth - How many levels of recursive orchestration to allow in workers. Defaults to `0`.
|
|
222
|
+
*/
|
|
223
|
+
constructor(source: WorkflowManager | Workflow, { recursive_depth }?: {
|
|
224
|
+
recursive_depth?: number | undefined;
|
|
225
|
+
});
|
|
226
|
+
/**
|
|
227
|
+
* Update the workflow/manager reference used to spawn new workers.
|
|
228
|
+
* This must be called when a persisted pool is reused by a new workflow,
|
|
229
|
+
* so that new workers are spawned from the current (live) workflow
|
|
230
|
+
* instead of a previously disposed one.
|
|
231
|
+
*/
|
|
232
|
+
update_source(source: WorkflowManager | Workflow): void;
|
|
233
|
+
/**
|
|
234
|
+
* Launch a new background worker and return its ID.
|
|
235
|
+
*
|
|
236
|
+
* @param prompt - The instruction for the worker.
|
|
237
|
+
* @param options - Configuration for the worker (system prompt, tools, session forking, custom ID).
|
|
238
|
+
*/
|
|
239
|
+
start(prompt: string, options?: SubagentOptions): string;
|
|
240
|
+
/**
|
|
241
|
+
* Return all worker IDs in the pool.
|
|
242
|
+
*/
|
|
243
|
+
list(): string[];
|
|
244
|
+
/**
|
|
245
|
+
* Get state snapshots for the given worker IDs, or all workers if omitted.
|
|
246
|
+
*
|
|
247
|
+
* @param ids - Worker IDs to query. Omit to query all.
|
|
248
|
+
*/
|
|
249
|
+
state(...ids: string[]): WorkerState[];
|
|
250
|
+
/**
|
|
251
|
+
* Cancel a running worker by ID.
|
|
252
|
+
*
|
|
253
|
+
* @param id - The worker ID to cancel.
|
|
254
|
+
*/
|
|
255
|
+
cancel(id: string): void;
|
|
256
|
+
/**
|
|
257
|
+
* Pop completed workers from the pool and return their states. Skips workers still running.
|
|
258
|
+
*
|
|
259
|
+
* @param ids - Worker IDs to acknowledge. Omit to acknowledge all completed.
|
|
260
|
+
*/
|
|
261
|
+
ack(...ids: string[]): WorkerState[];
|
|
262
|
+
/**
|
|
263
|
+
* Dispose all workers in the pool, cancelling any that are still running.
|
|
264
|
+
*/
|
|
265
|
+
[Symbol.dispose](): void;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Runs multiple prompts concurrently, each as an independent child agent.
|
|
270
|
+
* Returns when all complete.
|
|
271
|
+
*/
|
|
272
|
+
declare class ParallelOrchestrator extends Orchestrator {
|
|
273
|
+
/**
|
|
274
|
+
* Run all tasks concurrently and return when every child agent has completed.
|
|
275
|
+
*
|
|
276
|
+
* @param tasks - Array of task configs, each with a `prompt` and optional `SubagentOptions`.
|
|
277
|
+
*/
|
|
278
|
+
execute(tasks: Array<{
|
|
279
|
+
prompt: string;
|
|
280
|
+
} & SubagentOptions>): Promise<SubagentResult[]>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type BackgroundParams = {
|
|
284
|
+
action: "start" | "list" | "state" | "cancel" | "ack";
|
|
285
|
+
prompts?: string[];
|
|
286
|
+
system?: string;
|
|
287
|
+
fork_session?: boolean;
|
|
288
|
+
ids?: string[];
|
|
289
|
+
};
|
|
290
|
+
type BackgroundToolSuccess = ToolSuccessResult & {
|
|
291
|
+
ids?: string[];
|
|
292
|
+
workers?: WorkerState[];
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Tool that lets a model manage a pool of background worker agents. Supports
|
|
296
|
+
* starting tasks, listing workers, checking state, cancelling, and collecting
|
|
297
|
+
* results without blocking the main conversation.
|
|
298
|
+
*/
|
|
299
|
+
declare const BackgroundTaskPool: ToolClass<BackgroundParams, BackgroundToolSuccess>;
|
|
300
|
+
|
|
301
|
+
type ParallelParams = {
|
|
302
|
+
prompts: string[];
|
|
303
|
+
system?: string;
|
|
304
|
+
fork_session?: boolean;
|
|
305
|
+
};
|
|
306
|
+
type ParallelToolSuccess = ToolSuccessResult & {
|
|
307
|
+
responses: Array<{
|
|
308
|
+
id: string;
|
|
309
|
+
response: string;
|
|
310
|
+
end_reason: string;
|
|
311
|
+
}>;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Tool that lets a model run multiple subtasks concurrently, each handled by its
|
|
315
|
+
* own subagent with a separate conversation. All subagents start immediately and
|
|
316
|
+
* the tool returns once every subagent has completed.
|
|
317
|
+
*/
|
|
318
|
+
declare const ParallelAgentTask: ToolClass<ParallelParams, ParallelToolSuccess>;
|
|
319
|
+
|
|
320
|
+
type SubagentParams = {
|
|
321
|
+
prompt: string;
|
|
322
|
+
system?: string;
|
|
323
|
+
fork_session?: boolean;
|
|
324
|
+
};
|
|
325
|
+
type SubagentToolSuccess = ToolSuccessResult & {
|
|
326
|
+
id: string;
|
|
327
|
+
response: string;
|
|
328
|
+
end_reason: string;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Tool that lets a model spawn an autonomous subagent with its own conversation
|
|
332
|
+
* to handle a subtask independently. The subagent runs to completion and returns
|
|
333
|
+
* its final response.
|
|
334
|
+
*/
|
|
335
|
+
declare const SubagentTask: ToolClass<SubagentParams, SubagentToolSuccess>;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* All orchestration tools as a ready-to-use toolkit.
|
|
339
|
+
*/
|
|
340
|
+
declare const OrchestrationToolkit: ToolClass[];
|
|
341
|
+
|
|
342
|
+
export { BackgroundAgentPool, type BackgroundHandle, BackgroundOrchestrator, BackgroundTaskPool, ORCHESTRATION_DEPTH_KEY, OrchestrationToolkit, Orchestrator, ParallelAgentTask, ParallelOrchestrator, type SubagentOptions, SubagentOrchestrator, type SubagentResult, SubagentTask, type WorkerState };
|