@directive-run/ai 0.4.2 → 0.7.0
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/LICENSE +1 -1
- package/dist/anthropic.cjs +3 -2
- package/dist/anthropic.cjs.map +1 -1
- package/dist/anthropic.d.cts +1 -1
- package/dist/anthropic.d.ts +1 -1
- package/dist/anthropic.js +3 -2
- package/dist/anthropic.js.map +1 -1
- package/dist/gemini.cjs +3 -2
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts +1 -1
- package/dist/gemini.d.ts +1 -1
- package/dist/gemini.js +3 -2
- package/dist/gemini.js.map +1 -1
- package/dist/index.cjs +54 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +660 -6
- package/dist/index.d.ts +660 -6
- package/dist/index.js +54 -54
- package/dist/index.js.map +1 -1
- package/dist/{multi-agent-orchestrator-CFOzWVNd.d.cts → multi-agent-orchestrator-C3VKkLzg.d.cts} +3 -650
- package/dist/{multi-agent-orchestrator-CH-4Fqzg.d.ts → multi-agent-orchestrator-DHp8gHXi.d.ts} +3 -650
- package/dist/ollama.d.cts +1 -1
- package/dist/ollama.d.ts +1 -1
- package/dist/openai.cjs +3 -2
- package/dist/openai.cjs.map +1 -1
- package/dist/openai.d.cts +1 -1
- package/dist/openai.d.ts +1 -1
- package/dist/openai.js +3 -2
- package/dist/openai.js.map +1 -1
- package/dist/testing.cjs +13 -13
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +13 -13
- package/dist/testing.js.map +1 -1
- package/dist/{types-D5veI9su.d.cts → types-BM-6xZf_.d.cts} +1 -1
- package/dist/{types-D5veI9su.d.ts → types-BM-6xZf_.d.ts} +1 -1
- package/package.json +3 -3
package/dist/{multi-agent-orchestrator-CH-4Fqzg.d.ts → multi-agent-orchestrator-DHp8gHXi.d.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Message$1,
|
|
1
|
+
import { M as Message$1, k as RunResult, A as AgentLike, G as GuardrailFn, O as OutputGuardrailData, aX as StreamingCallbackRunner, n as DebugEvent, a7 as DebugEventType, b as AgentRunner, ay as OrchestratorState, at as NamedGuardrail, I as InputGuardrailData, N as Checkpoint, F as BreakpointModifications, H as BreakpointRequest, l as OrchestratorConstraint, aw as OrchestratorResolver, ai as GuardrailsConfig, w as ApprovalRequest, au as OrchestratorDebugConfig, t as AgentRetryConfig, av as OrchestratorLifecycleHooks, aU as SelfHealingConfig, Z as CheckpointStore, z as BreakpointConfig, al as HealthMonitorConfig, m as RunOptions, T as ToolCallGuardrailData, P as PatternCheckpointConfig, g as DagPattern, j as GoalPattern, h as GoalNode, e as AgentSelectionStrategy, R as RelaxationTier, o as GoalResult, aa as GoalCheckpointState, aV as SequentialCheckpointState, aY as SupervisorCheckpointState, aG as ReflectCheckpointState, a4 as DebateCheckpointState, a1 as DagCheckpointState, aS as Scratchpad, ar as MultiAgentLifecycleHooks, as as MultiAgentSelfHealingConfig, ap as MultiAgentBreakpointType, $ as CrossAgentDerivationFn, aA as PatternCheckpointState, U as CheckpointDiff, W as CheckpointProgress } from './types-BM-6xZf_.js';
|
|
2
2
|
import { Plugin, System, Requirement } from '@directive-run/core';
|
|
3
3
|
import { CircuitBreaker } from '@directive-run/core/plugins';
|
|
4
4
|
|
|
@@ -678,7 +678,7 @@ declare function createDebugTimeline(options?: DebugTimelineOptions): DebugTimel
|
|
|
678
678
|
* @example
|
|
679
679
|
* ```typescript
|
|
680
680
|
* const timeline = createDebugTimeline();
|
|
681
|
-
* const plugin = createDebugTimelinePlugin(timeline, () => system.
|
|
681
|
+
* const plugin = createDebugTimelinePlugin(timeline, () => system.history?.currentIndex ?? null);
|
|
682
682
|
* ```
|
|
683
683
|
*/
|
|
684
684
|
declare function createDebugTimelinePlugin(timeline: DebugTimeline, getSnapshotId: () => number | null): Plugin;
|
|
@@ -1902,652 +1902,5 @@ interface MultiAgentOrchestrator {
|
|
|
1902
1902
|
* @public
|
|
1903
1903
|
*/
|
|
1904
1904
|
declare function createMultiAgentOrchestrator(options: MultiAgentOrchestratorOptions): MultiAgentOrchestrator;
|
|
1905
|
-
/**
|
|
1906
|
-
* Create a parallel execution pattern that runs handlers concurrently and merges results.
|
|
1907
|
-
*
|
|
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.
|
|
1912
|
-
*
|
|
1913
|
-
* @example
|
|
1914
|
-
* ```typescript
|
|
1915
|
-
* const researchPattern = parallel(
|
|
1916
|
-
* ['researcher', 'researcher', 'researcher'],
|
|
1917
|
-
* (results) => results.map(r => r.output).join('\n'),
|
|
1918
|
-
* );
|
|
1919
|
-
* ```
|
|
1920
|
-
*/
|
|
1921
|
-
declare function parallel<T>(handlers: string[], merge: (results: RunResult<unknown>[]) => T | Promise<T>, options?: {
|
|
1922
|
-
minSuccess?: number;
|
|
1923
|
-
timeout?: number;
|
|
1924
|
-
}): ParallelPattern<T>;
|
|
1925
|
-
/**
|
|
1926
|
-
* Create a sequential execution pattern that pipes output from one handler to the next.
|
|
1927
|
-
*
|
|
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.
|
|
1931
|
-
*
|
|
1932
|
-
* @example
|
|
1933
|
-
* ```typescript
|
|
1934
|
-
* const writeReviewPattern = sequential(
|
|
1935
|
-
* ['writer', 'reviewer'],
|
|
1936
|
-
* { transform: (output) => `Review this: ${output}` },
|
|
1937
|
-
* );
|
|
1938
|
-
* ```
|
|
1939
|
-
*/
|
|
1940
|
-
declare function sequential<T>(handlers: string[], options?: {
|
|
1941
|
-
transform?: (output: unknown, handlerId: string, index: number) => string;
|
|
1942
|
-
extract?: (output: unknown) => T;
|
|
1943
|
-
continueOnError?: boolean;
|
|
1944
|
-
}): SequentialPattern<T>;
|
|
1945
|
-
/**
|
|
1946
|
-
* Create a supervisor pattern where a coordinating agent delegates work to a pool of workers.
|
|
1947
|
-
*
|
|
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.
|
|
1955
|
-
*
|
|
1956
|
-
* @example
|
|
1957
|
-
* ```typescript
|
|
1958
|
-
* const managedPattern = supervisor(
|
|
1959
|
-
* 'manager',
|
|
1960
|
-
* ['worker1', 'worker2'],
|
|
1961
|
-
* { maxRounds: 3 },
|
|
1962
|
-
* );
|
|
1963
|
-
* ```
|
|
1964
|
-
*/
|
|
1965
|
-
declare function supervisor<T>(supervisorAgent: string, workers: string[], options?: {
|
|
1966
|
-
maxRounds?: number;
|
|
1967
|
-
extract?: (supervisorOutput: unknown, workerResults: RunResult<unknown>[]) => T;
|
|
1968
|
-
}): SupervisorPattern<T>;
|
|
1969
|
-
/**
|
|
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.
|
|
1974
|
-
*
|
|
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.
|
|
1979
|
-
*
|
|
1980
|
-
* @example
|
|
1981
|
-
* ```typescript
|
|
1982
|
-
* const researchPipeline = dag(
|
|
1983
|
-
* {
|
|
1984
|
-
* fetch: { handler: 'fetcher' },
|
|
1985
|
-
* analyze: { handler: 'analyzer', deps: ['fetch'] },
|
|
1986
|
-
* summarize: { handler: 'summarizer', deps: ['analyze'] },
|
|
1987
|
-
* },
|
|
1988
|
-
* (context) => context.outputs.summarize,
|
|
1989
|
-
* );
|
|
1990
|
-
* ```
|
|
1991
|
-
*/
|
|
1992
|
-
declare function dag<T = Record<string, unknown>>(nodes: Record<string, DagNode>, merge?: (context: DagExecutionContext) => T | Promise<T>, options?: {
|
|
1993
|
-
/** Overall timeout in ms for the entire DAG. */
|
|
1994
|
-
timeout?: number;
|
|
1995
|
-
/** Max nodes running concurrently. Default: Infinity */
|
|
1996
|
-
maxConcurrent?: number;
|
|
1997
|
-
/**
|
|
1998
|
-
* Error handling strategy.
|
|
1999
|
-
* - `"fail"` — abort entire DAG on first node error (default)
|
|
2000
|
-
* - `"skip-downstream"` — mark downstream nodes as skipped, other branches continue
|
|
2001
|
-
* - `"continue"` — ignore errors, other branches continue
|
|
2002
|
-
*/
|
|
2003
|
-
onNodeError?: "fail" | "skip-downstream" | "continue";
|
|
2004
|
-
}): DagPattern<T>;
|
|
2005
|
-
/**
|
|
2006
|
-
* Create a reflect pattern that iterates between a producer and evaluator until quality is met.
|
|
2007
|
-
*
|
|
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.
|
|
2016
|
-
*
|
|
2017
|
-
* @example
|
|
2018
|
-
* ```typescript
|
|
2019
|
-
* const reviewPattern = reflect('writer', 'reviewer', { maxIterations: 2 });
|
|
2020
|
-
* ```
|
|
2021
|
-
*/
|
|
2022
|
-
declare function reflect<T>(handler: string, evaluator: string, options?: {
|
|
2023
|
-
maxIterations?: number;
|
|
2024
|
-
parseEvaluation?: (output: unknown) => ReflectionEvaluation;
|
|
2025
|
-
buildRetryInput?: (input: string, feedback: string, iteration: number) => string;
|
|
2026
|
-
extract?: (output: unknown) => T;
|
|
2027
|
-
onExhausted?: "accept-last" | "accept-best" | "throw";
|
|
2028
|
-
onIteration?: (record: ReflectIterationRecord) => void;
|
|
2029
|
-
signal?: AbortSignal;
|
|
2030
|
-
timeout?: number;
|
|
2031
|
-
threshold?: number | ((iteration: number) => number);
|
|
2032
|
-
}): ReflectPattern<T>;
|
|
2033
|
-
/**
|
|
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.
|
|
2038
|
-
*
|
|
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.
|
|
2042
|
-
*
|
|
2043
|
-
* @example
|
|
2044
|
-
* ```typescript
|
|
2045
|
-
* const fastest = race(['fast-model', 'smart-model'], { timeout: 5000 });
|
|
2046
|
-
* ```
|
|
2047
|
-
*/
|
|
2048
|
-
declare function race<T>(handlers: string[], options?: {
|
|
2049
|
-
extract?: (result: RunResult<unknown>) => T;
|
|
2050
|
-
timeout?: number;
|
|
2051
|
-
minSuccess?: number;
|
|
2052
|
-
signal?: AbortSignal;
|
|
2053
|
-
}): RacePattern<T>;
|
|
2054
|
-
/**
|
|
2055
|
-
* Create a goal-driven execution pattern where agents are selected and run
|
|
2056
|
-
* until a goal condition is satisfied.
|
|
2057
|
-
*
|
|
2058
|
-
* Declare what each agent produces and requires. The runtime automatically
|
|
2059
|
-
* infers the execution graph from dependency analysis and drives agents
|
|
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.
|
|
2066
|
-
*
|
|
2067
|
-
* @example
|
|
2068
|
-
* ```typescript
|
|
2069
|
-
* const pipeline = goal(
|
|
2070
|
-
* {
|
|
2071
|
-
* researcher: {
|
|
2072
|
-
* handler: "researcher",
|
|
2073
|
-
* produces: ["research.findings"],
|
|
2074
|
-
* requires: ["research.topic"],
|
|
2075
|
-
* extractOutput: (r) => ({ "research.findings": r.output }),
|
|
2076
|
-
* },
|
|
2077
|
-
* writer: {
|
|
2078
|
-
* handler: "writer",
|
|
2079
|
-
* produces: ["article.draft"],
|
|
2080
|
-
* requires: ["research.findings"],
|
|
2081
|
-
* extractOutput: (r) => ({ "article.draft": r.output }),
|
|
2082
|
-
* },
|
|
2083
|
-
* },
|
|
2084
|
-
* (facts) => facts["article.draft"] != null,
|
|
2085
|
-
* { maxSteps: 10, extract: (facts) => facts["article.draft"] },
|
|
2086
|
-
* );
|
|
2087
|
-
* ```
|
|
2088
|
-
*/
|
|
2089
|
-
declare function goal<T = Record<string, unknown>>(nodes: Record<string, GoalNode>, when: (facts: Record<string, unknown>) => boolean, options?: {
|
|
2090
|
-
satisfaction?: (facts: Record<string, unknown>) => number;
|
|
2091
|
-
maxSteps?: number;
|
|
2092
|
-
extract?: (facts: Record<string, unknown>) => T;
|
|
2093
|
-
timeout?: number;
|
|
2094
|
-
signal?: AbortSignal;
|
|
2095
|
-
selectionStrategy?: AgentSelectionStrategy;
|
|
2096
|
-
relaxation?: RelaxationTier[];
|
|
2097
|
-
onStep?: (step: number, facts: Record<string, unknown>, readyNodes: string[]) => void;
|
|
2098
|
-
onStall?: (step: number, metrics: GoalMetrics) => void;
|
|
2099
|
-
checkpoint?: PatternCheckpointConfig;
|
|
2100
|
-
}): GoalPattern<T>;
|
|
2101
|
-
/**
|
|
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.
|
|
2107
|
-
*/
|
|
2108
|
-
declare function allReadyStrategy(): AgentSelectionStrategy;
|
|
2109
|
-
/**
|
|
2110
|
-
* Create a selection strategy that picks agents with the highest historical impact.
|
|
2111
|
-
*
|
|
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.
|
|
2116
|
-
*/
|
|
2117
|
-
declare function highestImpactStrategy(opts?: {
|
|
2118
|
-
topN?: number;
|
|
2119
|
-
}): AgentSelectionStrategy;
|
|
2120
|
-
/**
|
|
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.
|
|
2126
|
-
*/
|
|
2127
|
-
declare function costEfficientStrategy(): AgentSelectionStrategy;
|
|
2128
|
-
/**
|
|
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.
|
|
2136
|
-
*
|
|
2137
|
-
* @example
|
|
2138
|
-
* ```typescript
|
|
2139
|
-
* const constraints = {
|
|
2140
|
-
* routeToExpert: selectAgent(
|
|
2141
|
-
* (facts) => facts.complexity > 0.8,
|
|
2142
|
-
* 'expert',
|
|
2143
|
-
* (facts) => facts.query,
|
|
2144
|
-
* ),
|
|
2145
|
-
* };
|
|
2146
|
-
* ```
|
|
2147
|
-
*/
|
|
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>>;
|
|
2149
|
-
/**
|
|
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.
|
|
2156
|
-
*
|
|
2157
|
-
* @example
|
|
2158
|
-
* ```typescript
|
|
2159
|
-
* constraints: {
|
|
2160
|
-
* needsResearch: {
|
|
2161
|
-
* when: (facts) => facts.hasUnknowns,
|
|
2162
|
-
* require: (facts) => runAgentRequirement('researcher', facts.query as string),
|
|
2163
|
-
* },
|
|
2164
|
-
* }
|
|
2165
|
-
* ```
|
|
2166
|
-
*/
|
|
2167
|
-
declare function runAgentRequirement(agent: string, input: string, context?: Record<string, unknown>): RunAgentRequirement;
|
|
2168
|
-
/**
|
|
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.
|
|
2174
|
-
*/
|
|
2175
|
-
declare function concatResults(results: RunResult<unknown>[], separator?: string): string;
|
|
2176
|
-
/**
|
|
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.
|
|
2183
|
-
*/
|
|
2184
|
-
declare function pickBestResult<T>(results: RunResult<T>[], score: (result: RunResult<T>) => number): RunResult<T>;
|
|
2185
|
-
/**
|
|
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.
|
|
2190
|
-
*/
|
|
2191
|
-
declare function collectOutputs<T>(results: RunResult<T>[]): T[];
|
|
2192
|
-
/**
|
|
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.
|
|
2197
|
-
*/
|
|
2198
|
-
declare function aggregateTokens(results: RunResult<unknown>[]): number;
|
|
2199
|
-
/**
|
|
2200
|
-
* Compose multiple execution patterns into a pipeline where each pattern's
|
|
2201
|
-
* output feeds as input to the next.
|
|
2202
|
-
*
|
|
2203
|
-
* @remarks
|
|
2204
|
-
* Between patterns, output is converted to a string input:
|
|
2205
|
-
* - `string` output passes through directly
|
|
2206
|
-
* - Objects are JSON-stringified
|
|
2207
|
-
* - Optionally provide a `transform` to customize between steps
|
|
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
|
-
*
|
|
2212
|
-
* @example
|
|
2213
|
-
* ```typescript
|
|
2214
|
-
* const workflow = composePatterns(
|
|
2215
|
-
* parallel(['researcher', 'researcher'], concatResults),
|
|
2216
|
-
* sequential(['writer', 'reviewer']),
|
|
2217
|
-
* );
|
|
2218
|
-
*
|
|
2219
|
-
* const result = await workflow(orchestrator, 'Research topic X');
|
|
2220
|
-
* ```
|
|
2221
|
-
*/
|
|
2222
|
-
declare function composePatterns(...patterns: ExecutionPattern[]): (orchestrator: MultiAgentOrchestrator, input: string) => Promise<unknown>;
|
|
2223
|
-
/**
|
|
2224
|
-
* Find agents in a registry that match all required capabilities.
|
|
2225
|
-
*
|
|
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.
|
|
2229
|
-
*
|
|
2230
|
-
* @example
|
|
2231
|
-
* ```typescript
|
|
2232
|
-
* const agents = {
|
|
2233
|
-
* researcher: { agent: researchAgent, capabilities: ['search', 'summarize'] },
|
|
2234
|
-
* coder: { agent: coderAgent, capabilities: ['code', 'debug'] },
|
|
2235
|
-
* writer: { agent: writerAgent, capabilities: ['write', 'edit'] },
|
|
2236
|
-
* };
|
|
2237
|
-
*
|
|
2238
|
-
* const matches = findAgentsByCapability(agents, ['search']);
|
|
2239
|
-
* // Returns ['researcher']
|
|
2240
|
-
* ```
|
|
2241
|
-
*/
|
|
2242
|
-
declare function findAgentsByCapability(registry: AgentRegistry, requiredCapabilities: string[]): string[];
|
|
2243
|
-
/**
|
|
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.
|
|
2254
|
-
*
|
|
2255
|
-
* @example
|
|
2256
|
-
* ```typescript
|
|
2257
|
-
* const routeByCapability = capabilityRoute(
|
|
2258
|
-
* agents,
|
|
2259
|
-
* (facts) => facts.requiredCapabilities as string[],
|
|
2260
|
-
* (facts) => facts.query as string,
|
|
2261
|
-
* );
|
|
2262
|
-
* ```
|
|
2263
|
-
*/
|
|
2264
|
-
declare function capabilityRoute(registry: AgentRegistry, getCapabilities: (facts: Record<string, unknown>) => string[], getInput: (facts: Record<string, unknown>) => string, options?: {
|
|
2265
|
-
priority?: number;
|
|
2266
|
-
select?: (matches: string[], registry: AgentRegistry) => string;
|
|
2267
|
-
}): OrchestratorConstraint<Record<string, unknown>>;
|
|
2268
|
-
/**
|
|
2269
|
-
* Options for spawnOnCondition.
|
|
2270
|
-
*/
|
|
2271
|
-
interface SpawnOnConditionOptions {
|
|
2272
|
-
/** Priority for the constraint (higher = evaluated first) */
|
|
2273
|
-
priority?: number;
|
|
2274
|
-
/** Additional context passed to the agent */
|
|
2275
|
-
context?: Record<string, unknown>;
|
|
2276
|
-
}
|
|
2277
|
-
/**
|
|
2278
|
-
* Create a constraint that auto-runs a single agent when a condition is met.
|
|
2279
|
-
*
|
|
2280
|
-
* The orchestrator's built-in `RUN_AGENT` resolver handles execution --
|
|
2281
|
-
* you only need to add this to your `constraints` config.
|
|
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
|
-
*
|
|
2286
|
-
* @example
|
|
2287
|
-
* ```typescript
|
|
2288
|
-
* const orchestrator = createMultiAgentOrchestrator({
|
|
2289
|
-
* agents: { reviewer: { agent: reviewerAgent } },
|
|
2290
|
-
* constraints: {
|
|
2291
|
-
* autoReview: spawnOnCondition({
|
|
2292
|
-
* when: (facts) => (facts.confidence as number) < 0.7,
|
|
2293
|
-
* agent: 'reviewer',
|
|
2294
|
-
* input: (facts) => `Review this: ${facts.lastOutput}`,
|
|
2295
|
-
* }),
|
|
2296
|
-
* },
|
|
2297
|
-
* });
|
|
2298
|
-
* ```
|
|
2299
|
-
*/
|
|
2300
|
-
declare function spawnOnCondition(config: {
|
|
2301
|
-
when: (facts: Record<string, unknown>) => boolean;
|
|
2302
|
-
agent: string;
|
|
2303
|
-
input: (facts: Record<string, unknown>) => string;
|
|
2304
|
-
/** Priority for the constraint (higher = evaluated first) */
|
|
2305
|
-
priority?: number;
|
|
2306
|
-
/** Additional context passed to the agent */
|
|
2307
|
-
context?: Record<string, unknown>;
|
|
2308
|
-
options?: SpawnOnConditionOptions;
|
|
2309
|
-
}): OrchestratorConstraint<Record<string, unknown>>;
|
|
2310
|
-
/** Configuration for the debate() factory and runDebate() imperative API. @see DebatePattern */
|
|
2311
|
-
type DebateConfig<T = unknown> = Omit<DebatePattern<T>, "type">;
|
|
2312
|
-
/**
|
|
2313
|
-
* Create a debate pattern where agents compete and an evaluator picks the best.
|
|
2314
|
-
*
|
|
2315
|
-
* @remarks
|
|
2316
|
-
* Flow:
|
|
2317
|
-
* 1. All agents produce proposals in parallel
|
|
2318
|
-
* 2. Evaluator receives all proposals and picks a winner
|
|
2319
|
-
* 3. Optionally repeat with evaluator feedback for refinement
|
|
2320
|
-
*
|
|
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
|
|
2324
|
-
*
|
|
2325
|
-
* @example
|
|
2326
|
-
* ```typescript
|
|
2327
|
-
* const orchestrator = createMultiAgentOrchestrator({
|
|
2328
|
-
* agents: {
|
|
2329
|
-
* optimist: { agent: optimistAgent },
|
|
2330
|
-
* pessimist: { agent: pessimistAgent },
|
|
2331
|
-
* judge: { agent: judgeAgent },
|
|
2332
|
-
* },
|
|
2333
|
-
* patterns: {
|
|
2334
|
-
* debate: debate({
|
|
2335
|
-
* handlers: ['optimist', 'pessimist'],
|
|
2336
|
-
* evaluator: 'judge',
|
|
2337
|
-
* maxRounds: 2,
|
|
2338
|
-
* }),
|
|
2339
|
-
* },
|
|
2340
|
-
* });
|
|
2341
|
-
*
|
|
2342
|
-
* const result = await orchestrator.runPattern('debate', 'Should we invest in X?');
|
|
2343
|
-
* ```
|
|
2344
|
-
*/
|
|
2345
|
-
declare function debate<T = unknown>(config: DebateConfig<T>): DebatePattern<T>;
|
|
2346
|
-
/**
|
|
2347
|
-
* Run a debate imperatively on an orchestrator without pattern registration.
|
|
2348
|
-
*
|
|
2349
|
-
* Delegates to `orchestrator.runDebate()` so that lifecycle hooks, debug timeline,
|
|
2350
|
-
* and signal propagation all work correctly.
|
|
2351
|
-
*
|
|
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
|
|
2357
|
-
*/
|
|
2358
|
-
declare function runDebate<T>(orchestrator: MultiAgentOrchestrator, config: DebateConfig<T>, input: string): Promise<DebateResult<T>>;
|
|
2359
|
-
/**
|
|
2360
|
-
* Create a constraint that fires when a cross-agent derivation meets a condition.
|
|
2361
|
-
*
|
|
2362
|
-
* @remarks
|
|
2363
|
-
* Wire this into the orchestrator's `derive` config and `constraints` config together.
|
|
2364
|
-
* The constraint's `when()` reads the derivation value from the orchestrator's derived snapshot.
|
|
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
|
-
*
|
|
2371
|
-
* @example
|
|
2372
|
-
* ```typescript
|
|
2373
|
-
* const orchestrator = createMultiAgentOrchestrator({
|
|
2374
|
-
* agents: { ... },
|
|
2375
|
-
* derive: {
|
|
2376
|
-
* totalCost: (snap) => snap.coordinator.globalTokens * 0.001,
|
|
2377
|
-
* },
|
|
2378
|
-
* constraints: {
|
|
2379
|
-
* budgetAlert: derivedConstraint('totalCost', (cost) => cost > 5.0, {
|
|
2380
|
-
* agent: 'budget-manager',
|
|
2381
|
-
* input: (value) => `Budget exceeded: $${value}`,
|
|
2382
|
-
* }),
|
|
2383
|
-
* },
|
|
2384
|
-
* });
|
|
2385
|
-
* ```
|
|
2386
|
-
*/
|
|
2387
|
-
declare function derivedConstraint(derivationId: string, condition: (value: unknown) => boolean, action: {
|
|
2388
|
-
agent: string;
|
|
2389
|
-
input: (value: unknown) => string;
|
|
2390
|
-
priority?: number;
|
|
2391
|
-
context?: Record<string, unknown>;
|
|
2392
|
-
}): OrchestratorConstraint<Record<string, unknown>>;
|
|
2393
|
-
/** Configuration for spawnPool constraint-driven auto-scaling */
|
|
2394
|
-
interface SpawnPoolConfig {
|
|
2395
|
-
/** Agent ID to spawn (must be registered in the orchestrator) */
|
|
2396
|
-
agent: string;
|
|
2397
|
-
/** Build the input for each spawned agent. Receives current facts and spawn index (0-based). */
|
|
2398
|
-
input: (facts: Record<string, unknown>, index: number) => string;
|
|
2399
|
-
/** How many agents to spawn. Number or function of facts for dynamic scaling. */
|
|
2400
|
-
count: number | ((facts: Record<string, unknown>) => number);
|
|
2401
|
-
/** Priority for the constraint. @default undefined */
|
|
2402
|
-
priority?: number;
|
|
2403
|
-
/** Additional context passed to each spawned agent */
|
|
2404
|
-
context?: Record<string, unknown>;
|
|
2405
|
-
}
|
|
2406
|
-
/**
|
|
2407
|
-
* Create a constraint that spawns a pool of agent instances when a condition is met.
|
|
2408
|
-
*
|
|
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
|
|
2412
|
-
* re-fires on subsequent cycles as long as `when()` returns true, spawning one agent per cycle.
|
|
2413
|
-
*
|
|
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
|
|
2418
|
-
*
|
|
2419
|
-
* @example
|
|
2420
|
-
* ```typescript
|
|
2421
|
-
* const orchestrator = createMultiAgentOrchestrator({
|
|
2422
|
-
* agents: { worker: { agent: workerAgent } },
|
|
2423
|
-
* constraints: {
|
|
2424
|
-
* scaleWorkers: spawnPool(
|
|
2425
|
-
* (facts) => (facts.pendingTasks as number) > 0,
|
|
2426
|
-
* {
|
|
2427
|
-
* agent: 'worker',
|
|
2428
|
-
* count: (facts) => Math.min(facts.pendingTasks as number, 5),
|
|
2429
|
-
* input: (facts, i) => `Process task ${i + 1}`,
|
|
2430
|
-
* },
|
|
2431
|
-
* ),
|
|
2432
|
-
* },
|
|
2433
|
-
* });
|
|
2434
|
-
* ```
|
|
2435
|
-
*/
|
|
2436
|
-
declare function spawnPool(when: (facts: Record<string, unknown>) => boolean, config: SpawnPoolConfig): OrchestratorConstraint<Record<string, unknown>>;
|
|
2437
|
-
/** Serialized DAG node (functions stripped) */
|
|
2438
|
-
interface SerializedDagNode {
|
|
2439
|
-
handler: string;
|
|
2440
|
-
agent?: string;
|
|
2441
|
-
deps?: string[];
|
|
2442
|
-
timeout?: number;
|
|
2443
|
-
priority?: number;
|
|
2444
|
-
}
|
|
2445
|
-
/** JSON-safe representation of any execution pattern (all functions stripped) */
|
|
2446
|
-
type SerializedPattern = {
|
|
2447
|
-
type: "parallel";
|
|
2448
|
-
handlers: string[];
|
|
2449
|
-
minSuccess?: number;
|
|
2450
|
-
timeout?: number;
|
|
2451
|
-
} | {
|
|
2452
|
-
type: "sequential";
|
|
2453
|
-
handlers: string[];
|
|
2454
|
-
continueOnError?: boolean;
|
|
2455
|
-
} | {
|
|
2456
|
-
type: "supervisor";
|
|
2457
|
-
supervisor: string;
|
|
2458
|
-
workers: string[];
|
|
2459
|
-
maxRounds?: number;
|
|
2460
|
-
} | {
|
|
2461
|
-
type: "dag";
|
|
2462
|
-
nodes: Record<string, SerializedDagNode>;
|
|
2463
|
-
timeout?: number;
|
|
2464
|
-
maxConcurrent?: number;
|
|
2465
|
-
onNodeError?: "fail" | "skip-downstream" | "continue";
|
|
2466
|
-
} | {
|
|
2467
|
-
type: "reflect";
|
|
2468
|
-
handler: string;
|
|
2469
|
-
evaluator: string;
|
|
2470
|
-
maxIterations?: number;
|
|
2471
|
-
onExhausted?: "accept-last" | "accept-best" | "throw";
|
|
2472
|
-
timeout?: number;
|
|
2473
|
-
threshold?: number;
|
|
2474
|
-
} | {
|
|
2475
|
-
type: "race";
|
|
2476
|
-
handlers: string[];
|
|
2477
|
-
timeout?: number;
|
|
2478
|
-
minSuccess?: number;
|
|
2479
|
-
} | {
|
|
2480
|
-
type: "debate";
|
|
2481
|
-
handlers: string[];
|
|
2482
|
-
evaluator: string;
|
|
2483
|
-
maxRounds?: number;
|
|
2484
|
-
timeout?: number;
|
|
2485
|
-
} | {
|
|
2486
|
-
type: "goal";
|
|
2487
|
-
nodes: Record<string, SerializedGoalNode>;
|
|
2488
|
-
maxSteps?: number;
|
|
2489
|
-
timeout?: number;
|
|
2490
|
-
};
|
|
2491
|
-
/** Serialized goal node (functions stripped) */
|
|
2492
|
-
interface SerializedGoalNode {
|
|
2493
|
-
handler: string;
|
|
2494
|
-
agent?: string;
|
|
2495
|
-
produces: string[];
|
|
2496
|
-
requires?: string[];
|
|
2497
|
-
allowRerun?: boolean;
|
|
2498
|
-
priority?: number;
|
|
2499
|
-
}
|
|
2500
|
-
/**
|
|
2501
|
-
* Serialize an execution pattern to a JSON-safe object.
|
|
2502
|
-
*
|
|
2503
|
-
* @remarks
|
|
2504
|
-
* Strips all function callbacks and runtime objects (AbortSignal) while
|
|
2505
|
-
* preserving the topology -- which agents, in what structure, with what
|
|
2506
|
-
* numeric/string/boolean options.
|
|
2507
|
-
*
|
|
2508
|
-
* Use this for visual editors, LLM-generated plans, persistence, or
|
|
2509
|
-
* debugging. Restore with {@link patternFromJSON}.
|
|
2510
|
-
*
|
|
2511
|
-
* Function-form `threshold` on reflect patterns is not serializable and will be dropped.
|
|
2512
|
-
* Re-supply it via `overrides` when calling {@link patternFromJSON}.
|
|
2513
|
-
*
|
|
2514
|
-
* @param pattern - The execution pattern to serialize.
|
|
2515
|
-
* @returns A {@link SerializedPattern} safe for `JSON.stringify`.
|
|
2516
|
-
*
|
|
2517
|
-
* @example
|
|
2518
|
-
* ```typescript
|
|
2519
|
-
* const p = parallel(['a', 'b'], (r) => r);
|
|
2520
|
-
* const json = patternToJSON(p);
|
|
2521
|
-
* // { type: "parallel", handlers: ["a", "b"] }
|
|
2522
|
-
* localStorage.setItem("plan", JSON.stringify(json));
|
|
2523
|
-
* ```
|
|
2524
|
-
*/
|
|
2525
|
-
declare function patternToJSON(pattern: ExecutionPattern<unknown>): SerializedPattern;
|
|
2526
|
-
/**
|
|
2527
|
-
* Restore an execution pattern from its serialized JSON form.
|
|
2528
|
-
*
|
|
2529
|
-
* @remarks
|
|
2530
|
-
* Returns the data structure with all function fields set to `undefined`.
|
|
2531
|
-
* Supply callbacks via the optional `overrides` parameter to re-attach
|
|
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.
|
|
2539
|
-
*
|
|
2540
|
-
* @example
|
|
2541
|
-
* ```typescript
|
|
2542
|
-
* const json = JSON.parse(localStorage.getItem("plan")!);
|
|
2543
|
-
* const pattern = patternFromJSON<string[]>(json, {
|
|
2544
|
-
* merge: (results) => results.map(r => r.output as string),
|
|
2545
|
-
* });
|
|
2546
|
-
* if (pattern.type === "parallel") {
|
|
2547
|
-
* const result = await orchestrator.runParallel(pattern.handlers, input, pattern.merge);
|
|
2548
|
-
* }
|
|
2549
|
-
* ```
|
|
2550
|
-
*/
|
|
2551
|
-
declare function patternFromJSON<T = unknown>(json: SerializedPattern, overrides?: Partial<ExecutionPattern<T>>): ExecutionPattern<T>;
|
|
2552
1905
|
|
|
2553
|
-
export { type SafeParseResult as $, type
|
|
1906
|
+
export { type SafeParseResult as $, type AgentRegistry as A, type BackpressureStrategy as B, type MessageSummarizer as C, type DebatePattern as D, type ExecutionPattern as E, type MultiAgentOrchestratorOptions as F, type GuardrailTriggeredChunk as G, type HealthMonitor as H, type MultiAgentRunCallOptions as I, type MultiAgentState as J, type MultiplexedStreamChunk as K, type MultiplexedStreamResult as L, type MultiAgentOrchestrator as M, type OrchestratorStreamChunk as N, type OrchestratorOptions as O, type ParallelPattern as P, type OrchestratorStreamResult as Q, type RacePattern as R, type SequentialPattern as S, type ProgressChunk as T, type RaceResult as U, type RaceSuccessEntry as V, type ReflectionConfig as W, type ReflectionContext as X, type ReflectionEvaluator as Y, ReflectionExhaustedError as Z, type RunCallOptions as _, type ReflectionEvaluation as a, type SafeParseable as a0, Semaphore as a1, type StreamChunk as a2, type StreamRunOptions as a3, type StreamRunner as a4, type StreamingGuardrail as a5, type StreamingGuardrailResult as a6, type StreamingRunResult as a7, type StructuredOutputConfig as a8, StructuredOutputError as a9, filterStream as aA, forkFromCheckpoint as aB, getCheckpointProgress as aC, getPatternStep as aD, mapStream as aE, mergeTaggedStreams as aF, tapStream as aG, withReflection as aH, withStructuredOutput as aI, type TaskContext as aa, type TaskRegistration as ab, type TokenChunk as ac, type ToolEndChunk as ad, type ToolStartChunk as ae, adaptOutputGuardrail as af, collectTokens as ag, combineStreamingGuardrails as ah, createAgentMemory as ai, createAgentOrchestrator as aj, createDebugTimeline as ak, createDebugTimelinePlugin as al, createHealthMonitor as am, createHybridStrategy as an, createKeyPointsSummarizer as ao, createLLMSummarizer as ap, createLengthStreamingGuardrail as aq, createMultiAgentOrchestrator as ar, createPatternStreamingGuardrail as as, createSlidingWindowStrategy as at, createStreamingRunner as au, createTokenBasedStrategy as av, createToxicityStreamingGuardrail as aw, createTruncationSummarizer as ax, diffCheckpoints as ay, extractJsonFromOutput as az, type ReflectIterationRecord as b, type ReflectPattern as c, type SupervisorPattern as d, type RunAgentRequirement as e, type DebateResult as f, type AgentHealthMetrics as g, type DebugTimeline as h, type AgentMemory as i, type AgentMemoryConfig as j, type AgentOrchestrator as k, type AgentRegistration as l, type DebugTimelineListener as m, type DebugTimelineOptions as n, type DoneChunk as o, type ErrorChunk as p, type HandoffRequest as q, type HandoffResult as r, type HealthCircuitState as s, type MemoryManageResult as t, type MemoryState as u, type MemoryStrategy as v, type MemoryStrategyConfig as w, type MemoryStrategyResult as x, type MergedTaggedStreamResult as y, type MessageChunk as z };
|