@simulacra-ai/orchestration 0.0.2 → 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.
Files changed (53) hide show
  1. package/README.md +61 -61
  2. package/dist/index.cjs +706 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +342 -0
  5. package/dist/index.d.ts +342 -8
  6. package/dist/index.js +669 -7
  7. package/dist/index.js.map +1 -1
  8. package/package.json +11 -5
  9. package/dist/background-agent-pool.d.ts +0 -56
  10. package/dist/background-agent-pool.d.ts.map +0 -1
  11. package/dist/background-agent-pool.js +0 -102
  12. package/dist/background-agent-pool.js.map +0 -1
  13. package/dist/background-agent.d.ts +0 -59
  14. package/dist/background-agent.d.ts.map +0 -1
  15. package/dist/background-agent.js +0 -135
  16. package/dist/background-agent.js.map +0 -1
  17. package/dist/index.d.ts.map +0 -1
  18. package/dist/orchestrator.d.ts +0 -43
  19. package/dist/orchestrator.d.ts.map +0 -1
  20. package/dist/orchestrator.js +0 -124
  21. package/dist/orchestrator.js.map +0 -1
  22. package/dist/parallel-agent.d.ts +0 -17
  23. package/dist/parallel-agent.d.ts.map +0 -1
  24. package/dist/parallel-agent.js +0 -33
  25. package/dist/parallel-agent.js.map +0 -1
  26. package/dist/subagent.d.ts +0 -18
  27. package/dist/subagent.d.ts.map +0 -1
  28. package/dist/subagent.js +0 -19
  29. package/dist/subagent.js.map +0 -1
  30. package/dist/tools/background-worker-pool.d.ts +0 -16
  31. package/dist/tools/background-worker-pool.d.ts.map +0 -1
  32. package/dist/tools/background-worker-pool.js +0 -126
  33. package/dist/tools/background-worker-pool.js.map +0 -1
  34. package/dist/tools/index.d.ts +0 -9
  35. package/dist/tools/index.d.ts.map +0 -1
  36. package/dist/tools/index.js +0 -15
  37. package/dist/tools/index.js.map +0 -1
  38. package/dist/tools/parallel-agent-task.d.ts +0 -16
  39. package/dist/tools/parallel-agent-task.d.ts.map +0 -1
  40. package/dist/tools/parallel-agent-task.js +0 -68
  41. package/dist/tools/parallel-agent-task.js.map +0 -1
  42. package/dist/tools/subagent-task.d.ts +0 -14
  43. package/dist/tools/subagent-task.d.ts.map +0 -1
  44. package/dist/tools/subagent-task.js +0 -58
  45. package/dist/tools/subagent-task.js.map +0 -1
  46. package/dist/tools/utils.d.ts +0 -8
  47. package/dist/tools/utils.d.ts.map +0 -1
  48. package/dist/tools/utils.js +0 -25
  49. package/dist/tools/utils.js.map +0 -1
  50. package/dist/types.d.ts +0 -90
  51. package/dist/types.d.ts.map +0 -1
  52. package/dist/types.js +0 -2
  53. package/dist/types.js.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Simulacra Agent Orchestration
2
2
 
3
- Multi-agent orchestration patterns for the Simulacra conversation engine. Child agents run independently with their own conversations and tool access.
3
+ The orchestration package provides multi-agent patterns for Simulacra. Real workloads often call for delegation, parallelism, or long-running background tasks. Each worker agent gets its own conversation and tool access, and the orchestrator manages spawning, cancellation, and result collection.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,113 +10,113 @@ npm install @simulacra-ai/core @simulacra-ai/orchestration
10
10
 
11
11
  ## Setup
12
12
 
13
- All orchestration patterns require a `WorkflowManager` wrapping a conversation with tools:
13
+ All orchestration patterns build on top of a `WorkflowManager`. The orchestrator spawns child conversations from the parent, so each worker agent inherits the provider, tools, and system prompt.
14
14
 
15
15
  ```typescript
16
- import { Conversation, WorkflowManager } from "@simulacra-ai/core";
17
-
18
- const conversation = new Conversation(provider);
19
- conversation.toolkit = [/* your tools */];
20
- const workflowManager = new WorkflowManager(conversation);
16
+ // create a conversation and workflow manager
17
+ using conversation = new Conversation(provider);
18
+ conversation.toolkit = [/* tools */];
19
+ using workflowManager = new WorkflowManager(conversation);
21
20
  ```
22
21
 
23
- ## Usage
22
+ ## Patterns
23
+
24
+ Each pattern can be used in two ways. As a tool added to a conversation's toolkit, letting the model decide when and how to delegate. Or as a direct API call from application code for explicit control over orchestration.
24
25
 
25
26
  ### SubagentOrchestrator
26
27
 
27
- Spawns a child agent and blocks until it completes.
28
+ The simplest pattern. Spawns a child agent, blocks until it completes, and returns the result.
28
29
 
29
30
  ```typescript
30
- import { SubagentOrchestrator } from "@simulacra-ai/orchestration";
31
-
31
+ // spawn a subagent and wait for it to finish
32
32
  const agent = new SubagentOrchestrator(workflowManager);
33
33
  const result = await agent.execute("Analyze this data and report findings");
34
34
 
35
- console.log(result.end_reason); // "complete" | "cancel" | "error"
35
+ console.log(result.end_reason);
36
36
  console.log(result.messages);
37
37
  ```
38
38
 
39
- ### BackgroundOrchestrator
39
+ ### ParallelOrchestrator
40
40
 
41
- A single background worker. Call `execute` once to start, then inspect or collect.
41
+ Fans out multiple prompts concurrently and waits for all of them to complete. Each prompt gets its own agent, and all results are returned together.
42
42
 
43
43
  ```typescript
44
- import { BackgroundOrchestrator } from "@simulacra-ai/orchestration";
44
+ // fan out three tasks in parallel
45
+ const agent = new ParallelOrchestrator(workflowManager);
46
+ const results = await agent.execute([
47
+ { prompt: "Analyze dataset A" },
48
+ { prompt: "Analyze dataset B" },
49
+ { prompt: "Analyze dataset C", system: "Focus on outliers" },
50
+ ]);
51
+ ```
45
52
 
53
+ ### BackgroundOrchestrator
54
+
55
+ A background worker that runs independently. Start it with `execute`, then check on it or collect results later.
56
+
57
+ ```typescript
58
+ // start a background worker
46
59
  using worker = new BackgroundOrchestrator(workflowManager);
47
60
  worker.execute("Monitor the feed for changes");
48
61
 
49
- // later
50
- worker.status; // "running" | "completed" | "cancelled"
51
- worker.done; // true when completed or cancelled
52
- worker.rounds; // number of agentic turns
53
- worker.tool_call_count; // total tool calls made
54
- worker.latest_message; // last assistant text
62
+ // check on it later
63
+ setTimeout(() => {
64
+ console.log(worker.status);
65
+ }, 5000);
55
66
 
56
- const result = await worker.collect(); // await completion, get full result
57
- worker.cancel(); // cancel if still running
58
- // automatically disposed at end of scope
67
+ // wait for it to finish and get the full result
68
+ const result = await worker.collect();
59
69
  ```
60
70
 
61
71
  ### BackgroundAgentPool
62
72
 
63
- Manages multiple background workers with batch operations.
73
+ Manages multiple background workers with batch operations. Useful for parallelizing independent research or processing tasks where each worker runs on its own.
64
74
 
65
75
  ```typescript
66
- import { BackgroundAgentPool } from "@simulacra-ai/orchestration";
67
-
76
+ // create a pool and start some workers
68
77
  using pool = new BackgroundAgentPool(workflowManager);
69
78
 
70
- const id1 = pool.start("Research topic A");
71
- const id2 = pool.start("Research topic B");
72
- const id3 = pool.start("Research topic C");
73
-
74
- pool.list(); // [id1, id2, id3]
75
- pool.state(id1, id2); // WorkerState[] with status, rounds, tool_call_count, latest_message
76
- pool.cancel(id2); // cancel a specific worker
79
+ pool.start("Research topic A");
80
+ pool.start("Research topic B");
81
+ pool.start("Research topic C");
77
82
 
78
- const done = pool.ack(); // pop all completed workers, returns their states
79
- // all remaining workers cancelled and cleaned up at end of scope
83
+ // wait, then collect completed workers
84
+ setTimeout(() => {
85
+ const done = pool.ack();
86
+ }, 30000);
80
87
  ```
81
88
 
82
- ### ParallelOrchestrator
89
+ ### Recursive Depth
83
90
 
84
- Runs multiple prompts concurrently and waits for all to complete.
91
+ All three constructors (`SubagentOrchestrator`, `ParallelOrchestrator`, `BackgroundAgentPool`) accept a `{ recursive_depth }` option that controls how many levels of nested delegation the spawned agents are allowed to perform.
85
92
 
86
93
  ```typescript
87
- import { ParallelOrchestrator } from "@simulacra-ai/orchestration";
88
-
89
- const agent = new ParallelOrchestrator(workflowManager);
90
- const results = await agent.execute([
91
- { prompt: "Analyze dataset A" },
92
- { prompt: "Analyze dataset B" },
93
- { prompt: "Analyze dataset C", system: "Focus on outliers" },
94
- ]);
94
+ const agent = new SubagentOrchestrator(workflowManager, { recursive_depth: 2 });
95
95
  ```
96
96
 
97
- ## LLM Tools
97
+ ## Agentic Orchestration
98
98
 
99
- Each pattern is available as a `ToolClass` for model-driven orchestration.
100
-
101
- > **Note:** By default, orchestration tools are stripped from child agents to prevent recursive nesting. Pass `strip_tools: false` to the `Orchestrator` constructor to allow it.
99
+ Orchestration patterns are also available as task tools that can be added to a model's toolkit, allowing the model to decide when and how to delegate work.
102
100
 
103
101
  ```typescript
104
- import { OrchestrationToolkit } from "@simulacra-ai/orchestration";
105
-
102
+ // give the model access to all orchestration tools
106
103
  conversation.toolkit = [...conversation.toolkit, ...OrchestrationToolkit];
104
+
105
+ // give the model access to specific tools
106
+ conversation.toolkit = [...conversation.toolkit, SubagentTask, ParallelAgentTask, BackgroundTaskPool];
107
107
  ```
108
108
 
109
- Individual tools (`SubagentTask`, `BackgroundWorkerPool`, `ParallelAgentTask`) are also exported if you want to pick selectively.
109
+ By default, spawned agents cannot delegate further. Nested delegation can be enabled by setting `ORCHESTRATION_DEPTH_KEY` in `context_data`.
110
+
111
+ ```typescript
112
+ import { ORCHESTRATION_DEPTH_KEY } from "@simulacra-ai/orchestration";
110
113
 
111
- `BackgroundWorkerPool` exposes a worker pool to the model with these actions:
114
+ // allows one level of nested delegation (agent > subagent > sub-subagent)
115
+ using manager = new WorkflowManager(conversation, {
116
+ context_data: { [ORCHESTRATION_DEPTH_KEY]: 1 },
117
+ });
118
+ ```
112
119
 
113
- Action|Description
114
- -|-
115
- `start`|Launch one or more background workers (requires `prompts`)
116
- `list`|List all worker IDs
117
- `state`|Get status, rounds, tool calls, latest message (optional `ids`)
118
- `cancel`|Stop workers (requires `ids`)
119
- `ack`|Pop completed workers and return their states (optional `ids`)
120
120
 
121
121
  ## License
122
122