@framers/agentos 0.1.111 → 0.1.113
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/api/strategies/debate.d.ts +12 -1
- package/dist/api/strategies/debate.d.ts.map +1 -1
- package/dist/api/strategies/debate.js +41 -5
- package/dist/api/strategies/debate.js.map +1 -1
- package/dist/api/strategies/hierarchical.d.ts +15 -1
- package/dist/api/strategies/hierarchical.d.ts.map +1 -1
- package/dist/api/strategies/hierarchical.js +51 -7
- package/dist/api/strategies/hierarchical.js.map +1 -1
- package/dist/api/strategies/index.d.ts +26 -4
- package/dist/api/strategies/index.d.ts.map +1 -1
- package/dist/api/strategies/index.js +26 -4
- package/dist/api/strategies/index.js.map +1 -1
- package/dist/api/strategies/parallel.d.ts +15 -4
- package/dist/api/strategies/parallel.d.ts.map +1 -1
- package/dist/api/strategies/parallel.js +53 -16
- package/dist/api/strategies/parallel.js.map +1 -1
- package/dist/api/strategies/review-loop.d.ts +15 -1
- package/dist/api/strategies/review-loop.d.ts.map +1 -1
- package/dist/api/strategies/review-loop.js +36 -10
- package/dist/api/strategies/review-loop.js.map +1 -1
- package/dist/api/strategies/sequential.d.ts +11 -1
- package/dist/api/strategies/sequential.d.ts.map +1 -1
- package/dist/api/strategies/sequential.js +39 -8
- package/dist/api/strategies/sequential.js.map +1 -1
- package/dist/api/strategies/shared.d.ts +71 -7
- package/dist/api/strategies/shared.d.ts.map +1 -1
- package/dist/api/strategies/shared.js +89 -10
- package/dist/api/strategies/shared.js.map +1 -1
- package/dist/api/types.d.ts +54 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/memory/facade/Memory.d.ts.map +1 -1
- package/dist/memory/facade/Memory.js +8 -0
- package/dist/memory/facade/Memory.js.map +1 -1
- package/dist/memory/facade/types.d.ts +10 -0
- package/dist/memory/facade/types.d.ts.map +1 -1
- package/dist/memory/index.d.ts +6 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +5 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/observation/MemoryObserver.d.ts +63 -1
- package/dist/memory/observation/MemoryObserver.d.ts.map +1 -1
- package/dist/memory/observation/MemoryObserver.js +115 -4
- package/dist/memory/observation/MemoryObserver.js.map +1 -1
- package/dist/memory/observation/ObservationCompressor.d.ts +88 -0
- package/dist/memory/observation/ObservationCompressor.d.ts.map +1 -0
- package/dist/memory/observation/ObservationCompressor.js +207 -0
- package/dist/memory/observation/ObservationCompressor.js.map +1 -0
- package/dist/memory/observation/ObservationReflector.d.ts +82 -0
- package/dist/memory/observation/ObservationReflector.d.ts.map +1 -0
- package/dist/memory/observation/ObservationReflector.js +212 -0
- package/dist/memory/observation/ObservationReflector.js.map +1 -0
- package/dist/memory/observation/temporal.d.ts +54 -0
- package/dist/memory/observation/temporal.d.ts.map +1 -0
- package/dist/memory/observation/temporal.js +115 -0
- package/dist/memory/observation/temporal.js.map +1 -0
- package/dist/orchestration/builders/VoiceNodeBuilder.d.ts +82 -25
- package/dist/orchestration/builders/VoiceNodeBuilder.d.ts.map +1 -1
- package/dist/orchestration/builders/VoiceNodeBuilder.js +86 -26
- package/dist/orchestration/builders/VoiceNodeBuilder.js.map +1 -1
- package/dist/orchestration/events/GraphEvent.d.ts +67 -5
- package/dist/orchestration/events/GraphEvent.d.ts.map +1 -1
- package/dist/orchestration/events/GraphEvent.js.map +1 -1
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts +102 -25
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts.map +1 -1
- package/dist/orchestration/runtime/VoiceNodeExecutor.js +133 -38
- package/dist/orchestration/runtime/VoiceNodeExecutor.js.map +1 -1
- package/dist/orchestration/runtime/VoiceTransportAdapter.d.ts +94 -32
- package/dist/orchestration/runtime/VoiceTransportAdapter.d.ts.map +1 -1
- package/dist/orchestration/runtime/VoiceTransportAdapter.js +82 -28
- package/dist/orchestration/runtime/VoiceTransportAdapter.js.map +1 -1
- package/dist/orchestration/runtime/VoiceTurnCollector.d.ts +73 -20
- package/dist/orchestration/runtime/VoiceTurnCollector.d.ts.map +1 -1
- package/dist/orchestration/runtime/VoiceTurnCollector.js +84 -23
- package/dist/orchestration/runtime/VoiceTurnCollector.js.map +1 -1
- package/dist/voice/CallManager.d.ts.map +1 -1
- package/dist/voice/CallManager.js +9 -1
- package/dist/voice/CallManager.js.map +1 -1
- package/dist/voice/MediaStreamParser.d.ts +115 -6
- package/dist/voice/MediaStreamParser.d.ts.map +1 -1
- package/dist/voice/MediaStreamParser.js +44 -0
- package/dist/voice/MediaStreamParser.js.map +1 -1
- package/dist/voice/TelephonyStreamTransport.d.ts +112 -20
- package/dist/voice/TelephonyStreamTransport.d.ts.map +1 -1
- package/dist/voice/TelephonyStreamTransport.js +136 -30
- package/dist/voice/TelephonyStreamTransport.js.map +1 -1
- package/dist/voice/parsers/PlivoMediaStreamParser.d.ts +64 -6
- package/dist/voice/parsers/PlivoMediaStreamParser.d.ts.map +1 -1
- package/dist/voice/parsers/PlivoMediaStreamParser.js +67 -6
- package/dist/voice/parsers/PlivoMediaStreamParser.js.map +1 -1
- package/dist/voice/parsers/TelnyxMediaStreamParser.d.ts +55 -8
- package/dist/voice/parsers/TelnyxMediaStreamParser.d.ts.map +1 -1
- package/dist/voice/parsers/TelnyxMediaStreamParser.js +60 -9
- package/dist/voice/parsers/TelnyxMediaStreamParser.js.map +1 -1
- package/dist/voice/parsers/TwilioMediaStreamParser.d.ts +73 -11
- package/dist/voice/parsers/TwilioMediaStreamParser.d.ts.map +1 -1
- package/dist/voice/parsers/TwilioMediaStreamParser.js +81 -12
- package/dist/voice/parsers/TwilioMediaStreamParser.js.map +1 -1
- package/dist/voice/providers/plivo.d.ts +108 -12
- package/dist/voice/providers/plivo.d.ts.map +1 -1
- package/dist/voice/providers/plivo.js +106 -9
- package/dist/voice/providers/plivo.js.map +1 -1
- package/dist/voice/providers/telnyx.d.ts +110 -20
- package/dist/voice/providers/telnyx.d.ts.map +1 -1
- package/dist/voice/providers/telnyx.js +111 -20
- package/dist/voice/providers/telnyx.js.map +1 -1
- package/dist/voice/providers/twilio.d.ts +91 -13
- package/dist/voice/providers/twilio.d.ts.map +1 -1
- package/dist/voice/providers/twilio.js +94 -14
- package/dist/voice/providers/twilio.js.map +1 -1
- package/dist/voice/twiml.d.ts +70 -12
- package/dist/voice/twiml.d.ts.map +1 -1
- package/dist/voice/twiml.js +70 -12
- package/dist/voice/twiml.js.map +1 -1
- package/dist/voice/types.d.ts +142 -15
- package/dist/voice/types.d.ts.map +1 -1
- package/dist/voice/types.js +34 -3
- package/dist/voice/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -9,8 +9,19 @@ import type { AgencyOptions, CompiledStrategy, Agent, BaseAgentConfig } from '..
|
|
|
9
9
|
*
|
|
10
10
|
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
11
11
|
* @param agencyConfig - Agency-level configuration providing fallback model/provider/tools.
|
|
12
|
+
* Must include `model` or `provider` for the synthesis step.
|
|
12
13
|
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
13
|
-
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
14
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
15
|
+
* for the synthesis step.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const strategy = compileDebate(
|
|
20
|
+
* { optimist: { instructions: 'Argue the positive case.' }, pessimist: { instructions: 'Argue the risks.' } },
|
|
21
|
+
* { model: 'openai:gpt-4o', maxRounds: 2, agents: { ... } },
|
|
22
|
+
* );
|
|
23
|
+
* const result = await strategy.execute('Should we adopt this new technology?');
|
|
24
|
+
* ```
|
|
14
25
|
*/
|
|
15
26
|
export declare function compileDebate(agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
16
27
|
//# sourceMappingURL=debate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debate.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/debate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debate.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/debate.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAEhB,MAAM,aAAa,CAAC;AAIrB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,EAC/C,YAAY,EAAE,aAAa,GAC1B,gBAAgB,CAwHlB"}
|
|
@@ -2,10 +2,28 @@
|
|
|
2
2
|
* @file debate.ts
|
|
3
3
|
* Debate strategy compiler for the Agency API.
|
|
4
4
|
*
|
|
5
|
+
* ## Execution model
|
|
6
|
+
*
|
|
5
7
|
* Agents argue in rounds over a shared task. Each round, every agent sees all
|
|
6
8
|
* prior arguments from every other agent, enabling progressive refinement
|
|
7
9
|
* through adversarial discourse. After all rounds complete, a synthesizer
|
|
8
10
|
* distils the collected arguments into a single coherent response.
|
|
11
|
+
*
|
|
12
|
+
* ## Why debate?
|
|
13
|
+
*
|
|
14
|
+
* Debate is effective for tasks where multiple perspectives lead to better
|
|
15
|
+
* outcomes: ethical reasoning, policy analysis, creative brainstorming,
|
|
16
|
+
* risk assessment. Each agent is forced to defend its position while
|
|
17
|
+
* considering others, reducing blind spots.
|
|
18
|
+
*
|
|
19
|
+
* ## Round structure
|
|
20
|
+
*
|
|
21
|
+
* For `N` agents and `R` rounds, the total agent calls are `N * R` plus one
|
|
22
|
+
* synthesis call. In each round, agents are called in declaration order.
|
|
23
|
+
* Each agent receives the full argument history from all prior agents/rounds.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link compileStrategy} -- the dispatcher that selects this compiler.
|
|
26
|
+
* @see {@link compileReviewLoop} -- an alternative iterative strategy with explicit approval.
|
|
9
27
|
*/
|
|
10
28
|
import { agent as createAgent } from '../agent.js';
|
|
11
29
|
import { AgencyConfigError } from '../types.js';
|
|
@@ -20,13 +38,26 @@ import { resolveAgent, checkBeforeAgent } from './shared.js';
|
|
|
20
38
|
*
|
|
21
39
|
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
22
40
|
* @param agencyConfig - Agency-level configuration providing fallback model/provider/tools.
|
|
41
|
+
* Must include `model` or `provider` for the synthesis step.
|
|
23
42
|
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
24
|
-
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
43
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
44
|
+
* for the synthesis step.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const strategy = compileDebate(
|
|
49
|
+
* { optimist: { instructions: 'Argue the positive case.' }, pessimist: { instructions: 'Argue the risks.' } },
|
|
50
|
+
* { model: 'openai:gpt-4o', maxRounds: 2, agents: { ... } },
|
|
51
|
+
* );
|
|
52
|
+
* const result = await strategy.execute('Should we adopt this new technology?');
|
|
53
|
+
* ```
|
|
25
54
|
*/
|
|
26
55
|
export function compileDebate(agents, agencyConfig) {
|
|
27
56
|
if (!agencyConfig.model && !agencyConfig.provider) {
|
|
28
57
|
throw new AgencyConfigError('Debate strategy requires an agency-level model or provider for result synthesis.');
|
|
29
58
|
}
|
|
59
|
+
// Default to 3 rounds when not specified -- enough for meaningful discourse
|
|
60
|
+
// without excessive token consumption.
|
|
30
61
|
const maxRounds = agencyConfig.maxRounds ?? 3;
|
|
31
62
|
return {
|
|
32
63
|
async execute(prompt, opts) {
|
|
@@ -36,13 +67,16 @@ export function compileDebate(agents, agencyConfig) {
|
|
|
36
67
|
const collectedArguments = [];
|
|
37
68
|
for (let round = 0; round < maxRounds; round++) {
|
|
38
69
|
for (const [name, agentOrConfig] of entries) {
|
|
39
|
-
|
|
70
|
+
// HITL: check beforeAgent gate before invoking this agent.
|
|
40
71
|
const decision = await checkBeforeAgent(name, prompt, agentCalls, agencyConfig);
|
|
41
72
|
if (decision && !decision.approved) {
|
|
42
|
-
|
|
73
|
+
// Agent was rejected -- skip this agent in this round.
|
|
43
74
|
continue;
|
|
44
75
|
}
|
|
45
76
|
const a = resolveAgent(agentOrConfig, agencyConfig);
|
|
77
|
+
// Build the debate context: original task + all prior arguments.
|
|
78
|
+
// The first agent in the first round sees "You are the first to argue."
|
|
79
|
+
// which prevents confusion about missing prior context.
|
|
46
80
|
const debateContext = `Task: ${prompt}\n\n` +
|
|
47
81
|
(collectedArguments.length > 0
|
|
48
82
|
? `Previous arguments:\n${collectedArguments.join('\n---\n')}`
|
|
@@ -54,6 +88,8 @@ export function compileDebate(agents, agencyConfig) {
|
|
|
54
88
|
const resultText = result.text ?? '';
|
|
55
89
|
const resultUsage = result.usage ?? {};
|
|
56
90
|
const resultToolCalls = result.toolCalls ?? [];
|
|
91
|
+
// Label each argument with the agent name and round for traceability
|
|
92
|
+
// in the synthesis prompt.
|
|
57
93
|
collectedArguments.push(`[${name}, round ${round + 1}]: ${resultText}`);
|
|
58
94
|
agentCalls.push({
|
|
59
95
|
agent: name,
|
|
@@ -72,7 +108,7 @@ export function compileDebate(agents, agencyConfig) {
|
|
|
72
108
|
totalUsage.totalTokens += resultUsage.totalTokens ?? 0;
|
|
73
109
|
}
|
|
74
110
|
}
|
|
75
|
-
|
|
111
|
+
// Synthesize all arguments into a final answer using the agency-level model.
|
|
76
112
|
const synthInstructions = agencyConfig.instructions
|
|
77
113
|
? `\n\n${agencyConfig.instructions}`
|
|
78
114
|
: '';
|
|
@@ -94,7 +130,7 @@ export function compileDebate(agents, agencyConfig) {
|
|
|
94
130
|
return { ...synthesis, agentCalls, usage: totalUsage };
|
|
95
131
|
},
|
|
96
132
|
stream(prompt, opts) {
|
|
97
|
-
|
|
133
|
+
/**
|
|
98
134
|
* For v1: streaming delegates to execute() and wraps the resolved text
|
|
99
135
|
* as a single-chunk async iterable. A future version will stream the
|
|
100
136
|
* synthesis step in real-time.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debate.js","sourceRoot":"","sources":["../../../src/api/strategies/debate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"debate.js","sourceRoot":"","sources":["../../../src/api/strategies/debate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAQnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAA0B,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA+C,EAC/C,YAA2B;IAE3B,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;QAClD,MAAM,IAAI,iBAAiB,CACzB,kFAAkF,CACnF,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,uCAAuC;IACvC,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,IAAI,CAAC,CAAC;IAE9C,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI;YACxB,MAAM,UAAU,GAAsB,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACvC,MAAM,UAAU,GAAG,EAAE,YAAY,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;YAC5E,MAAM,kBAAkB,GAAa,EAAE,CAAC;YAExC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC;gBAC/C,KAAK,MAAM,CAAC,IAAI,EA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AY,IAAI,UAAU,CAAC,YAAY,IAAI,CAAC,CAAC;YACxD,UAAU,CAAC,gBAAgB,IAAI,UAAU,CAAC,gBAAgB,IAAI,CAAC,CAAC;YAChE,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,WAAW,IAAI,CAAC,CAAC;YAEtD,OAAO,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;QACzD,CAAC;QAED,MAAM,CAAC,MAAM,EAAE,IAAI;YACjB;;;;eAIG;YACH,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAqC,CAAC;YACrF,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAE,CAAC,CAAC,IAAe,IAAI,EAAE,CAAC,CAAC;YAExE,OAAO;gBACL,UAAU,EAAE,CAAC,KAAK,SAAS,CAAC;oBAC1B,MAAM,MAAM,WAAW,CAAC;gBAC1B,CAAC,CAAC,EAAE;gBACJ,UAAU,EAAE,CAAC,KAAK,SAAS,CAAC;oBAC1B,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC;oBAC/B,MAAM,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC;gBACxC,CAAC,CAAC,EAAE;gBACJ,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;aAC1C,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -14,7 +14,21 @@ import type { AgencyOptions, CompiledStrategy, Agent, BaseAgentConfig } from '..
|
|
|
14
14
|
* @param agencyConfig - Agency-level configuration; must include `model` or `provider`
|
|
15
15
|
* for the manager agent.
|
|
16
16
|
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
17
|
-
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
17
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
18
|
+
* for the manager agent.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const strategy = compileHierarchical(
|
|
23
|
+
* {
|
|
24
|
+
* researcher: { instructions: 'Find academic sources.' },
|
|
25
|
+
* writer: { instructions: 'Write clear prose.' },
|
|
26
|
+
* },
|
|
27
|
+
* { model: 'openai:gpt-4o', agents: { ... } },
|
|
28
|
+
* );
|
|
29
|
+
* const result = await strategy.execute('Write a literature review on LLMs.');
|
|
30
|
+
* // The manager decided which agents to call and in what order.
|
|
31
|
+
* ```
|
|
18
32
|
*/
|
|
19
33
|
export declare function compileHierarchical(agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
20
34
|
//# sourceMappingURL=hierarchical.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hierarchical.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/hierarchical.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hierarchical.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/hierarchical.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAEhB,MAAM,aAAa,CAAC;AAqBrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,EAC/C,YAAY,EAAE,aAAa,GAC1B,gBAAgB,CA0HlB"}
|
|
@@ -2,10 +2,30 @@
|
|
|
2
2
|
* @file hierarchical.ts
|
|
3
3
|
* Hierarchical strategy compiler for the Agency API.
|
|
4
4
|
*
|
|
5
|
+
* ## Execution model
|
|
6
|
+
*
|
|
5
7
|
* A manager agent (instantiated from the agency-level config) delegates
|
|
6
8
|
* subtasks to sub-agents via tool calls. Each sub-agent is exposed as a
|
|
7
9
|
* `delegate_to_<name>` tool that the manager can invoke to assign work.
|
|
8
10
|
* The manager synthesizes sub-agent outputs into a final answer.
|
|
11
|
+
*
|
|
12
|
+
* ## Emergent wiring
|
|
13
|
+
*
|
|
14
|
+
* The manager does not follow a fixed execution order. It decides which
|
|
15
|
+
* agents to call, in what order, and with what subtasks -- based on the
|
|
16
|
+
* user prompt and its system instructions. This makes hierarchical the
|
|
17
|
+
* most flexible strategy, but also the most dependent on the manager
|
|
18
|
+
* model's ability to plan and delegate effectively.
|
|
19
|
+
*
|
|
20
|
+
* ## Tool-based delegation
|
|
21
|
+
*
|
|
22
|
+
* Each sub-agent becomes a tool with a JSON Schema parameter (`task: string`).
|
|
23
|
+
* The tool's `execute` function invokes the sub-agent's `generate()` and
|
|
24
|
+
* returns the result text. This leverages the LLM's native tool-calling
|
|
25
|
+
* capability for delegation, avoiding custom routing logic.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link compileStrategy} -- the dispatcher that selects this compiler.
|
|
28
|
+
* @see {@link compileAdaptiveWrapper} -- wraps other strategies with a hierarchical manager.
|
|
9
29
|
*/
|
|
10
30
|
import { agent as createAgent } from '../agent.js';
|
|
11
31
|
import { AgencyConfigError } from '../types.js';
|
|
@@ -13,6 +33,9 @@ import { isAgent, resolveAgent, checkBeforeAgent } from './shared.js';
|
|
|
13
33
|
/**
|
|
14
34
|
* Extracts a human-readable description from an agent config or instance.
|
|
15
35
|
*
|
|
36
|
+
* Used to build the team roster in the manager's system prompt so the manager
|
|
37
|
+
* knows what each sub-agent specialises in.
|
|
38
|
+
*
|
|
16
39
|
* @param agentOrConfig - Either a pre-built Agent or a raw BaseAgentConfig.
|
|
17
40
|
* @returns The instructions string if available, otherwise a generic label.
|
|
18
41
|
*/
|
|
@@ -37,7 +60,21 @@ function getAgentDescription(agentOrConfig) {
|
|
|
37
60
|
* @param agencyConfig - Agency-level configuration; must include `model` or `provider`
|
|
38
61
|
* for the manager agent.
|
|
39
62
|
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
40
|
-
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
63
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
64
|
+
* for the manager agent.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const strategy = compileHierarchical(
|
|
69
|
+
* {
|
|
70
|
+
* researcher: { instructions: 'Find academic sources.' },
|
|
71
|
+
* writer: { instructions: 'Write clear prose.' },
|
|
72
|
+
* },
|
|
73
|
+
* { model: 'openai:gpt-4o', agents: { ... } },
|
|
74
|
+
* );
|
|
75
|
+
* const result = await strategy.execute('Write a literature review on LLMs.');
|
|
76
|
+
* // The manager decided which agents to call and in what order.
|
|
77
|
+
* ```
|
|
41
78
|
*/
|
|
42
79
|
export function compileHierarchical(agents, agencyConfig) {
|
|
43
80
|
if (!agencyConfig.model && !agencyConfig.provider) {
|
|
@@ -46,7 +83,9 @@ export function compileHierarchical(agents, agencyConfig) {
|
|
|
46
83
|
return {
|
|
47
84
|
async execute(prompt, opts) {
|
|
48
85
|
const agentCalls = [];
|
|
49
|
-
|
|
86
|
+
// Build one tool per sub-agent for the manager to delegate to.
|
|
87
|
+
// The tool name follows the `delegate_to_<name>` convention so the
|
|
88
|
+
// manager can infer the agent's role from the tool name alone.
|
|
50
89
|
const agentTools = {};
|
|
51
90
|
for (const [name, agentOrConfig] of Object.entries(agents)) {
|
|
52
91
|
const description = getAgentDescription(agentOrConfig);
|
|
@@ -60,13 +99,13 @@ export function compileHierarchical(agents, agencyConfig) {
|
|
|
60
99
|
required: ['task'],
|
|
61
100
|
},
|
|
62
101
|
execute: async (args) => {
|
|
63
|
-
|
|
102
|
+
// HITL: check beforeAgent gate before delegating to this sub-agent.
|
|
64
103
|
const decision = await checkBeforeAgent(name, args.task, agentCalls, agencyConfig);
|
|
65
104
|
if (decision && !decision.approved) {
|
|
66
105
|
return { success: false, data: `Agent "${name}" execution was rejected by HITL.` };
|
|
67
106
|
}
|
|
68
107
|
const a = resolveAgent(agentOrConfig, agencyConfig);
|
|
69
|
-
|
|
108
|
+
// Apply instruction modifications from the approval decision if any.
|
|
70
109
|
const effectiveTask = decision?.modifications?.instructions
|
|
71
110
|
? `${args.task}\n\n[Additional instructions]: ${decision.modifications.instructions}`
|
|
72
111
|
: args.task;
|
|
@@ -76,6 +115,7 @@ export function compileHierarchical(agents, agencyConfig) {
|
|
|
76
115
|
const resultText = result.text ?? '';
|
|
77
116
|
const resultUsage = result.usage ?? {};
|
|
78
117
|
const resultToolCalls = result.toolCalls ?? [];
|
|
118
|
+
// Record the sub-agent call for the final result's agentCalls array.
|
|
79
119
|
agentCalls.push({
|
|
80
120
|
agent: name,
|
|
81
121
|
input: args.task,
|
|
@@ -92,7 +132,8 @@ export function compileHierarchical(agents, agencyConfig) {
|
|
|
92
132
|
},
|
|
93
133
|
};
|
|
94
134
|
}
|
|
95
|
-
|
|
135
|
+
// Build the team roster description for the manager's system prompt.
|
|
136
|
+
// This tells the manager who is on the team and what each member does.
|
|
96
137
|
const teamRoster = Object.entries(agents)
|
|
97
138
|
.map(([name, c]) => `- ${name}: ${getAgentDescription(c)}`)
|
|
98
139
|
.join('\n');
|
|
@@ -100,7 +141,8 @@ export function compileHierarchical(agents, agencyConfig) {
|
|
|
100
141
|
`Available team members:\n${teamRoster}\n\n` +
|
|
101
142
|
`Use the delegate_to_<name> tools to assign work. Synthesize their outputs into a final answer.` +
|
|
102
143
|
(agencyConfig.instructions ? `\n\n${agencyConfig.instructions}` : '');
|
|
103
|
-
|
|
144
|
+
// Merge agency-level tools with the delegation tools. Agency tools
|
|
145
|
+
// (e.g. shared search, calculator) are available alongside delegation.
|
|
104
146
|
const mergedTools = { ...(agencyConfig.tools ?? {}), ...agentTools };
|
|
105
147
|
const manager = createAgent({
|
|
106
148
|
model: agencyConfig.model,
|
|
@@ -109,13 +151,15 @@ export function compileHierarchical(agents, agencyConfig) {
|
|
|
109
151
|
baseUrl: agencyConfig.baseUrl,
|
|
110
152
|
instructions: managerInstructions,
|
|
111
153
|
tools: mergedTools,
|
|
154
|
+
// Higher maxSteps than default because the manager needs room to
|
|
155
|
+
// call multiple delegation tools before synthesizing.
|
|
112
156
|
maxSteps: agencyConfig.maxSteps ?? 10,
|
|
113
157
|
});
|
|
114
158
|
const result = (await manager.generate(prompt, opts));
|
|
115
159
|
return { ...result, agentCalls };
|
|
116
160
|
},
|
|
117
161
|
stream(prompt, opts) {
|
|
118
|
-
|
|
162
|
+
/**
|
|
119
163
|
* For v1: streaming delegates to execute() and wraps the resolved text
|
|
120
164
|
* as a single-chunk async iterable. A future version will stream the
|
|
121
165
|
* manager's output in real-time.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hierarchical.js","sourceRoot":"","sources":["../../../src/api/strategies/hierarchical.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hierarchical.js","sourceRoot":"","sources":["../../../src/api/strategies/hierarchical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAAiB,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErF;;;;;;;;GAQG;AACH,SAAS,mBAAmB,CAAC,aAAsC;IACjE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAK,aAAiC,CAAC,YAAY,EAAE,CAAC;QAC/E,OAAQ,aAAiC,CAAC,YAAa,CAAC;IAC1D,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA+C,EAC/C,YAA2B;IAE3B,IAAI,CAAC,YAAY,CAAC,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AC1B,CAAC,CAAC,EAAE;gBACJ,UAAU,EAAE,CAAC,KAAK,SAAS,CAAC;oBAC1B,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC;oBAC/B,MAAM,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC;gBACxC,CAAC,CAAC,EAAE;gBACJ,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;aAC1C,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -4,9 +4,23 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Maps an {@link AgencyStrategy} discriminant to the concrete compiler that
|
|
6
6
|
* produces a {@link CompiledStrategy}. Supports sequential, parallel, debate,
|
|
7
|
-
* review-loop, and
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* review-loop, hierarchical, and graph strategies.
|
|
8
|
+
*
|
|
9
|
+
* ## Adaptive mode
|
|
10
|
+
*
|
|
11
|
+
* When `adaptive` mode is enabled on a non-hierarchical strategy, the dispatcher
|
|
12
|
+
* wraps it with an implicit hierarchical manager that may override the default
|
|
13
|
+
* strategy at runtime. This works by:
|
|
14
|
+
*
|
|
15
|
+
* 1. Appending strategy-awareness instructions to the manager prompt.
|
|
16
|
+
* 2. Setting `adaptive: false` on the inner call to prevent infinite recursion.
|
|
17
|
+
* 3. Delegating to `compileHierarchical()` which creates delegation tools.
|
|
18
|
+
*
|
|
19
|
+
* The adaptive wrapper is transparent to the caller -- it still receives a
|
|
20
|
+
* standard {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link compileStrategy} -- the main entry point for strategy compilation.
|
|
23
|
+
* @see {@link agency} -- the factory that calls compileStrategy during construction.
|
|
10
24
|
*/
|
|
11
25
|
import type { AgencyStrategy, AgencyOptions, CompiledStrategy, Agent, BaseAgentConfig } from '../types.js';
|
|
12
26
|
/**
|
|
@@ -21,7 +35,15 @@ import type { AgencyStrategy, AgencyOptions, CompiledStrategy, Agent, BaseAgentC
|
|
|
21
35
|
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
22
36
|
* @param agencyConfig - Full agency-level configuration providing fallback values.
|
|
23
37
|
* @returns A compiled strategy with `execute` and `stream` methods.
|
|
24
|
-
* @throws {Error} When the requested strategy is not yet implemented.
|
|
38
|
+
* @throws {Error} When the requested strategy is not yet implemented (e.g. a
|
|
39
|
+
* future strategy discriminant that has been added to `AgencyStrategy`
|
|
40
|
+
* but not yet wired here).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const strategy = compileStrategy('sequential', agents, agencyConfig);
|
|
45
|
+
* const result = await strategy.execute('Summarise AI research.');
|
|
46
|
+
* ```
|
|
25
47
|
*/
|
|
26
48
|
export declare function compileStrategy(strategy: AgencyStrategy, agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
27
49
|
export { compileSequential } from './sequential.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAChB,MAAM,aAAa,CAAC;AAQrB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,EAC/C,YAAY,EAAE,aAAa,GAC1B,gBAAgB,CAUlB;AAgFD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -16,10 +16,21 @@ import { compileGraph } from './graph.js';
|
|
|
16
16
|
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
17
17
|
* @param agencyConfig - Full agency-level configuration providing fallback values.
|
|
18
18
|
* @returns A compiled strategy with `execute` and `stream` methods.
|
|
19
|
-
* @throws {Error} When the requested strategy is not yet implemented.
|
|
19
|
+
* @throws {Error} When the requested strategy is not yet implemented (e.g. a
|
|
20
|
+
* future strategy discriminant that has been added to `AgencyStrategy`
|
|
21
|
+
* but not yet wired here).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const strategy = compileStrategy('sequential', agents, agencyConfig);
|
|
26
|
+
* const result = await strategy.execute('Summarise AI research.');
|
|
27
|
+
* ```
|
|
20
28
|
*/
|
|
21
29
|
export function compileStrategy(strategy, agents, agencyConfig) {
|
|
22
|
-
|
|
30
|
+
// When adaptive mode is enabled on non-hierarchical strategies, wrap with
|
|
31
|
+
// a manager that can override the strategy at runtime. Hierarchical is
|
|
32
|
+
// excluded because it IS the manager pattern -- wrapping it again would
|
|
33
|
+
// create a pointless double-manager layer.
|
|
23
34
|
if (agencyConfig.adaptive && strategy !== 'hierarchical') {
|
|
24
35
|
return compileAdaptiveWrapper(strategy, agents, agencyConfig);
|
|
25
36
|
}
|
|
@@ -28,10 +39,15 @@ export function compileStrategy(strategy, agents, agencyConfig) {
|
|
|
28
39
|
/**
|
|
29
40
|
* Core strategy compiler without adaptive wrapping.
|
|
30
41
|
*
|
|
42
|
+
* Dispatches on the strategy discriminant to the appropriate concrete compiler.
|
|
43
|
+
* Each compiler returns a {@link CompiledStrategy} with consistent `execute`
|
|
44
|
+
* and `stream` method signatures.
|
|
45
|
+
*
|
|
31
46
|
* @param strategy - Strategy discriminant.
|
|
32
47
|
* @param agents - Named agent roster.
|
|
33
48
|
* @param agencyConfig - Agency-level configuration.
|
|
34
49
|
* @returns A compiled strategy.
|
|
50
|
+
* @throws {Error} When the strategy is not recognised.
|
|
35
51
|
* @internal
|
|
36
52
|
*/
|
|
37
53
|
function compileStrategyCore(strategy, agents, agencyConfig) {
|
|
@@ -61,7 +77,13 @@ function compileStrategyCore(strategy, agents, agencyConfig) {
|
|
|
61
77
|
* just like the hierarchical strategy, but with the additional context of the
|
|
62
78
|
* original intended strategy.
|
|
63
79
|
*
|
|
64
|
-
*
|
|
80
|
+
* ## Recursion prevention
|
|
81
|
+
*
|
|
82
|
+
* `adaptive: false` is set on the inner config to prevent the hierarchical
|
|
83
|
+
* compiler from re-entering the adaptive wrapper, which would cause infinite
|
|
84
|
+
* recursion.
|
|
85
|
+
*
|
|
86
|
+
* @param defaultStrategy - The user-declared default strategy (e.g. `"sequential"`).
|
|
65
87
|
* @param agents - Named agent roster.
|
|
66
88
|
* @param agencyConfig - Agency-level configuration.
|
|
67
89
|
* @returns A compiled hierarchical strategy with adaptive instructions.
|
|
@@ -74,7 +96,7 @@ function compileAdaptiveWrapper(defaultStrategy, agents, agencyConfig) {
|
|
|
74
96
|
const adaptiveConfig = {
|
|
75
97
|
...agencyConfig,
|
|
76
98
|
instructions: adaptiveInstructions,
|
|
77
|
-
|
|
99
|
+
// Disable adaptive on the inner call to prevent infinite recursion.
|
|
78
100
|
adaptive: false,
|
|
79
101
|
};
|
|
80
102
|
return compileHierarchical(agents, adaptiveConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/strategies/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/strategies/index.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAwB,EACxB,MAA+C,EAC/C,YAA2B;IAE3B,0EAA0E;IAC1E,uEAAuE;IACvE,wEAAwE;IACxE,2CAA2C;IAC3C,IAAI,YAAY,CAAC,QAAQ,IAAI,QAAQ,KAAK,cAAc,EAAE,CAAC;QACzD,OAAO,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,mBAAmB,CAC1B,QAAwB,EACxB,MAA+C,EAC/C,YAA2B;IAE3B,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,iBAAiB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACjD,KAAK,UAAU;YACb,OAAO,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC/C,KAAK,QAAQ;YACX,OAAO,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC7C,KAAK,aAAa;YAChB,OAAO,iBAAiB,CA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y.
|
|
4
4
|
*
|
|
5
5
|
* All agents are invoked concurrently with the same prompt via
|
|
6
|
-
* `Promise.
|
|
7
|
-
* (instantiated from the agency-level config) combines the
|
|
8
|
-
* outputs into a single coherent response.
|
|
6
|
+
* `Promise.allSettled`. Once every agent has responded (or failed), a
|
|
7
|
+
* synthesis agent (instantiated from the agency-level config) combines the
|
|
8
|
+
* individual outputs into a single coherent response.
|
|
9
9
|
*
|
|
10
10
|
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
11
11
|
* @param agencyConfig - Agency-level configuration; must include `model` or `provider`
|
|
12
12
|
* for the synthesis step.
|
|
13
13
|
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
14
|
-
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
14
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available
|
|
15
|
+
* for the synthesis step. The synthesis agent needs an LLM to combine the
|
|
16
|
+
* parallel outputs.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const strategy = compileParallel(
|
|
21
|
+
* { factChecker: factAgent, writer: writeAgent },
|
|
22
|
+
* { model: 'openai:gpt-4o', agents: { factChecker: factAgent, writer: writeAgent } },
|
|
23
|
+
* );
|
|
24
|
+
* const result = await strategy.execute('Write a fact-checked article.');
|
|
25
|
+
* ```
|
|
15
26
|
*/
|
|
16
27
|
export declare function compileParallel(agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
17
28
|
//# sourceMappingURL=parallel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/parallel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/parallel.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAEhB,MAAM,aAAa,CAAC;AAIrB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,EAC/C,YAAY,EAAE,aAAa,GAC1B,gBAAgB,CAiJlB"}
|