@backendkit-labs/agent-core 0.38.0 → 0.40.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/README.md +28 -6
- package/dist/commands/index.d.ts +0 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +1 -3
- package/dist/commands/index.js.map +1 -1
- package/dist/engine/AgentEngine.d.ts +1 -22
- package/dist/engine/AgentEngine.d.ts.map +1 -1
- package/dist/engine/AgentEngine.js +17 -109
- package/dist/engine/AgentEngine.js.map +1 -1
- package/dist/engine/ApprovalGate.d.ts +4 -3
- package/dist/engine/ApprovalGate.d.ts.map +1 -1
- package/dist/engine/ApprovalGate.js +9 -13
- package/dist/engine/ApprovalGate.js.map +1 -1
- package/dist/engine/MCPRegistrar.js +1 -1
- package/dist/engine/MCPRegistrar.js.map +1 -1
- package/dist/engine/coding-pipeline-hooks.d.ts +28 -0
- package/dist/engine/coding-pipeline-hooks.d.ts.map +1 -0
- package/dist/engine/coding-pipeline-hooks.js +91 -0
- package/dist/engine/coding-pipeline-hooks.js.map +1 -0
- package/dist/engine/createBaseEngine.d.ts +16 -40
- package/dist/engine/createBaseEngine.d.ts.map +1 -1
- package/dist/engine/createBaseEngine.js +20 -16
- package/dist/engine/createBaseEngine.js.map +1 -1
- package/dist/engine/qa-orchestrator.d.ts +11 -12
- package/dist/engine/qa-orchestrator.d.ts.map +1 -1
- package/dist/engine/qa-orchestrator.js +13 -16
- package/dist/engine/qa-orchestrator.js.map +1 -1
- package/dist/governance/hooks.d.ts +2 -0
- package/dist/governance/hooks.d.ts.map +1 -1
- package/dist/governance/hooks.js.map +1 -1
- package/dist/governance/policy.d.ts +5 -0
- package/dist/governance/policy.d.ts.map +1 -1
- package/dist/governance/policy.js +15 -1
- package/dist/governance/policy.js.map +1 -1
- package/dist/index.d.ts +11 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -82
- package/dist/index.js.map +1 -1
- package/dist/reflection/index.d.ts +0 -7
- package/dist/reflection/index.d.ts.map +1 -1
- package/dist/reflection/index.js +1 -16
- package/dist/reflection/index.js.map +1 -1
- package/dist/sandbox/types.d.ts +2 -2
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/shared/llm/chat-client.d.ts +16 -0
- package/dist/shared/llm/chat-client.d.ts.map +1 -0
- package/dist/shared/llm/chat-client.js +27 -0
- package/dist/shared/llm/chat-client.js.map +1 -0
- package/dist/shared/llm/resilient-client.d.ts +1 -1
- package/dist/shared/llm/resilient-client.d.ts.map +1 -1
- package/dist/skills/activator.d.ts +0 -2
- package/dist/skills/activator.d.ts.map +1 -1
- package/dist/skills/activator.js +0 -61
- package/dist/skills/activator.js.map +1 -1
- package/dist/skills/index.d.ts +1 -8
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +4 -17
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/types.d.ts +0 -27
- package/dist/skills/types.d.ts.map +1 -1
- package/dist/sources/index.d.ts +54 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +71 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/tools/defineTool.d.ts +2 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +1 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/services.d.ts +7 -0
- package/dist/tools/services.d.ts.map +1 -0
- package/dist/tools/services.js +11 -0
- package/dist/tools/services.js.map +1 -0
- package/dist/types/index.d.ts +14 -38
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +89 -93
package/README.md
CHANGED
|
@@ -1114,14 +1114,35 @@ const engine = createBaseEngine({ ...opts, hooks: [review], maxHookContinues: 3
|
|
|
1114
1114
|
|
|
1115
1115
|
---
|
|
1116
1116
|
|
|
1117
|
+
## Sources of agents, skills and instructions
|
|
1118
|
+
|
|
1119
|
+
The engine reads no file by itself. Where its agents, skills and instruction layers come from is declared with sources, and an engine built without them touches no disk:
|
|
1120
|
+
|
|
1121
|
+
```typescript
|
|
1122
|
+
const engine = createBaseEngine({
|
|
1123
|
+
...opts,
|
|
1124
|
+
agentSources: [{ list: async () => myAgents() }], // AgentSource: merged with `agents`, a later source wins by id
|
|
1125
|
+
skillSources: [{ list: async () => mySkills() }], // SkillSource: merged with `skills` and `loadSkills`
|
|
1126
|
+
instructionSources: [{ load: async ({ cwd }) => [ // InstructionSource: layers for the system prompt
|
|
1127
|
+
{ title: 'House rules', content: await readRules(cwd) },
|
|
1128
|
+
] }],
|
|
1129
|
+
});
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
Instruction layers are sanitized (`sanitizeDiskContent`) and added after the other sections of the system prompt, through a `systemPrompt` hook. A source that throws fails the turn.
|
|
1133
|
+
|
|
1134
|
+
The file-based adapters of a terminal app (`AGENT.md`, `USER.md`, `~/.appName/agents`, skills from GitHub or skills.sh, the built-in slash commands, workspaces, checkpoints and trust) live in `@backendkit-labs/agent-coding/cli`: `fileAgentSource`, `fileInstructionSource`, `SkillLoader`, `registerBuiltinCommands`...
|
|
1135
|
+
|
|
1136
|
+
---
|
|
1137
|
+
|
|
1117
1138
|
## Skills and slash commands
|
|
1118
1139
|
|
|
1119
|
-
Skills are reusable prompt snippets that augment agent behavior. Slash commands let users invoke agent features directly.
|
|
1140
|
+
Skills are reusable prompt snippets that augment agent behavior. Slash commands let users invoke agent features directly. The registries (`SkillRegistry`, `SkillActivator`, `SlashCommandRegistry`) are in core; loading, installing and the built-in commands are in `@backendkit-labs/agent-coding/cli`.
|
|
1120
1141
|
|
|
1121
1142
|
### Loading built-in skills
|
|
1122
1143
|
|
|
1123
1144
|
```typescript
|
|
1124
|
-
import { SkillLoader, createSkillManager } from '@backendkit-labs/agent-
|
|
1145
|
+
import { SkillLoader, createSkillManager } from '@backendkit-labs/agent-coding/cli';
|
|
1125
1146
|
|
|
1126
1147
|
const manager = createSkillManager('my-app');
|
|
1127
1148
|
|
|
@@ -1167,7 +1188,8 @@ const systemContext = activator.buildContext(['pr-review']);
|
|
|
1167
1188
|
Built-in commands: `/help`, `/clear`, `/status`, `/skills`, `/agents`, `/workspace`, `/checkpoint`.
|
|
1168
1189
|
|
|
1169
1190
|
```typescript
|
|
1170
|
-
import { SlashCommandRegistry
|
|
1191
|
+
import { SlashCommandRegistry } from '@backendkit-labs/agent-core';
|
|
1192
|
+
import { registerBuiltinCommands } from '@backendkit-labs/agent-coding/cli';
|
|
1171
1193
|
|
|
1172
1194
|
const cmds = new SlashCommandRegistry();
|
|
1173
1195
|
registerBuiltinCommands(cmds);
|
|
@@ -1200,7 +1222,7 @@ Save and restore session state for recovery and branching.
|
|
|
1200
1222
|
### Save a checkpoint
|
|
1201
1223
|
|
|
1202
1224
|
```typescript
|
|
1203
|
-
import { createCheckpoint, listCheckpoints, readCheckpoint } from '@backendkit-labs/agent-
|
|
1225
|
+
import { createCheckpoint, listCheckpoints, readCheckpoint } from '@backendkit-labs/agent-coding/cli';
|
|
1204
1226
|
|
|
1205
1227
|
// After a successful milestone
|
|
1206
1228
|
await createCheckpoint({
|
|
@@ -1231,7 +1253,7 @@ await engine.run('Continue from where we left off');
|
|
|
1231
1253
|
### Compact a long session
|
|
1232
1254
|
|
|
1233
1255
|
```typescript
|
|
1234
|
-
import { compactSession } from '@backendkit-labs/agent-
|
|
1256
|
+
import { compactSession } from '@backendkit-labs/agent-coding/cli';
|
|
1235
1257
|
|
|
1236
1258
|
// Compress a 200-message conversation to a short summary
|
|
1237
1259
|
const compacted = await compactSession(
|
|
@@ -1253,7 +1275,7 @@ Manage multiple projects and let agents switch context between them.
|
|
|
1253
1275
|
import {
|
|
1254
1276
|
loadWorkspaces, createWorkspace, addProject,
|
|
1255
1277
|
setActiveProject, buildWorkspaceContext,
|
|
1256
|
-
} from '@backendkit-labs/agent-
|
|
1278
|
+
} from '@backendkit-labs/agent-coding/cli';
|
|
1257
1279
|
|
|
1258
1280
|
// One-time setup
|
|
1259
1281
|
const config = await loadWorkspaces('my-app');
|
package/dist/commands/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { SlashCommandRegistry } from './SlashCommandRegistry';
|
|
2
2
|
export type { SlashCommand, SlashCommandHandler, CommandContext, CommandAgentInfo, CommandSkillInfo } from './SlashCommandRegistry';
|
|
3
|
-
export { registerBuiltinCommands } from './builtin';
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/commands/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SlashCommandRegistry = void 0;
|
|
4
4
|
var SlashCommandRegistry_1 = require("./SlashCommandRegistry");
|
|
5
5
|
Object.defineProperty(exports, "SlashCommandRegistry", { enumerable: true, get: function () { return SlashCommandRegistry_1.SlashCommandRegistry; } });
|
|
6
|
-
var builtin_1 = require("./builtin");
|
|
7
|
-
Object.defineProperty(exports, "registerBuiltinCommands", { enumerable: true, get: function () { return builtin_1.registerBuiltinCommands; } });
|
|
8
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA"}
|
|
@@ -11,8 +11,6 @@ import type { MemorySystem } from '../agent-memory/MemorySystem';
|
|
|
11
11
|
import type { CommandContext } from '../commands/SlashCommandRegistry';
|
|
12
12
|
import type { WorkflowDef, WorkflowResult, WorkflowRunOptions } from '../workflow/types';
|
|
13
13
|
import type { WorkflowBuilder } from '../workflow/WorkflowBuilder';
|
|
14
|
-
import type { Orchestrator } from '../orchestration/orchestrator';
|
|
15
|
-
import type { QAService } from '../qa/qa-service';
|
|
16
14
|
import { type IterationMode, type IterationStats } from './IterationManager';
|
|
17
15
|
export interface AgentEngineOptions extends EngineOptions {
|
|
18
16
|
agents: AgentRegistry;
|
|
@@ -32,23 +30,10 @@ export interface AgentEngineOptions extends EngineOptions {
|
|
|
32
30
|
* Set true to keep that behavior while the profiles are fixed.
|
|
33
31
|
*/
|
|
34
32
|
allowUnlistedTools?: boolean;
|
|
35
|
-
/** Orchestrator para clasificacion de tareas, risk scoring y FSM */
|
|
36
|
-
orchestrator?: Orchestrator;
|
|
37
|
-
/**
|
|
38
|
-
* What run() does when the orchestrator throws. 'closed' (default) rethrows: the gates it would have
|
|
39
|
-
* applied cannot be silently skipped. 'open' warns on the transport and runs without orchestration.
|
|
40
|
-
*/
|
|
41
|
-
orchestratorFailureMode?: 'closed' | 'open';
|
|
42
|
-
/** QA service para revisar respuestas y registrar gates */
|
|
43
|
-
qaService?: QAService;
|
|
44
|
-
/** Si true, deshabilita las revisiones de QA automaticas */
|
|
45
|
-
noQA?: boolean;
|
|
46
|
-
/** Callback invocado cuando el QA genera una revision */
|
|
47
|
-
onQAReview?: (review: string) => void;
|
|
48
33
|
/** MCP client manager — connects to external MCP servers and registers their tools */
|
|
49
34
|
mcpManager?: MCPClientManager;
|
|
50
35
|
/**
|
|
51
|
-
* Called before executing write/execute tools (
|
|
36
|
+
* Called before executing write/execute tools (tools that declare `readOnly: false`) when
|
|
52
37
|
* iteration mode is 'manual'. Return 'approve' to run, 'approve_all' to run and disable
|
|
53
38
|
* further prompts this session, 'reject' to skip the tool call.
|
|
54
39
|
*/
|
|
@@ -300,12 +285,6 @@ export declare class AgentEngine {
|
|
|
300
285
|
private getCurrentProfile;
|
|
301
286
|
private buildAgentRoster;
|
|
302
287
|
private buildSystemPrompt;
|
|
303
|
-
/**
|
|
304
|
-
* Converts an OrchestrationResult into a system-prompt section that tells the
|
|
305
|
-
* default agent which specialists to use, in what order, and what gates apply.
|
|
306
|
-
* This closes the gap between the deterministic policy layer and the LLM layer.
|
|
307
|
-
*/
|
|
308
|
-
private buildOrchestrationBrief;
|
|
309
288
|
private resolvesDelegateTo;
|
|
310
289
|
private getToolsForAgent;
|
|
311
290
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentEngine.d.ts","sourceRoot":"","sources":["../../src/engine/AgentEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AgentEngine.d.ts","sourceRoot":"","sources":["../../src/engine/AgentEngine.ts"],"names":[],"mappings":"AAaA,OAAO,EAA2D,KAAK,WAAW,EAAmB,MAAM,qBAAqB,CAAC;AACjI,OAAO,KAAK,EAER,aAAa,EACb,QAAQ,EAMR,SAAS,EACT,QAAQ,EAIR,UAAU,EACb,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EAER,aAAa,EAIb,iBAAiB,EAGpB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAA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IAMjB,uGAAuG;YACzF,YAAY;IAc1B,OAAO,CAAC,oBAAoB;IAS5B;;;;OAIG;YACW,cAAc;YAsCd,UAAU;IAoDxB;;;OAGG;YACW,eAAe;YAQf,UAAU;IAiExB;;;;;;;;OAQG;IACH,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAI7C;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAE3B,8DAA8D;IAC9D,kBAAkB,IAAI,IAAI;IAG1B,qGAAqG;IACrG,OAAO,CAAC,YAAY;IASpB;;;;OAIG;YACW,WAAW;IA+BzB,OAAO,CAAC,YAAY;CA4CvB"}
|
|
@@ -13,7 +13,6 @@ const node_crypto_1 = require("node:crypto");
|
|
|
13
13
|
const audit_1 = require("../governance/audit");
|
|
14
14
|
const policy_1 = require("../governance/policy");
|
|
15
15
|
const approval_1 = require("../governance/approval");
|
|
16
|
-
const package_install_1 = require("./package-install");
|
|
17
16
|
const hooks_1 = require("../governance/hooks");
|
|
18
17
|
const canonical_json_1 = require("../shared/utils/canonical-json");
|
|
19
18
|
const DelegationBus_1 = require("../delegation/DelegationBus");
|
|
@@ -21,7 +20,6 @@ const SessionMemory_1 = require("../memory/SessionMemory");
|
|
|
21
20
|
const activator_1 = require("../skills/activator");
|
|
22
21
|
const WorkflowRunner_1 = require("../workflow/WorkflowRunner");
|
|
23
22
|
const IterationManager_1 = require("./IterationManager");
|
|
24
|
-
const qa_orchestrator_1 = require("./qa-orchestrator");
|
|
25
23
|
const MAX_INPUT_BYTES = 100_000; // Fix #17: 100 KB hard cap on user input
|
|
26
24
|
const ASK_AGENT_TOOL = {
|
|
27
25
|
name: 'ask_agent',
|
|
@@ -131,10 +129,10 @@ class AgentEngine {
|
|
|
131
129
|
if (this.governed) {
|
|
132
130
|
const someoneToAsk = !!(opts.approver || opts.approvals || opts.onToolApproval);
|
|
133
131
|
const configured = opts.policy ? (Array.isArray(opts.policy) ? opts.policy : [opts.policy]) : [];
|
|
134
|
-
//
|
|
132
|
+
// What a tool declares with `alwaysAsk` always asks a person, whatever the configured policy says.
|
|
135
133
|
this.policies = [
|
|
136
134
|
...(configured.length > 0 ? configured : someoneToAsk ? [policy_1.defaultToolPolicy] : []),
|
|
137
|
-
|
|
135
|
+
policy_1.declaredAskPolicy,
|
|
138
136
|
];
|
|
139
137
|
if (opts.approver) {
|
|
140
138
|
this.approver = opts.approver;
|
|
@@ -401,20 +399,6 @@ class AgentEngine {
|
|
|
401
399
|
const profile = this.getCurrentProfile();
|
|
402
400
|
if (!profile)
|
|
403
401
|
throw new Error(`Default agent "${this.currentAgentId}" not registered`);
|
|
404
|
-
// Orquestar la tarea para obtener clasificacion, risk scoring y gates requeridos
|
|
405
|
-
let orchestrationResult;
|
|
406
|
-
if (this.opts.orchestrator) {
|
|
407
|
-
try {
|
|
408
|
-
orchestrationResult = await this.opts.orchestrator.orchestrate(input);
|
|
409
|
-
}
|
|
410
|
-
catch (err) {
|
|
411
|
-
const reason = err instanceof Error ? err.message : String(err);
|
|
412
|
-
if ((this.opts.orchestratorFailureMode ?? 'closed') === 'closed') {
|
|
413
|
-
throw new Error(`Orchestrator failed; refusing to run without its gates: ${reason}`);
|
|
414
|
-
}
|
|
415
|
-
this.opts.transport.emit({ type: 'system', level: 'warn', text: `[Orchestrator] failed (${reason}); running without classification or gates` });
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
402
|
// Hooks of this turn share one context (SPEC-0014 F3). A throwing hook fails the turn.
|
|
419
403
|
this.runController = new AbortController();
|
|
420
404
|
this.lastAnswer = '';
|
|
@@ -423,12 +407,13 @@ class AgentEngine {
|
|
|
423
407
|
input,
|
|
424
408
|
state: new Map(),
|
|
425
409
|
signal: this.runController.signal,
|
|
410
|
+
hasAgent: (id) => this.opts.agents.has(id),
|
|
426
411
|
emit: (event) => this.opts.transport.emit(event),
|
|
427
412
|
};
|
|
428
413
|
try {
|
|
429
414
|
await (0, hooks_1.runHooks)(this.hooks, 'beforeRun', h => h.beforeRun(this.runCtx));
|
|
430
415
|
this.history.push({ role: 'user', content: input });
|
|
431
|
-
await this.runLoop(profile
|
|
416
|
+
await this.runLoop(profile);
|
|
432
417
|
this.saveHistory();
|
|
433
418
|
const finished = this.runCtx;
|
|
434
419
|
await (0, hooks_1.runHooks)(this.hooks, 'afterRun', h => h.afterRun(finished, { text: this.lastAnswer }));
|
|
@@ -469,7 +454,7 @@ class AgentEngine {
|
|
|
469
454
|
toolHookContext(principal) {
|
|
470
455
|
return this.runCtx
|
|
471
456
|
? { ...this.runCtx, principal }
|
|
472
|
-
: { principal, input: '', state: new Map(), signal: new AbortController().signal, emit: (e) => this.opts.transport.emit(e) };
|
|
457
|
+
: { principal, input: '', state: new Map(), signal: new AbortController().signal, hasAgent: (id) => this.opts.agents.has(id), emit: (e) => this.opts.transport.emit(e) };
|
|
473
458
|
}
|
|
474
459
|
async runWorkflow(defOrBuilder, opts = {}) {
|
|
475
460
|
if (this.pendingContextLoad)
|
|
@@ -761,65 +746,24 @@ class AgentEngine {
|
|
|
761
746
|
}
|
|
762
747
|
return parts.join('\n');
|
|
763
748
|
}
|
|
764
|
-
buildSystemPrompt(profile,
|
|
749
|
+
buildSystemPrompt(profile, hookSections = []) {
|
|
765
750
|
const isOrchestrator = profile.id === this.opts.defaultAgentId;
|
|
766
751
|
const parts = [profile.systemPrompt];
|
|
767
752
|
if (isOrchestrator)
|
|
768
753
|
parts.push(this.buildAgentRoster(profile.id));
|
|
769
754
|
if (this.opts.workingDir) {
|
|
770
755
|
parts.push(`## Working Directory\n` +
|
|
771
|
-
`\`${this.opts.workingDir}
|
|
772
|
-
`ALWAYS use RELATIVE paths with tools (e.g. \`src/index.ts\`, \`package.json\`). ` +
|
|
773
|
-
`NEVER invent absolute paths like \`/workspace/...\` or \`/home/...\`.`);
|
|
756
|
+
`\`${this.opts.workingDir}\``);
|
|
774
757
|
}
|
|
775
758
|
if (this.opts.projectContext)
|
|
776
759
|
parts.push(this.opts.projectContext);
|
|
777
|
-
// Per-agent session notes (tool quirks, learnings routed by LearningRouter)
|
|
778
|
-
const agentNotes = this.opts.store?.getAgentNotes?.(profile.id);
|
|
779
|
-
if (agentNotes)
|
|
780
|
-
parts.push(`## Agent Session Notes\n${agentNotes}`);
|
|
781
760
|
if (this.memoryContextBlock)
|
|
782
761
|
parts.push(this.memoryContextBlock);
|
|
783
762
|
if (this.activeSkillAddition)
|
|
784
763
|
parts.push(this.activeSkillAddition);
|
|
785
|
-
if (isOrchestrator && orchestrationResult) {
|
|
786
|
-
parts.push(this.buildOrchestrationBrief(orchestrationResult));
|
|
787
|
-
}
|
|
788
764
|
parts.push(...hookSections);
|
|
789
765
|
return parts.join('\n\n');
|
|
790
766
|
}
|
|
791
|
-
/**
|
|
792
|
-
* Converts an OrchestrationResult into a system-prompt section that tells the
|
|
793
|
-
* default agent which specialists to use, in what order, and what gates apply.
|
|
794
|
-
* This closes the gap between the deterministic policy layer and the LLM layer.
|
|
795
|
-
*/
|
|
796
|
-
buildOrchestrationBrief(result) {
|
|
797
|
-
const { task, selectedAgents, agentPipeline, requiredGates } = result;
|
|
798
|
-
const lines = ['## Orchestrator Analysis — Current Task'];
|
|
799
|
-
const domains = task.domains.length > 0 ? task.domains.join(', ') : 'general';
|
|
800
|
-
lines.push(`**Intent:** ${task.actionType} | **Risk:** ${task.riskLevel} | **Domains:** ${domains}`);
|
|
801
|
-
// Only surface non-trivial agent selections (skip sole-fallback case)
|
|
802
|
-
const nonFallback = selectedAgents.filter(a => !(a.agentId === 'general' && a.score <= 50));
|
|
803
|
-
if (nonFallback.length > 0) {
|
|
804
|
-
lines.push('\n**Recommended agents for this task (highest priority first):**');
|
|
805
|
-
for (const a of nonFallback) {
|
|
806
|
-
lines.push(`- ${a.agentId} — ${a.reason}`);
|
|
807
|
-
}
|
|
808
|
-
lines.push('\nWhen delegating via ask_agent, prioritize the agents listed above. ' +
|
|
809
|
-
'Do not delegate to unlisted agents unless the task explicitly requires it.');
|
|
810
|
-
}
|
|
811
|
-
if (agentPipeline && agentPipeline.length > 0) {
|
|
812
|
-
lines.push('\n**Suggested execution pipeline (respect this order):**');
|
|
813
|
-
agentPipeline.forEach((phase, i) => {
|
|
814
|
-
lines.push(`${i + 1}. [${phase.phase}] ${phase.agentId} — ${phase.purpose}`);
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
if (requiredGates.length > 0) {
|
|
818
|
-
lines.push(`\n**Required gates before commit:** ${requiredGates.join(', ')}`);
|
|
819
|
-
lines.push('Ensure each gate is satisfied before considering the task complete.');
|
|
820
|
-
}
|
|
821
|
-
return lines.join('\n');
|
|
822
|
-
}
|
|
823
767
|
resolvesDelegateTo(profile) {
|
|
824
768
|
if (!profile.delegatesTo || profile.delegatesTo.length === 0)
|
|
825
769
|
return [];
|
|
@@ -860,7 +804,7 @@ class AgentEngine {
|
|
|
860
804
|
parts.push(`## Orchestrator Analysis\n${trimmed}`);
|
|
861
805
|
return parts.join('\n\n');
|
|
862
806
|
}
|
|
863
|
-
async runLoop(profile
|
|
807
|
+
async runLoop(profile) {
|
|
864
808
|
let currentProfile = profile;
|
|
865
809
|
this.iterationManager.reset();
|
|
866
810
|
const iterManager = this.iterationManager;
|
|
@@ -882,7 +826,7 @@ class AgentEngine {
|
|
|
882
826
|
await this.prepareContext();
|
|
883
827
|
const systemMsg = {
|
|
884
828
|
role: 'system',
|
|
885
|
-
content: this.buildSystemPrompt(currentProfile,
|
|
829
|
+
content: this.buildSystemPrompt(currentProfile, await this.hookPromptSections(currentProfile)),
|
|
886
830
|
};
|
|
887
831
|
const tools = this.getToolsForAgent(currentProfile);
|
|
888
832
|
const safeHistory = this.history.sanitized();
|
|
@@ -1070,41 +1014,6 @@ class AgentEngine {
|
|
|
1070
1014
|
toolResults.push({ role: 'tool', tool_call_id: call.id, content: results[i] });
|
|
1071
1015
|
});
|
|
1072
1016
|
}
|
|
1073
|
-
// ── QA orchestration: runs when response is final (no tool calls) ─
|
|
1074
|
-
if (toolResults.length === 0 && this.opts.orchestrator && this.opts.qaService && orchestrationResult) {
|
|
1075
|
-
const qaAgentId = this.opts.agents.has('qa-engineer') ? 'qa-engineer' : undefined;
|
|
1076
|
-
const qaCtx = {
|
|
1077
|
-
clean: streamBuffer,
|
|
1078
|
-
orchestrationResult,
|
|
1079
|
-
orchestrator: this.opts.orchestrator,
|
|
1080
|
-
qaService: this.opts.qaService,
|
|
1081
|
-
allAgents: this.opts.agents.getAll(),
|
|
1082
|
-
messages: this.history.getAll(),
|
|
1083
|
-
effectiveAgentId: currentProfile.id,
|
|
1084
|
-
defaultAgentId: this.opts.defaultAgentId,
|
|
1085
|
-
qaAgentId,
|
|
1086
|
-
noQA: this.opts.noQA,
|
|
1087
|
-
onQAReview: this.opts.onQAReview,
|
|
1088
|
-
setEffectiveAgent: (agentId) => {
|
|
1089
|
-
const p = this.opts.agents.get(agentId);
|
|
1090
|
-
if (p)
|
|
1091
|
-
currentProfile = p;
|
|
1092
|
-
},
|
|
1093
|
-
};
|
|
1094
|
-
await (0, qa_orchestrator_1.advanceRequiredGates)(qaCtx);
|
|
1095
|
-
const qaProfile = (0, qa_orchestrator_1.activateQaEngineerIfNeeded)(qaCtx);
|
|
1096
|
-
if (qaProfile) {
|
|
1097
|
-
currentProfile = qaProfile;
|
|
1098
|
-
continue; // re-enter loop as qa-engineer
|
|
1099
|
-
}
|
|
1100
|
-
if (qaAgentId && currentProfile.id === qaAgentId) {
|
|
1101
|
-
await (0, qa_orchestrator_1.processQaEngineerResponse)(qaCtx);
|
|
1102
|
-
currentProfile = profile; // reset to original agent
|
|
1103
|
-
}
|
|
1104
|
-
else {
|
|
1105
|
-
await (0, qa_orchestrator_1.processInlineQaReview)(qaCtx);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
1017
|
if (toolResults.length === 0) {
|
|
1109
1018
|
// The model answered without tools: afterTurn hooks may force another pass (SPEC-0014 F3).
|
|
1110
1019
|
this.lastAnswer = streamBuffer;
|
|
@@ -1155,7 +1064,7 @@ class AgentEngine {
|
|
|
1155
1064
|
historySlice = (0, HistoryManager_1.sanitizeMessages)(historySlice);
|
|
1156
1065
|
}
|
|
1157
1066
|
const messages = [
|
|
1158
|
-
{ role: 'system', content: this.buildSystemPrompt(profile,
|
|
1067
|
+
{ role: 'system', content: this.buildSystemPrompt(profile, await this.hookPromptSections(profile)) },
|
|
1159
1068
|
...historySlice,
|
|
1160
1069
|
{ role: 'user', content: context ? `${question}\n\nContext:\n${context}` : question },
|
|
1161
1070
|
];
|
|
@@ -1494,7 +1403,7 @@ class AgentEngine {
|
|
|
1494
1403
|
const sandboxAsk = this.opts.sandbox?.approvalFor
|
|
1495
1404
|
? this.opts.sandbox.approvalFor({ agentId, sessionId: this.opts.sessionId ?? 'default' }, call.name)
|
|
1496
1405
|
: undefined;
|
|
1497
|
-
const gate = await this.serialize(() => this.approvalGate.check(call, agentId, sandboxAsk));
|
|
1406
|
+
const gate = await this.serialize(() => this.approvalGate.check(call, agentId, sandboxAsk, this.opts.tools.get(call.name)));
|
|
1498
1407
|
if (gate === 'rejected') {
|
|
1499
1408
|
return { run: false, decision: 'deny', reason: 'rejected by the approver', message: `Tool call "${call.name}" was rejected by the user.` };
|
|
1500
1409
|
}
|
|
@@ -1728,21 +1637,20 @@ class AgentEngine {
|
|
|
1728
1637
|
const id = agentId ?? this.currentAgentId;
|
|
1729
1638
|
const principal = this.principalFor(id, chain);
|
|
1730
1639
|
const profile = this.opts.agents.get(id);
|
|
1731
|
-
const
|
|
1732
|
-
const
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1640
|
+
const additionalRoots = this.opts.additionalRoots ?? [];
|
|
1641
|
+
const serviceSource = this.opts.services;
|
|
1642
|
+
const serviceMap = serviceSource
|
|
1643
|
+
? new Map(Object.entries(typeof serviceSource === 'function' ? serviceSource(profile) : serviceSource))
|
|
1644
|
+
: undefined;
|
|
1736
1645
|
return {
|
|
1737
1646
|
agentId: id,
|
|
1738
1647
|
sessionId: this.opts.sessionId ?? 'default',
|
|
1739
1648
|
principal,
|
|
1740
1649
|
workingDir: this.opts.workingDir,
|
|
1741
1650
|
memory: this.memory,
|
|
1742
|
-
|
|
1651
|
+
...(serviceMap ? { services: serviceMap } : {}),
|
|
1743
1652
|
advancedMemory: this.opts.memorySystem,
|
|
1744
1653
|
...(additionalRoots.length ? { additionalRoots } : {}),
|
|
1745
|
-
...(profile?.blockedCommands?.length ? { blockedCommands: profile.blockedCommands } : {}),
|
|
1746
1654
|
askAgent: async (agentId, question, context) => {
|
|
1747
1655
|
const result = await this.bus.runSingle({ agentId, question, context, fromAgentId: id, depth: depth + 1, chain: principal.chain });
|
|
1748
1656
|
return result.content;
|