@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.
- package/README.md +61 -61
- 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 -56
- package/dist/background-agent-pool.d.ts.map +0 -1
- package/dist/background-agent-pool.js +0 -102
- 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 -135
- package/dist/background-agent.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/orchestrator.d.ts +0 -43
- package/dist/orchestrator.d.ts.map +0 -1
- package/dist/orchestrator.js +0 -124
- 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 -18
- package/dist/subagent.d.ts.map +0 -1
- package/dist/subagent.js +0 -19
- package/dist/subagent.js.map +0 -1
- package/dist/tools/background-worker-pool.d.ts +0 -16
- package/dist/tools/background-worker-pool.d.ts.map +0 -1
- package/dist/tools/background-worker-pool.js +0 -126
- package/dist/tools/background-worker-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 -16
- package/dist/tools/parallel-agent-task.d.ts.map +0 -1
- package/dist/tools/parallel-agent-task.js +0 -68
- package/dist/tools/parallel-agent-task.js.map +0 -1
- package/dist/tools/subagent-task.d.ts +0 -14
- package/dist/tools/subagent-task.d.ts.map +0 -1
- package/dist/tools/subagent-task.js +0 -58
- 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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Simulacra Agent Orchestration
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
##
|
|
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
|
|
28
|
+
The simplest pattern. Spawns a child agent, blocks until it completes, and returns the result.
|
|
28
29
|
|
|
29
30
|
```typescript
|
|
30
|
-
|
|
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);
|
|
35
|
+
console.log(result.end_reason);
|
|
36
36
|
console.log(result.messages);
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
###
|
|
39
|
+
### ParallelOrchestrator
|
|
40
40
|
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
worker.
|
|
52
|
-
|
|
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
|
-
|
|
57
|
-
worker.
|
|
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
|
-
|
|
67
|
-
|
|
76
|
+
// create a pool and start some workers
|
|
68
77
|
using pool = new BackgroundAgentPool(workflowManager);
|
|
69
78
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
79
|
-
|
|
83
|
+
// wait, then collect completed workers
|
|
84
|
+
setTimeout(() => {
|
|
85
|
+
const done = pool.ack();
|
|
86
|
+
}, 30000);
|
|
80
87
|
```
|
|
81
88
|
|
|
82
|
-
###
|
|
89
|
+
### Recursive Depth
|
|
83
90
|
|
|
84
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
97
|
+
## Agentic Orchestration
|
|
98
98
|
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|