@framers/agentos 0.1.97 → 0.1.99
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 +58 -13
- package/dist/api/agency.d.ts +51 -0
- package/dist/api/agency.d.ts.map +1 -0
- package/dist/api/agency.js +645 -0
- package/dist/api/agency.js.map +1 -0
- package/dist/api/agent.d.ts +15 -54
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +14 -7
- package/dist/api/agent.js.map +1 -1
- package/dist/api/generateText.d.ts +16 -0
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js.map +1 -1
- package/dist/api/hitl.d.ts +139 -0
- package/dist/api/hitl.d.ts.map +1 -0
- package/dist/api/hitl.js +211 -0
- package/dist/api/hitl.js.map +1 -0
- package/dist/api/strategies/debate.d.ts +16 -0
- package/dist/api/strategies/debate.d.ts.map +1 -0
- package/dist/api/strategies/debate.js +118 -0
- package/dist/api/strategies/debate.js.map +1 -0
- package/dist/api/strategies/hierarchical.d.ts +20 -0
- package/dist/api/strategies/hierarchical.d.ts.map +1 -0
- package/dist/api/strategies/hierarchical.js +140 -0
- package/dist/api/strategies/hierarchical.js.map +1 -0
- package/dist/api/strategies/index.d.ts +41 -0
- package/dist/api/strategies/index.d.ts.map +1 -0
- package/dist/api/strategies/index.js +95 -0
- package/dist/api/strategies/index.js.map +1 -0
- package/dist/api/strategies/parallel.d.ts +17 -0
- package/dist/api/strategies/parallel.d.ts.map +1 -0
- package/dist/api/strategies/parallel.js +122 -0
- package/dist/api/strategies/parallel.js.map +1 -0
- package/dist/api/strategies/review-loop.d.ts +18 -0
- package/dist/api/strategies/review-loop.d.ts.map +1 -0
- package/dist/api/strategies/review-loop.js +153 -0
- package/dist/api/strategies/review-loop.js.map +1 -0
- package/dist/api/strategies/sequential.d.ts +15 -0
- package/dist/api/strategies/sequential.d.ts.map +1 -0
- package/dist/api/strategies/sequential.js +94 -0
- package/dist/api/strategies/sequential.js.map +1 -0
- package/dist/api/strategies/shared.d.ts +36 -0
- package/dist/api/strategies/shared.d.ts.map +1 -0
- package/dist/api/strategies/shared.js +82 -0
- package/dist/api/strategies/shared.js.map +1 -0
- package/dist/api/types.d.ts +806 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +25 -0
- package/dist/api/types.js.map +1 -0
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts +7 -0
- package/dist/discovery/CapabilityDiscoveryEngine.d.ts.map +1 -1
- package/dist/discovery/CapabilityDiscoveryEngine.js +21 -0
- package/dist/discovery/CapabilityDiscoveryEngine.js.map +1 -1
- package/dist/discovery/types.d.ts +2 -0
- package/dist/discovery/types.d.ts.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.d.ts +16 -0
- package/dist/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.js +51 -0
- package/dist/emergent/EmergentCapabilityEngine.js.map +1 -1
- package/dist/emergent/EmergentToolRegistry.d.ts +8 -0
- package/dist/emergent/EmergentToolRegistry.d.ts.map +1 -1
- package/dist/emergent/EmergentToolRegistry.js +42 -1
- package/dist/emergent/EmergentToolRegistry.js.map +1 -1
- package/dist/emergent/ToolPackage.d.ts +57 -0
- package/dist/emergent/ToolPackage.d.ts.map +1 -0
- package/dist/emergent/ToolPackage.js +145 -0
- package/dist/emergent/ToolPackage.js.map +1 -0
- package/dist/emergent/index.d.ts +2 -0
- package/dist/emergent/index.d.ts.map +1 -1
- package/dist/emergent/index.js +1 -0
- package/dist/emergent/index.js.map +1 -1
- package/dist/emergent/types.d.ts +27 -0
- package/dist/emergent/types.d.ts.map +1 -1
- package/dist/emergent/types.js +2 -0
- package/dist/emergent/types.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file debate.ts
|
|
3
|
+
* Debate strategy compiler for the Agency API.
|
|
4
|
+
*
|
|
5
|
+
* Agents argue in rounds over a shared task. Each round, every agent sees all
|
|
6
|
+
* prior arguments from every other agent, enabling progressive refinement
|
|
7
|
+
* through adversarial discourse. After all rounds complete, a synthesizer
|
|
8
|
+
* distils the collected arguments into a single coherent response.
|
|
9
|
+
*/
|
|
10
|
+
import { agent as createAgent } from '../agent.js';
|
|
11
|
+
import { AgencyConfigError } from '../types.js';
|
|
12
|
+
import { resolveAgent, checkBeforeAgent } from './shared.js';
|
|
13
|
+
/**
|
|
14
|
+
* Compiles a debate execution strategy.
|
|
15
|
+
*
|
|
16
|
+
* Agents are iterated in rounds. During each round, every agent receives the
|
|
17
|
+
* original task plus all previously collected arguments, and contributes its
|
|
18
|
+
* own perspective. After `maxRounds` complete, a synthesizer agent (using the
|
|
19
|
+
* agency-level model) distils all arguments into a final answer.
|
|
20
|
+
*
|
|
21
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
22
|
+
* @param agencyConfig - Agency-level configuration providing fallback model/provider/tools.
|
|
23
|
+
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
24
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available for synthesis.
|
|
25
|
+
*/
|
|
26
|
+
export function compileDebate(agents, agencyConfig) {
|
|
27
|
+
if (!agencyConfig.model && !agencyConfig.provider) {
|
|
28
|
+
throw new AgencyConfigError('Debate strategy requires an agency-level model or provider for result synthesis.');
|
|
29
|
+
}
|
|
30
|
+
const maxRounds = agencyConfig.maxRounds ?? 3;
|
|
31
|
+
return {
|
|
32
|
+
async execute(prompt, opts) {
|
|
33
|
+
const agentCalls = [];
|
|
34
|
+
const entries = Object.entries(agents);
|
|
35
|
+
const totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
36
|
+
const collectedArguments = [];
|
|
37
|
+
for (let round = 0; round < maxRounds; round++) {
|
|
38
|
+
for (const [name, agentOrConfig] of entries) {
|
|
39
|
+
/* HITL: check beforeAgent gate before invoking this agent. */
|
|
40
|
+
const decision = await checkBeforeAgent(name, prompt, agentCalls, agencyConfig);
|
|
41
|
+
if (decision && !decision.approved) {
|
|
42
|
+
/* Agent was rejected — skip this agent in this round. */
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const a = resolveAgent(agentOrConfig, agencyConfig);
|
|
46
|
+
const debateContext = `Task: ${prompt}\n\n` +
|
|
47
|
+
(collectedArguments.length > 0
|
|
48
|
+
? `Previous arguments:\n${collectedArguments.join('\n---\n')}`
|
|
49
|
+
: 'You are the first to argue.') +
|
|
50
|
+
`\n\nPresent your perspective as ${name} (round ${round + 1}/${maxRounds}).`;
|
|
51
|
+
const start = Date.now();
|
|
52
|
+
const result = (await a.generate(debateContext, opts));
|
|
53
|
+
const durationMs = Date.now() - start;
|
|
54
|
+
const resultText = result.text ?? '';
|
|
55
|
+
const resultUsage = result.usage ?? {};
|
|
56
|
+
const resultToolCalls = result.toolCalls ?? [];
|
|
57
|
+
collectedArguments.push(`[${name}, round ${round + 1}]: ${resultText}`);
|
|
58
|
+
agentCalls.push({
|
|
59
|
+
agent: name,
|
|
60
|
+
input: debateContext,
|
|
61
|
+
output: resultText,
|
|
62
|
+
toolCalls: resultToolCalls,
|
|
63
|
+
usage: {
|
|
64
|
+
promptTokens: resultUsage.promptTokens ?? 0,
|
|
65
|
+
completionTokens: resultUsage.completionTokens ?? 0,
|
|
66
|
+
totalTokens: resultUsage.totalTokens ?? 0,
|
|
67
|
+
},
|
|
68
|
+
durationMs,
|
|
69
|
+
});
|
|
70
|
+
totalUsage.promptTokens += resultUsage.promptTokens ?? 0;
|
|
71
|
+
totalUsage.completionTokens += resultUsage.completionTokens ?? 0;
|
|
72
|
+
totalUsage.totalTokens += resultUsage.totalTokens ?? 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/* Synthesize all arguments into a final answer using the agency-level model. */
|
|
76
|
+
const synthInstructions = agencyConfig.instructions
|
|
77
|
+
? `\n\n${agencyConfig.instructions}`
|
|
78
|
+
: '';
|
|
79
|
+
const synthPrompt = `A debate was held on the following task:\n"${prompt}"\n\n` +
|
|
80
|
+
`All arguments:\n${collectedArguments.join('\n---\n')}\n\n` +
|
|
81
|
+
`Synthesize these perspectives into a single coherent answer.${synthInstructions}`;
|
|
82
|
+
const synthesizer = createAgent({
|
|
83
|
+
model: agencyConfig.model,
|
|
84
|
+
provider: agencyConfig.provider,
|
|
85
|
+
apiKey: agencyConfig.apiKey,
|
|
86
|
+
baseUrl: agencyConfig.baseUrl,
|
|
87
|
+
maxSteps: 1,
|
|
88
|
+
});
|
|
89
|
+
const synthesis = (await synthesizer.generate(synthPrompt, opts));
|
|
90
|
+
const synthUsage = synthesis.usage ?? {};
|
|
91
|
+
totalUsage.promptTokens += synthUsage.promptTokens ?? 0;
|
|
92
|
+
totalUsage.completionTokens += synthUsage.completionTokens ?? 0;
|
|
93
|
+
totalUsage.totalTokens += synthUsage.totalTokens ?? 0;
|
|
94
|
+
return { ...synthesis, agentCalls, usage: totalUsage };
|
|
95
|
+
},
|
|
96
|
+
stream(prompt, opts) {
|
|
97
|
+
/*
|
|
98
|
+
* For v1: streaming delegates to execute() and wraps the resolved text
|
|
99
|
+
* as a single-chunk async iterable. A future version will stream the
|
|
100
|
+
* synthesis step in real-time.
|
|
101
|
+
*/
|
|
102
|
+
const resultPromise = this.execute(prompt, opts);
|
|
103
|
+
const textPromise = resultPromise.then((r) => r.text ?? '');
|
|
104
|
+
return {
|
|
105
|
+
textStream: (async function* () {
|
|
106
|
+
yield await textPromise;
|
|
107
|
+
})(),
|
|
108
|
+
fullStream: (async function* () {
|
|
109
|
+
const text = await textPromise;
|
|
110
|
+
yield { type: 'text', text };
|
|
111
|
+
})(),
|
|
112
|
+
text: textPromise,
|
|
113
|
+
usage: resultPromise.then((r) => r.usage),
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
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ACzD,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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgencyOptions, CompiledStrategy, Agent, BaseAgentConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles a hierarchical execution strategy.
|
|
4
|
+
*
|
|
5
|
+
* A manager agent is instantiated from the agency-level model/provider/instructions.
|
|
6
|
+
* Each sub-agent in the roster is exposed as a `delegate_to_<name>` tool that the
|
|
7
|
+
* manager can invoke. When the manager calls a delegation tool, the corresponding
|
|
8
|
+
* sub-agent runs the subtask and its output is returned as the tool result.
|
|
9
|
+
*
|
|
10
|
+
* All sub-agent call records are collected and returned alongside the manager's
|
|
11
|
+
* final synthesized answer.
|
|
12
|
+
*
|
|
13
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
14
|
+
* @param agencyConfig - Agency-level configuration; must include `model` or `provider`
|
|
15
|
+
* for the manager agent.
|
|
16
|
+
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
17
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available for the manager.
|
|
18
|
+
*/
|
|
19
|
+
export declare function compileHierarchical(agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
20
|
+
//# sourceMappingURL=hierarchical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/hierarchical.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAEhB,MAAM,aAAa,CAAC;AAmBrB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,EAC/C,YAAY,EAAE,aAAa,GAC1B,gBAAgB,CAmHlB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file hierarchical.ts
|
|
3
|
+
* Hierarchical strategy compiler for the Agency API.
|
|
4
|
+
*
|
|
5
|
+
* A manager agent (instantiated from the agency-level config) delegates
|
|
6
|
+
* subtasks to sub-agents via tool calls. Each sub-agent is exposed as a
|
|
7
|
+
* `delegate_to_<name>` tool that the manager can invoke to assign work.
|
|
8
|
+
* The manager synthesizes sub-agent outputs into a final answer.
|
|
9
|
+
*/
|
|
10
|
+
import { agent as createAgent } from '../agent.js';
|
|
11
|
+
import { AgencyConfigError } from '../types.js';
|
|
12
|
+
import { isAgent } from './index.js';
|
|
13
|
+
import { resolveAgent, checkBeforeAgent } from './shared.js';
|
|
14
|
+
/**
|
|
15
|
+
* Extracts a human-readable description from an agent config or instance.
|
|
16
|
+
*
|
|
17
|
+
* @param agentOrConfig - Either a pre-built Agent or a raw BaseAgentConfig.
|
|
18
|
+
* @returns The instructions string if available, otherwise a generic label.
|
|
19
|
+
*/
|
|
20
|
+
function getAgentDescription(agentOrConfig) {
|
|
21
|
+
if (!isAgent(agentOrConfig) && agentOrConfig.instructions) {
|
|
22
|
+
return agentOrConfig.instructions;
|
|
23
|
+
}
|
|
24
|
+
return 'General purpose';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compiles a hierarchical execution strategy.
|
|
28
|
+
*
|
|
29
|
+
* A manager agent is instantiated from the agency-level model/provider/instructions.
|
|
30
|
+
* Each sub-agent in the roster is exposed as a `delegate_to_<name>` tool that the
|
|
31
|
+
* manager can invoke. When the manager calls a delegation tool, the corresponding
|
|
32
|
+
* sub-agent runs the subtask and its output is returned as the tool result.
|
|
33
|
+
*
|
|
34
|
+
* All sub-agent call records are collected and returned alongside the manager's
|
|
35
|
+
* final synthesized answer.
|
|
36
|
+
*
|
|
37
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
38
|
+
* @param agencyConfig - Agency-level configuration; must include `model` or `provider`
|
|
39
|
+
* for the manager agent.
|
|
40
|
+
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
41
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available for the manager.
|
|
42
|
+
*/
|
|
43
|
+
export function compileHierarchical(agents, agencyConfig) {
|
|
44
|
+
if (!agencyConfig.model && !agencyConfig.provider) {
|
|
45
|
+
throw new AgencyConfigError('Hierarchical strategy requires an agency-level model or provider for the manager agent.');
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
async execute(prompt, opts) {
|
|
49
|
+
const agentCalls = [];
|
|
50
|
+
/* Build one tool per sub-agent for the manager to delegate to. */
|
|
51
|
+
const agentTools = {};
|
|
52
|
+
for (const [name, agentOrConfig] of Object.entries(agents)) {
|
|
53
|
+
const description = getAgentDescription(agentOrConfig);
|
|
54
|
+
agentTools[`delegate_to_${name}`] = {
|
|
55
|
+
description: `Delegate a subtask to the ${name} agent. ${description}`,
|
|
56
|
+
parameters: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
task: { type: 'string', description: 'The subtask to delegate' },
|
|
60
|
+
},
|
|
61
|
+
required: ['task'],
|
|
62
|
+
},
|
|
63
|
+
execute: async (args) => {
|
|
64
|
+
/* HITL: check beforeAgent gate before delegating to this sub-agent. */
|
|
65
|
+
const decision = await checkBeforeAgent(name, args.task, agentCalls, agencyConfig);
|
|
66
|
+
if (decision && !decision.approved) {
|
|
67
|
+
return { success: false, data: `Agent "${name}" execution was rejected by HITL.` };
|
|
68
|
+
}
|
|
69
|
+
const a = resolveAgent(agentOrConfig, agencyConfig);
|
|
70
|
+
/* Apply instruction modifications from the approval decision if any. */
|
|
71
|
+
const effectiveTask = decision?.modifications?.instructions
|
|
72
|
+
? `${args.task}\n\n[Additional instructions]: ${decision.modifications.instructions}`
|
|
73
|
+
: args.task;
|
|
74
|
+
const start = Date.now();
|
|
75
|
+
const result = (await a.generate(effectiveTask, opts));
|
|
76
|
+
const durationMs = Date.now() - start;
|
|
77
|
+
const resultText = result.text ?? '';
|
|
78
|
+
const resultUsage = result.usage ?? {};
|
|
79
|
+
const resultToolCalls = result.toolCalls ?? [];
|
|
80
|
+
agentCalls.push({
|
|
81
|
+
agent: name,
|
|
82
|
+
input: args.task,
|
|
83
|
+
output: resultText,
|
|
84
|
+
toolCalls: resultToolCalls,
|
|
85
|
+
usage: {
|
|
86
|
+
promptTokens: resultUsage.promptTokens ?? 0,
|
|
87
|
+
completionTokens: resultUsage.completionTokens ?? 0,
|
|
88
|
+
totalTokens: resultUsage.totalTokens ?? 0,
|
|
89
|
+
},
|
|
90
|
+
durationMs,
|
|
91
|
+
});
|
|
92
|
+
return { success: true, data: resultText };
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/* Build the team roster description for the manager's system prompt. */
|
|
97
|
+
const teamRoster = Object.entries(agents)
|
|
98
|
+
.map(([name, c]) => `- ${name}: ${getAgentDescription(c)}`)
|
|
99
|
+
.join('\n');
|
|
100
|
+
const managerInstructions = `You are a manager agent. Your task is to accomplish the user's goal by delegating subtasks to your team members.\n\n` +
|
|
101
|
+
`Available team members:\n${teamRoster}\n\n` +
|
|
102
|
+
`Use the delegate_to_<name> tools to assign work. Synthesize their outputs into a final answer.` +
|
|
103
|
+
(agencyConfig.instructions ? `\n\n${agencyConfig.instructions}` : '');
|
|
104
|
+
/* Merge agency-level tools with the delegation tools. */
|
|
105
|
+
const mergedTools = { ...(agencyConfig.tools ?? {}), ...agentTools };
|
|
106
|
+
const manager = createAgent({
|
|
107
|
+
model: agencyConfig.model,
|
|
108
|
+
provider: agencyConfig.provider,
|
|
109
|
+
apiKey: agencyConfig.apiKey,
|
|
110
|
+
baseUrl: agencyConfig.baseUrl,
|
|
111
|
+
instructions: managerInstructions,
|
|
112
|
+
tools: mergedTools,
|
|
113
|
+
maxSteps: agencyConfig.maxSteps ?? 10,
|
|
114
|
+
});
|
|
115
|
+
const result = (await manager.generate(prompt, opts));
|
|
116
|
+
return { ...result, agentCalls };
|
|
117
|
+
},
|
|
118
|
+
stream(prompt, opts) {
|
|
119
|
+
/*
|
|
120
|
+
* For v1: streaming delegates to execute() and wraps the resolved text
|
|
121
|
+
* as a single-chunk async iterable. A future version will stream the
|
|
122
|
+
* manager's output in real-time.
|
|
123
|
+
*/
|
|
124
|
+
const resultPromise = this.execute(prompt, opts);
|
|
125
|
+
const textPromise = resultPromise.then((r) => r.text ?? '');
|
|
126
|
+
return {
|
|
127
|
+
textStream: (async function* () {
|
|
128
|
+
yield await textPromise;
|
|
129
|
+
})(),
|
|
130
|
+
fullStream: (async function* () {
|
|
131
|
+
const text = await textPromise;
|
|
132
|
+
yield { type: 'text', text };
|
|
133
|
+
})(),
|
|
134
|
+
text: textPromise,
|
|
135
|
+
usage: resultPromise.then((r) => r.usage),
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=hierarchical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical.js","sourceRoot":"","sources":["../../../src/api/strategies/hierarchical.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAiB,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E;;;;;GAKG;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;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA+C,EAC/C,YAA2B;IAE3B,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;QAClD,MAAM,IAAI,iBAAiB,CACzB,yFAAyF,CAC1F,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI;YACxB,MAAM,UAAU,GAAsB,EAAE,CAAC;YAEzC,kEAAkE;YAClE,MAAM,UAAU,GAAsB,EAAE,CAAC;YACzC,KAAK,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3D,MAAM,WAAW,GAAG,mBAAmB,CAAC,aAAa,CAAC,CAAC;gBAEvD,UAAU,CAAC,eAAe,IAAI,EAAE,CAAC,GAAG;oBAClC,WAAW,EAAE,6BAA6B,IAAI,WAA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AAE,mBAAmB;gBACjC,KAAK,EAAE,WAAW;gBAClB,QAAQ,EAAE,YAAY,CAAC,QAAQ,IAAI,EAAE;aACtC,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAuC,CAAC;YAC5F,OAAO,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC;QACnC,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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* Strategy compiler dispatcher for the Agency API.
|
|
4
|
+
*
|
|
5
|
+
* Maps an {@link AgencyStrategy} discriminant to the concrete compiler that
|
|
6
|
+
* produces a {@link CompiledStrategy}. Supports sequential, parallel, debate,
|
|
7
|
+
* review-loop, and hierarchical strategies. When `adaptive` mode is enabled
|
|
8
|
+
* on a non-hierarchical strategy, the dispatcher wraps it with an implicit
|
|
9
|
+
* hierarchical manager that may override the default strategy at runtime.
|
|
10
|
+
*/
|
|
11
|
+
import type { AgencyStrategy, AgencyOptions, CompiledStrategy, Agent, BaseAgentConfig } from '../types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Compile an orchestration strategy into an executable {@link CompiledStrategy}.
|
|
14
|
+
*
|
|
15
|
+
* When `agencyConfig.adaptive` is `true` and the requested strategy is not
|
|
16
|
+
* already `"hierarchical"`, the compiled strategy is wrapped in an adaptive
|
|
17
|
+
* hierarchical manager that may override the default strategy at runtime
|
|
18
|
+
* based on task complexity signals.
|
|
19
|
+
*
|
|
20
|
+
* @param strategy - Strategy discriminant (e.g. `"sequential"`, `"parallel"`).
|
|
21
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
22
|
+
* @param agencyConfig - Full agency-level configuration providing fallback values.
|
|
23
|
+
* @returns A compiled strategy with `execute` and `stream` methods.
|
|
24
|
+
* @throws {Error} When the requested strategy is not yet implemented.
|
|
25
|
+
*/
|
|
26
|
+
export declare function compileStrategy(strategy: AgencyStrategy, agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard that checks whether a value is a pre-built {@link Agent} instance
|
|
29
|
+
* (has a `generate` method) vs a raw {@link BaseAgentConfig} object.
|
|
30
|
+
*
|
|
31
|
+
* @param value - Either a config object or a running agent.
|
|
32
|
+
* @returns `true` when the value is a pre-built `Agent`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isAgent(value: BaseAgentConfig | Agent): value is Agent;
|
|
35
|
+
export { compileSequential } from './sequential.js';
|
|
36
|
+
export { compileParallel } from './parallel.js';
|
|
37
|
+
export { compileDebate } from './debate.js';
|
|
38
|
+
export { compileReviewLoop } from './review-loop.js';
|
|
39
|
+
export { compileHierarchical } from './hierarchical.js';
|
|
40
|
+
export { mergeDefaults, resolveAgent, checkBeforeAgent } from './shared.js';
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAChB,MAAM,aAAa,CAAC;AAOrB;;;;;;;;;;;;;GAaG;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,CAOlB;AAmED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,GAAG,KAAK,IAAI,KAAK,CAEtE;AAED,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,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { compileSequential } from './sequential.js';
|
|
2
|
+
import { compileParallel } from './parallel.js';
|
|
3
|
+
import { compileDebate } from './debate.js';
|
|
4
|
+
import { compileReviewLoop } from './review-loop.js';
|
|
5
|
+
import { compileHierarchical } from './hierarchical.js';
|
|
6
|
+
/**
|
|
7
|
+
* Compile an orchestration strategy into an executable {@link CompiledStrategy}.
|
|
8
|
+
*
|
|
9
|
+
* When `agencyConfig.adaptive` is `true` and the requested strategy is not
|
|
10
|
+
* already `"hierarchical"`, the compiled strategy is wrapped in an adaptive
|
|
11
|
+
* hierarchical manager that may override the default strategy at runtime
|
|
12
|
+
* based on task complexity signals.
|
|
13
|
+
*
|
|
14
|
+
* @param strategy - Strategy discriminant (e.g. `"sequential"`, `"parallel"`).
|
|
15
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
16
|
+
* @param agencyConfig - Full agency-level configuration providing fallback values.
|
|
17
|
+
* @returns A compiled strategy with `execute` and `stream` methods.
|
|
18
|
+
* @throws {Error} When the requested strategy is not yet implemented.
|
|
19
|
+
*/
|
|
20
|
+
export function compileStrategy(strategy, agents, agencyConfig) {
|
|
21
|
+
/* When adaptive mode is enabled on non-hierarchical strategies, wrap with a manager. */
|
|
22
|
+
if (agencyConfig.adaptive && strategy !== 'hierarchical') {
|
|
23
|
+
return compileAdaptiveWrapper(strategy, agents, agencyConfig);
|
|
24
|
+
}
|
|
25
|
+
return compileStrategyCore(strategy, agents, agencyConfig);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Core strategy compiler without adaptive wrapping.
|
|
29
|
+
*
|
|
30
|
+
* @param strategy - Strategy discriminant.
|
|
31
|
+
* @param agents - Named agent roster.
|
|
32
|
+
* @param agencyConfig - Agency-level configuration.
|
|
33
|
+
* @returns A compiled strategy.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
function compileStrategyCore(strategy, agents, agencyConfig) {
|
|
37
|
+
switch (strategy) {
|
|
38
|
+
case 'sequential':
|
|
39
|
+
return compileSequential(agents, agencyConfig);
|
|
40
|
+
case 'parallel':
|
|
41
|
+
return compileParallel(agents, agencyConfig);
|
|
42
|
+
case 'debate':
|
|
43
|
+
return compileDebate(agents, agencyConfig);
|
|
44
|
+
case 'review-loop':
|
|
45
|
+
return compileReviewLoop(agents, agencyConfig);
|
|
46
|
+
case 'hierarchical':
|
|
47
|
+
return compileHierarchical(agents, agencyConfig);
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Strategy '${strategy}' not yet implemented`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Wraps a non-hierarchical strategy in an adaptive hierarchical manager.
|
|
54
|
+
*
|
|
55
|
+
* The manager prompt declares the default strategy and instructs the manager
|
|
56
|
+
* that it may override strategy selection if the task clearly does not require
|
|
57
|
+
* all agents. In practice, the manager delegates to the sub-agents via tools
|
|
58
|
+
* just like the hierarchical strategy, but with the additional context of the
|
|
59
|
+
* original intended strategy.
|
|
60
|
+
*
|
|
61
|
+
* @param defaultStrategy - The user-declared default strategy.
|
|
62
|
+
* @param agents - Named agent roster.
|
|
63
|
+
* @param agencyConfig - Agency-level configuration.
|
|
64
|
+
* @returns A compiled hierarchical strategy with adaptive instructions.
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
function compileAdaptiveWrapper(defaultStrategy, agents, agencyConfig) {
|
|
68
|
+
const adaptiveInstructions = (agencyConfig.instructions ? agencyConfig.instructions + '\n\n' : '') +
|
|
69
|
+
`Your default strategy is "${defaultStrategy}". You may override it if the task clearly doesn't need all agents. ` +
|
|
70
|
+
`Use your judgment to decide whether to engage all team members or delegate to a subset.`;
|
|
71
|
+
const adaptiveConfig = {
|
|
72
|
+
...agencyConfig,
|
|
73
|
+
instructions: adaptiveInstructions,
|
|
74
|
+
/* Disable adaptive on the inner call to prevent infinite recursion. */
|
|
75
|
+
adaptive: false,
|
|
76
|
+
};
|
|
77
|
+
return compileHierarchical(agents, adaptiveConfig);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Type guard that checks whether a value is a pre-built {@link Agent} instance
|
|
81
|
+
* (has a `generate` method) vs a raw {@link BaseAgentConfig} object.
|
|
82
|
+
*
|
|
83
|
+
* @param value - Either a config object or a running agent.
|
|
84
|
+
* @returns `true` when the value is a pre-built `Agent`.
|
|
85
|
+
*/
|
|
86
|
+
export function isAgent(value) {
|
|
87
|
+
return typeof value.generate === 'function';
|
|
88
|
+
}
|
|
89
|
+
export { compileSequential } from './sequential.js';
|
|
90
|
+
export { compileParallel } from './parallel.js';
|
|
91
|
+
export { compileDebate } from './debate.js';
|
|
92
|
+
export { compileReviewLoop } from './review-loop.js';
|
|
93
|
+
export { compileHierarchical } from './hierarchical.js';
|
|
94
|
+
export { mergeDefaults, resolveAgent, checkBeforeAgent } from './shared.js';
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/strategies/index.ts"],"names":[],"mappings":"AAiBA,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;AAExD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAwB,EACxB,MAA+C,EAC/C,YAA2B;IAE3B,wFAAwF;IACxF,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;;;;;;;;GAQG;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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aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AgencyOptions, CompiledStrategy, Agent, BaseAgentConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles a parallel execution strategy.
|
|
4
|
+
*
|
|
5
|
+
* All agents are invoked concurrently with the same prompt via
|
|
6
|
+
* `Promise.all`. Once every agent has responded, a synthesis agent
|
|
7
|
+
* (instantiated from the agency-level config) combines the individual
|
|
8
|
+
* outputs into a single coherent response.
|
|
9
|
+
*
|
|
10
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
11
|
+
* @param agencyConfig - Agency-level configuration; must include `model` or `provider`
|
|
12
|
+
* for the synthesis step.
|
|
13
|
+
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
14
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available for synthesis.
|
|
15
|
+
*/
|
|
16
|
+
export declare function compileParallel(agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
17
|
+
//# sourceMappingURL=parallel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/parallel.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAEhB,MAAM,aAAa,CAAC;AAKrB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,EAC/C,YAAY,EAAE,aAAa,GAC1B,gBAAgB,CAoHlB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file parallel.ts
|
|
3
|
+
* Parallel strategy compiler for the Agency API.
|
|
4
|
+
*
|
|
5
|
+
* Runs all agents concurrently on the same prompt, then synthesizes their
|
|
6
|
+
* outputs into a single coherent response using the agency-level model.
|
|
7
|
+
* Requires an agency-level `model` or `provider` for the synthesis step.
|
|
8
|
+
*/
|
|
9
|
+
import { agent as createAgent } from '../agent.js';
|
|
10
|
+
import { AgencyConfigError } from '../types.js';
|
|
11
|
+
import { isAgent } from './index.js';
|
|
12
|
+
import { mergeDefaults, checkBeforeAgent } from './shared.js';
|
|
13
|
+
/**
|
|
14
|
+
* Compiles a parallel execution strategy.
|
|
15
|
+
*
|
|
16
|
+
* All agents are invoked concurrently with the same prompt via
|
|
17
|
+
* `Promise.all`. Once every agent has responded, a synthesis agent
|
|
18
|
+
* (instantiated from the agency-level config) combines the individual
|
|
19
|
+
* outputs into a single coherent response.
|
|
20
|
+
*
|
|
21
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
22
|
+
* @param agencyConfig - Agency-level configuration; must include `model` or `provider`
|
|
23
|
+
* for the synthesis step.
|
|
24
|
+
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
25
|
+
* @throws {AgencyConfigError} When no agency-level model/provider is available for synthesis.
|
|
26
|
+
*/
|
|
27
|
+
export function compileParallel(agents, agencyConfig) {
|
|
28
|
+
if (!agencyConfig.model && !agencyConfig.provider) {
|
|
29
|
+
throw new AgencyConfigError('Parallel strategy requires an agency-level model or provider for result synthesis.');
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
async execute(prompt, opts) {
|
|
33
|
+
/* Run every agent concurrently, gated by beforeAgent HITL. */
|
|
34
|
+
const entries = Object.entries(agents);
|
|
35
|
+
const settled = (await Promise.all(entries.map(async ([name, agentOrConfig]) => {
|
|
36
|
+
/* HITL: check beforeAgent gate before invoking this agent. */
|
|
37
|
+
const decision = await checkBeforeAgent(name, prompt, [], agencyConfig);
|
|
38
|
+
if (decision && !decision.approved) {
|
|
39
|
+
/* Agent was rejected — exclude from results. */
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const a = isAgent(agentOrConfig)
|
|
43
|
+
? agentOrConfig
|
|
44
|
+
: createAgent({ ...mergeDefaults(agentOrConfig, agencyConfig) });
|
|
45
|
+
/* Apply instruction modifications from the approval decision if any. */
|
|
46
|
+
const effectivePrompt = decision?.modifications?.instructions
|
|
47
|
+
? `${prompt}\n\n[Additional instructions]: ${decision.modifications.instructions}`
|
|
48
|
+
: prompt;
|
|
49
|
+
const start = Date.now();
|
|
50
|
+
const result = (await a.generate(effectivePrompt, opts));
|
|
51
|
+
const durationMs = Date.now() - start;
|
|
52
|
+
return { name, result, durationMs };
|
|
53
|
+
}))).filter((r) => r !== null);
|
|
54
|
+
/* Collect agent call records and aggregate usage. */
|
|
55
|
+
const agentCalls = [];
|
|
56
|
+
const totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
57
|
+
for (const { name, result, durationMs } of settled) {
|
|
58
|
+
const resultUsage = result.usage ?? {};
|
|
59
|
+
const resultToolCalls = result.toolCalls ?? [];
|
|
60
|
+
agentCalls.push({
|
|
61
|
+
agent: name,
|
|
62
|
+
input: prompt,
|
|
63
|
+
output: result.text ?? '',
|
|
64
|
+
toolCalls: resultToolCalls,
|
|
65
|
+
usage: {
|
|
66
|
+
promptTokens: resultUsage.promptTokens ?? 0,
|
|
67
|
+
completionTokens: resultUsage.completionTokens ?? 0,
|
|
68
|
+
totalTokens: resultUsage.totalTokens ?? 0,
|
|
69
|
+
},
|
|
70
|
+
durationMs,
|
|
71
|
+
});
|
|
72
|
+
totalUsage.promptTokens += resultUsage.promptTokens ?? 0;
|
|
73
|
+
totalUsage.completionTokens += resultUsage.completionTokens ?? 0;
|
|
74
|
+
totalUsage.totalTokens += resultUsage.totalTokens ?? 0;
|
|
75
|
+
}
|
|
76
|
+
/* Synthesize outputs using the agency-level model. */
|
|
77
|
+
const agentOutputsBlock = settled
|
|
78
|
+
.map(({ name, result }) => `--- ${name} ---\n${result.text ?? ''}`)
|
|
79
|
+
.join('\n\n');
|
|
80
|
+
const synthInstructions = agencyConfig.instructions
|
|
81
|
+
? `\n\n${agencyConfig.instructions}`
|
|
82
|
+
: '';
|
|
83
|
+
const synthPrompt = `Multiple agents analyzed the following task:\n"${prompt}"\n\n` +
|
|
84
|
+
`${agentOutputsBlock}\n\n` +
|
|
85
|
+
`Synthesize these into a single coherent response.${synthInstructions}`;
|
|
86
|
+
const synthesizer = createAgent({
|
|
87
|
+
model: agencyConfig.model,
|
|
88
|
+
provider: agencyConfig.provider,
|
|
89
|
+
apiKey: agencyConfig.apiKey,
|
|
90
|
+
baseUrl: agencyConfig.baseUrl,
|
|
91
|
+
maxSteps: 1,
|
|
92
|
+
});
|
|
93
|
+
const synthesis = (await synthesizer.generate(synthPrompt, opts));
|
|
94
|
+
const synthUsage = synthesis.usage ?? {};
|
|
95
|
+
totalUsage.promptTokens += synthUsage.promptTokens ?? 0;
|
|
96
|
+
totalUsage.completionTokens += synthUsage.completionTokens ?? 0;
|
|
97
|
+
totalUsage.totalTokens += synthUsage.totalTokens ?? 0;
|
|
98
|
+
return { ...synthesis, agentCalls, usage: totalUsage };
|
|
99
|
+
},
|
|
100
|
+
stream(prompt, opts) {
|
|
101
|
+
/*
|
|
102
|
+
* For v1: streaming delegates to execute() and wraps the resolved text
|
|
103
|
+
* as a single-chunk async iterable. A future version will stream the
|
|
104
|
+
* synthesis step in real-time.
|
|
105
|
+
*/
|
|
106
|
+
const resultPromise = this.execute(prompt, opts);
|
|
107
|
+
const textPromise = resultPromise.then((r) => r.text ?? '');
|
|
108
|
+
return {
|
|
109
|
+
textStream: (async function* () {
|
|
110
|
+
yield await textPromise;
|
|
111
|
+
})(),
|
|
112
|
+
fullStream: (async function* () {
|
|
113
|
+
const text = await textPromise;
|
|
114
|
+
yield { type: 'text', text };
|
|
115
|
+
})(),
|
|
116
|
+
text: textPromise,
|
|
117
|
+
usage: resultPromise.then((r) => r.usage),
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=parallel.js.map
|
|
@@ -0,0 +1 @@
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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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgencyOptions, CompiledStrategy, Agent, BaseAgentConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles a review-loop execution strategy.
|
|
4
|
+
*
|
|
5
|
+
* The first declared agent acts as the producer, the second as the reviewer.
|
|
6
|
+
* The producer generates or revises a draft, then the reviewer evaluates it.
|
|
7
|
+
* If the reviewer approves (responds with `{ "approved": true }`), the loop
|
|
8
|
+
* terminates early. Otherwise the reviewer's feedback is fed back into the
|
|
9
|
+
* producer for revision, up to `maxRounds` iterations.
|
|
10
|
+
*
|
|
11
|
+
* @param agents - Named roster of agent configs or pre-built `Agent` instances.
|
|
12
|
+
* At least two agents are required (producer + reviewer).
|
|
13
|
+
* @param agencyConfig - Agency-level configuration providing fallback model/provider/tools.
|
|
14
|
+
* @returns A {@link CompiledStrategy} with `execute` and `stream` methods.
|
|
15
|
+
* @throws {AgencyConfigError} When fewer than two agents are provided.
|
|
16
|
+
*/
|
|
17
|
+
export declare function compileReviewLoop(agents: Record<string, BaseAgentConfig | Agent>, agencyConfig: AgencyOptions): CompiledStrategy;
|
|
18
|
+
//# sourceMappingURL=review-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review-loop.d.ts","sourceRoot":"","sources":["../../../src/api/strategies/review-loop.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,eAAe,EAEhB,MAAM,aAAa,CAAC;AA8BrB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,EAC/C,YAAY,EAAE,aAAa,GAC1B,gBAAgB,CAqIlB"}
|