@directive-run/ai 0.4.0 → 0.4.2
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/anthropic.cjs.map +1 -1
- package/dist/anthropic.js.map +1 -1
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.js.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +165 -26
- package/dist/index.d.ts +165 -26
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{multi-agent-orchestrator-YFs28JsF.d.cts → multi-agent-orchestrator-CFOzWVNd.d.cts} +274 -86
- package/dist/{multi-agent-orchestrator-D-WuP4jP.d.ts → multi-agent-orchestrator-CH-4Fqzg.d.ts} +274 -86
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.js.map +1 -1
- package/dist/openai.cjs.map +1 -1
- package/dist/openai.js.map +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +7 -1
- package/dist/testing.d.ts +7 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
package/dist/{multi-agent-orchestrator-D-WuP4jP.d.ts → multi-agent-orchestrator-CH-4Fqzg.d.ts}
RENAMED
|
@@ -130,9 +130,13 @@ interface AgentMemory {
|
|
|
130
130
|
import(state: MemoryState): void;
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
* Create a sliding window memory strategy.
|
|
133
|
+
* Create a sliding window memory strategy that keeps the most recent N messages.
|
|
134
134
|
*
|
|
135
|
-
*
|
|
135
|
+
* Messages beyond `maxMessages` are moved to the summarization queue.
|
|
136
|
+
* The most recent `preserveRecentCount` messages are always kept.
|
|
137
|
+
*
|
|
138
|
+
* @param defaultConfig - Default strategy configuration (can be overridden per-call).
|
|
139
|
+
* @returns A {@link MemoryStrategy} function.
|
|
136
140
|
*
|
|
137
141
|
* @example
|
|
138
142
|
* ```typescript
|
|
@@ -141,12 +145,17 @@ interface AgentMemory {
|
|
|
141
145
|
* preserveRecentCount: 10,
|
|
142
146
|
* });
|
|
143
147
|
* ```
|
|
148
|
+
* @public
|
|
144
149
|
*/
|
|
145
150
|
declare function createSlidingWindowStrategy(defaultConfig?: MemoryStrategyConfig): MemoryStrategy;
|
|
146
151
|
/**
|
|
147
|
-
* Create a token-based memory strategy.
|
|
152
|
+
* Create a token-based memory strategy that keeps messages until a token limit is reached.
|
|
153
|
+
*
|
|
154
|
+
* Adds messages from newest to oldest until `maxTokens` would be exceeded,
|
|
155
|
+
* then moves the remaining older messages to the summarization queue.
|
|
148
156
|
*
|
|
149
|
-
*
|
|
157
|
+
* @param defaultConfig - Default strategy configuration (can be overridden per-call).
|
|
158
|
+
* @returns A {@link MemoryStrategy} function.
|
|
150
159
|
*
|
|
151
160
|
* @example
|
|
152
161
|
* ```typescript
|
|
@@ -155,11 +164,18 @@ declare function createSlidingWindowStrategy(defaultConfig?: MemoryStrategyConfi
|
|
|
155
164
|
* preserveRecentCount: 5,
|
|
156
165
|
* });
|
|
157
166
|
* ```
|
|
167
|
+
* @public
|
|
158
168
|
*/
|
|
159
169
|
declare function createTokenBasedStrategy(defaultConfig?: MemoryStrategyConfig): MemoryStrategy;
|
|
160
170
|
/**
|
|
161
171
|
* Create a hybrid strategy that combines message count and token limits.
|
|
162
172
|
*
|
|
173
|
+
* Applies both {@link createSlidingWindowStrategy} and {@link createTokenBasedStrategy},
|
|
174
|
+
* then uses whichever result keeps fewer messages (the more restrictive outcome).
|
|
175
|
+
*
|
|
176
|
+
* @param defaultConfig - Default strategy configuration (can be overridden per-call).
|
|
177
|
+
* @returns A {@link MemoryStrategy} function.
|
|
178
|
+
*
|
|
163
179
|
* @example
|
|
164
180
|
* ```typescript
|
|
165
181
|
* const strategy = createHybridStrategy({
|
|
@@ -168,10 +184,18 @@ declare function createTokenBasedStrategy(defaultConfig?: MemoryStrategyConfig):
|
|
|
168
184
|
* preserveRecentCount: 5,
|
|
169
185
|
* });
|
|
170
186
|
* ```
|
|
187
|
+
* @public
|
|
171
188
|
*/
|
|
172
189
|
declare function createHybridStrategy(defaultConfig?: MemoryStrategyConfig): MemoryStrategy;
|
|
173
190
|
/**
|
|
174
|
-
* Create an agent memory instance.
|
|
191
|
+
* Create an agent memory instance for managing conversation history.
|
|
192
|
+
*
|
|
193
|
+
* Provides sliding window management, automatic summarization of older messages,
|
|
194
|
+
* and import/export for persistence. Pass the returned instance to an orchestrator's
|
|
195
|
+
* `memory` option to auto-inject context and auto-store results.
|
|
196
|
+
*
|
|
197
|
+
* @param config - Memory configuration including strategy, optional summarizer, and auto-manage settings.
|
|
198
|
+
* @returns An {@link AgentMemory} instance with `addMessage`, `getContextMessages`, `manage`, and `export`/`import` APIs.
|
|
175
199
|
*
|
|
176
200
|
* @example
|
|
177
201
|
* ```typescript
|
|
@@ -190,20 +214,38 @@ declare function createHybridStrategy(defaultConfig?: MemoryStrategyConfig): Mem
|
|
|
190
214
|
* autoManage: true,
|
|
191
215
|
* });
|
|
192
216
|
* ```
|
|
217
|
+
* @public
|
|
193
218
|
*/
|
|
194
219
|
declare function createAgentMemory(config: AgentMemoryConfig): AgentMemory;
|
|
195
220
|
/**
|
|
196
|
-
* Create a simple truncation
|
|
197
|
-
*
|
|
221
|
+
* Create a simple truncation summarizer that clips messages to a maximum length.
|
|
222
|
+
*
|
|
223
|
+
* Useful for testing or when LLM-based summarization is not needed.
|
|
224
|
+
* Concatenates non-system messages with role prefixes and truncates to `maxLength`.
|
|
225
|
+
*
|
|
226
|
+
* @param maxLength - Maximum character length of the summary (default: 500).
|
|
227
|
+
* @returns A {@link MessageSummarizer} function.
|
|
228
|
+
* @public
|
|
198
229
|
*/
|
|
199
230
|
declare function createTruncationSummarizer(maxLength?: number): MessageSummarizer;
|
|
200
231
|
/**
|
|
201
|
-
* Create a summarizer that extracts
|
|
232
|
+
* Create a summarizer that extracts user questions from messages.
|
|
233
|
+
*
|
|
234
|
+
* Scans for sentences ending with `?` in user messages and lists them as key topics.
|
|
235
|
+
*
|
|
236
|
+
* @returns A {@link MessageSummarizer} function.
|
|
237
|
+
* @public
|
|
202
238
|
*/
|
|
203
239
|
declare function createKeyPointsSummarizer(): MessageSummarizer;
|
|
204
240
|
/**
|
|
205
|
-
* Create a summarizer
|
|
206
|
-
*
|
|
241
|
+
* Create a summarizer that delegates to an LLM for conversation compression.
|
|
242
|
+
*
|
|
243
|
+
* You provide the LLM call function; this handles prompt construction
|
|
244
|
+
* including length limits and key-fact preservation instructions.
|
|
245
|
+
*
|
|
246
|
+
* @param llmCall - Async function that sends a prompt to an LLM and returns the response text.
|
|
247
|
+
* @param options - Optional `maxSummaryLength` and `preserveKeyFacts` settings.
|
|
248
|
+
* @returns A {@link MessageSummarizer} function.
|
|
207
249
|
*
|
|
208
250
|
* @example
|
|
209
251
|
* ```typescript
|
|
@@ -215,6 +257,7 @@ declare function createKeyPointsSummarizer(): MessageSummarizer;
|
|
|
215
257
|
* return response.choices[0].message.content ?? '';
|
|
216
258
|
* });
|
|
217
259
|
* ```
|
|
260
|
+
* @public
|
|
218
261
|
*/
|
|
219
262
|
declare function createLLMSummarizer(llmCall: (prompt: string) => Promise<string>, options?: {
|
|
220
263
|
maxSummaryLength?: number;
|
|
@@ -549,6 +592,12 @@ interface MergedTaggedStreamResult {
|
|
|
549
592
|
/** Number of chunks dropped due to buffer overflow */
|
|
550
593
|
getDroppedCount: () => number;
|
|
551
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* Merge multiple tagged async iterables into a single multiplexed stream.
|
|
597
|
+
*
|
|
598
|
+
* @param sources - Array of tagged source streams to merge.
|
|
599
|
+
* @returns A merged stream result with a `getDroppedCount` accessor.
|
|
600
|
+
*/
|
|
552
601
|
declare function mergeTaggedStreams(sources: TaggedSource[]): MergedTaggedStreamResult;
|
|
553
602
|
|
|
554
603
|
/**
|
|
@@ -953,11 +1002,19 @@ interface AgentOrchestrator<F extends Record<string, unknown>> {
|
|
|
953
1002
|
dispose(): void;
|
|
954
1003
|
}
|
|
955
1004
|
/**
|
|
956
|
-
* Create a constraint-driven agent orchestrator.
|
|
1005
|
+
* Create a constraint-driven agent orchestrator backed by a Directive System.
|
|
1006
|
+
*
|
|
1007
|
+
* Wraps a single agent runner with reactive state, guardrails, streaming,
|
|
1008
|
+
* approval workflows, breakpoints, structured output, and lifecycle hooks.
|
|
1009
|
+
* Constraints and resolvers let you declaratively control agent behavior
|
|
1010
|
+
* based on runtime facts.
|
|
1011
|
+
*
|
|
1012
|
+
* @param options - Orchestrator configuration including runner, guardrails, constraints, and plugins.
|
|
1013
|
+
* @returns An {@link AgentOrchestrator} instance with `run`, `runStream`, `approve`/`reject`, and checkpoint APIs.
|
|
957
1014
|
*
|
|
958
1015
|
* @example
|
|
959
1016
|
* ```typescript
|
|
960
|
-
* import { run as runner } from '@openai/agents'
|
|
1017
|
+
* import { run as runner } from '@openai/agents';
|
|
961
1018
|
*
|
|
962
1019
|
* const orchestrator = createAgentOrchestrator({
|
|
963
1020
|
* runner,
|
|
@@ -994,7 +1051,8 @@ interface AgentOrchestrator<F extends Record<string, unknown>> {
|
|
|
994
1051
|
* const result = await orchestrator.run(myAgent, 'Hello, can you help me?');
|
|
995
1052
|
* ```
|
|
996
1053
|
*
|
|
997
|
-
* @throws
|
|
1054
|
+
* @throws If autoApproveToolCalls is false but no onApprovalRequest callback is provided
|
|
1055
|
+
* @public
|
|
998
1056
|
*/
|
|
999
1057
|
declare function createAgentOrchestrator<F extends Record<string, unknown> = Record<string, never>>(options: OrchestratorOptions<F>): AgentOrchestrator<F>;
|
|
1000
1058
|
|
|
@@ -1150,11 +1208,39 @@ declare class ReflectionExhaustedError extends Error {
|
|
|
1150
1208
|
*/
|
|
1151
1209
|
declare function withReflection<T = unknown>(runner: AgentRunner, config: ReflectionConfig<T>): AgentRunner;
|
|
1152
1210
|
|
|
1153
|
-
/**
|
|
1211
|
+
/**
|
|
1212
|
+
* Get the current step/round/iteration count from a pattern checkpoint state.
|
|
1213
|
+
*
|
|
1214
|
+
* Maps each pattern type to its natural progress counter: `step` for sequential
|
|
1215
|
+
* and goal, `round` for supervisor and debate, `iteration` for reflect, and
|
|
1216
|
+
* `completedCount` for DAG.
|
|
1217
|
+
*
|
|
1218
|
+
* @param state - The pattern checkpoint state to inspect.
|
|
1219
|
+
* @returns The current progress count for the pattern.
|
|
1220
|
+
*/
|
|
1154
1221
|
declare function getPatternStep(state: PatternCheckpointState): number;
|
|
1155
|
-
/**
|
|
1222
|
+
/**
|
|
1223
|
+
* Compute progress metrics from a pattern checkpoint state.
|
|
1224
|
+
*
|
|
1225
|
+
* Returns percentage complete, steps completed/remaining, tokens consumed,
|
|
1226
|
+
* and estimated tokens remaining (when computable). Each pattern type
|
|
1227
|
+
* calculates these metrics from its own state structure.
|
|
1228
|
+
*
|
|
1229
|
+
* @param state - The pattern checkpoint state to analyze.
|
|
1230
|
+
* @returns A {@link CheckpointProgress} object with completion metrics.
|
|
1231
|
+
*/
|
|
1156
1232
|
declare function getCheckpointProgress(state: PatternCheckpointState): CheckpointProgress;
|
|
1157
|
-
/**
|
|
1233
|
+
/**
|
|
1234
|
+
* Compute the diff between two checkpoint states of the same pattern type.
|
|
1235
|
+
*
|
|
1236
|
+
* Returns the delta in steps, tokens, and time between checkpoints.
|
|
1237
|
+
* Useful for understanding how much progress occurred between saves.
|
|
1238
|
+
*
|
|
1239
|
+
* @param a - The earlier checkpoint state.
|
|
1240
|
+
* @param b - The later checkpoint state.
|
|
1241
|
+
* @returns A {@link CheckpointDiff} with step, token, and time deltas.
|
|
1242
|
+
* @throws If the two checkpoints have different pattern types.
|
|
1243
|
+
*/
|
|
1158
1244
|
declare function diffCheckpoints(a: PatternCheckpointState, b: PatternCheckpointState): CheckpointDiff;
|
|
1159
1245
|
/**
|
|
1160
1246
|
* Fork an orchestrator from a checkpoint — creates a new independent orchestrator
|
|
@@ -1776,7 +1862,10 @@ interface MultiAgentOrchestrator {
|
|
|
1776
1862
|
*
|
|
1777
1863
|
* Each registered agent becomes a namespaced Directive module with reactive state,
|
|
1778
1864
|
* constraint evaluation, guardrails, streaming, approval, memory, retry, budget,
|
|
1779
|
-
* hooks, and time-travel debugging
|
|
1865
|
+
* hooks, and time-travel debugging -- all features at parity with {@link createAgentOrchestrator}.
|
|
1866
|
+
*
|
|
1867
|
+
* @param options - Orchestrator configuration including runner, agent registry, patterns, guardrails, and plugins.
|
|
1868
|
+
* @returns A {@link MultiAgentOrchestrator} instance with `runAgent`, `runPattern`, `handoff`, and checkpoint APIs.
|
|
1780
1869
|
*
|
|
1781
1870
|
* @example
|
|
1782
1871
|
* ```typescript
|
|
@@ -1808,22 +1897,24 @@ interface MultiAgentOrchestrator {
|
|
|
1808
1897
|
* }
|
|
1809
1898
|
* ```
|
|
1810
1899
|
*
|
|
1811
|
-
* @throws
|
|
1812
|
-
* @throws
|
|
1900
|
+
* @throws If a pattern references an agent that is not in the registry
|
|
1901
|
+
* @throws If autoApproveToolCalls is false but no onApprovalRequest callback is provided
|
|
1902
|
+
* @public
|
|
1813
1903
|
*/
|
|
1814
1904
|
declare function createMultiAgentOrchestrator(options: MultiAgentOrchestratorOptions): MultiAgentOrchestrator;
|
|
1815
1905
|
/**
|
|
1816
|
-
* Create a parallel pattern
|
|
1906
|
+
* Create a parallel execution pattern that runs handlers concurrently and merges results.
|
|
1817
1907
|
*
|
|
1818
|
-
* @param handlers - Handler IDs (agents or tasks) to run concurrently
|
|
1819
|
-
* @param merge - Combine all handler results into a single output
|
|
1820
|
-
* @param options - Optional `minSuccess` and `timeout` overrides
|
|
1908
|
+
* @param handlers - Handler IDs (agents or tasks) to run concurrently.
|
|
1909
|
+
* @param merge - Combine all handler results into a single output (array may be shorter than handlers when `minSuccess` is set).
|
|
1910
|
+
* @param options - Optional `minSuccess` and `timeout` overrides.
|
|
1911
|
+
* @returns A {@link ParallelPattern} configuration object.
|
|
1821
1912
|
*
|
|
1822
1913
|
* @example
|
|
1823
1914
|
* ```typescript
|
|
1824
1915
|
* const researchPattern = parallel(
|
|
1825
1916
|
* ['researcher', 'researcher', 'researcher'],
|
|
1826
|
-
* (results) => results.map(r => r.output).join('\n')
|
|
1917
|
+
* (results) => results.map(r => r.output).join('\n'),
|
|
1827
1918
|
* );
|
|
1828
1919
|
* ```
|
|
1829
1920
|
*/
|
|
@@ -1832,16 +1923,17 @@ declare function parallel<T>(handlers: string[], merge: (results: RunResult<unkn
|
|
|
1832
1923
|
timeout?: number;
|
|
1833
1924
|
}): ParallelPattern<T>;
|
|
1834
1925
|
/**
|
|
1835
|
-
* Create a sequential pattern
|
|
1926
|
+
* Create a sequential execution pattern that pipes output from one handler to the next.
|
|
1836
1927
|
*
|
|
1837
|
-
* @param handlers - Handler IDs (agents or tasks) to run in order
|
|
1838
|
-
* @param options - Optional `transform`, `extract`, `continueOnError`
|
|
1928
|
+
* @param handlers - Handler IDs (agents or tasks) to run in order, where each handler's output feeds as input to the next.
|
|
1929
|
+
* @param options - Optional `transform`, `extract`, and `continueOnError` overrides.
|
|
1930
|
+
* @returns A {@link SequentialPattern} configuration object.
|
|
1839
1931
|
*
|
|
1840
1932
|
* @example
|
|
1841
1933
|
* ```typescript
|
|
1842
1934
|
* const writeReviewPattern = sequential(
|
|
1843
1935
|
* ['writer', 'reviewer'],
|
|
1844
|
-
* { transform: (output) => `Review this: ${output}` }
|
|
1936
|
+
* { transform: (output) => `Review this: ${output}` },
|
|
1845
1937
|
* );
|
|
1846
1938
|
* ```
|
|
1847
1939
|
*/
|
|
@@ -1851,18 +1943,22 @@ declare function sequential<T>(handlers: string[], options?: {
|
|
|
1851
1943
|
continueOnError?: boolean;
|
|
1852
1944
|
}): SequentialPattern<T>;
|
|
1853
1945
|
/**
|
|
1854
|
-
* Create a supervisor pattern
|
|
1946
|
+
* Create a supervisor pattern where a coordinating agent delegates work to a pool of workers.
|
|
1855
1947
|
*
|
|
1856
|
-
*
|
|
1857
|
-
*
|
|
1858
|
-
*
|
|
1948
|
+
* The supervisor runs first, then dispatches tasks to workers based on its output.
|
|
1949
|
+
* This repeats for up to `maxRounds` until the supervisor signals completion.
|
|
1950
|
+
*
|
|
1951
|
+
* @param supervisorAgent - Agent ID that coordinates the workers.
|
|
1952
|
+
* @param workers - Agent IDs for the worker pool.
|
|
1953
|
+
* @param options - Optional `maxRounds` and `extract` overrides.
|
|
1954
|
+
* @returns A {@link SupervisorPattern} configuration object.
|
|
1859
1955
|
*
|
|
1860
1956
|
* @example
|
|
1861
1957
|
* ```typescript
|
|
1862
1958
|
* const managedPattern = supervisor(
|
|
1863
1959
|
* 'manager',
|
|
1864
1960
|
* ['worker1', 'worker2'],
|
|
1865
|
-
* { maxRounds: 3 }
|
|
1961
|
+
* { maxRounds: 3 },
|
|
1866
1962
|
* );
|
|
1867
1963
|
* ```
|
|
1868
1964
|
*/
|
|
@@ -1871,11 +1967,15 @@ declare function supervisor<T>(supervisorAgent: string, workers: string[], optio
|
|
|
1871
1967
|
extract?: (supervisorOutput: unknown, workerResults: RunResult<unknown>[]) => T;
|
|
1872
1968
|
}): SupervisorPattern<T>;
|
|
1873
1969
|
/**
|
|
1874
|
-
* Create a DAG execution pattern.
|
|
1970
|
+
* Create a directed acyclic graph (DAG) execution pattern.
|
|
1971
|
+
*
|
|
1972
|
+
* Nodes run concurrently when their dependencies are satisfied. The runtime
|
|
1973
|
+
* validates the graph is acyclic and that all dependency references are valid.
|
|
1875
1974
|
*
|
|
1876
|
-
* @param nodes - Node definitions keyed by ID, each with `handler` and optional `deps`
|
|
1877
|
-
* @param merge - Combine DAG outputs into a single result (defaults to `context.outputs`)
|
|
1878
|
-
* @param options - Optional `timeout`, `maxConcurrent`, `onNodeError`
|
|
1975
|
+
* @param nodes - Node definitions keyed by ID, each with a `handler` and optional `deps` array.
|
|
1976
|
+
* @param merge - Combine DAG outputs into a single result (defaults to `context.outputs`).
|
|
1977
|
+
* @param options - Optional `timeout`, `maxConcurrent`, and `onNodeError` strategy.
|
|
1978
|
+
* @returns A {@link DagPattern} configuration object.
|
|
1879
1979
|
*
|
|
1880
1980
|
* @example
|
|
1881
1981
|
* ```typescript
|
|
@@ -1903,11 +2003,16 @@ declare function dag<T = Record<string, unknown>>(nodes: Record<string, DagNode>
|
|
|
1903
2003
|
onNodeError?: "fail" | "skip-downstream" | "continue";
|
|
1904
2004
|
}): DagPattern<T>;
|
|
1905
2005
|
/**
|
|
1906
|
-
* Create a reflect pattern
|
|
2006
|
+
* Create a reflect pattern that iterates between a producer and evaluator until quality is met.
|
|
1907
2007
|
*
|
|
1908
|
-
*
|
|
1909
|
-
*
|
|
1910
|
-
*
|
|
2008
|
+
* The producer generates output, then the evaluator scores it. If the score
|
|
2009
|
+
* is below the threshold, the producer retries with evaluator feedback,
|
|
2010
|
+
* up to `maxIterations` times.
|
|
2011
|
+
*
|
|
2012
|
+
* @param handler - Producer handler ID (agent or task) that generates output.
|
|
2013
|
+
* @param evaluator - Evaluator handler ID that judges quality and provides feedback.
|
|
2014
|
+
* @param options - Optional iteration, parsing, signal, and threshold configuration.
|
|
2015
|
+
* @returns A {@link ReflectPattern} configuration object.
|
|
1911
2016
|
*
|
|
1912
2017
|
* @example
|
|
1913
2018
|
* ```typescript
|
|
@@ -1926,10 +2031,14 @@ declare function reflect<T>(handler: string, evaluator: string, options?: {
|
|
|
1926
2031
|
threshold?: number | ((iteration: number) => number);
|
|
1927
2032
|
}): ReflectPattern<T>;
|
|
1928
2033
|
/**
|
|
1929
|
-
* Create a race pattern
|
|
2034
|
+
* Create a race pattern that runs handlers concurrently and returns the first successful result.
|
|
2035
|
+
*
|
|
2036
|
+
* All handlers start simultaneously. The first to complete successfully wins;
|
|
2037
|
+
* remaining handlers are aborted. Use `minSuccess` to wait for N results before picking.
|
|
1930
2038
|
*
|
|
1931
|
-
* @param handlers - Handler IDs (agents or tasks) to race concurrently
|
|
1932
|
-
* @param options - Optional `extract`, `timeout`, `minSuccess`, `signal`
|
|
2039
|
+
* @param handlers - Handler IDs (agents or tasks) to race concurrently.
|
|
2040
|
+
* @param options - Optional `extract`, `timeout`, `minSuccess`, and `signal` overrides.
|
|
2041
|
+
* @returns A {@link RacePattern} configuration object.
|
|
1933
2042
|
*
|
|
1934
2043
|
* @example
|
|
1935
2044
|
* ```typescript
|
|
@@ -1943,11 +2052,17 @@ declare function race<T>(handlers: string[], options?: {
|
|
|
1943
2052
|
signal?: AbortSignal;
|
|
1944
2053
|
}): RacePattern<T>;
|
|
1945
2054
|
/**
|
|
1946
|
-
* Create a goal execution pattern
|
|
2055
|
+
* Create a goal-driven execution pattern where agents are selected and run
|
|
2056
|
+
* until a goal condition is satisfied.
|
|
1947
2057
|
*
|
|
1948
2058
|
* Declare what each agent produces and requires. The runtime automatically
|
|
1949
2059
|
* infers the execution graph from dependency analysis and drives agents
|
|
1950
|
-
*
|
|
2060
|
+
* toward goal achievement, with optional satisfaction scoring and relaxation tiers.
|
|
2061
|
+
*
|
|
2062
|
+
* @param nodes - Goal node definitions keyed by ID, each declaring `produces`, `requires`, and a `handler`.
|
|
2063
|
+
* @param when - Predicate that returns `true` when the goal is achieved.
|
|
2064
|
+
* @param options - Optional `satisfaction`, `maxSteps`, `extract`, `timeout`, `selectionStrategy`, and `relaxation` config.
|
|
2065
|
+
* @returns A {@link GoalPattern} configuration object.
|
|
1951
2066
|
*
|
|
1952
2067
|
* @example
|
|
1953
2068
|
* ```typescript
|
|
@@ -1984,23 +2099,40 @@ declare function goal<T = Record<string, unknown>>(nodes: Record<string, GoalNod
|
|
|
1984
2099
|
checkpoint?: PatternCheckpointConfig;
|
|
1985
2100
|
}): GoalPattern<T>;
|
|
1986
2101
|
/**
|
|
1987
|
-
*
|
|
2102
|
+
* Create a selection strategy that runs all ready agents concurrently.
|
|
2103
|
+
*
|
|
2104
|
+
* This is the default strategy for {@link goal} patterns.
|
|
2105
|
+
*
|
|
2106
|
+
* @returns An {@link AgentSelectionStrategy} that selects every ready agent.
|
|
1988
2107
|
*/
|
|
1989
2108
|
declare function allReadyStrategy(): AgentSelectionStrategy;
|
|
1990
2109
|
/**
|
|
1991
|
-
*
|
|
2110
|
+
* Create a selection strategy that picks agents with the highest historical impact.
|
|
1992
2111
|
*
|
|
1993
|
-
* Sorts by average satisfaction delta (descending) and
|
|
2112
|
+
* Sorts ready agents by average satisfaction delta (descending) and selects the top N.
|
|
2113
|
+
*
|
|
2114
|
+
* @param opts - Optional `topN` to limit how many agents are selected (default: 3).
|
|
2115
|
+
* @returns An {@link AgentSelectionStrategy} that prioritizes high-impact agents.
|
|
1994
2116
|
*/
|
|
1995
2117
|
declare function highestImpactStrategy(opts?: {
|
|
1996
2118
|
topN?: number;
|
|
1997
2119
|
}): AgentSelectionStrategy;
|
|
1998
2120
|
/**
|
|
1999
|
-
*
|
|
2121
|
+
* Create a selection strategy that prefers agents with lower token cost per satisfaction delta.
|
|
2122
|
+
*
|
|
2123
|
+
* Agents without historical metrics are prioritized first (to gather data).
|
|
2124
|
+
*
|
|
2125
|
+
* @returns An {@link AgentSelectionStrategy} that optimizes for cost efficiency.
|
|
2000
2126
|
*/
|
|
2001
2127
|
declare function costEfficientStrategy(): AgentSelectionStrategy;
|
|
2002
2128
|
/**
|
|
2003
|
-
* Create
|
|
2129
|
+
* Create a constraint that routes to a specific agent when a condition is met.
|
|
2130
|
+
*
|
|
2131
|
+
* @param when - Predicate that triggers the constraint (may be async).
|
|
2132
|
+
* @param agent - Agent ID or function returning an agent ID to route to.
|
|
2133
|
+
* @param input - Input string or function returning the input for the selected agent.
|
|
2134
|
+
* @param priority - Optional constraint priority (higher = evaluated first).
|
|
2135
|
+
* @returns An {@link OrchestratorConstraint} that emits a `RUN_AGENT` requirement.
|
|
2004
2136
|
*
|
|
2005
2137
|
* @example
|
|
2006
2138
|
* ```typescript
|
|
@@ -2008,14 +2140,19 @@ declare function costEfficientStrategy(): AgentSelectionStrategy;
|
|
|
2008
2140
|
* routeToExpert: selectAgent(
|
|
2009
2141
|
* (facts) => facts.complexity > 0.8,
|
|
2010
2142
|
* 'expert',
|
|
2011
|
-
* (facts) => facts.query
|
|
2143
|
+
* (facts) => facts.query,
|
|
2012
2144
|
* ),
|
|
2013
2145
|
* };
|
|
2014
2146
|
* ```
|
|
2015
2147
|
*/
|
|
2016
2148
|
declare function selectAgent(when: (facts: Record<string, unknown>) => boolean | Promise<boolean>, agent: string | ((facts: Record<string, unknown>) => string), input: string | ((facts: Record<string, unknown>) => string), priority?: number): OrchestratorConstraint<Record<string, unknown>>;
|
|
2017
2149
|
/**
|
|
2018
|
-
* Create a RUN_AGENT requirement.
|
|
2150
|
+
* Create a `RUN_AGENT` requirement object for use in constraint `require()` functions.
|
|
2151
|
+
*
|
|
2152
|
+
* @param agent - The agent ID to run.
|
|
2153
|
+
* @param input - The input string for the agent.
|
|
2154
|
+
* @param context - Optional additional context passed to the agent runner.
|
|
2155
|
+
* @returns A `RUN_AGENT` {@link RunAgentRequirement} object.
|
|
2019
2156
|
*
|
|
2020
2157
|
* @example
|
|
2021
2158
|
* ```typescript
|
|
@@ -2029,31 +2166,49 @@ declare function selectAgent(when: (facts: Record<string, unknown>) => boolean |
|
|
|
2029
2166
|
*/
|
|
2030
2167
|
declare function runAgentRequirement(agent: string, input: string, context?: Record<string, unknown>): RunAgentRequirement;
|
|
2031
2168
|
/**
|
|
2032
|
-
* Merge results by concatenating outputs.
|
|
2169
|
+
* Merge run results by concatenating their outputs into a single string.
|
|
2170
|
+
*
|
|
2171
|
+
* @param results - Array of run results to concatenate.
|
|
2172
|
+
* @param separator - String inserted between outputs (default: `"\n\n"`).
|
|
2173
|
+
* @returns The concatenated output string.
|
|
2033
2174
|
*/
|
|
2034
2175
|
declare function concatResults(results: RunResult<unknown>[], separator?: string): string;
|
|
2035
2176
|
/**
|
|
2036
|
-
*
|
|
2177
|
+
* Pick the highest-scoring result from an array using a scoring function.
|
|
2178
|
+
*
|
|
2179
|
+
* @param results - Array of run results to compare.
|
|
2180
|
+
* @param score - Function that assigns a numeric score to each result (higher wins).
|
|
2181
|
+
* @returns The {@link RunResult} with the highest score.
|
|
2182
|
+
* @throws If the results array is empty.
|
|
2037
2183
|
*/
|
|
2038
2184
|
declare function pickBestResult<T>(results: RunResult<T>[], score: (result: RunResult<T>) => number): RunResult<T>;
|
|
2039
2185
|
/**
|
|
2040
|
-
*
|
|
2186
|
+
* Extract the `output` value from each run result into an array.
|
|
2187
|
+
*
|
|
2188
|
+
* @param results - Array of run results to collect from.
|
|
2189
|
+
* @returns An array of output values in the same order as the input results.
|
|
2041
2190
|
*/
|
|
2042
2191
|
declare function collectOutputs<T>(results: RunResult<T>[]): T[];
|
|
2043
2192
|
/**
|
|
2044
|
-
*
|
|
2193
|
+
* Sum the total token counts from an array of run results.
|
|
2194
|
+
*
|
|
2195
|
+
* @param results - Array of run results to aggregate.
|
|
2196
|
+
* @returns The total number of tokens consumed across all results.
|
|
2045
2197
|
*/
|
|
2046
2198
|
declare function aggregateTokens(results: RunResult<unknown>[]): number;
|
|
2047
2199
|
/**
|
|
2048
|
-
* Compose multiple patterns into a pipeline where each pattern's
|
|
2049
|
-
* output feeds as input to the next.
|
|
2050
|
-
* that runs the pipeline on a given orchestrator.
|
|
2200
|
+
* Compose multiple execution patterns into a pipeline where each pattern's
|
|
2201
|
+
* output feeds as input to the next.
|
|
2051
2202
|
*
|
|
2203
|
+
* @remarks
|
|
2052
2204
|
* Between patterns, output is converted to a string input:
|
|
2053
2205
|
* - `string` output passes through directly
|
|
2054
2206
|
* - Objects are JSON-stringified
|
|
2055
2207
|
* - Optionally provide a `transform` to customize between steps
|
|
2056
2208
|
*
|
|
2209
|
+
* @param patterns - One or more execution patterns to chain together.
|
|
2210
|
+
* @returns An async function that runs the pipeline on a given orchestrator.
|
|
2211
|
+
*
|
|
2057
2212
|
* @example
|
|
2058
2213
|
* ```typescript
|
|
2059
2214
|
* const workflow = composePatterns(
|
|
@@ -2066,10 +2221,11 @@ declare function aggregateTokens(results: RunResult<unknown>[]): number;
|
|
|
2066
2221
|
*/
|
|
2067
2222
|
declare function composePatterns(...patterns: ExecutionPattern[]): (orchestrator: MultiAgentOrchestrator, input: string) => Promise<unknown>;
|
|
2068
2223
|
/**
|
|
2069
|
-
*
|
|
2224
|
+
* Find agents in a registry that match all required capabilities.
|
|
2070
2225
|
*
|
|
2071
|
-
*
|
|
2072
|
-
* that
|
|
2226
|
+
* @param registry - The agent registry to search.
|
|
2227
|
+
* @param requiredCapabilities - Capabilities that each matching agent must have.
|
|
2228
|
+
* @returns An array of agent IDs whose `capabilities` include every required capability.
|
|
2073
2229
|
*
|
|
2074
2230
|
* @example
|
|
2075
2231
|
* ```typescript
|
|
@@ -2081,14 +2237,20 @@ declare function composePatterns(...patterns: ExecutionPattern[]): (orchestrator
|
|
|
2081
2237
|
*
|
|
2082
2238
|
* const matches = findAgentsByCapability(agents, ['search']);
|
|
2083
2239
|
* // Returns ['researcher']
|
|
2084
|
-
*
|
|
2085
|
-
* const matches2 = findAgentsByCapability(agents, ['write', 'edit']);
|
|
2086
|
-
* // Returns ['writer']
|
|
2087
2240
|
* ```
|
|
2088
2241
|
*/
|
|
2089
2242
|
declare function findAgentsByCapability(registry: AgentRegistry, requiredCapabilities: string[]): string[];
|
|
2090
2243
|
/**
|
|
2091
|
-
* Create a constraint that auto-routes to an agent based on capabilities.
|
|
2244
|
+
* Create a constraint that auto-routes to an agent based on required capabilities.
|
|
2245
|
+
*
|
|
2246
|
+
* When the condition fires, it finds agents matching the capabilities returned by
|
|
2247
|
+
* `getCapabilities`, then emits a `RUN_AGENT` requirement for the best match.
|
|
2248
|
+
*
|
|
2249
|
+
* @param registry - The agent registry to search for matching capabilities.
|
|
2250
|
+
* @param getCapabilities - Function that extracts required capabilities from facts.
|
|
2251
|
+
* @param getInput - Function that extracts the input string from facts.
|
|
2252
|
+
* @param options - Optional `priority` and custom `select` function.
|
|
2253
|
+
* @returns An {@link OrchestratorConstraint} that routes to a capability-matched agent.
|
|
2092
2254
|
*
|
|
2093
2255
|
* @example
|
|
2094
2256
|
* ```typescript
|
|
@@ -2113,11 +2275,14 @@ interface SpawnOnConditionOptions {
|
|
|
2113
2275
|
context?: Record<string, unknown>;
|
|
2114
2276
|
}
|
|
2115
2277
|
/**
|
|
2116
|
-
* Create a constraint that auto-runs
|
|
2278
|
+
* Create a constraint that auto-runs a single agent when a condition is met.
|
|
2117
2279
|
*
|
|
2118
|
-
* The orchestrator's built-in RUN_AGENT resolver handles execution
|
|
2280
|
+
* The orchestrator's built-in `RUN_AGENT` resolver handles execution --
|
|
2119
2281
|
* you only need to add this to your `constraints` config.
|
|
2120
2282
|
*
|
|
2283
|
+
* @param config - Condition, agent ID, input builder, and optional priority/context.
|
|
2284
|
+
* @returns An {@link OrchestratorConstraint} that emits a `RUN_AGENT` requirement.
|
|
2285
|
+
*
|
|
2121
2286
|
* @example
|
|
2122
2287
|
* ```typescript
|
|
2123
2288
|
* const orchestrator = createMultiAgentOrchestrator({
|
|
@@ -2147,13 +2312,15 @@ type DebateConfig<T = unknown> = Omit<DebatePattern<T>, "type">;
|
|
|
2147
2312
|
/**
|
|
2148
2313
|
* Create a debate pattern where agents compete and an evaluator picks the best.
|
|
2149
2314
|
*
|
|
2315
|
+
* @remarks
|
|
2150
2316
|
* Flow:
|
|
2151
2317
|
* 1. All agents produce proposals in parallel
|
|
2152
2318
|
* 2. Evaluator receives all proposals and picks a winner
|
|
2153
2319
|
* 3. Optionally repeat with evaluator feedback for refinement
|
|
2154
2320
|
*
|
|
2155
|
-
* @param config - Debate configuration with `handlers`, `evaluator`, and optional settings
|
|
2156
|
-
* @
|
|
2321
|
+
* @param config - Debate configuration with `handlers`, `evaluator`, and optional settings.
|
|
2322
|
+
* @returns A {@link DebatePattern} configuration object.
|
|
2323
|
+
* @see {@link runDebate} for the imperative API
|
|
2157
2324
|
*
|
|
2158
2325
|
* @example
|
|
2159
2326
|
* ```typescript
|
|
@@ -2177,23 +2344,30 @@ type DebateConfig<T = unknown> = Omit<DebatePattern<T>, "type">;
|
|
|
2177
2344
|
*/
|
|
2178
2345
|
declare function debate<T = unknown>(config: DebateConfig<T>): DebatePattern<T>;
|
|
2179
2346
|
/**
|
|
2180
|
-
* Run a debate imperatively on an orchestrator
|
|
2347
|
+
* Run a debate imperatively on an orchestrator without pattern registration.
|
|
2348
|
+
*
|
|
2181
2349
|
* Delegates to `orchestrator.runDebate()` so that lifecycle hooks, debug timeline,
|
|
2182
2350
|
* and signal propagation all work correctly.
|
|
2183
2351
|
*
|
|
2184
|
-
* @param orchestrator - The multi-agent orchestrator instance
|
|
2185
|
-
* @param config - Debate configuration with agents, evaluator, and optional settings
|
|
2186
|
-
* @param input - The initial input/prompt for the debate
|
|
2187
|
-
* @
|
|
2188
|
-
* @
|
|
2352
|
+
* @param orchestrator - The multi-agent orchestrator instance to run the debate on.
|
|
2353
|
+
* @param config - Debate configuration with agents, evaluator, and optional settings.
|
|
2354
|
+
* @param input - The initial input/prompt for the debate.
|
|
2355
|
+
* @returns The winning agent's output, the winner ID, and all proposals from each round.
|
|
2356
|
+
* @see {@link debate} for the declarative pattern API
|
|
2189
2357
|
*/
|
|
2190
2358
|
declare function runDebate<T>(orchestrator: MultiAgentOrchestrator, config: DebateConfig<T>, input: string): Promise<DebateResult<T>>;
|
|
2191
2359
|
/**
|
|
2192
2360
|
* Create a constraint that fires when a cross-agent derivation meets a condition.
|
|
2193
2361
|
*
|
|
2362
|
+
* @remarks
|
|
2194
2363
|
* Wire this into the orchestrator's `derive` config and `constraints` config together.
|
|
2195
2364
|
* The constraint's `when()` reads the derivation value from the orchestrator's derived snapshot.
|
|
2196
2365
|
*
|
|
2366
|
+
* @param derivationId - The ID of the cross-agent derivation to watch.
|
|
2367
|
+
* @param condition - Predicate that receives the derivation value and returns `true` when the constraint should fire.
|
|
2368
|
+
* @param action - Agent ID, input builder, and optional priority/context for the emitted requirement.
|
|
2369
|
+
* @returns An {@link OrchestratorConstraint} that emits a `RUN_AGENT` requirement when the derivation condition is met.
|
|
2370
|
+
*
|
|
2197
2371
|
* @example
|
|
2198
2372
|
* ```typescript
|
|
2199
2373
|
* const orchestrator = createMultiAgentOrchestrator({
|
|
@@ -2232,11 +2406,15 @@ interface SpawnPoolConfig {
|
|
|
2232
2406
|
/**
|
|
2233
2407
|
* Create a constraint that spawns a pool of agent instances when a condition is met.
|
|
2234
2408
|
*
|
|
2235
|
-
*
|
|
2236
|
-
*
|
|
2409
|
+
* @remarks
|
|
2410
|
+
* Unlike {@link spawnOnCondition} (which spawns one agent), `spawnPool` can target N agents.
|
|
2411
|
+
* However, only one requirement is emitted per constraint evaluation cycle -- the constraint
|
|
2237
2412
|
* re-fires on subsequent cycles as long as `when()` returns true, spawning one agent per cycle.
|
|
2238
2413
|
*
|
|
2239
|
-
* @
|
|
2414
|
+
* @param when - Predicate that triggers the pool spawn.
|
|
2415
|
+
* @param config - Pool configuration with agent ID, input builder, count, and optional priority/context.
|
|
2416
|
+
* @returns An {@link OrchestratorConstraint} that emits `RUN_AGENT` requirements.
|
|
2417
|
+
* @see {@link spawnOnCondition} for spawning a single agent
|
|
2240
2418
|
*
|
|
2241
2419
|
* @example
|
|
2242
2420
|
* ```typescript
|
|
@@ -2322,19 +2500,23 @@ interface SerializedGoalNode {
|
|
|
2322
2500
|
/**
|
|
2323
2501
|
* Serialize an execution pattern to a JSON-safe object.
|
|
2324
2502
|
*
|
|
2503
|
+
* @remarks
|
|
2325
2504
|
* Strips all function callbacks and runtime objects (AbortSignal) while
|
|
2326
|
-
* preserving the topology
|
|
2505
|
+
* preserving the topology -- which agents, in what structure, with what
|
|
2327
2506
|
* numeric/string/boolean options.
|
|
2328
2507
|
*
|
|
2329
2508
|
* Use this for visual editors, LLM-generated plans, persistence, or
|
|
2330
2509
|
* debugging. Restore with {@link patternFromJSON}.
|
|
2331
2510
|
*
|
|
2332
|
-
*
|
|
2511
|
+
* Function-form `threshold` on reflect patterns is not serializable and will be dropped.
|
|
2333
2512
|
* Re-supply it via `overrides` when calling {@link patternFromJSON}.
|
|
2334
2513
|
*
|
|
2514
|
+
* @param pattern - The execution pattern to serialize.
|
|
2515
|
+
* @returns A {@link SerializedPattern} safe for `JSON.stringify`.
|
|
2516
|
+
*
|
|
2335
2517
|
* @example
|
|
2336
2518
|
* ```typescript
|
|
2337
|
-
* const p = parallel(
|
|
2519
|
+
* const p = parallel(['a', 'b'], (r) => r);
|
|
2338
2520
|
* const json = patternToJSON(p);
|
|
2339
2521
|
* // { type: "parallel", handlers: ["a", "b"] }
|
|
2340
2522
|
* localStorage.setItem("plan", JSON.stringify(json));
|
|
@@ -2342,11 +2524,18 @@ interface SerializedGoalNode {
|
|
|
2342
2524
|
*/
|
|
2343
2525
|
declare function patternToJSON(pattern: ExecutionPattern<unknown>): SerializedPattern;
|
|
2344
2526
|
/**
|
|
2345
|
-
* Restore an execution pattern from its serialized form.
|
|
2527
|
+
* Restore an execution pattern from its serialized JSON form.
|
|
2346
2528
|
*
|
|
2529
|
+
* @remarks
|
|
2347
2530
|
* Returns the data structure with all function fields set to `undefined`.
|
|
2348
2531
|
* Supply callbacks via the optional `overrides` parameter to re-attach
|
|
2349
|
-
* runtime behavior.
|
|
2532
|
+
* runtime behavior. Handles legacy field migrations (`agent` to `handler`,
|
|
2533
|
+
* `agents` to `handlers`, `converge` to `goal`).
|
|
2534
|
+
*
|
|
2535
|
+
* @param json - The serialized pattern from {@link patternToJSON} or persisted storage.
|
|
2536
|
+
* @param overrides - Optional partial pattern to re-attach function callbacks (e.g. `merge`, `extract`).
|
|
2537
|
+
* @returns A fully typed {@link ExecutionPattern} ready for use with the imperative API.
|
|
2538
|
+
* @throws If the pattern type is invalid or unknown.
|
|
2350
2539
|
*
|
|
2351
2540
|
* @example
|
|
2352
2541
|
* ```typescript
|
|
@@ -2354,7 +2543,6 @@ declare function patternToJSON(pattern: ExecutionPattern<unknown>): SerializedPa
|
|
|
2354
2543
|
* const pattern = patternFromJSON<string[]>(json, {
|
|
2355
2544
|
* merge: (results) => results.map(r => r.output as string),
|
|
2356
2545
|
* });
|
|
2357
|
-
* // Use the imperative API — runPattern takes a registered pattern ID, not an object
|
|
2358
2546
|
* if (pattern.type === "parallel") {
|
|
2359
2547
|
* const result = await orchestrator.runParallel(pattern.handlers, input, pattern.merge);
|
|
2360
2548
|
* }
|