@mcp-abap-adt/llm-agent-server 17.0.0 → 18.0.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/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/smart-agent/build-stepper-root.d.ts +97 -0
- package/dist/smart-agent/build-stepper-root.d.ts.map +1 -0
- package/dist/smart-agent/build-stepper-root.js +242 -0
- package/dist/smart-agent/build-stepper-root.js.map +1 -0
- package/dist/smart-agent/config.d.ts +119 -1
- package/dist/smart-agent/config.d.ts.map +1 -1
- package/dist/smart-agent/config.js +219 -24
- package/dist/smart-agent/config.js.map +1 -1
- package/dist/smart-agent/jsonl-knowledge-backend.d.ts +19 -0
- package/dist/smart-agent/jsonl-knowledge-backend.d.ts.map +1 -0
- package/dist/smart-agent/jsonl-knowledge-backend.js +46 -0
- package/dist/smart-agent/jsonl-knowledge-backend.js.map +1 -0
- package/dist/smart-agent/session-meta-store.d.ts +53 -0
- package/dist/smart-agent/session-meta-store.d.ts.map +1 -0
- package/dist/smart-agent/session-meta-store.js +36 -0
- package/dist/smart-agent/session-meta-store.js.map +1 -0
- package/dist/smart-agent/smart-server.d.ts +99 -2
- package/dist/smart-agent/smart-server.d.ts.map +1 -1
- package/dist/smart-agent/smart-server.js +546 -8
- package/dist/smart-agent/smart-server.js.map +1 -1
- package/dist/smart-agent/stepper-coordinator-handler.d.ts +36 -0
- package/dist/smart-agent/stepper-coordinator-handler.d.ts.map +1 -0
- package/dist/smart-agent/stepper-coordinator-handler.js +214 -0
- package/dist/smart-agent/stepper-coordinator-handler.js.map +1 -0
- package/package.json +26 -26
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "
|
|
1
|
+
export declare const PACKAGE_VERSION = "18.0.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type IKnowledgeRagHandle, type ILlm, type IStepper, type ITaskFormalizer, type LlmCallEntry, TokenLedger } from '@mcp-abap-adt/llm-agent';
|
|
2
|
+
import { RootFinalizer, Stepper } from '@mcp-abap-adt/llm-agent-libs';
|
|
3
|
+
import { type NormalizedLlmMap, type StepperCompositionSpec, type StepperCoordinatorConfig } from './config.js';
|
|
4
|
+
import type { SmartServerLlmConfig } from './smart-server.js';
|
|
5
|
+
export interface BuildStepperRootInput {
|
|
6
|
+
/** Raw coordinator config object (e.g. the `coordinator:` YAML block). */
|
|
7
|
+
coordCfg: Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Pre-built named registry of subagent Steppers — DI/test override for
|
|
10
|
+
* deep-stepper mode. When non-empty it is used as childSteppers verbatim;
|
|
11
|
+
* when empty, child Steppers are built from `subagents` (the normal path).
|
|
12
|
+
*/
|
|
13
|
+
registry: ReadonlyMap<string, IStepper>;
|
|
14
|
+
/**
|
|
15
|
+
* Declared subagents (name + description) from the `subagents:` YAML block.
|
|
16
|
+
* In deep-stepper mode each becomes a recursive child Stepper sharing this
|
|
17
|
+
* run's planner/executor/reviewer/ledger, and is advertised to the planner so
|
|
18
|
+
* it can delegate sub-goals via a node's `agent`. Ignored in other modes.
|
|
19
|
+
*/
|
|
20
|
+
subagents?: ReadonlyArray<{
|
|
21
|
+
name: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** Factory to build an ILlm from a config; used for all roles. */
|
|
25
|
+
makeLlm: (config: SmartServerLlmConfig) => Promise<ILlm>;
|
|
26
|
+
/** Per-sessionId knowledge RAG factory. */
|
|
27
|
+
knowledgeRagFor: (sessionId: string) => IKnowledgeRagHandle;
|
|
28
|
+
/** Shared tools RAG handle. */
|
|
29
|
+
toolsRag: import('@mcp-abap-adt/llm-agent').IToolsRagHandle;
|
|
30
|
+
/** MCP tool invoker. */
|
|
31
|
+
callMcp: (name: string, args: unknown, signal?: AbortSignal) => Promise<string>;
|
|
32
|
+
/** Monotonically-unique stepper-ID minter. */
|
|
33
|
+
mintStepperId: () => string;
|
|
34
|
+
/**
|
|
35
|
+
* Normalized per-role LLM map (top-level `llm:` block after normalization).
|
|
36
|
+
* Roles resolve via: llmMap[role] → llmMap.main → pipelineFallback.
|
|
37
|
+
* When both are undefined, roles fall back to a stub (test path).
|
|
38
|
+
*/
|
|
39
|
+
llmMap?: NormalizedLlmMap;
|
|
40
|
+
/**
|
|
41
|
+
* Pipeline fallback config (`pipeline.llm.main`). Used as last resort when
|
|
42
|
+
* a role is absent from llmMap.
|
|
43
|
+
*/
|
|
44
|
+
pipelineFallback?: SmartServerLlmConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Optional usage logger. When supplied, every per-role LLM call is logged
|
|
47
|
+
* via a LoggingLlm decorator so byComponent is populated in requestLogger.
|
|
48
|
+
* Matches IRequestLogger.logLlmCall(entry) — pass a bound wrapper that
|
|
49
|
+
* injects the traceId as requestId.
|
|
50
|
+
*/
|
|
51
|
+
logLlmCall?: (entry: LlmCallEntry) => void;
|
|
52
|
+
}
|
|
53
|
+
export interface BuiltStepperRoot {
|
|
54
|
+
rootStepper: Stepper;
|
|
55
|
+
finalizer: RootFinalizer;
|
|
56
|
+
budget: {
|
|
57
|
+
depthRemaining: number;
|
|
58
|
+
tokens: TokenLedger;
|
|
59
|
+
};
|
|
60
|
+
maxParallelSteps: number;
|
|
61
|
+
/**
|
|
62
|
+
* Present only when `coordinator.formalizeTask` is enabled. The handler calls
|
|
63
|
+
* it ONCE on the raw prompt and threads the resulting TaskSpec into
|
|
64
|
+
* rootStepper.run. Absent → no formalization (behaves as before).
|
|
65
|
+
*/
|
|
66
|
+
taskFormalizer?: ITaskFormalizer;
|
|
67
|
+
}
|
|
68
|
+
export type { CompositionNode, StepperCompositionSpec } from './config.js';
|
|
69
|
+
/** Build-time dependencies (everything not part of the composition itself). */
|
|
70
|
+
export interface BuildFromCompositionDeps {
|
|
71
|
+
makeLlm: (config: SmartServerLlmConfig) => Promise<ILlm>;
|
|
72
|
+
callMcp: (name: string, args: unknown, signal?: AbortSignal) => Promise<string>;
|
|
73
|
+
mintStepperId: () => string;
|
|
74
|
+
llmMap?: NormalizedLlmMap;
|
|
75
|
+
pipelineFallback?: SmartServerLlmConfig;
|
|
76
|
+
logLlmCall?: (entry: LlmCallEntry) => void;
|
|
77
|
+
subagents?: ReadonlyArray<{
|
|
78
|
+
name: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
}>;
|
|
81
|
+
registry: ReadonlyMap<string, IStepper>;
|
|
82
|
+
}
|
|
83
|
+
/** Map a parsed coordinator config to the front-end-agnostic composition spec. */
|
|
84
|
+
export declare function toCompositionSpec(config: StepperCoordinatorConfig): StepperCompositionSpec;
|
|
85
|
+
/**
|
|
86
|
+
* yaml front-end: parse the raw coordinator config block → composition spec →
|
|
87
|
+
* build. Thin wrapper over {@link buildFromComposition}; a code builder can call
|
|
88
|
+
* buildFromComposition directly with a spec it constructs itself (parity).
|
|
89
|
+
*/
|
|
90
|
+
export declare function buildStepperRoot(input: BuildStepperRootInput): Promise<BuiltStepperRoot>;
|
|
91
|
+
/**
|
|
92
|
+
* Build the root Stepper + finalizer from a front-end-agnostic composition spec.
|
|
93
|
+
* The yaml path reaches here via buildStepperRoot; a code builder can call this
|
|
94
|
+
* directly. Each role LLM resolves via llmMap[role] → llmMap.main → fallback.
|
|
95
|
+
*/
|
|
96
|
+
export declare function buildFromComposition(spec: StepperCompositionSpec, deps: BuildFromCompositionDeps): Promise<BuiltStepperRoot>;
|
|
97
|
+
//# sourceMappingURL=build-stepper-root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-stepper-root.d.ts","sourceRoot":"","sources":["../../src/smart-agent/build-stepper-root.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,IAAI,EAET,KAAK,QAAQ,EAEb,KAAK,eAAe,EACpB,KAAK,YAAY,EAEjB,WAAW,EACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO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,242 @@
|
|
|
1
|
+
import { TokenLedger, } from '@mcp-abap-adt/llm-agent';
|
|
2
|
+
import { CyclicReActExecutor, LlmNeedResolver, LlmReviewStrategy, LlmStepperPlanner, LlmTaskFormalizer, LoggingLlm, RootFinalizer, StaticPlanner, Stepper, StepperInterpreter, } from '@mcp-abap-adt/llm-agent-libs';
|
|
3
|
+
import { parseStepperCoordinatorConfig, resolveLlmConfig, } from './config.js';
|
|
4
|
+
const STUB_LLM_CFG = {
|
|
5
|
+
provider: 'openai',
|
|
6
|
+
apiKey: '',
|
|
7
|
+
model: 'stub',
|
|
8
|
+
};
|
|
9
|
+
/** Map a parsed coordinator config to the front-end-agnostic composition spec. */
|
|
10
|
+
export function toCompositionSpec(config) {
|
|
11
|
+
return {
|
|
12
|
+
planner: config.flow.planner,
|
|
13
|
+
granularity: config.flow.granularity,
|
|
14
|
+
...(config.flow.plan ? { plan: config.flow.plan } : {}),
|
|
15
|
+
...(config.flow.nodes ? { nodes: config.flow.nodes } : {}),
|
|
16
|
+
executor: config.flow.executor,
|
|
17
|
+
finalizer: config.flow.finalizer,
|
|
18
|
+
...(config.flow.plannerSystemPrompt
|
|
19
|
+
? { plannerSystemPrompt: config.flow.plannerSystemPrompt }
|
|
20
|
+
: {}),
|
|
21
|
+
...(config.flow.executorSystemPrompt
|
|
22
|
+
? { executorSystemPrompt: config.flow.executorSystemPrompt }
|
|
23
|
+
: {}),
|
|
24
|
+
reviewerAtDepths: config.reviewerAtDepths,
|
|
25
|
+
maxParallelSteps: config.maxParallelSteps,
|
|
26
|
+
maxDepth: config.maxDepth,
|
|
27
|
+
tokenBudget: config.tokenBudget,
|
|
28
|
+
formalizeTask: config.formalizeTask,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* yaml front-end: parse the raw coordinator config block → composition spec →
|
|
33
|
+
* build. Thin wrapper over {@link buildFromComposition}; a code builder can call
|
|
34
|
+
* buildFromComposition directly with a spec it constructs itself (parity).
|
|
35
|
+
*/
|
|
36
|
+
export async function buildStepperRoot(input) {
|
|
37
|
+
const config = parseStepperCoordinatorConfig(input.coordCfg);
|
|
38
|
+
return buildFromComposition(toCompositionSpec(config), {
|
|
39
|
+
makeLlm: input.makeLlm,
|
|
40
|
+
callMcp: input.callMcp,
|
|
41
|
+
mintStepperId: input.mintStepperId,
|
|
42
|
+
llmMap: input.llmMap,
|
|
43
|
+
pipelineFallback: input.pipelineFallback,
|
|
44
|
+
logLlmCall: input.logLlmCall,
|
|
45
|
+
subagents: input.subagents,
|
|
46
|
+
registry: input.registry,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build the root Stepper + finalizer from a front-end-agnostic composition spec.
|
|
51
|
+
* The yaml path reaches here via buildStepperRoot; a code builder can call this
|
|
52
|
+
* directly. Each role LLM resolves via llmMap[role] → llmMap.main → fallback.
|
|
53
|
+
*/
|
|
54
|
+
export async function buildFromComposition(spec, deps) {
|
|
55
|
+
const { registry, makeLlm, callMcp, mintStepperId, llmMap, pipelineFallback, logLlmCall, } = deps;
|
|
56
|
+
// Shared token ledger — ONE instance per run (review R2-F1). Created up-front
|
|
57
|
+
// so every role's LLM decorator can spend on it (see resolveRoleLlm).
|
|
58
|
+
const tokens = new TokenLedger(spec.tokenBudget);
|
|
59
|
+
// ---- Per-role LLM resolver -----------------------------------------------
|
|
60
|
+
// Priority chain: llmMap[role] → llmMap.main → pipelineFallback → STUB_LLM_CFG.
|
|
61
|
+
// Mirrors the resolution chain used in buildDagCoordinatorDeps.
|
|
62
|
+
//
|
|
63
|
+
// `spendOnLedger` makes the role's LLM decrement the SHARED token ledger after
|
|
64
|
+
// each call, so coordinator.stepper.tokenBudget bounds ALL stepper work — not
|
|
65
|
+
// just the executor (review Finding 2). The executor passes `false`: it spends
|
|
66
|
+
// on the same ledger itself (see CyclicReActExecutor) and double-counting must
|
|
67
|
+
// be avoided. The decorator is now installed whenever EITHER logging or ledger
|
|
68
|
+
// accounting is needed (previously it was skipped entirely without a logger).
|
|
69
|
+
const resolveRoleLlm = async (role, component, spendOnLedger) => {
|
|
70
|
+
const cfg = resolveLlmConfig(llmMap, role, pipelineFallback) ?? STUB_LLM_CFG;
|
|
71
|
+
const inner = await makeLlm(cfg);
|
|
72
|
+
if (!logLlmCall && !spendOnLedger)
|
|
73
|
+
return inner;
|
|
74
|
+
// Wrap with LoggingLlm so every call to this role's LLM is (a) logged to
|
|
75
|
+
// byComponent and (b) charged to the shared ledger. Fires once per call
|
|
76
|
+
// (chat or streamChat) after usage is known.
|
|
77
|
+
return new LoggingLlm(inner, (usage, durationMs) => {
|
|
78
|
+
if (logLlmCall) {
|
|
79
|
+
logLlmCall({
|
|
80
|
+
component,
|
|
81
|
+
model: inner.model ?? cfg.model ?? 'unknown',
|
|
82
|
+
promptTokens: usage.promptTokens,
|
|
83
|
+
completionTokens: usage.completionTokens,
|
|
84
|
+
totalTokens: usage.totalTokens,
|
|
85
|
+
durationMs,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (spendOnLedger)
|
|
89
|
+
tokens.spend(usage);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
// ---- Build per-role LLMs --------------------------------------------------
|
|
93
|
+
// Every non-executor role charges the shared ledger; the executor self-spends.
|
|
94
|
+
const plannerLlm = await resolveRoleLlm('planner', 'planner', true);
|
|
95
|
+
const executorLlm = await resolveRoleLlm('executor', 'tool-loop', false);
|
|
96
|
+
const finalizerLlm = await resolveRoleLlm('finalizer', 'finalizer', true);
|
|
97
|
+
const reviewerLlm = await resolveRoleLlm('reviewer', 'reviewer', true);
|
|
98
|
+
// Tool-definer LLM: detects an unmet-tool-need ("I can't … no tool") in a
|
|
99
|
+
// candidate final answer and yields the phrase to search toolsRag with before
|
|
100
|
+
// the retry. Logged under its OWN component 'tool-definer' — NOT 'classifier'
|
|
101
|
+
// — so its cost is distinct from the (skipped-in-stepper) request classifier
|
|
102
|
+
// and the name reflects its actual job. Resolves via role 'classifier' (falls
|
|
103
|
+
// back to main); point it at a small model via `llm.classifier` in YAML.
|
|
104
|
+
const toolDefinerLlm = await resolveRoleLlm('classifier', 'tool-definer', true);
|
|
105
|
+
// ---- Reviewer (always built; Stepper only invokes at configured depths) ---
|
|
106
|
+
const reviewer = new LlmReviewStrategy(reviewerLlm);
|
|
107
|
+
// One shared interpreter + need-resolver across the whole tree.
|
|
108
|
+
const interpreter = new StepperInterpreter();
|
|
109
|
+
const needResolver = new LlmNeedResolver(toolDefinerLlm);
|
|
110
|
+
// Leaf executor per spec.executor profile (reuses the shared executor LLM +
|
|
111
|
+
// need-resolver): 'simple' = single pass (maxIter 2); cyclic-react/recursive
|
|
112
|
+
// run the full ReAct loop (maxIter 10).
|
|
113
|
+
const makeExecutor = (s) => new CyclicReActExecutor({
|
|
114
|
+
llm: executorLlm,
|
|
115
|
+
callMcp,
|
|
116
|
+
component: 'tool-loop',
|
|
117
|
+
maxIterations: s.executor === 'simple' ? 2 : 10,
|
|
118
|
+
needResolver,
|
|
119
|
+
...(s.executorSystemPrompt
|
|
120
|
+
? { systemPrompt: s.executorSystemPrompt }
|
|
121
|
+
: {}),
|
|
122
|
+
});
|
|
123
|
+
const trivialPlanner = {
|
|
124
|
+
name: 'trivial',
|
|
125
|
+
async plan(inp) {
|
|
126
|
+
return {
|
|
127
|
+
objective: inp.prompt,
|
|
128
|
+
nodes: [{ id: 'root', goal: inp.prompt }],
|
|
129
|
+
createdAt: 0,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
// Recursive composition builder. LLMs, token ledger, reviewer, interpreter are
|
|
134
|
+
// SHARED across the whole tree (shared-ledger invariant); only the planner, the
|
|
135
|
+
// executor profile and the childSteppers vary per (nested) spec.
|
|
136
|
+
const buildNode = (s, depth) => {
|
|
137
|
+
const ex = makeExecutor(s);
|
|
138
|
+
const childMap = new Map();
|
|
139
|
+
const nodes = s.nodes ?? [];
|
|
140
|
+
// Planner selection. Declared `nodes` ⇒ static plan over them (nested nodes
|
|
141
|
+
// carry agent=id so the interpreter routes them into their child Stepper).
|
|
142
|
+
let planner;
|
|
143
|
+
if (nodes.length > 0) {
|
|
144
|
+
const planNodes = nodes.map((n) => ({
|
|
145
|
+
id: n.id,
|
|
146
|
+
goal: n.goal,
|
|
147
|
+
...(n.dependsOn ? { dependsOn: n.dependsOn } : {}),
|
|
148
|
+
...(n.flow ? { agent: n.id } : {}),
|
|
149
|
+
}));
|
|
150
|
+
planner = new StaticPlanner(planNodes);
|
|
151
|
+
}
|
|
152
|
+
else if (s.planner === 'none') {
|
|
153
|
+
planner = trivialPlanner;
|
|
154
|
+
}
|
|
155
|
+
else if (s.planner === 'static') {
|
|
156
|
+
planner = new StaticPlanner(s.plan ?? []);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
planner = new LlmStepperPlanner(plannerLlm, s.granularity, s.plannerSystemPrompt);
|
|
160
|
+
}
|
|
161
|
+
// (a) Structural recursion: declared nested-flow nodes → child Steppers.
|
|
162
|
+
for (const n of nodes) {
|
|
163
|
+
if (n.flow)
|
|
164
|
+
childMap.set(n.id, buildNode(n.flow, depth + 1));
|
|
165
|
+
}
|
|
166
|
+
// (b) Runtime subagent recursion (executor: recursive) — only when NO nested
|
|
167
|
+
// nodes were declared; preserves the existing deep-stepper behaviour. Children
|
|
168
|
+
// share this run's planner/executor/reviewer + role LLMs (shared ledger), and
|
|
169
|
+
// point childSteppers back to the SAME map so recursion continues.
|
|
170
|
+
let catalog = [];
|
|
171
|
+
if (s.executor === 'recursive' && nodes.length === 0) {
|
|
172
|
+
catalog = (deps.subagents ?? []).map((sa) => ({
|
|
173
|
+
name: sa.name,
|
|
174
|
+
description: sa.description,
|
|
175
|
+
}));
|
|
176
|
+
if (registry.size > 0) {
|
|
177
|
+
for (const [k, v] of registry)
|
|
178
|
+
childMap.set(k, v);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
for (const sa of catalog) {
|
|
182
|
+
childMap.set(sa.name, new Stepper({
|
|
183
|
+
name: sa.name,
|
|
184
|
+
planner,
|
|
185
|
+
interpreter,
|
|
186
|
+
executor: ex,
|
|
187
|
+
childSteppers: childMap,
|
|
188
|
+
reviewer,
|
|
189
|
+
reviewerAtDepths: s.reviewerAtDepths,
|
|
190
|
+
depth: depth + 1,
|
|
191
|
+
maxParallelSteps: s.maxParallelSteps,
|
|
192
|
+
mintStepperId,
|
|
193
|
+
childAgentCatalog: catalog,
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return new Stepper({
|
|
199
|
+
name: depth === 0 ? 'root' : `node-d${depth}`,
|
|
200
|
+
planner,
|
|
201
|
+
interpreter,
|
|
202
|
+
executor: ex,
|
|
203
|
+
childSteppers: childMap,
|
|
204
|
+
reviewer,
|
|
205
|
+
reviewerAtDepths: s.reviewerAtDepths,
|
|
206
|
+
depth,
|
|
207
|
+
maxParallelSteps: s.maxParallelSteps,
|
|
208
|
+
mintStepperId,
|
|
209
|
+
childAgentCatalog: catalog,
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
const rootStepper = buildNode(spec, 0);
|
|
213
|
+
// Depth budget covers BOTH declared nesting and runtime recursion.
|
|
214
|
+
const nestingDepth = (s) => {
|
|
215
|
+
const ds = (s.nodes ?? [])
|
|
216
|
+
.filter((n) => n.flow)
|
|
217
|
+
.map((n) => 1 + nestingDepth(n.flow));
|
|
218
|
+
return ds.length ? Math.max(...ds) : 0;
|
|
219
|
+
};
|
|
220
|
+
const anyRecursive = (s) => s.executor === 'recursive' ||
|
|
221
|
+
(s.nodes ?? []).some((n) => !!n.flow && anyRecursive(n.flow));
|
|
222
|
+
const baseDepth = spec.executor === 'recursive'
|
|
223
|
+
? spec.maxDepth
|
|
224
|
+
: spec.planner === 'none' && (spec.nodes?.length ?? 0) === 0
|
|
225
|
+
? 0
|
|
226
|
+
: 1;
|
|
227
|
+
const depthRemaining = Math.max(baseDepth, nestingDepth(spec), anyRecursive(spec) ? spec.maxDepth : 0);
|
|
228
|
+
const finalizer = new RootFinalizer(finalizerLlm);
|
|
229
|
+
// Task formalizer (opt-in): uses the strong planner-tier LLM to produce a
|
|
230
|
+
// compact TaskSpec once at the root. Built only when configured.
|
|
231
|
+
const taskFormalizer = spec.formalizeTask
|
|
232
|
+
? new LlmTaskFormalizer(plannerLlm)
|
|
233
|
+
: undefined;
|
|
234
|
+
return {
|
|
235
|
+
rootStepper,
|
|
236
|
+
finalizer,
|
|
237
|
+
budget: { depthRemaining, tokens },
|
|
238
|
+
maxParallelSteps: spec.maxParallelSteps,
|
|
239
|
+
...(taskFormalizer ? { taskFormalizer } : {}),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=build-stepper-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-stepper-root.js","sourceRoot":"","sources":["../../src/smart-agent/build-stepper-root.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACP,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEL,6BAA6B,EAC7B,gBAAgB,GAGjB,MAAM,aAAa,CAAC;AAkErB,MAAM,YAAY,GAAyB;IACzC,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,EAAE;IACV,KAAK,EAAE,MAAM;CACL,CAAC;AAuBX,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAC/B,MAAgC;IAEhC,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;QAC5B,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW;QACpC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IA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,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared config utilities for SmartServer.
|
|
3
3
|
*/
|
|
4
|
-
import type { IFinalizer, ILlm, ISubAgentContextBuilder, IToolSelectionStrategy } from '@mcp-abap-adt/llm-agent';
|
|
4
|
+
import type { IFinalizer, ILlm, ISubAgentContextBuilder, IToolSelectionStrategy, PlanNode } from '@mcp-abap-adt/llm-agent';
|
|
5
5
|
import { AutoActivation, ExplicitActivation, HybridDispatch, OneShotPlanning, ReplanOnErrorPlanning, SelfDispatch, SkillStepsPlanning, SubAgentDispatch } from '@mcp-abap-adt/llm-agent-libs';
|
|
6
6
|
import type { SmartServerConfig, SmartServerLlmConfig } from './smart-server.js';
|
|
7
7
|
export type LlmConfigMap = Record<string, SmartServerLlmConfig>;
|
|
@@ -147,4 +147,122 @@ export interface ResolveSmartServerConfigOptions {
|
|
|
147
147
|
configPath?: string;
|
|
148
148
|
}
|
|
149
149
|
export declare function resolveSmartServerConfig(args?: ResolveConfigArgs, yaml?: YamlConfig, env?: NodeJS.ProcessEnv, options?: ResolveSmartServerConfigOptions): Omit<SmartServerConfig, 'log'>;
|
|
150
|
+
/**
|
|
151
|
+
* Stepper coordinator modes.
|
|
152
|
+
*/
|
|
153
|
+
export type StepperMode = 'cyclic-react' | 'planned-react';
|
|
154
|
+
/**
|
|
155
|
+
* Configuration for the recursive Stepper coordinator.
|
|
156
|
+
*/
|
|
157
|
+
/**
|
|
158
|
+
* A node of a declared composition tree. A leaf executes via the executor; a
|
|
159
|
+
* node with a nested `flow` runs as a child Stepper (structural recursion —
|
|
160
|
+
* the sub-cycle is declared and visible).
|
|
161
|
+
*/
|
|
162
|
+
export interface CompositionNode {
|
|
163
|
+
id: string;
|
|
164
|
+
goal: string;
|
|
165
|
+
dependsOn?: string[];
|
|
166
|
+
flow?: StepperCompositionSpec;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Front-end-agnostic description of a Stepper composition. Produced by BOTH the
|
|
170
|
+
* yaml parser (`toCompositionSpec`) and a code builder; consumed by the runtime
|
|
171
|
+
* (`buildFromComposition`). Recursive via `nodes[].flow`.
|
|
172
|
+
*/
|
|
173
|
+
export interface StepperCompositionSpec {
|
|
174
|
+
planner: 'none' | 'llm' | 'static';
|
|
175
|
+
granularity: 'shallow' | 'detailed';
|
|
176
|
+
plan?: PlanNode[];
|
|
177
|
+
/** Declared composition nodes; a node with a nested `flow` is a sub-Stepper. */
|
|
178
|
+
nodes?: CompositionNode[];
|
|
179
|
+
executor: 'simple' | 'cyclic-react' | 'recursive';
|
|
180
|
+
finalizer: 'llm';
|
|
181
|
+
/** Optional system-prompt overrides (consumer-supplied via yaml/builder).
|
|
182
|
+
* Undefined → the built-in STEPPER_PLANNER_SYSTEM / EXECUTOR_SYSTEM. */
|
|
183
|
+
plannerSystemPrompt?: string;
|
|
184
|
+
executorSystemPrompt?: string;
|
|
185
|
+
reviewerAtDepths: {
|
|
186
|
+
has(depth: number): boolean;
|
|
187
|
+
};
|
|
188
|
+
maxParallelSteps: number;
|
|
189
|
+
maxDepth: number;
|
|
190
|
+
tokenBudget: number;
|
|
191
|
+
formalizeTask: boolean;
|
|
192
|
+
}
|
|
193
|
+
export interface StepperCoordinatorConfig {
|
|
194
|
+
mode: StepperMode;
|
|
195
|
+
reviewerAtDepths: {
|
|
196
|
+
has(depth: number): boolean;
|
|
197
|
+
};
|
|
198
|
+
maxParallelSteps: number;
|
|
199
|
+
maxDepth: number;
|
|
200
|
+
tokenBudget: number;
|
|
201
|
+
/**
|
|
202
|
+
* Session-scope knowledge entries written into a NEW session's knowledge-RAG
|
|
203
|
+
* before planning. A deployment/config PARAMETER (not agent code) — the
|
|
204
|
+
* operator fills it with guidance for THEIR actual MCP tools (e.g. which read
|
|
205
|
+
* tool reads what). Surfaced to the planner/executor as "Known facts", and the
|
|
206
|
+
* executor enriches its tool-search query with these facts, so a tool named in
|
|
207
|
+
* a seed takes priority over tools the bare-prompt MCP search would surface.
|
|
208
|
+
* The runtime stays MCP-agnostic: tool knowledge lives here as data.
|
|
209
|
+
*/
|
|
210
|
+
knowledgeSeed: ReadonlyArray<{
|
|
211
|
+
content: string;
|
|
212
|
+
artifactType: string;
|
|
213
|
+
}>;
|
|
214
|
+
/**
|
|
215
|
+
* Opt-in (default false): formalize the raw prompt into a compact TaskSpec
|
|
216
|
+
* (objective + scope + constraints + deliverable) ONCE at the root, then
|
|
217
|
+
* thread it down to every planner and executor as a persistent anchor and as
|
|
218
|
+
* the overall-intent prefix for tool search. Off → behaves exactly as before.
|
|
219
|
+
*/
|
|
220
|
+
formalizeTask: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Resolved program flow (the composition the coordinator runs). Always
|
|
223
|
+
* present: parsed from an explicit `coordinator.flow` block when given, else
|
|
224
|
+
* derived from `mode` as a preset (so `mode` is now just a preset alias).
|
|
225
|
+
*
|
|
226
|
+
* - planner 'none' → trivial single-node plan (node goal = prompt)
|
|
227
|
+
* 'llm' → LlmStepperPlanner (LLM decomposition)
|
|
228
|
+
* 'static' → StaticPlanner (declarative `flow.plan`, no LLM)
|
|
229
|
+
* - executor 'cyclic-react' → leaf ReAct loop, no recursion
|
|
230
|
+
* 'recursive' → may spawn child Steppers up to maxDepth
|
|
231
|
+
* - finalizer 'llm' (RootFinalizer). 'passthrough' is reserved (not yet built).
|
|
232
|
+
*/
|
|
233
|
+
flow: {
|
|
234
|
+
planner: 'none' | 'llm' | 'static';
|
|
235
|
+
/** How much the LLM planner decomposes up front (eager): 'shallow' (few
|
|
236
|
+
* high-level steps) | 'detailed' (full concrete-leaf decomposition).
|
|
237
|
+
* Ignored by 'none'/'static'. Default 'shallow'. */
|
|
238
|
+
granularity: 'shallow' | 'detailed';
|
|
239
|
+
/** Leaf executor profile: 'simple' (single pass) | 'cyclic-react' (ReAct
|
|
240
|
+
* loop) | 'recursive' (spawns child Steppers — lazy decomposition). */
|
|
241
|
+
executor: 'simple' | 'cyclic-react' | 'recursive';
|
|
242
|
+
finalizer: 'llm';
|
|
243
|
+
/** Optional per-role system-prompt overrides:
|
|
244
|
+
* `flow.planner.systemPrompt` / `flow.executor.systemPrompt`. */
|
|
245
|
+
plannerSystemPrompt?: string;
|
|
246
|
+
executorSystemPrompt?: string;
|
|
247
|
+
/** Declarative plan nodes, required when planner === 'static'. */
|
|
248
|
+
plan?: PlanNode[];
|
|
249
|
+
/**
|
|
250
|
+
* Declared composition nodes (the "yaml is a tree" shape). A node with a
|
|
251
|
+
* nested `flow` is a sub-Stepper. When present at the root, the planner is
|
|
252
|
+
* effectively static over these nodes.
|
|
253
|
+
*/
|
|
254
|
+
nodes?: CompositionNode[];
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Parse stepper coordinator configuration from a raw config object.
|
|
259
|
+
*
|
|
260
|
+
* Supports:
|
|
261
|
+
* - `mode` (string) — default 'planned-react'; one of cyclic-react | planned-react
|
|
262
|
+
* - `stepper.maxParallelSteps` (number) — default 4
|
|
263
|
+
* - `stepper.maxDepth` (number) — default 4
|
|
264
|
+
* - `stepper.tokenBudget` (number) — default 1,000,000
|
|
265
|
+
* - `stepper.reviewer.atDepths` (number[] | 'all') — default [0,1]; 'all' means accept any depth
|
|
266
|
+
*/
|
|
267
|
+
export declare function parseStepperCoordinatorConfig(coord: Record<string, unknown>): StepperCoordinatorConfig;
|
|
150
268
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/smart-agent/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EACV,UAAU,EACV,IAAI,EACJ,uBAAuB,EACvB,sBAAsB,
|
|
1
|
+
{"version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