@simulacra-ai/orchestration 0.0.3 → 0.0.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.
Files changed (52) hide show
  1. package/dist/index.cjs +706 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +342 -0
  4. package/dist/index.d.ts +342 -8
  5. package/dist/index.js +669 -7
  6. package/dist/index.js.map +1 -1
  7. package/package.json +11 -5
  8. package/dist/background-agent-pool.d.ts +0 -59
  9. package/dist/background-agent-pool.d.ts.map +0 -1
  10. package/dist/background-agent-pool.js +0 -107
  11. package/dist/background-agent-pool.js.map +0 -1
  12. package/dist/background-agent.d.ts +0 -59
  13. package/dist/background-agent.d.ts.map +0 -1
  14. package/dist/background-agent.js +0 -143
  15. package/dist/background-agent.js.map +0 -1
  16. package/dist/index.d.ts.map +0 -1
  17. package/dist/orchestrator.d.ts +0 -48
  18. package/dist/orchestrator.d.ts.map +0 -1
  19. package/dist/orchestrator.js +0 -134
  20. package/dist/orchestrator.js.map +0 -1
  21. package/dist/parallel-agent.d.ts +0 -17
  22. package/dist/parallel-agent.d.ts.map +0 -1
  23. package/dist/parallel-agent.js +0 -33
  24. package/dist/parallel-agent.js.map +0 -1
  25. package/dist/subagent.d.ts +0 -19
  26. package/dist/subagent.d.ts.map +0 -1
  27. package/dist/subagent.js +0 -20
  28. package/dist/subagent.js.map +0 -1
  29. package/dist/tools/background-task-pool.d.ts +0 -21
  30. package/dist/tools/background-task-pool.d.ts.map +0 -1
  31. package/dist/tools/background-task-pool.js +0 -133
  32. package/dist/tools/background-task-pool.js.map +0 -1
  33. package/dist/tools/index.d.ts +0 -9
  34. package/dist/tools/index.d.ts.map +0 -1
  35. package/dist/tools/index.js +0 -15
  36. package/dist/tools/index.js.map +0 -1
  37. package/dist/tools/parallel-agent-task.d.ts +0 -21
  38. package/dist/tools/parallel-agent-task.d.ts.map +0 -1
  39. package/dist/tools/parallel-agent-task.js +0 -75
  40. package/dist/tools/parallel-agent-task.js.map +0 -1
  41. package/dist/tools/subagent-task.d.ts +0 -19
  42. package/dist/tools/subagent-task.d.ts.map +0 -1
  43. package/dist/tools/subagent-task.js +0 -65
  44. package/dist/tools/subagent-task.js.map +0 -1
  45. package/dist/tools/utils.d.ts +0 -8
  46. package/dist/tools/utils.d.ts.map +0 -1
  47. package/dist/tools/utils.js +0 -25
  48. package/dist/tools/utils.js.map +0 -1
  49. package/dist/types.d.ts +0 -90
  50. package/dist/types.d.ts.map +0 -1
  51. package/dist/types.js +0 -2
  52. package/dist/types.js.map +0 -1
@@ -1,134 +0,0 @@
1
- import { Workflow, WorkflowManager } from "@simulacra-ai/core";
2
- const ORCHESTRATION_TOOL_NAMES = new Set(["subagent", "background", "parallel"]);
3
- /**
4
- * Context key used to propagate the remaining orchestration depth to child agents.
5
- */
6
- export const ORCHESTRATION_DEPTH_KEY = "__orchestration_depth";
7
- /**
8
- * Remove orchestration tools from a toolkit to prevent child agents from nesting.
9
- *
10
- * @param toolkit - The toolkit to filter.
11
- */
12
- function strip_orchestration_tools(toolkit) {
13
- return toolkit.filter((t) => !ORCHESTRATION_TOOL_NAMES.has(t.get_definition().name));
14
- }
15
- /**
16
- * Base class for orchestration patterns.
17
- *
18
- * Accepts a `WorkflowManager` (for programmatic use) or a `Workflow`
19
- * (for tool integration). Provides the shared child-spawning logic
20
- * that all orchestration patterns build on.
21
- *
22
- * By default, `recursive_depth` is `0`, which strips orchestration tools
23
- * from child agents to prevent nesting. Set to a positive number to allow
24
- * that many levels of recursive orchestration, or `-1` for unlimited depth.
25
- */
26
- export class Orchestrator {
27
- #manager;
28
- #workflow;
29
- #recursive_depth;
30
- /**
31
- * @param source - A `WorkflowManager` or `Workflow` to spawn children from.
32
- * @param options.recursive_depth - How many levels of recursive orchestration to allow. `0` (default) strips orchestration tools from children, `-1` allows unlimited nesting.
33
- */
34
- constructor(source, { recursive_depth = 0 } = {}) {
35
- if (!Number.isInteger(recursive_depth) || recursive_depth < -1) {
36
- throw new Error("invalid value for recursive_depth");
37
- }
38
- if (source instanceof WorkflowManager) {
39
- this.#manager = source;
40
- }
41
- else {
42
- this.#workflow = source;
43
- }
44
- this.#recursive_depth = recursive_depth;
45
- }
46
- /**
47
- * The conversation associated with the orchestrator.
48
- */
49
- get conversation() {
50
- if (this.#manager) {
51
- return this.#manager.conversation;
52
- }
53
- if (this.#workflow) {
54
- return this.#workflow.conversation;
55
- }
56
- throw new Error("no source");
57
- }
58
- /**
59
- * The parent workflow, if available. Used to establish parent-child workflow relationships.
60
- */
61
- get parent_workflow() {
62
- if (this.#manager) {
63
- return this.#manager.current_workflow;
64
- }
65
- return this.#workflow;
66
- }
67
- /**
68
- * Spawn a child agent with its own conversation and workflow.
69
- *
70
- * Creates a child conversation, assigns tools (stripping orchestration
71
- * tools when depth is exhausted), and starts the workflow. Returns a
72
- * handle for awaiting, inspecting, or cancelling the child.
73
- *
74
- * @param prompt - The instruction to send to the child agent.
75
- * @param options - Configuration for the child agent (system prompt, tools, session forking, custom ID).
76
- */
77
- spawn(prompt, options) {
78
- const conversation = this.conversation;
79
- const child = conversation.spawn_child(options?.fork_session, options?.id, options?.system ?? conversation.system);
80
- const toolkit = options?.toolkit ?? [...conversation.toolkit];
81
- child.toolkit = this.#recursive_depth === 0 ? strip_orchestration_tools(toolkit) : toolkit;
82
- const next_depth = this.#recursive_depth === -1 ? -1 : Math.max(0, this.#recursive_depth - 1);
83
- const child_context = { [ORCHESTRATION_DEPTH_KEY]: next_depth };
84
- const parent = this.parent_workflow;
85
- const child_workflow = parent && parent.state !== "disposed"
86
- ? parent.spawn_child(child, options?.id, child_context)
87
- : new Workflow(child, { context_data: child_context });
88
- let settled = false;
89
- const promise = new Promise((resolve) => {
90
- child_workflow.once("workflow_end", (event) => {
91
- settled = true;
92
- resolve({
93
- id: child_workflow.id,
94
- messages: child_workflow.messages,
95
- end_reason: event.reason,
96
- });
97
- if (child.state !== "disposed") {
98
- child[Symbol.dispose]();
99
- }
100
- });
101
- try {
102
- child_workflow.start();
103
- child.prompt(prompt);
104
- }
105
- catch {
106
- if (!settled) {
107
- settled = true;
108
- resolve({
109
- id: child_workflow.id,
110
- messages: child_workflow.messages,
111
- end_reason: "cancel",
112
- });
113
- if (child.state !== "disposed") {
114
- child[Symbol.dispose]();
115
- }
116
- }
117
- }
118
- });
119
- return {
120
- get id() {
121
- return child_workflow.id;
122
- },
123
- get workflow() {
124
- return child_workflow;
125
- },
126
- promise,
127
- get done() {
128
- return settled;
129
- },
130
- cancel: () => child_workflow.cancel(),
131
- };
132
- }
133
- }
134
- //# sourceMappingURL=orchestrator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAI/D,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;AAEjF;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAE/D;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,OAAoB;IACrD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACvF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,YAAY;IACvB,QAAQ,CAAmB;IAC3B,SAAS,CAAY;IACrB,gBAAgB,CAAS;IAElC;;;OAGG;IACH,YAAY,MAAkC,EAAE,EAAE,eAAe,GAAG,CAAC,EAAE,GAAG,EAAE;QAC1E,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,KAAK,CAAC,mC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IAAI,CAAC;oBACf,OAAO,CAAC;wBACN,EAAE,EAAE,cAAc,CAAC,EAAE;wBACrB,QAAQ,EAAE,cAAc,CAAC,QAAQ;wBACjC,UAAU,EAAE,QAAQ;qBACrB,CAAC,CAAC;oBACH,IAAI,KAAK,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;wBAC/B,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC1B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,IAAI,EAAE;gBACJ,OAAO,cAAc,CAAC,EAAE,CAAC;YAC3B,CAAC;YACD,IAAI,QAAQ;gBACV,OAAO,cAAc,CAAC;YACxB,CAAC;YACD,OAAO;YACP,IAAI,IAAI;gBACN,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,MAAM,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE;SACtC,CAAC;IACJ,CAAC;CACF"}
@@ -1,17 +0,0 @@
1
- import { Orchestrator } from "./orchestrator.ts";
2
- import type { SubagentOptions, SubagentResult } from "./types.ts";
3
- /**
4
- * Runs multiple prompts concurrently, each as an independent child agent.
5
- * Returns when all complete.
6
- */
7
- export declare class ParallelOrchestrator extends Orchestrator {
8
- /**
9
- * Run all tasks concurrently and return when every child agent has completed.
10
- *
11
- * @param tasks - Array of task configs, each with a `prompt` and optional `SubagentOptions`.
12
- */
13
- execute(tasks: Array<{
14
- prompt: string;
15
- } & SubagentOptions>): Promise<SubagentResult[]>;
16
- }
17
- //# sourceMappingURL=parallel-agent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-agent.d.ts","sourceRoot":"","sources":["../src/parallel-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAoB,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpF;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,YAAY;IACpD;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe,CAAC,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;CAkB7F"}
@@ -1,33 +0,0 @@
1
- import { Orchestrator } from "./orchestrator.js";
2
- /**
3
- * Runs multiple prompts concurrently, each as an independent child agent.
4
- * Returns when all complete.
5
- */
6
- export class ParallelOrchestrator extends Orchestrator {
7
- /**
8
- * Run all tasks concurrently and return when every child agent has completed.
9
- *
10
- * @param tasks - Array of task configs, each with a `prompt` and optional `SubagentOptions`.
11
- */
12
- async execute(tasks) {
13
- const handles = [];
14
- try {
15
- for (const { prompt, ...options } of tasks) {
16
- handles.push(this.spawn(prompt, options));
17
- }
18
- }
19
- catch (error) {
20
- for (const handle of handles) {
21
- try {
22
- handle.cancel();
23
- }
24
- catch {
25
- /* ignore */
26
- }
27
- }
28
- throw error;
29
- }
30
- return Promise.all(handles.map((h) => h.promise));
31
- }
32
- }
33
- //# sourceMappingURL=parallel-agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-agent.js","sourceRoot":"","sources":["../src/parallel-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IACpD;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,KAAkD;QAC9D,MAAM,OAAO,GAAuB,EAAE,CAAC;QACvC,IAAI,CAAC;YACH,KAAK,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,IAAI,KAAK,EAAE,CAAC;gBAC3C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,IAAI,CAAC;oBACH,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,CAAC;gBAAC,MAAM,CAAC;oBACP,YAAY;gBACd,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -1,19 +0,0 @@
1
- import { Orchestrator } from "./orchestrator.ts";
2
- import type { SubagentOptions, SubagentResult } from "./types.ts";
3
- /**
4
- * Spawns a child agent and blocks until it completes.
5
- *
6
- * The child runs its own agentic loop with access to the parent's tools.
7
- * Orchestration tools are excluded when `recursive_depth` is 0 (the default)
8
- * and included when a positive depth is configured.
9
- */
10
- export declare class SubagentOrchestrator extends Orchestrator {
11
- /**
12
- * Run a prompt as an autonomous child agent and return when it completes.
13
- *
14
- * @param prompt - The instruction for the child agent.
15
- * @param options - Configuration for the child agent (system prompt, tools, session forking, custom ID).
16
- */
17
- execute(prompt: string, options?: SubagentOptions): Promise<SubagentResult>;
18
- }
19
- //# sourceMappingURL=subagent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../src/subagent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;GAMG;AACH,qBAAa,oBAAqB,SAAQ,YAAY;IACpD;;;;;OAKG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAGlF"}
package/dist/subagent.js DELETED
@@ -1,20 +0,0 @@
1
- import { Orchestrator } from "./orchestrator.js";
2
- /**
3
- * Spawns a child agent and blocks until it completes.
4
- *
5
- * The child runs its own agentic loop with access to the parent's tools.
6
- * Orchestration tools are excluded when `recursive_depth` is 0 (the default)
7
- * and included when a positive depth is configured.
8
- */
9
- export class SubagentOrchestrator extends Orchestrator {
10
- /**
11
- * Run a prompt as an autonomous child agent and return when it completes.
12
- *
13
- * @param prompt - The instruction for the child agent.
14
- * @param options - Configuration for the child agent (system prompt, tools, session forking, custom ID).
15
- */
16
- async execute(prompt, options) {
17
- return this.spawn(prompt, options).promise;
18
- }
19
- }
20
- //# sourceMappingURL=subagent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subagent.js","sourceRoot":"","sources":["../src/subagent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;;;;GAMG;AACH,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IACpD;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,OAAyB;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC;IAC7C,CAAC;CACF"}
@@ -1,21 +0,0 @@
1
- import type { ToolClass, ToolSuccessResult } from "@simulacra-ai/core";
2
- import type { WorkerState } from "../types.ts";
3
- type BackgroundParams = {
4
- action: "start" | "list" | "state" | "cancel" | "ack";
5
- prompts?: string[];
6
- system?: string;
7
- fork_session?: boolean;
8
- ids?: string[];
9
- };
10
- type BackgroundToolSuccess = ToolSuccessResult & {
11
- ids?: string[];
12
- workers?: WorkerState[];
13
- };
14
- /**
15
- * Tool that lets a model manage a pool of background worker agents. Supports
16
- * starting tasks, listing workers, checking state, cancelling, and collecting
17
- * results without blocking the main conversation.
18
- */
19
- export declare const BackgroundTaskPool: ToolClass<BackgroundParams, BackgroundToolSuccess>;
20
- export {};
21
- //# sourceMappingURL=background-task-pool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"background-task-pool.d.ts","sourceRoot":"","sources":["../../src/tools/background-task-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAIT,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,KAAK,qBAAqB,GAAG,iBAAiB,GAAG;IAC/C,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB,CAAC;AAkIF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,CAAC,gBAAgB,EAAE,qBAAqB,CAC1D,CAAC"}
@@ -1,133 +0,0 @@
1
- import { BackgroundAgentPool } from "../background-agent-pool.js";
2
- import { ORCHESTRATION_DEPTH_KEY } from "../orchestrator.js";
3
- class BackgroundTaskPoolImpl {
4
- #pool;
5
- constructor(context) {
6
- const POOL_KEY = "__background_agent_pool";
7
- if (!context[POOL_KEY]) {
8
- const depth = context[ORCHESTRATION_DEPTH_KEY] ?? 0;
9
- context[POOL_KEY] = new BackgroundAgentPool(context.workflow, { recursive_depth: depth });
10
- }
11
- const pool = context[POOL_KEY];
12
- pool.update_source(context.workflow);
13
- this.#pool = pool;
14
- }
15
- async execute({ action, prompts, system, fork_session, ids }) {
16
- try {
17
- switch (action) {
18
- case "start": {
19
- if (!prompts?.length) {
20
- return {
21
- result: false,
22
- message: "prompts is required for start",
23
- };
24
- }
25
- const started_ids = prompts.map((p) => this.#pool.start(p, { system, fork_session }));
26
- return { result: true, ids: started_ids };
27
- }
28
- case "list": {
29
- const worker_ids = this.#pool.list();
30
- return { result: true, ids: worker_ids };
31
- }
32
- case "state": {
33
- const workers = ids?.length ? this.#pool.state(...ids) : this.#pool.state();
34
- return { result: true, workers };
35
- }
36
- case "cancel": {
37
- if (!ids?.length) {
38
- return {
39
- result: false,
40
- message: "ids is required for cancel",
41
- };
42
- }
43
- const errors = [];
44
- for (const id of ids) {
45
- try {
46
- this.#pool.cancel(id);
47
- }
48
- catch (e) {
49
- errors.push(`${id}: ${e instanceof Error ? e.message : String(e)}`);
50
- }
51
- }
52
- if (errors.length) {
53
- return {
54
- result: false,
55
- message: `some cancels failed: ${errors.join("; ")}`,
56
- };
57
- }
58
- return { result: true, ids };
59
- }
60
- case "ack": {
61
- const workers = ids?.length ? this.#pool.ack(...ids) : this.#pool.ack();
62
- return { result: true, workers };
63
- }
64
- default: {
65
- return {
66
- result: false,
67
- message: `unknown action: ${action}`,
68
- };
69
- }
70
- }
71
- }
72
- catch (error) {
73
- return {
74
- result: false,
75
- message: error instanceof Error ? error.message : String(error),
76
- error,
77
- };
78
- }
79
- }
80
- static get_definition() {
81
- return {
82
- name: "background",
83
- description: "Manage background worker agents. Workers run independently with their own " +
84
- "conversations and tools. Use 'start' to launch workers, 'list' to see all " +
85
- "worker IDs, 'state' to check progress (rounds, tool calls, latest message), " +
86
- "'cancel' to stop workers, 'ack' to collect results from completed workers " +
87
- "and remove them from the pool.",
88
- parameters: [
89
- {
90
- name: "action",
91
- description: "The operation to perform",
92
- type: "string",
93
- required: true,
94
- enum: ["start", "list", "state", "cancel", "ack"],
95
- },
96
- {
97
- name: "prompts",
98
- description: "Instructions for workers to start, one per worker. Required and must not be empty when action is 'start'.",
99
- type: "array",
100
- required: false,
101
- items: { type: "string", required: true },
102
- },
103
- {
104
- name: "system",
105
- description: "Override the system prompt (only for 'start')",
106
- type: "string",
107
- required: false,
108
- },
109
- {
110
- name: "fork_session",
111
- description: "Start with current conversation history (only for 'start')",
112
- type: "boolean",
113
- required: false,
114
- },
115
- {
116
- name: "ids",
117
- description: "Worker IDs to operate on (for 'state', 'cancel', 'ack'). Omit for all.",
118
- type: "array",
119
- required: false,
120
- items: { type: "string", required: true },
121
- },
122
- ],
123
- parallelizable: false,
124
- };
125
- }
126
- }
127
- /**
128
- * Tool that lets a model manage a pool of background worker agents. Supports
129
- * starting tasks, listing workers, checking state, cancelling, and collecting
130
- * results without blocking the main conversation.
131
- */
132
- export const BackgroundTaskPool = BackgroundTaskPoolImpl;
133
- //# sourceMappingURL=background-task-pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"background-task-pool.js","sourceRoot":"","sources":["../../src/tools/background-task-pool.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAgB7D,MAAM,sBAAsB;IACjB,KAAK,CAAsB;IAEpC,YAAY,OAAoB;QAC9B,MAAM,QAAQ,GAAG,yBAAyB,CAAC;QAC3C,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,KAAK,GAAI,OAAO,CAAC,uBAAuB,CAAY,IAAI,CAAC,CAAC;YAChE,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,mBAAmB,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5F,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAwB,CAAC;QACtD,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAoB;QAC5E,IAAI,CAAC;YACH,QAAQ,MAAM,EAAE,CA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AAY;YAClB,WAAW,EACT,4EAA4E;gBAC5E,4EAA4E;gBAC5E,8EAA8E;gBAC9E,4EAA4E;gBAC5E,gCAAgC;YAClC,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,0BAA0B;oBACvC,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC;iBAClD;gBACD;oBACE,IAAI,EAAE,SAAS;oBACf,WAAW,EACT,2GAA2G;oBAC7G,IAAI,EAAE,OAAO;oBACb,QAAQ,EAAE,KAAK;oBACf,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;iBAC1C;gBACD;oBACE,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,+CAA+C;oBAC5D,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,KAAK;iBAChB;gBACD;oBACE,IAAI,EAAE,cAAc;oBACpB,WAAW,EAAE,4DAA4D;oBACzE,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,KAAK;iBAChB;gBACD;oBACE,IAAI,EAAE,KAAK;oBACX,WAAW,EAAE,wEAAwE;oBACrF,IAAI,EAAE,OAAO;oBACb,QAAQ,EAAE,KAAK;oBACf,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;iBAC1C;aACF;YACD,cAAc,EAAE,KAAK;SACtB,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,sBAAsB,CAAC"}
@@ -1,9 +0,0 @@
1
- import type { ToolClass } from "@simulacra-ai/core";
2
- export { BackgroundTaskPool } from "./background-task-pool.ts";
3
- export { ParallelAgentTask } from "./parallel-agent-task.ts";
4
- export { SubagentTask } from "./subagent-task.ts";
5
- /**
6
- * All orchestration tools as a ready-to-use toolkit.
7
- */
8
- export declare const OrchestrationToolkit: ToolClass[];
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,EAI3C,CAAC"}
@@ -1,15 +0,0 @@
1
- export { BackgroundTaskPool } from "./background-task-pool.js";
2
- export { ParallelAgentTask } from "./parallel-agent-task.js";
3
- export { SubagentTask } from "./subagent-task.js";
4
- import { BackgroundTaskPool } from "./background-task-pool.js";
5
- import { ParallelAgentTask } from "./parallel-agent-task.js";
6
- import { SubagentTask } from "./subagent-task.js";
7
- /**
8
- * All orchestration tools as a ready-to-use toolkit.
9
- */
10
- export const OrchestrationToolkit = [
11
- SubagentTask,
12
- ParallelAgentTask,
13
- BackgroundTaskPool,
14
- ];
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,YAAY;IACZ,iBAAiB;IACjB,kBAAkB;CACnB,CAAC"}
@@ -1,21 +0,0 @@
1
- import type { ToolClass, ToolSuccessResult } from "@simulacra-ai/core";
2
- type ParallelParams = {
3
- prompts: string[];
4
- system?: string;
5
- fork_session?: boolean;
6
- };
7
- type ParallelToolSuccess = ToolSuccessResult & {
8
- responses: Array<{
9
- id: string;
10
- response: string;
11
- end_reason: string;
12
- }>;
13
- };
14
- /**
15
- * Tool that lets a model run multiple subtasks concurrently, each handled by its
16
- * own subagent with a separate conversation. All subagents start immediately and
17
- * the tool returns once every subagent has completed.
18
- */
19
- export declare const ParallelAgentTask: ToolClass<ParallelParams, ParallelToolSuccess>;
20
- export {};
21
- //# sourceMappingURL=parallel-agent-task.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-agent-task.d.ts","sourceRoot":"","sources":["../../src/tools/parallel-agent-task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAIT,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAK5B,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,KAAK,mBAAmB,GAAG,iBAAiB,GAAG;IAC7C,SAAS,EAAE,KAAK,CAAC;QACf,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ,CAAC;AAuEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,CAAC,cAAc,EAAE,mBAAmB,CACtD,CAAC"}
@@ -1,75 +0,0 @@
1
- import { ORCHESTRATION_DEPTH_KEY } from "../orchestrator.js";
2
- import { ParallelOrchestrator } from "../parallel-agent.js";
3
- import { extract_response } from "./utils.js";
4
- class ParallelAgentTaskImpl {
5
- #agent;
6
- constructor(context) {
7
- const depth = context[ORCHESTRATION_DEPTH_KEY] ?? 0;
8
- this.#agent = new ParallelOrchestrator(context.workflow, { recursive_depth: depth });
9
- }
10
- async execute({ prompts, system, fork_session }) {
11
- try {
12
- if (!prompts?.length) {
13
- return {
14
- result: false,
15
- message: "prompts is required and must not be empty",
16
- };
17
- }
18
- const tasks = prompts.map((prompt) => ({ prompt, system, fork_session }));
19
- const results = await this.#agent.execute(tasks);
20
- return {
21
- result: true,
22
- responses: results.map((r) => ({
23
- id: r.id,
24
- response: extract_response(r),
25
- end_reason: r.end_reason,
26
- })),
27
- };
28
- }
29
- catch (error) {
30
- return {
31
- result: false,
32
- message: error instanceof Error ? error.message : String(error),
33
- error,
34
- };
35
- }
36
- }
37
- static get_definition() {
38
- return {
39
- name: "parallel",
40
- description: "Run multiple prompts as concurrent sub-agents. All agents start immediately " +
41
- "and the tool returns when every agent has completed. Each sub-agent has its " +
42
- "own conversation and access to the same tools. Use when tasks are independent " +
43
- "and can benefit from concurrent execution.",
44
- parameters: [
45
- {
46
- name: "prompts",
47
- description: "Array of instructions, one per sub-agent",
48
- type: "array",
49
- required: true,
50
- items: { type: "string", required: true },
51
- },
52
- {
53
- name: "system",
54
- description: "Override the system prompt for all sub-agents",
55
- type: "string",
56
- required: false,
57
- },
58
- {
59
- name: "fork_session",
60
- description: "If true, each sub-agent starts with the current conversation history",
61
- type: "boolean",
62
- required: false,
63
- },
64
- ],
65
- parallelizable: false,
66
- };
67
- }
68
- }
69
- /**
70
- * Tool that lets a model run multiple subtasks concurrently, each handled by its
71
- * own subagent with a separate conversation. All subagents start immediately and
72
- * the tool returns once every subagent has completed.
73
- */
74
- export const ParallelAgentTask = ParallelAgentTaskImpl;
75
- //# sourceMappingURL=parallel-agent-task.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-agent-task.js","sourceRoot":"","sources":["../../src/tools/parallel-agent-task.ts"],"names":[],"mappings":"A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AAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC/D,KAAK;aACa,CAAC;QACvB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,cAAc;QACnB,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,WAAW,EACT,8EAA8E;gBAC9E,8EAA8E;gBAC9E,gFAAgF;gBAChF,4CAA4C;YAC9C,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,0CAA0C;oBACvD,IAAI,EAAE,OAAO;oBACb,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;iBAC1C;gBACD;oBACE,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,+CAA+C;oBAC5D,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,KAAK;iBAChB;gBACD;oBACE,IAAI,EAAE,cAAc;oBACpB,WAAW,EAAE,sEAAsE;oBACnF,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,KAAK;iBAChB;aACF;YACD,cAAc,EAAE,KAAK;SACtB,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,qBAAqB,CAAC"}
@@ -1,19 +0,0 @@
1
- import type { ToolClass, ToolSuccessResult } from "@simulacra-ai/core";
2
- type SubagentParams = {
3
- prompt: string;
4
- system?: string;
5
- fork_session?: boolean;
6
- };
7
- type SubagentToolSuccess = ToolSuccessResult & {
8
- id: string;
9
- response: string;
10
- end_reason: string;
11
- };
12
- /**
13
- * Tool that lets a model spawn an autonomous subagent with its own conversation
14
- * to handle a subtask independently. The subagent runs to completion and returns
15
- * its final response.
16
- */
17
- export declare const SubagentTask: ToolClass<SubagentParams, SubagentToolSuccess>;
18
- export {};
19
- //# sourceMappingURL=subagent-task.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subagent-task.d.ts","sourceRoot":"","sources":["../../src/tools/subagent-task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAIT,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAK5B,KAAK,cAAc,GAAG;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,KAAK,mBAAmB,GAAG,iBAAiB,GAAG;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AA8DF;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,CAAC,cAAc,EAAE,mBAAmB,CAAoB,CAAC"}
@@ -1,65 +0,0 @@
1
- import { ORCHESTRATION_DEPTH_KEY } from "../orchestrator.js";
2
- import { SubagentOrchestrator } from "../subagent.js";
3
- import { extract_response } from "./utils.js";
4
- class SubagentTaskImpl {
5
- #agent;
6
- constructor(context) {
7
- const depth = context[ORCHESTRATION_DEPTH_KEY] ?? 0;
8
- this.#agent = new SubagentOrchestrator(context.workflow, { recursive_depth: depth });
9
- }
10
- async execute({ prompt, system, fork_session }) {
11
- try {
12
- const result = await this.#agent.execute(prompt, { system, fork_session });
13
- return {
14
- result: true,
15
- id: result.id,
16
- response: extract_response(result),
17
- end_reason: result.end_reason,
18
- };
19
- }
20
- catch (error) {
21
- return {
22
- result: false,
23
- message: error instanceof Error ? error.message : String(error),
24
- error,
25
- };
26
- }
27
- }
28
- static get_definition() {
29
- return {
30
- name: "subagent",
31
- description: "Run a prompt as an autonomous sub-agent with its own conversation. " +
32
- "The sub-agent has access to the same tools and runs to completion, " +
33
- "returning its final response. Use for tasks that require independent " +
34
- "multi-step reasoning or tool use.",
35
- parameters: [
36
- {
37
- name: "prompt",
38
- description: "The instruction for the sub-agent",
39
- type: "string",
40
- required: true,
41
- },
42
- {
43
- name: "system",
44
- description: "Override the system prompt for this sub-agent",
45
- type: "string",
46
- required: false,
47
- },
48
- {
49
- name: "fork_session",
50
- description: "If true, the sub-agent starts with a copy of the current conversation history",
51
- type: "boolean",
52
- required: false,
53
- },
54
- ],
55
- parallelizable: true,
56
- };
57
- }
58
- }
59
- /**
60
- * Tool that lets a model spawn an autonomous subagent with its own conversation
61
- * to handle a subtask independently. The subagent runs to completion and returns
62
- * its final response.
63
- */
64
- export const SubagentTask = SubagentTaskImpl;
65
- //# sourceMappingURL=subagent-task.js.map