@simulacra-ai/orchestration 0.0.1
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 +123 -0
- package/dist/background-agent-pool.d.ts +56 -0
- package/dist/background-agent-pool.d.ts.map +1 -0
- package/dist/background-agent-pool.js +102 -0
- package/dist/background-agent-pool.js.map +1 -0
- package/dist/background-agent.d.ts +59 -0
- package/dist/background-agent.d.ts.map +1 -0
- package/dist/background-agent.js +135 -0
- package/dist/background-agent.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrator.d.ts +43 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +124 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/parallel-agent.d.ts +17 -0
- package/dist/parallel-agent.d.ts.map +1 -0
- package/dist/parallel-agent.js +33 -0
- package/dist/parallel-agent.js.map +1 -0
- package/dist/subagent.d.ts +18 -0
- package/dist/subagent.d.ts.map +1 -0
- package/dist/subagent.js +19 -0
- package/dist/subagent.js.map +1 -0
- package/dist/tools/background-worker-pool.d.ts +16 -0
- package/dist/tools/background-worker-pool.d.ts.map +1 -0
- package/dist/tools/background-worker-pool.js +126 -0
- package/dist/tools/background-worker-pool.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/parallel-agent-task.d.ts +16 -0
- package/dist/tools/parallel-agent-task.d.ts.map +1 -0
- package/dist/tools/parallel-agent-task.js +68 -0
- package/dist/tools/parallel-agent-task.js.map +1 -0
- package/dist/tools/subagent-task.d.ts +14 -0
- package/dist/tools/subagent-task.d.ts.map +1 -0
- package/dist/tools/subagent-task.js +58 -0
- package/dist/tools/subagent-task.js.map +1 -0
- package/dist/tools/utils.d.ts +8 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +25 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +23 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Workflow, WorkflowManager } from "@simulacra-ai/core";
|
|
2
|
+
const ORCHESTRATION_TOOL_NAMES = new Set(["subagent", "background", "parallel"]);
|
|
3
|
+
/**
|
|
4
|
+
* Remove orchestration tools from a toolkit to prevent child agents from nesting.
|
|
5
|
+
*
|
|
6
|
+
* @param toolkit - The toolkit to filter.
|
|
7
|
+
*/
|
|
8
|
+
function strip_orchestration_tools(toolkit) {
|
|
9
|
+
return toolkit.filter((t) => !ORCHESTRATION_TOOL_NAMES.has(t.get_definition().name));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Base class for orchestration patterns.
|
|
13
|
+
*
|
|
14
|
+
* Accepts a `WorkflowManager` (for programmatic use) or a `Workflow`
|
|
15
|
+
* (for tool integration). Provides the shared child-spawning logic
|
|
16
|
+
* that all orchestration patterns build on.
|
|
17
|
+
*
|
|
18
|
+
* By default, orchestration tools are stripped from child agents to
|
|
19
|
+
* prevent nesting. Pass `strip_tools: false` to allow it.
|
|
20
|
+
*/
|
|
21
|
+
export class Orchestrator {
|
|
22
|
+
#manager;
|
|
23
|
+
#workflow;
|
|
24
|
+
#strip_tools;
|
|
25
|
+
/**
|
|
26
|
+
* @param source - A `WorkflowManager` or `Workflow` to spawn children from.
|
|
27
|
+
* @param options.strip_tools - Remove orchestration tools from child agents. Defaults to `true`.
|
|
28
|
+
*/
|
|
29
|
+
constructor(source, { strip_tools = true } = {}) {
|
|
30
|
+
if (source instanceof WorkflowManager) {
|
|
31
|
+
this.#manager = source;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.#workflow = source;
|
|
35
|
+
}
|
|
36
|
+
this.#strip_tools = strip_tools;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The conversation associated with the orchestrator.
|
|
40
|
+
*/
|
|
41
|
+
get conversation() {
|
|
42
|
+
if (this.#manager) {
|
|
43
|
+
return this.#manager.conversation;
|
|
44
|
+
}
|
|
45
|
+
if (this.#workflow) {
|
|
46
|
+
return this.#workflow.conversation;
|
|
47
|
+
}
|
|
48
|
+
throw new Error("no source");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The parent workflow, if available. Used to establish parent-child workflow relationships.
|
|
52
|
+
*/
|
|
53
|
+
get parent_workflow() {
|
|
54
|
+
if (this.#manager) {
|
|
55
|
+
return this.#manager.current_workflow;
|
|
56
|
+
}
|
|
57
|
+
return this.#workflow;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Spawn a child agent with its own conversation and workflow.
|
|
61
|
+
*
|
|
62
|
+
* Creates a child conversation, assigns tools (stripping orchestration
|
|
63
|
+
* tools unless disabled), and starts the workflow. Returns a handle
|
|
64
|
+
* for awaiting, inspecting, or cancelling the child.
|
|
65
|
+
*
|
|
66
|
+
* @param prompt - The instruction to send to the child agent.
|
|
67
|
+
* @param options - Configuration for the child agent (system prompt, tools, session forking, custom ID).
|
|
68
|
+
*/
|
|
69
|
+
spawn(prompt, options) {
|
|
70
|
+
const conversation = this.conversation;
|
|
71
|
+
const child = conversation.spawn_child(options?.fork_session, options?.id, options?.system ?? conversation.system);
|
|
72
|
+
const toolkit = options?.toolkit ?? [...conversation.toolkit];
|
|
73
|
+
child.toolkit = this.#strip_tools ? strip_orchestration_tools(toolkit) : toolkit;
|
|
74
|
+
const parent = this.parent_workflow;
|
|
75
|
+
const child_workflow = parent && parent.state !== "disposed"
|
|
76
|
+
? parent.spawn_child(child, options?.id)
|
|
77
|
+
: new Workflow(child);
|
|
78
|
+
let settled = false;
|
|
79
|
+
const promise = new Promise((resolve) => {
|
|
80
|
+
child_workflow.once("workflow_end", (event) => {
|
|
81
|
+
settled = true;
|
|
82
|
+
resolve({
|
|
83
|
+
id: child_workflow.id,
|
|
84
|
+
messages: child_workflow.messages,
|
|
85
|
+
end_reason: event.reason,
|
|
86
|
+
});
|
|
87
|
+
if (child.state !== "disposed") {
|
|
88
|
+
child[Symbol.dispose]();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
child_workflow.start();
|
|
93
|
+
child.prompt(prompt);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
if (!settled) {
|
|
97
|
+
settled = true;
|
|
98
|
+
resolve({
|
|
99
|
+
id: child_workflow.id,
|
|
100
|
+
messages: child_workflow.messages,
|
|
101
|
+
end_reason: "cancel",
|
|
102
|
+
});
|
|
103
|
+
if (child.state !== "disposed") {
|
|
104
|
+
child[Symbol.dispose]();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
get id() {
|
|
111
|
+
return child_workflow.id;
|
|
112
|
+
},
|
|
113
|
+
get workflow() {
|
|
114
|
+
return child_workflow;
|
|
115
|
+
},
|
|
116
|
+
promise,
|
|
117
|
+
get done() {
|
|
118
|
+
return settled;
|
|
119
|
+
},
|
|
120
|
+
cancel: () => child_workflow.cancel(),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,OAAoB;IACrD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CA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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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* (minus orchestration tools).
|
|
8
|
+
*/
|
|
9
|
+
export declare 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
|
+
execute(prompt: string, options?: SubagentOptions): Promise<SubagentResult>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=subagent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;;GAKG;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
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
* (minus orchestration tools).
|
|
7
|
+
*/
|
|
8
|
+
export class SubagentOrchestrator extends Orchestrator {
|
|
9
|
+
/**
|
|
10
|
+
* Run a prompt as an autonomous child agent and return when it completes.
|
|
11
|
+
*
|
|
12
|
+
* @param prompt - The instruction for the child agent.
|
|
13
|
+
* @param options - Configuration for the child agent (system prompt, tools, session forking, custom ID).
|
|
14
|
+
*/
|
|
15
|
+
async execute(prompt, options) {
|
|
16
|
+
return this.spawn(prompt, options).promise;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=subagent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent.js","sourceRoot":"","sources":["../src/subagent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;;;GAKG;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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export declare const BackgroundWorkerPool: ToolClass<BackgroundParams, BackgroundToolSuccess>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=background-worker-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-worker-pool.d.ts","sourceRoot":"","sources":["../../src/tools/background-worker-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAIT,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,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;AAiIF,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAAC,gBAAgB,EAAE,qBAAqB,CAC1D,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { BackgroundAgentPool } from "../background-agent-pool.js";
|
|
2
|
+
class BackgroundWorkerPoolImpl {
|
|
3
|
+
#pool;
|
|
4
|
+
constructor(context) {
|
|
5
|
+
const POOL_KEY = "__background_agent_pool";
|
|
6
|
+
if (!context[POOL_KEY]) {
|
|
7
|
+
context[POOL_KEY] = new BackgroundAgentPool(context.workflow);
|
|
8
|
+
}
|
|
9
|
+
const pool = context[POOL_KEY];
|
|
10
|
+
pool.update_source(context.workflow);
|
|
11
|
+
this.#pool = pool;
|
|
12
|
+
}
|
|
13
|
+
async execute({ action, prompts, system, fork_session, ids }) {
|
|
14
|
+
try {
|
|
15
|
+
switch (action) {
|
|
16
|
+
case "start": {
|
|
17
|
+
if (!prompts?.length) {
|
|
18
|
+
return {
|
|
19
|
+
result: false,
|
|
20
|
+
message: "prompts is required for start",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const started_ids = prompts.map((p) => this.#pool.start(p, { system, fork_session }));
|
|
24
|
+
return { result: true, ids: started_ids };
|
|
25
|
+
}
|
|
26
|
+
case "list": {
|
|
27
|
+
const worker_ids = this.#pool.list();
|
|
28
|
+
return { result: true, ids: worker_ids };
|
|
29
|
+
}
|
|
30
|
+
case "state": {
|
|
31
|
+
const workers = ids?.length ? this.#pool.state(...ids) : this.#pool.state();
|
|
32
|
+
return { result: true, workers };
|
|
33
|
+
}
|
|
34
|
+
case "cancel": {
|
|
35
|
+
if (!ids?.length) {
|
|
36
|
+
return {
|
|
37
|
+
result: false,
|
|
38
|
+
message: "ids is required for cancel",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const errors = [];
|
|
42
|
+
for (const id of ids) {
|
|
43
|
+
try {
|
|
44
|
+
this.#pool.cancel(id);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
errors.push(`${id}: ${e instanceof Error ? e.message : String(e)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (errors.length) {
|
|
51
|
+
return {
|
|
52
|
+
result: false,
|
|
53
|
+
message: `some cancels failed: ${errors.join("; ")}`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return { result: true, ids };
|
|
57
|
+
}
|
|
58
|
+
case "ack": {
|
|
59
|
+
const workers = ids?.length ? this.#pool.ack(...ids) : this.#pool.ack();
|
|
60
|
+
return { result: true, workers };
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
return {
|
|
64
|
+
result: false,
|
|
65
|
+
message: `unknown action: ${action}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return {
|
|
72
|
+
result: false,
|
|
73
|
+
message: error instanceof Error ? error.message : String(error),
|
|
74
|
+
error,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
static get_definition() {
|
|
79
|
+
return {
|
|
80
|
+
name: "background",
|
|
81
|
+
description: "Manage background worker agents. Workers run independently with their own " +
|
|
82
|
+
"conversations and tools. Use 'start' to launch workers, 'list' to see all " +
|
|
83
|
+
"worker IDs, 'state' to check progress (rounds, tool calls, latest message), " +
|
|
84
|
+
"'cancel' to stop workers, 'ack' to collect results from completed workers " +
|
|
85
|
+
"and remove them from the pool.",
|
|
86
|
+
parameters: [
|
|
87
|
+
{
|
|
88
|
+
name: "action",
|
|
89
|
+
description: "The operation to perform",
|
|
90
|
+
type: "string",
|
|
91
|
+
required: true,
|
|
92
|
+
enum: ["start", "list", "state", "cancel", "ack"],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "prompts",
|
|
96
|
+
description: "Instructions for workers to start, one per worker. Required and must not be empty when action is 'start'.",
|
|
97
|
+
type: "array",
|
|
98
|
+
required: false,
|
|
99
|
+
items: { type: "string", required: true },
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "system",
|
|
103
|
+
description: "Override the system prompt (only for 'start')",
|
|
104
|
+
type: "string",
|
|
105
|
+
required: false,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "fork_session",
|
|
109
|
+
description: "Start with current conversation history (only for 'start')",
|
|
110
|
+
type: "boolean",
|
|
111
|
+
required: false,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "ids",
|
|
115
|
+
description: "Worker IDs to operate on (for 'state', 'cancel', 'ack'). Omit for all.",
|
|
116
|
+
type: "array",
|
|
117
|
+
required: false,
|
|
118
|
+
items: { type: "string", required: true },
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
parallelizable: false,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export const BackgroundWorkerPool = BackgroundWorkerPoolImpl;
|
|
126
|
+
//# sourceMappingURL=background-worker-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-worker-pool.js","sourceRoot":"","sources":["../../src/tools/background-worker-pool.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAgBlE,MAAM,wBAAwB;IACnB,KAAK,CAAsB;IAEpC,YAAY,OAAoB;QAC9B,MAAM,QAAQ,GAAG,yBAAyB,CAAC;QAC3C,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChE,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAwB,CAAC;QACtD,IAAI,CAAC,aAAa,CAA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C,MAAM,oBAAoB,GAC/B,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ToolClass } from "@simulacra-ai/core";
|
|
2
|
+
export { SubagentTask } from "./subagent-task.ts";
|
|
3
|
+
export { BackgroundWorkerPool } from "./background-worker-pool.ts";
|
|
4
|
+
export { ParallelAgentTask } from "./parallel-agent-task.ts";
|
|
5
|
+
/**
|
|
6
|
+
* All orchestration tools (`SubagentTask`, `BackgroundWorkerPool`, `ParallelAgentTask`) as a ready-to-use toolkit.
|
|
7
|
+
*/
|
|
8
|
+
export declare const OrchestrationToolkit: ToolClass[];
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAM7D;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,EAI3C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { SubagentTask } from "./subagent-task.js";
|
|
2
|
+
export { BackgroundWorkerPool } from "./background-worker-pool.js";
|
|
3
|
+
export { ParallelAgentTask } from "./parallel-agent-task.js";
|
|
4
|
+
import { SubagentTask } from "./subagent-task.js";
|
|
5
|
+
import { BackgroundWorkerPool } from "./background-worker-pool.js";
|
|
6
|
+
import { ParallelAgentTask } from "./parallel-agent-task.js";
|
|
7
|
+
/**
|
|
8
|
+
* All orchestration tools (`SubagentTask`, `BackgroundWorkerPool`, `ParallelAgentTask`) as a ready-to-use toolkit.
|
|
9
|
+
*/
|
|
10
|
+
export const OrchestrationToolkit = [
|
|
11
|
+
SubagentTask,
|
|
12
|
+
BackgroundWorkerPool,
|
|
13
|
+
ParallelAgentTask,
|
|
14
|
+
];
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,YAAY;IACZ,oBAAoB;IACpB,iBAAiB;CAClB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export declare const ParallelAgentTask: ToolClass<ParallelParams, ParallelToolSuccess>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=parallel-agent-task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAI5B,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;AAsEF,eAAO,MAAM,iBAAiB,EAAE,SAAS,CAAC,cAAc,EAAE,mBAAmB,CACtD,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ParallelOrchestrator } from "../parallel-agent.js";
|
|
2
|
+
import { extract_response } from "./utils.js";
|
|
3
|
+
class ParallelAgentTaskImpl {
|
|
4
|
+
#agent;
|
|
5
|
+
constructor(context) {
|
|
6
|
+
this.#agent = new ParallelOrchestrator(context.workflow);
|
|
7
|
+
}
|
|
8
|
+
async execute({ prompts, system, fork_session }) {
|
|
9
|
+
try {
|
|
10
|
+
if (!prompts?.length) {
|
|
11
|
+
return {
|
|
12
|
+
result: false,
|
|
13
|
+
message: "prompts is required and must not be empty",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const tasks = prompts.map((prompt) => ({ prompt, system, fork_session }));
|
|
17
|
+
const results = await this.#agent.execute(tasks);
|
|
18
|
+
return {
|
|
19
|
+
result: true,
|
|
20
|
+
responses: results.map((r) => ({
|
|
21
|
+
id: r.id,
|
|
22
|
+
response: extract_response(r),
|
|
23
|
+
end_reason: r.end_reason,
|
|
24
|
+
})),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return {
|
|
29
|
+
result: false,
|
|
30
|
+
message: error instanceof Error ? error.message : String(error),
|
|
31
|
+
error,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
static get_definition() {
|
|
36
|
+
return {
|
|
37
|
+
name: "parallel",
|
|
38
|
+
description: "Run multiple prompts as concurrent sub-agents. All agents start immediately " +
|
|
39
|
+
"and the tool returns when every agent has completed. Each sub-agent has its " +
|
|
40
|
+
"own conversation and access to the same tools. Use when tasks are independent " +
|
|
41
|
+
"and can benefit from concurrent execution.",
|
|
42
|
+
parameters: [
|
|
43
|
+
{
|
|
44
|
+
name: "prompts",
|
|
45
|
+
description: "Array of instructions, one per sub-agent",
|
|
46
|
+
type: "array",
|
|
47
|
+
required: true,
|
|
48
|
+
items: { type: "string", required: true },
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "system",
|
|
52
|
+
description: "Override the system prompt for all sub-agents",
|
|
53
|
+
type: "string",
|
|
54
|
+
required: false,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "fork_session",
|
|
58
|
+
description: "If true, each sub-agent starts with the current conversation history",
|
|
59
|
+
type: "boolean",
|
|
60
|
+
required: false,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
parallelizable: false,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export const ParallelAgentTask = ParallelAgentTaskImpl;
|
|
68
|
+
//# sourceMappingURL=parallel-agent-task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-agent-task.js","sourceRoot":"","sources":["../../src/tools/parallel-agent-task.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAgB9C,MAAM,qBAAqB;IAChB,MAAM,CAAuB;IAEtC,YAAY,OAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;I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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,MAAM,CAAC,MAAM,iBAAiB,GAC5B,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export declare const SubagentTask: ToolClass<SubagentParams, SubagentToolSuccess>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=subagent-task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAI5B,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;AA6DF,eAAO,MAAM,YAAY,EAAE,SAAS,CAAC,cAAc,EAAE,mBAAmB,CAAoB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SubagentOrchestrator } from "../subagent.js";
|
|
2
|
+
import { extract_response } from "./utils.js";
|
|
3
|
+
class SubagentTaskImpl {
|
|
4
|
+
#agent;
|
|
5
|
+
constructor(context) {
|
|
6
|
+
this.#agent = new SubagentOrchestrator(context.workflow);
|
|
7
|
+
}
|
|
8
|
+
async execute({ prompt, system, fork_session }) {
|
|
9
|
+
try {
|
|
10
|
+
const result = await this.#agent.execute(prompt, { system, fork_session });
|
|
11
|
+
return {
|
|
12
|
+
result: true,
|
|
13
|
+
id: result.id,
|
|
14
|
+
response: extract_response(result),
|
|
15
|
+
end_reason: result.end_reason,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return {
|
|
20
|
+
result: false,
|
|
21
|
+
message: error instanceof Error ? error.message : String(error),
|
|
22
|
+
error,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
static get_definition() {
|
|
27
|
+
return {
|
|
28
|
+
name: "subagent",
|
|
29
|
+
description: "Run a prompt as an autonomous sub-agent with its own conversation. " +
|
|
30
|
+
"The sub-agent has access to the same tools and runs to completion, " +
|
|
31
|
+
"returning its final response. Use for tasks that require independent " +
|
|
32
|
+
"multi-step reasoning or tool use.",
|
|
33
|
+
parameters: [
|
|
34
|
+
{
|
|
35
|
+
name: "prompt",
|
|
36
|
+
description: "The instruction for the sub-agent",
|
|
37
|
+
type: "string",
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "system",
|
|
42
|
+
description: "Override the system prompt for this sub-agent",
|
|
43
|
+
type: "string",
|
|
44
|
+
required: false,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "fork_session",
|
|
48
|
+
description: "If true, the sub-agent starts with a copy of the current conversation history",
|
|
49
|
+
type: "boolean",
|
|
50
|
+
required: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
parallelizable: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const SubagentTask = SubagentTaskImpl;
|
|
58
|
+
//# sourceMappingURL=subagent-task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-task.js","sourceRoot":"","sources":["../../src/tools/subagent-task.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAc9C,MAAM,gBAAgB;IACX,MAAM,CAAuB;IAEtC,YAAY,OAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAkB;QAC5D,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;YAC3E,OAAO;gBACL,MAAM,EAAE,IAAa;gBACrB,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC;gBAClC,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,MAAM,EAAE,KAAc;gBACtB,OAAO,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,qEAAqE;gBACrE,qEAAqE;gBACrE,uEAAuE;gBACvE,mCAAmC;YACrC,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,mCAAmC;oBAChD,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;iBACf;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,EACT,+EAA+E;oBACjF,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,KAAK;iBAChB;aACF;YACD,cAAc,EAAE,IAAI;SACrB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,CAAC,MAAM,YAAY,GAAmD,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SubagentResult } from "../types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Extract the final text response from a subagent result.
|
|
4
|
+
*
|
|
5
|
+
* @param result - The completed subagent result.
|
|
6
|
+
*/
|
|
7
|
+
export declare function extract_response(result: SubagentResult): string;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAkB/D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the final text response from a subagent result.
|
|
3
|
+
*
|
|
4
|
+
* @param result - The completed subagent result.
|
|
5
|
+
*/
|
|
6
|
+
export function extract_response(result) {
|
|
7
|
+
for (let i = result.messages.length - 1; i >= 0; i--) {
|
|
8
|
+
const message = result.messages[i];
|
|
9
|
+
if (message.role !== "assistant") {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const content = message.content;
|
|
13
|
+
if (!content) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
for (let j = content.length - 1; j >= 0; j--) {
|
|
17
|
+
const block = content[j];
|
|
18
|
+
if (block.type === "text" && block.text) {
|
|
19
|
+
return block.text;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return "(no text response)";
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|