@nookplot/runtime 0.5.147 → 0.5.149
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/__tests__/goalLoop.test.d.ts +2 -0
- package/dist/__tests__/goalLoop.test.d.ts.map +1 -0
- package/dist/__tests__/goalLoop.test.js +358 -0
- package/dist/__tests__/goalLoop.test.js.map +1 -0
- package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -1
- package/dist/__tests__/helpers/mockRuntime.js +7 -0
- package/dist/__tests__/helpers/mockRuntime.js.map +1 -1
- package/dist/__tests__/loadProfile.test.d.ts +8 -0
- package/dist/__tests__/loadProfile.test.d.ts.map +1 -0
- package/dist/__tests__/loadProfile.test.js +134 -0
- package/dist/__tests__/loadProfile.test.js.map +1 -0
- package/dist/__tests__/usdcBudget.test.d.ts +2 -0
- package/dist/__tests__/usdcBudget.test.d.ts.map +1 -0
- package/dist/__tests__/usdcBudget.test.js +128 -0
- package/dist/__tests__/usdcBudget.test.js.map +1 -0
- package/dist/__tests__/x402.test.d.ts +2 -0
- package/dist/__tests__/x402.test.d.ts.map +1 -0
- package/dist/__tests__/x402.test.js +117 -0
- package/dist/__tests__/x402.test.js.map +1 -0
- package/dist/actionCatalog.generated.d.ts +1 -1
- package/dist/actionCatalog.generated.d.ts.map +1 -1
- package/dist/actionCatalog.generated.js +13 -3
- package/dist/actionCatalog.generated.js.map +1 -1
- package/dist/goal/goalLoop.d.ts +78 -0
- package/dist/goal/goalLoop.d.ts.map +1 -0
- package/dist/goal/goalLoop.js +388 -0
- package/dist/goal/goalLoop.js.map +1 -0
- package/dist/goal/goalPrompts.d.ts +20 -0
- package/dist/goal/goalPrompts.d.ts.map +1 -0
- package/dist/goal/goalPrompts.js +54 -0
- package/dist/goal/goalPrompts.js.map +1 -0
- package/dist/goal/types.d.ts +102 -0
- package/dist/goal/types.d.ts.map +1 -0
- package/dist/goal/types.js +7 -0
- package/dist/goal/types.js.map +1 -0
- package/dist/identity.d.ts +51 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +50 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/loadProfile.d.ts +100 -0
- package/dist/loadProfile.d.ts.map +1 -0
- package/dist/loadProfile.js +221 -0
- package/dist/loadProfile.js.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/usdcBudget.d.ts +90 -0
- package/dist/usdcBudget.d.ts.map +1 -0
- package/dist/usdcBudget.js +155 -0
- package/dist/usdcBudget.js.map +1 -0
- package/dist/x402.d.ts +69 -0
- package/dist/x402.d.ts.map +1 -0
- package/dist/x402.js +139 -0
- package/dist/x402.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GoalLoop — the L3 step-by-step execution engine for goal-driven agents.
|
|
3
|
+
*
|
|
4
|
+
* Invoked by `AutonomousAgent.bootstrapGoal()` when an agent was forged
|
|
5
|
+
* with `initial_goal` set (typically via an L1 swarm suggestion).
|
|
6
|
+
*
|
|
7
|
+
* The loop:
|
|
8
|
+
* 1. Asks the LLM "what's the next step?" given the goal + recent history
|
|
9
|
+
* 2. Parses a JSON decision from the response
|
|
10
|
+
* 3. Executes or records the decision
|
|
11
|
+
* 4. Checks termination conditions (complete, budget, stuck, capability gap)
|
|
12
|
+
*
|
|
13
|
+
* Design choices (see ROADMAP_orchestrator-swarm-autodeploy.md §3):
|
|
14
|
+
* - Atomic goals, no project decomposition (v1 simplification)
|
|
15
|
+
* - Budget is soft — the real gate is owner NOOK balance, not the goal cap
|
|
16
|
+
* - 3 reformulations of the same step → blocked_stuck
|
|
17
|
+
* - 3 consecutive no-ops → treat as complete (the agent has nothing else to do)
|
|
18
|
+
*
|
|
19
|
+
* @module goal/goalLoop
|
|
20
|
+
*/
|
|
21
|
+
import { GOAL_STEP_SYSTEM_PROMPT, buildGoalStepUserPrompt } from "./goalPrompts.js";
|
|
22
|
+
import { buildCorrectivePrompt, checkForDoomLoopFromSignatures, makeSignature, } from "../doomLoop.js";
|
|
23
|
+
const DEFAULT_MAX_STEPS = 20;
|
|
24
|
+
const DEFAULT_MAX_NOOPS = 3;
|
|
25
|
+
const DEFAULT_MAX_REFORMULATIONS = 3;
|
|
26
|
+
const DOOM_LOOP_MAX_TRIGGERS = 3;
|
|
27
|
+
const DOOM_LOOP_SIGNATURE_WINDOW = 30;
|
|
28
|
+
export class GoalLoop {
|
|
29
|
+
runtime;
|
|
30
|
+
goal;
|
|
31
|
+
budgetNook;
|
|
32
|
+
maxSteps;
|
|
33
|
+
maxNoops;
|
|
34
|
+
maxReformulations;
|
|
35
|
+
verbose;
|
|
36
|
+
inferenceCall;
|
|
37
|
+
parentSwarmId;
|
|
38
|
+
recentSteps = [];
|
|
39
|
+
spentNook = 0n;
|
|
40
|
+
stepsExecuted = 0;
|
|
41
|
+
toolSignatures = [];
|
|
42
|
+
doomLoopTriggers = 0;
|
|
43
|
+
doomLoopNote = null;
|
|
44
|
+
constructor(opts) {
|
|
45
|
+
this.runtime = opts.runtime;
|
|
46
|
+
this.goal = opts.goal;
|
|
47
|
+
this.budgetNook = opts.budgetNook;
|
|
48
|
+
this.maxSteps = opts.maxSteps ?? DEFAULT_MAX_STEPS;
|
|
49
|
+
this.maxNoops = opts.maxConsecutiveNoops ?? DEFAULT_MAX_NOOPS;
|
|
50
|
+
this.maxReformulations = opts.maxReformulations ?? DEFAULT_MAX_REFORMULATIONS;
|
|
51
|
+
this.verbose = opts.verbose ?? false;
|
|
52
|
+
this.parentSwarmId = opts.parentSwarmId ?? null;
|
|
53
|
+
this.inferenceCall = opts.inferenceCall ?? this.defaultInferenceCall.bind(this);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Run the loop to completion. Returns exactly one of four outcomes.
|
|
57
|
+
* Never throws for normal termination — only throws for unrecoverable
|
|
58
|
+
* infrastructure errors (e.g. runtime not connected).
|
|
59
|
+
*/
|
|
60
|
+
async run() {
|
|
61
|
+
let consecutiveNoops = 0;
|
|
62
|
+
let sameStepRepetitions = 0;
|
|
63
|
+
let lastStepDescription = "";
|
|
64
|
+
for (let step = 0; step < this.maxSteps; step++) {
|
|
65
|
+
// Hard USDC spend cap (budgetUsdc) — a per-agent ledger shared with every
|
|
66
|
+
// pay_api dispatch site in this process. Unlike budgetNook (soft/warn-only
|
|
67
|
+
// below) this TERMINATES the loop so goal work can't continue spending
|
|
68
|
+
// once the cap is consumed. Optional-chained so mock runtimes without a
|
|
69
|
+
// usdcBudget (tests) are unaffected.
|
|
70
|
+
if (this.runtime.usdcBudget?.isExhausted()) {
|
|
71
|
+
return {
|
|
72
|
+
outcome: "blocked_budget",
|
|
73
|
+
spentNook: this.spentNook,
|
|
74
|
+
spentUsdcBaseUnits: this.runtime.usdcBudget.spent,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const decision = await this.askLLMForNextAction();
|
|
78
|
+
if (!decision) {
|
|
79
|
+
consecutiveNoops++;
|
|
80
|
+
if (consecutiveNoops >= this.maxNoops) {
|
|
81
|
+
return this.finalizeFallback("LLM returned unparseable output 3x");
|
|
82
|
+
}
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
// --- Termination check: complete ---
|
|
86
|
+
if (decision.type === "complete") {
|
|
87
|
+
return {
|
|
88
|
+
outcome: "complete",
|
|
89
|
+
artifact: {
|
|
90
|
+
title: decision.title?.slice(0, 200) || "Goal artifact",
|
|
91
|
+
body: decision.body?.slice(0, 80_000) || "(empty)",
|
|
92
|
+
domain: decision.domain?.slice(0, 120) || "general",
|
|
93
|
+
},
|
|
94
|
+
stepsExecuted: this.stepsExecuted,
|
|
95
|
+
spentNook: this.spentNook,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// --- Termination check: capability gap ---
|
|
99
|
+
if (decision.type === "needs_capability") {
|
|
100
|
+
return {
|
|
101
|
+
outcome: "blocked_capability",
|
|
102
|
+
capabilityNeeded: decision.description.slice(0, 1000),
|
|
103
|
+
suggestedPreset: decision.suggestedPreset,
|
|
104
|
+
spentNook: this.spentNook,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// --- Stuck detection (same step repeated N times) ---
|
|
108
|
+
if (decision.description === lastStepDescription) {
|
|
109
|
+
sameStepRepetitions++;
|
|
110
|
+
if (sameStepRepetitions >= this.maxReformulations) {
|
|
111
|
+
return {
|
|
112
|
+
outcome: "blocked_stuck",
|
|
113
|
+
stuckReason: decision.description.slice(0, 1000),
|
|
114
|
+
spentNook: this.spentNook,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
sameStepRepetitions = 0;
|
|
120
|
+
}
|
|
121
|
+
lastStepDescription = decision.description;
|
|
122
|
+
// --- No-op ---
|
|
123
|
+
if (decision.type === "noop") {
|
|
124
|
+
consecutiveNoops++;
|
|
125
|
+
if (consecutiveNoops >= this.maxNoops) {
|
|
126
|
+
return this.finalizeFallback("agent returned 3 no-ops in a row");
|
|
127
|
+
}
|
|
128
|
+
await this.recordStepRemotely(step + 1, "noop", decision.description, "", 0);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
consecutiveNoops = 0;
|
|
132
|
+
// --- Execute the action ---
|
|
133
|
+
const execResult = await this.executeAction(decision);
|
|
134
|
+
this.spentNook += BigInt(Math.max(0, Math.round(execResult.costNook)));
|
|
135
|
+
this.stepsExecuted++;
|
|
136
|
+
this.recentSteps.push({
|
|
137
|
+
stepNumber: step + 1,
|
|
138
|
+
actionType: decision.actionName,
|
|
139
|
+
outputSummary: execResult.output,
|
|
140
|
+
});
|
|
141
|
+
if (this.recentSteps.length > 16)
|
|
142
|
+
this.recentSteps.shift();
|
|
143
|
+
await this.recordStepRemotely(step + 1, decision.actionName, decision.description, execResult.output, execResult.costNook);
|
|
144
|
+
// --- Doom-loop detection (same tool+args 3x, or A,B,A,B patterns) ---
|
|
145
|
+
// Triggers inject a corrective prompt for the next turn.
|
|
146
|
+
// 3 triggers in one goal short-circuits to blocked_stuck.
|
|
147
|
+
this.toolSignatures.push(makeSignature(decision.actionName, decision.actionParams));
|
|
148
|
+
if (this.toolSignatures.length > DOOM_LOOP_SIGNATURE_WINDOW) {
|
|
149
|
+
this.toolSignatures = this.toolSignatures.slice(-DOOM_LOOP_SIGNATURE_WINDOW);
|
|
150
|
+
}
|
|
151
|
+
const offender = checkForDoomLoopFromSignatures(this.toolSignatures);
|
|
152
|
+
if (offender) {
|
|
153
|
+
this.doomLoopTriggers++;
|
|
154
|
+
if (this.doomLoopTriggers >= DOOM_LOOP_MAX_TRIGGERS) {
|
|
155
|
+
return {
|
|
156
|
+
outcome: "blocked_stuck",
|
|
157
|
+
stuckReason: `doom loop on '${offender}' (${this.doomLoopTriggers} triggers)`.slice(0, 1000),
|
|
158
|
+
spentNook: this.spentNook,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
this.doomLoopNote = buildCorrectivePrompt(offender);
|
|
162
|
+
}
|
|
163
|
+
// --- Soft budget warning (non-blocking) ---
|
|
164
|
+
if (this.spentNook > this.budgetNook) {
|
|
165
|
+
if (this.verbose) {
|
|
166
|
+
console.warn(`[goalLoop] Over soft budget: spent=${this.spentNook} budget=${this.budgetNook}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Hit maxSteps cap without calling `complete` — treat as done.
|
|
171
|
+
return this.finalizeFallback(`hit maxSteps cap (${this.maxSteps})`);
|
|
172
|
+
}
|
|
173
|
+
// =======================================================================
|
|
174
|
+
// Private helpers
|
|
175
|
+
// =======================================================================
|
|
176
|
+
async askLLMForNextAction() {
|
|
177
|
+
try {
|
|
178
|
+
let userPrompt = buildGoalStepUserPrompt(this.goal, this.recentSteps, this.spentNook, this.budgetNook);
|
|
179
|
+
if (this.doomLoopNote) {
|
|
180
|
+
userPrompt = `${this.doomLoopNote}\n\n---\n\n${userPrompt}`;
|
|
181
|
+
this.doomLoopNote = null;
|
|
182
|
+
}
|
|
183
|
+
const response = await this.inferenceCall({
|
|
184
|
+
systemPrompt: GOAL_STEP_SYSTEM_PROMPT,
|
|
185
|
+
userPrompt,
|
|
186
|
+
maxTokens: 1024,
|
|
187
|
+
temperature: 0.5,
|
|
188
|
+
});
|
|
189
|
+
this.spentNook += BigInt(Math.max(0, Math.round(response.costNook ?? 0)));
|
|
190
|
+
return parseGoalAction(response.content);
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
if (this.verbose) {
|
|
194
|
+
console.error("[goalLoop] LLM call failed:", err);
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Default inference caller — uses the runtime's inference API if available,
|
|
201
|
+
* otherwise returns a noop response. Consumers with custom inference wiring
|
|
202
|
+
* should pass `inferenceCall` in GoalLoopOptions.
|
|
203
|
+
*/
|
|
204
|
+
async defaultInferenceCall(input) {
|
|
205
|
+
// The runtime economy manager exposes inference via /v1/agents/me/inference.
|
|
206
|
+
// We don't take a hard dependency on its exact API here — cast through
|
|
207
|
+
// unknown so environments without inference wired up fall through cleanly.
|
|
208
|
+
const economy = this.runtime.economy;
|
|
209
|
+
if (!economy?.inference) {
|
|
210
|
+
throw new Error("GoalLoop has no inferenceCall configured and runtime.economy.inference is unavailable");
|
|
211
|
+
}
|
|
212
|
+
const result = (await economy.inference({
|
|
213
|
+
messages: [
|
|
214
|
+
{ role: "system", content: input.systemPrompt },
|
|
215
|
+
{ role: "user", content: input.userPrompt },
|
|
216
|
+
],
|
|
217
|
+
maxTokens: input.maxTokens,
|
|
218
|
+
temperature: input.temperature,
|
|
219
|
+
}));
|
|
220
|
+
return {
|
|
221
|
+
content: result.content ?? "",
|
|
222
|
+
costNook: result.costNook,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Execute one action via the runtime's action dispatch pipeline.
|
|
227
|
+
*
|
|
228
|
+
* All actions go through `POST /v1/actions/execute` which handles both
|
|
229
|
+
* off-chain (direct) and on-chain (sign-required) action types. This
|
|
230
|
+
* preserves the CLAUDE.md Rule 5 invariant that all on-chain state
|
|
231
|
+
* changes go through prepare → sign → relay.
|
|
232
|
+
*/
|
|
233
|
+
async executeAction(action) {
|
|
234
|
+
try {
|
|
235
|
+
const connection = this.runtime.connection;
|
|
236
|
+
if (!connection?.request) {
|
|
237
|
+
return { ok: false, output: "runtime not connected", costNook: 0 };
|
|
238
|
+
}
|
|
239
|
+
const dispatchResult = (await connection.request("POST", "/v1/actions/execute", {
|
|
240
|
+
toolName: `nookplot_${action.actionName}`,
|
|
241
|
+
payload: action.actionParams,
|
|
242
|
+
}));
|
|
243
|
+
const status = dispatchResult?.status ?? "completed";
|
|
244
|
+
if (status === "error") {
|
|
245
|
+
return {
|
|
246
|
+
ok: false,
|
|
247
|
+
output: String(dispatchResult.error ?? "action failed").slice(0, 500),
|
|
248
|
+
costNook: 0,
|
|
249
|
+
error: dispatchResult.error,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
// NOTE: sign_required actions are NOT auto-signed here. The goal loop
|
|
253
|
+
// v1 focuses on off-chain research/synthesis tools. If the LLM requests
|
|
254
|
+
// an on-chain action, we return it to the loop as output but do NOT
|
|
255
|
+
// execute — the autonomous signal path handles approval + relay for
|
|
256
|
+
// delegated actions separately.
|
|
257
|
+
if (status === "sign_required") {
|
|
258
|
+
return {
|
|
259
|
+
ok: true,
|
|
260
|
+
output: `[sign_required] ${action.actionName} — skipped in goal loop v1 (use directive or on-chain action flow)`,
|
|
261
|
+
costNook: 0,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const outputText = typeof dispatchResult.result === "string"
|
|
265
|
+
? dispatchResult.result
|
|
266
|
+
: JSON.stringify(dispatchResult.result ?? {}).slice(0, 500);
|
|
267
|
+
return {
|
|
268
|
+
ok: true,
|
|
269
|
+
output: outputText.slice(0, 500),
|
|
270
|
+
costNook: Number(dispatchResult.costNook ?? 0),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
275
|
+
return { ok: false, output: msg.slice(0, 500), costNook: 0, error: msg };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async recordStepRemotely(stepNumber, actionType, inputSummary, outputSummary, costNook) {
|
|
279
|
+
try {
|
|
280
|
+
await this.runtime.identity.recordGoalStep({
|
|
281
|
+
stepNumber,
|
|
282
|
+
actionType,
|
|
283
|
+
inputSummary: inputSummary.slice(0, 500),
|
|
284
|
+
outputSummary: outputSummary.slice(0, 500),
|
|
285
|
+
nookSpent: Math.max(0, Math.round(costNook)),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
if (this.verbose) {
|
|
290
|
+
console.error("[goalLoop] recordGoalStep failed:", err);
|
|
291
|
+
}
|
|
292
|
+
// Non-fatal — the loop continues
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Treat the current state as a completed goal. Used when the LLM stalls
|
|
297
|
+
* or the max step count is exceeded. Produces a summary artifact from
|
|
298
|
+
* the recent step history so the user has something to review.
|
|
299
|
+
*/
|
|
300
|
+
finalizeFallback(reason) {
|
|
301
|
+
const body = this.recentSteps.length === 0
|
|
302
|
+
? `Goal loop terminated: ${reason}.\n\nNo progress was made on: ${this.goal}`
|
|
303
|
+
: [
|
|
304
|
+
`# Goal Progress`,
|
|
305
|
+
``,
|
|
306
|
+
`**Goal:** ${this.goal}`,
|
|
307
|
+
``,
|
|
308
|
+
`**Termination:** ${reason}`,
|
|
309
|
+
``,
|
|
310
|
+
`**Steps executed:** ${this.stepsExecuted}`,
|
|
311
|
+
``,
|
|
312
|
+
`## Recent steps`,
|
|
313
|
+
``,
|
|
314
|
+
...this.recentSteps.map((s, i) => `${i + 1}. **${s.actionType ?? "?"}** — ${(s.outputSummary ?? "").slice(0, 200)}`),
|
|
315
|
+
].join("\n");
|
|
316
|
+
return {
|
|
317
|
+
outcome: "complete",
|
|
318
|
+
artifact: {
|
|
319
|
+
title: this.goal.slice(0, 200),
|
|
320
|
+
body,
|
|
321
|
+
domain: "goal-fallback",
|
|
322
|
+
},
|
|
323
|
+
stepsExecuted: this.stepsExecuted,
|
|
324
|
+
spentNook: this.spentNook,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// ---------------------------------------------------------------------------
|
|
329
|
+
// JSON parsing — tolerant to prose wrapping the JSON block
|
|
330
|
+
// ---------------------------------------------------------------------------
|
|
331
|
+
/**
|
|
332
|
+
* Parse a goal action from an LLM response. Tries to extract the first
|
|
333
|
+
* `{...}` JSON block from the content and coerce it into a GoalAction.
|
|
334
|
+
*
|
|
335
|
+
* Exported for unit testing.
|
|
336
|
+
*/
|
|
337
|
+
export function parseGoalAction(content) {
|
|
338
|
+
if (!content)
|
|
339
|
+
return null;
|
|
340
|
+
const match = content.match(/\{[\s\S]*\}/);
|
|
341
|
+
if (!match)
|
|
342
|
+
return null;
|
|
343
|
+
let parsed;
|
|
344
|
+
try {
|
|
345
|
+
parsed = JSON.parse(match[0]);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
if (!parsed || typeof parsed !== "object")
|
|
351
|
+
return null;
|
|
352
|
+
const obj = parsed;
|
|
353
|
+
const type = typeof obj.type === "string" ? obj.type : null;
|
|
354
|
+
if (!type)
|
|
355
|
+
return null;
|
|
356
|
+
if (type === "action") {
|
|
357
|
+
const actionName = typeof obj.action_name === "string" ? obj.action_name : "";
|
|
358
|
+
const actionParams = typeof obj.action_params === "object" && obj.action_params !== null
|
|
359
|
+
? obj.action_params
|
|
360
|
+
: {};
|
|
361
|
+
const description = typeof obj.description === "string" ? obj.description : actionName;
|
|
362
|
+
if (!actionName)
|
|
363
|
+
return null;
|
|
364
|
+
return { type: "action", actionName, actionParams, description };
|
|
365
|
+
}
|
|
366
|
+
if (type === "complete") {
|
|
367
|
+
const title = typeof obj.title === "string" ? obj.title : "";
|
|
368
|
+
const body = typeof obj.body === "string" ? obj.body : "";
|
|
369
|
+
const domain = typeof obj.domain === "string" ? obj.domain : "general";
|
|
370
|
+
const description = typeof obj.description === "string" ? obj.description : "complete";
|
|
371
|
+
if (!title || !body)
|
|
372
|
+
return null;
|
|
373
|
+
return { type: "complete", title, body, domain, description };
|
|
374
|
+
}
|
|
375
|
+
if (type === "noop") {
|
|
376
|
+
const description = typeof obj.description === "string" ? obj.description : "noop";
|
|
377
|
+
return { type: "noop", description };
|
|
378
|
+
}
|
|
379
|
+
if (type === "needs_capability") {
|
|
380
|
+
const description = typeof obj.description === "string" ? obj.description : "";
|
|
381
|
+
const suggestedPreset = typeof obj.suggested_preset === "string" ? obj.suggested_preset : undefined;
|
|
382
|
+
if (!description)
|
|
383
|
+
return null;
|
|
384
|
+
return { type: "needs_capability", description, suggestedPreset };
|
|
385
|
+
}
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=goalLoop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goalLoop.js","sourceRoot":"","sources":["../../src/goal/goalLoop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EACL,qBAAqB,EACrB,8BAA8B,EAC9B,aAAa,GAEd,MAAM,gBAAgB,CAAC;AAQxB,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,0BAA0B,GAAG,CAAC,CAAC;AACrC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,0BAA0B,G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
+
*
|
|
4
|
+
* The system prompt is deliberately terse — the agent's own soul (personality,
|
|
5
|
+
* style) is layered on top by whatever higher-level chat driver the consumer
|
|
6
|
+
* chooses. The goal loop cares only about producing valid JSON actions.
|
|
7
|
+
*
|
|
8
|
+
* @module goal/goalPrompts
|
|
9
|
+
*/
|
|
10
|
+
export declare const GOAL_STEP_SYSTEM_PROMPT = "You are an autonomous Nookplot agent working on a specific goal. Each turn, you choose the single next action that moves you toward completion.\n\nYou have access to tools including web_search (search the live web), search_knowledge (query your KG + mining traces + network), egress_request (call external APIs), and publishing actions.\n\nYour decision each turn is ONE of:\n\n1. Execute an action \u2014 return { \"type\": \"action\", \"action_name\": \"...\", \"action_params\": {...}, \"description\": \"...\" }\n2. Complete the goal \u2014 return { \"type\": \"complete\", \"title\": \"...\", \"body\": \"<final markdown artifact>\", \"domain\": \"<short topic>\", \"description\": \"...\" }\n3. Declare no-op \u2014 return { \"type\": \"noop\", \"description\": \"...\" } (use sparingly; 3 consecutive no-ops ends the goal)\n4. Declare capability gap \u2014 return { \"type\": \"needs_capability\", \"description\": \"...\", \"suggested_preset\": \"...\" | null }\n\nRules:\n- Be concise and focused. Do NOT explore beyond the goal.\n- Cite sources in the body when using web_search results.\n- Prefer search_knowledge (free) before web_search (costs credits) for anything that might be in the knowledge graph.\n- You have a hard cap of 20 steps. Do not waste them.\n- If the goal is ambiguous, interpret narrowly \u2014 complete a narrow version rather than wandering broadly.\n- Budget is a soft cap \u2014 stay under if you can, but the goal matters more than the estimate.\n- When finished, ALWAYS return type \"complete\" with the deliverable in \"body\". Do NOT keep iterating after the goal is achieved.\n\nReturn only valid JSON. No prose outside the JSON block.";
|
|
11
|
+
/**
|
|
12
|
+
* Build the per-step user prompt. Includes the goal, recent steps, and
|
|
13
|
+
* current spend. Kept deliberately compact to fit alongside the catalog
|
|
14
|
+
* of available actions that the consumer may choose to append.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildGoalStepUserPrompt(goal: string, previousSteps: Array<{
|
|
17
|
+
actionType: string | null;
|
|
18
|
+
outputSummary: string | null;
|
|
19
|
+
}>, spentNook: bigint, budgetNook: bigint): string;
|
|
20
|
+
//# sourceMappingURL=goalPrompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goalPrompts.d.ts","sourceRoot":"","sources":["../../src/goal/goalPrompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,uBAAuB,kpDAoBqB,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,KAAK,CAAC;IAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,EACjF,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,MAAM,CAkBR"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt templates for the goal loop.
|
|
3
|
+
*
|
|
4
|
+
* The system prompt is deliberately terse — the agent's own soul (personality,
|
|
5
|
+
* style) is layered on top by whatever higher-level chat driver the consumer
|
|
6
|
+
* chooses. The goal loop cares only about producing valid JSON actions.
|
|
7
|
+
*
|
|
8
|
+
* @module goal/goalPrompts
|
|
9
|
+
*/
|
|
10
|
+
export const GOAL_STEP_SYSTEM_PROMPT = `You are an autonomous Nookplot agent working on a specific goal. Each turn, you choose the single next action that moves you toward completion.
|
|
11
|
+
|
|
12
|
+
You have access to tools including web_search (search the live web), search_knowledge (query your KG + mining traces + network), egress_request (call external APIs), and publishing actions.
|
|
13
|
+
|
|
14
|
+
Your decision each turn is ONE of:
|
|
15
|
+
|
|
16
|
+
1. Execute an action — return { "type": "action", "action_name": "...", "action_params": {...}, "description": "..." }
|
|
17
|
+
2. Complete the goal — return { "type": "complete", "title": "...", "body": "<final markdown artifact>", "domain": "<short topic>", "description": "..." }
|
|
18
|
+
3. Declare no-op — return { "type": "noop", "description": "..." } (use sparingly; 3 consecutive no-ops ends the goal)
|
|
19
|
+
4. Declare capability gap — return { "type": "needs_capability", "description": "...", "suggested_preset": "..." | null }
|
|
20
|
+
|
|
21
|
+
Rules:
|
|
22
|
+
- Be concise and focused. Do NOT explore beyond the goal.
|
|
23
|
+
- Cite sources in the body when using web_search results.
|
|
24
|
+
- Prefer search_knowledge (free) before web_search (costs credits) for anything that might be in the knowledge graph.
|
|
25
|
+
- You have a hard cap of 20 steps. Do not waste them.
|
|
26
|
+
- If the goal is ambiguous, interpret narrowly — complete a narrow version rather than wandering broadly.
|
|
27
|
+
- Budget is a soft cap — stay under if you can, but the goal matters more than the estimate.
|
|
28
|
+
- When finished, ALWAYS return type "complete" with the deliverable in "body". Do NOT keep iterating after the goal is achieved.
|
|
29
|
+
|
|
30
|
+
Return only valid JSON. No prose outside the JSON block.`;
|
|
31
|
+
/**
|
|
32
|
+
* Build the per-step user prompt. Includes the goal, recent steps, and
|
|
33
|
+
* current spend. Kept deliberately compact to fit alongside the catalog
|
|
34
|
+
* of available actions that the consumer may choose to append.
|
|
35
|
+
*/
|
|
36
|
+
export function buildGoalStepUserPrompt(goal, previousSteps, spentNook, budgetNook) {
|
|
37
|
+
const spent = spentNook.toString();
|
|
38
|
+
const budget = budgetNook.toString();
|
|
39
|
+
const stepsText = previousSteps.length === 0
|
|
40
|
+
? "(no previous steps)"
|
|
41
|
+
: previousSteps
|
|
42
|
+
.slice(-8)
|
|
43
|
+
.map((s, i) => `${i + 1}. ${s.actionType ?? "?"}: ${(s.outputSummary ?? "").slice(0, 180)}`)
|
|
44
|
+
.join("\n");
|
|
45
|
+
return `Goal: ${goal}
|
|
46
|
+
|
|
47
|
+
Previous steps:
|
|
48
|
+
${stepsText}
|
|
49
|
+
|
|
50
|
+
Spent so far: ${spent} / ${budget} NOOK (soft cap)
|
|
51
|
+
|
|
52
|
+
Choose the next action. Return JSON only.`;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=goalPrompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goalPrompts.js","sourceRoot":"","sources":["../../src/goal/goalPrompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;yDAoBkB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAY,EACZ,aAAiF,EACjF,SAAiB,EACjB,UAAkB;IAElB,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;IACrC,MAAM,SAAS,GAAG,aAAa,CAAC,MAAM,KAAK,CAAC;QAC1C,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,aAAa;aACV,KAAK,CAAC,CAAC,CAAC,CAAC;aACT,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,UAAU,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;aAC3F,IAAI,CAAC,IAAI,CAAC,CAAC;IAElB,OAAO,SAAS,IAAI;;;EAGpB,SAAS;;gBAEK,KAAK,MAAM,MAAM;;0CAES,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal loop types — shared interfaces for the L3 autonomous goal execution loop.
|
|
3
|
+
*
|
|
4
|
+
* @module goal/types
|
|
5
|
+
*/
|
|
6
|
+
import type { NookplotRuntime } from "../index.js";
|
|
7
|
+
/**
|
|
8
|
+
* One action the LLM can return each turn of the goal loop.
|
|
9
|
+
* Parsed from the model's JSON response.
|
|
10
|
+
*/
|
|
11
|
+
export type GoalAction = {
|
|
12
|
+
type: "action";
|
|
13
|
+
actionName: string;
|
|
14
|
+
actionParams: Record<string, unknown>;
|
|
15
|
+
description: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "complete";
|
|
18
|
+
title: string;
|
|
19
|
+
body: string;
|
|
20
|
+
domain: string;
|
|
21
|
+
description: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "noop";
|
|
24
|
+
description: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: "needs_capability";
|
|
27
|
+
description: string;
|
|
28
|
+
suggestedPreset?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Terminal state of a GoalLoop.run() invocation. Always one of the four
|
|
32
|
+
* outcomes — the loop never throws for normal termination conditions.
|
|
33
|
+
*/
|
|
34
|
+
export type GoalResult = {
|
|
35
|
+
outcome: "complete";
|
|
36
|
+
artifact: {
|
|
37
|
+
title: string;
|
|
38
|
+
body: string;
|
|
39
|
+
domain: string;
|
|
40
|
+
};
|
|
41
|
+
stepsExecuted: number;
|
|
42
|
+
spentNook: bigint;
|
|
43
|
+
} | {
|
|
44
|
+
outcome: "blocked_budget";
|
|
45
|
+
spentNook: bigint;
|
|
46
|
+
/** USDC base units spent via `pay_api` when the hard `budgetUsdc` cap
|
|
47
|
+
* halted the loop. (The legacy `budgetNook` cap is soft/warn-only and
|
|
48
|
+
* never produces this outcome.) */
|
|
49
|
+
spentUsdcBaseUnits: bigint;
|
|
50
|
+
} | {
|
|
51
|
+
outcome: "blocked_stuck";
|
|
52
|
+
stuckReason: string;
|
|
53
|
+
spentNook: bigint;
|
|
54
|
+
} | {
|
|
55
|
+
outcome: "blocked_capability";
|
|
56
|
+
capabilityNeeded: string;
|
|
57
|
+
suggestedPreset?: string;
|
|
58
|
+
spentNook: bigint;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for a single run of the GoalLoop.
|
|
62
|
+
*/
|
|
63
|
+
export interface GoalLoopOptions {
|
|
64
|
+
runtime: NookplotRuntime;
|
|
65
|
+
goal: string;
|
|
66
|
+
/** Soft cap — loop continues past this but emits a warning. */
|
|
67
|
+
budgetNook: bigint;
|
|
68
|
+
parentSwarmId?: string | null;
|
|
69
|
+
/** Hard stop on step count. Default 20. */
|
|
70
|
+
maxSteps?: number;
|
|
71
|
+
/** Hard stop on consecutive no-op responses. Default 3. */
|
|
72
|
+
maxConsecutiveNoops?: number;
|
|
73
|
+
/** Hard stop on consecutive identical step descriptions. Default 3. */
|
|
74
|
+
maxReformulations?: number;
|
|
75
|
+
/** Optional verbose logging. */
|
|
76
|
+
verbose?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Optional LLM caller — defaults to runtime.economy.inference or a runtime
|
|
79
|
+
* provided by the consumer. The caller is abstracted because different
|
|
80
|
+
* environments wire inference differently (platform / BYOK / Ollama).
|
|
81
|
+
*/
|
|
82
|
+
inferenceCall?: (input: {
|
|
83
|
+
systemPrompt: string;
|
|
84
|
+
userPrompt: string;
|
|
85
|
+
maxTokens: number;
|
|
86
|
+
temperature: number;
|
|
87
|
+
}) => Promise<{
|
|
88
|
+
content: string;
|
|
89
|
+
costNook?: number;
|
|
90
|
+
}>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Result of executing a single step within the goal loop.
|
|
94
|
+
* costNook is optional because many actions are free (off-chain tools).
|
|
95
|
+
*/
|
|
96
|
+
export interface StepExecutionResult {
|
|
97
|
+
ok: boolean;
|
|
98
|
+
output: string;
|
|
99
|
+
costNook: number;
|
|
100
|
+
error?: string;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/goal/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,QAAQ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