@botbotgo/agent-harness 0.0.290 → 0.0.291
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 +20 -20
- package/README.zh.md +14 -14
- package/dist/acp.d.ts +5 -5
- package/dist/acp.js +3 -3
- package/dist/api.d.ts +20 -21
- package/dist/api.js +38 -50
- package/dist/cli.js +47 -43
- package/dist/config/agents/orchestra.yaml +3 -3
- package/dist/config/knowledge/knowledge-runtime.yaml +4 -4
- package/dist/config/runtime/runtime-memory.yaml +7 -7
- package/dist/config/runtime/workspace.yaml +7 -7
- package/dist/contracts/core.d.ts +1 -1
- package/dist/contracts/runtime.d.ts +35 -40
- package/dist/contracts/workspace.d.ts +2 -2
- package/dist/flow/build-flow-graph.js +20 -33
- package/dist/flow/export-sequence-mermaid.js +4 -4
- package/dist/flow/types.d.ts +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/init-project.js +10 -10
- package/dist/knowledge/module.js +37 -45
- package/dist/mcp.d.ts +9 -9
- package/dist/mcp.js +6 -6
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/file-store.d.ts +69 -69
- package/dist/persistence/file-store.js +224 -221
- package/dist/persistence/sqlite-request-context-store.d.ts +22 -0
- package/dist/persistence/sqlite-request-context-store.js +64 -0
- package/dist/persistence/sqlite-request-queue-store.d.ts +41 -0
- package/dist/persistence/sqlite-request-queue-store.js +120 -0
- package/dist/persistence/sqlite-store.d.ts +72 -72
- package/dist/persistence/sqlite-store.js +361 -361
- package/dist/persistence/types.d.ts +84 -84
- package/dist/protocol/a2a/http.js +79 -74
- package/dist/protocol/ag-ui/http.d.ts +7 -7
- package/dist/protocol/ag-ui/http.js +20 -20
- package/dist/resource/resource-impl.js +1 -1
- package/dist/runtime/adapter/compat/deepagent-compat.d.ts +2 -2
- package/dist/runtime/adapter/flow/invocation-flow.d.ts +6 -5
- package/dist/runtime/adapter/flow/invocation-flow.js +6 -5
- package/dist/runtime/adapter/flow/stream-runtime.d.ts +3 -3
- package/dist/runtime/adapter/flow/stream-runtime.js +5 -4
- package/dist/runtime/adapter/invocation-result.d.ts +6 -5
- package/dist/runtime/adapter/invocation-result.js +5 -4
- package/dist/runtime/adapter/middleware-assembly.js +3 -2
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -1
- package/dist/runtime/adapter/upstream-configurable-keys.d.ts +2 -0
- package/dist/runtime/adapter/upstream-configurable-keys.js +2 -0
- package/dist/runtime/agent-runtime-adapter.d.ts +11 -8
- package/dist/runtime/agent-runtime-adapter.js +36 -32
- package/dist/runtime/harness/events/events.d.ts +8 -8
- package/dist/runtime/harness/events/events.js +25 -19
- package/dist/runtime/harness/events/listener-runtime.d.ts +5 -4
- package/dist/runtime/harness/events/listener-runtime.js +7 -3
- package/dist/runtime/harness/events/runtime-event-operations.d.ts +7 -7
- package/dist/runtime/harness/events/runtime-event-operations.js +5 -5
- package/dist/runtime/harness/events/streaming.d.ts +8 -7
- package/dist/runtime/harness/events/streaming.js +20 -19
- package/dist/runtime/harness/events/timeline.js +6 -6
- package/dist/runtime/harness/index.d.ts +1 -1
- package/dist/runtime/harness/index.js +1 -1
- package/dist/runtime/harness/run/helpers.d.ts +14 -11
- package/dist/runtime/harness/run/helpers.js +10 -7
- package/dist/runtime/harness/run/inspection.d.ts +3 -2
- package/dist/runtime/harness/run/inspection.js +7 -7
- package/dist/runtime/harness/run/operator-overview.d.ts +2 -2
- package/dist/runtime/harness/run/operator-overview.js +18 -17
- package/dist/runtime/harness/run/queue-diagnostics.js +6 -6
- package/dist/runtime/harness/run/recovery.d.ts +15 -15
- package/dist/runtime/harness/run/recovery.js +53 -50
- package/dist/runtime/harness/run/resources.d.ts +2 -2
- package/dist/runtime/harness/run/resources.js +8 -8
- package/dist/runtime/harness/run/resume.d.ts +3 -3
- package/dist/runtime/harness/run/resume.js +4 -4
- package/dist/runtime/harness/run/routing.d.ts +4 -4
- package/dist/runtime/harness/run/routing.js +8 -8
- package/dist/runtime/harness/run/run-lifecycle.d.ts +12 -12
- package/dist/runtime/harness/run/run-lifecycle.js +26 -26
- package/dist/runtime/harness/run/run-operations.d.ts +45 -45
- package/dist/runtime/harness/run/run-operations.js +79 -78
- package/dist/runtime/harness/run/run-queue.d.ts +8 -8
- package/dist/runtime/harness/run/run-queue.js +16 -16
- package/dist/runtime/harness/run/run-slot-acquisition.d.ts +32 -32
- package/dist/runtime/harness/run/run-slot-acquisition.js +41 -41
- package/dist/runtime/harness/run/{thread-records.d.ts → session-records.d.ts} +6 -13
- package/dist/runtime/harness/run/{thread-records.js → session-records.js} +14 -60
- package/dist/runtime/harness/run/start-run.d.ts +36 -36
- package/dist/runtime/harness/run/start-run.js +55 -36
- package/dist/runtime/harness/run/startup-runtime.d.ts +9 -9
- package/dist/runtime/harness/run/startup-runtime.js +22 -20
- package/dist/runtime/harness/run/stream-run.d.ts +18 -18
- package/dist/runtime/harness/run/stream-run.js +52 -52
- package/dist/runtime/harness/runtime-defaults.d.ts +2 -2
- package/dist/runtime/harness/runtime-defaults.js +7 -7
- package/dist/runtime/harness/system/health-monitor.d.ts +3 -3
- package/dist/runtime/harness/system/health-monitor.js +18 -18
- package/dist/runtime/harness/system/mem0-ingestion-sync.d.ts +6 -6
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +36 -27
- package/dist/runtime/harness/system/runtime-memory-candidates.js +2 -2
- package/dist/runtime/harness/system/runtime-memory-manager.d.ts +13 -13
- package/dist/runtime/harness/system/runtime-memory-manager.js +41 -38
- package/dist/runtime/harness/system/runtime-memory-policy.d.ts +1 -1
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -1
- package/dist/runtime/harness/system/runtime-memory-records.d.ts +4 -2
- package/dist/runtime/harness/system/runtime-memory-records.js +21 -8
- package/dist/runtime/harness/system/runtime-memory-sync.d.ts +6 -6
- package/dist/runtime/harness/system/runtime-memory-sync.js +47 -44
- package/dist/runtime/harness/system/{thread-memory-sync.d.ts → session-memory-sync.d.ts} +7 -7
- package/dist/runtime/harness/system/{thread-memory-sync.js → session-memory-sync.js} +28 -28
- package/dist/runtime/harness.d.ts +33 -45
- package/dist/runtime/harness.js +273 -291
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -2
- package/dist/runtime/maintenance/file-checkpoint-saver.d.ts +1 -1
- package/dist/runtime/maintenance/file-checkpoint-saver.js +6 -6
- package/dist/runtime/maintenance/runtime-record-maintenance.d.ts +1 -1
- package/dist/runtime/maintenance/runtime-record-maintenance.js +33 -33
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.d.ts +1 -1
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +30 -10
- package/dist/runtime/support/harness-support.d.ts +2 -2
- package/dist/runtime/support/harness-support.js +7 -7
- package/dist/runtime/support/runtime-adapter-options.d.ts +2 -2
- package/dist/runtime/support/runtime-adapter-options.js +3 -3
- package/dist/runtime/support/runtime-factories.d.ts +2 -2
- package/dist/runtime/support/runtime-factories.js +10 -10
- package/dist/workspace/agent-binding-compiler.js +3 -3
- package/dist/workspace/object-loader.js +1 -1
- package/dist/workspace/support/workspace-ref-utils.d.ts +4 -3
- package/dist/workspace/support/workspace-ref-utils.js +5 -4
- package/package.json +1 -1
- package/dist/persistence/sqlite-run-context-store.d.ts +0 -22
- package/dist/persistence/sqlite-run-context-store.js +0 -64
- package/dist/persistence/sqlite-run-queue-store.d.ts +0 -41
- package/dist/persistence/sqlite-run-queue-store.js +0 -120
package/dist/runtime/harness.js
CHANGED
|
@@ -9,20 +9,20 @@ import { createBackgroundEventRuntime } from "./harness/background-runtime.js";
|
|
|
9
9
|
import { PolicyEngine } from "./harness/system/policy-engine.js";
|
|
10
10
|
import { getConcurrencyConfig, getRecoveryConfig, getRoutingDefaultAgentId, getRoutingRules, } from "../workspace/support/workspace-ref-utils.js";
|
|
11
11
|
import { createHarnessEvent, inferRoutingBindings, renderRuntimeFailure, } from "./support/harness-support.js";
|
|
12
|
-
import {
|
|
12
|
+
import { SessionMemorySync } from "./harness/system/session-memory-sync.js";
|
|
13
13
|
import { RuntimeMemorySync, readRuntimeMemorySyncConfig } from "./harness/system/runtime-memory-sync.js";
|
|
14
14
|
import { SqliteBackedStore } from "./harness/system/store.js";
|
|
15
15
|
import { HealthMonitor, readHealthMonitorConfig, } from "./harness/system/health-monitor.js";
|
|
16
|
-
import { normalizeInvocationEnvelope,
|
|
16
|
+
import { normalizeInvocationEnvelope, normalizeRequestPriority, resolveRequestListeners, } from "./harness/run/helpers.js";
|
|
17
17
|
import { emitHarnessEvent, } from "./harness/events/events.js";
|
|
18
18
|
import { createRuntimeEventOperations } from "./harness/events/runtime-event-operations.js";
|
|
19
|
-
import { appendAssistantMessage as appendLifecycleAssistantMessage,
|
|
19
|
+
import { appendAssistantMessage as appendLifecycleAssistantMessage, finalizeCancelledRequest as finalizeLifecycleCancelledRequest, finalizeContinuedRequest as finalizeLifecycleContinuedRequest, } from "./harness/run/run-lifecycle.js";
|
|
20
20
|
import { createListenerDispatchRuntime } from "./harness/events/listener-runtime.js";
|
|
21
21
|
import { buildResumePayload as buildHarnessResumePayload, resolveApprovalRecord as resolveHarnessApprovalRecord, } from "./harness/run/resume.js";
|
|
22
|
-
import {
|
|
22
|
+
import { cancelRequestOperation, executeQueuedRequestOperation, resumeRequest } from "./harness/run/run-operations.js";
|
|
23
23
|
import { projectOperatorOverview } from "./harness/run/operator-overview.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
24
|
+
import { acquireRequestSlot as acquireHarnessRunSlot } from "./harness/run/run-slot-acquisition.js";
|
|
25
|
+
import { dropPendingRequestSlot, enqueuePendingRequestSlot } from "./harness/run/run-queue.js";
|
|
26
26
|
import { getDefaultRuntimeEntryAgentId, resolveSelectedAgentId, routeAgentId } from "./harness/run/routing.js";
|
|
27
27
|
import { resolveStoreFromConfig, resolveVectorStore, } from "./harness/run/resources.js";
|
|
28
28
|
import { createRuntimeMcpServer, createToolMcpServerFromTools, serveRuntimeMcpOverStdio, serveToolsOverStdioFromHarness, } from "../mcp.js";
|
|
@@ -30,20 +30,20 @@ import { closeMcpClientsForWorkspace } from "../resource/mcp-tool-support.js";
|
|
|
30
30
|
import { getBindingRuntimeExecutionMode, } from "./support/compiled-binding.js";
|
|
31
31
|
import { bindingSupportsRunningReplay, getWorkspaceBinding, resolveWorkspaceAgentTools, } from "./harness/bindings.js";
|
|
32
32
|
import { describeWorkspaceInventory, getAgentInventoryRecord, listAgentSkills as listWorkspaceAgentSkills, } from "./harness/system/inventory.js";
|
|
33
|
-
import { createDefaultHealthSnapshot, isInventoryEnabled,
|
|
33
|
+
import { createDefaultHealthSnapshot, isInventoryEnabled, isSessionMemorySyncEnabled, } from "./harness/runtime-defaults.js";
|
|
34
34
|
import { Mem0IngestionSync, Mem0SemanticRecall, readMem0RuntimeConfig, } from "./harness/system/mem0-ingestion-sync.js";
|
|
35
35
|
import { createRuntimeMemoryManager, RuntimeMemoryFormationSync, readRuntimeMemoryFormationConfig, } from "./harness/system/runtime-memory-manager.js";
|
|
36
36
|
import { readRuntimeMemoryMaintenanceConfig, readRuntimeMemoryPolicyConfig, resolveMemoryNamespace, } from "./harness/system/runtime-memory-policy.js";
|
|
37
37
|
import { resolveRuntimeAdapterOptions } from "./support/runtime-adapter-options.js";
|
|
38
38
|
import { resolveKnowledgeStorePath } from "./support/runtime-layout.js";
|
|
39
|
-
import { initializeHarnessRuntime,
|
|
39
|
+
import { initializeHarnessRuntime, reclaimExpiredClaimedRequests as reclaimHarnessExpiredClaimedRequests, recoverStartupRequests as recoverHarnessStartupRequests, isStaleRunningRequest as isHarnessStaleRunningRequest, } from "./harness/run/startup-runtime.js";
|
|
40
40
|
import { traceStartupStage } from "./startup-tracing.js";
|
|
41
41
|
import { normalizeProcessExecutablePath } from "./support/runtime-env.js";
|
|
42
42
|
import { streamHarnessRun } from "./harness/run/stream-run.js";
|
|
43
43
|
import { defaultRequestedAgentId, prepareRunStart } from "./harness/run/start-run.js";
|
|
44
|
-
import { buildRequestInspectionRecord, buildSessionInspectionRecord, deleteSessionRecord,
|
|
44
|
+
import { buildRequestInspectionRecord, buildSessionInspectionRecord, deleteSessionRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/session-records.js";
|
|
45
45
|
import { createKnowledgeModule } from "../knowledge/index.js";
|
|
46
|
-
const
|
|
46
|
+
const ACTIVE_REQUEST_STATES = [
|
|
47
47
|
"queued",
|
|
48
48
|
"claimed",
|
|
49
49
|
"running",
|
|
@@ -51,10 +51,10 @@ const ACTIVE_RUN_STATES = [
|
|
|
51
51
|
"resuming",
|
|
52
52
|
"cancelling",
|
|
53
53
|
];
|
|
54
|
-
function
|
|
54
|
+
function toPublicRequestResultShape(result) {
|
|
55
55
|
return {
|
|
56
|
-
sessionId: result.sessionId ?? result.
|
|
57
|
-
requestId: result.requestId ?? result.
|
|
56
|
+
sessionId: result.sessionId ?? result.legacySessionId ?? "",
|
|
57
|
+
requestId: result.requestId ?? result.legacyRequestId ?? "",
|
|
58
58
|
state: result.state,
|
|
59
59
|
output: result.output,
|
|
60
60
|
finalMessageText: result.finalMessageText,
|
|
@@ -109,7 +109,7 @@ function toPublicHarnessStreamItem(item) {
|
|
|
109
109
|
case "result":
|
|
110
110
|
return {
|
|
111
111
|
type: "result",
|
|
112
|
-
result:
|
|
112
|
+
result: toPublicRequestResultShape(item.result),
|
|
113
113
|
};
|
|
114
114
|
default:
|
|
115
115
|
return item;
|
|
@@ -165,9 +165,9 @@ export class AgentHarnessRuntime {
|
|
|
165
165
|
workspace;
|
|
166
166
|
runtimeAdapterOptions;
|
|
167
167
|
static BACKGROUND_EVENT_TYPES = new Set([
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"
|
|
168
|
+
"request.created",
|
|
169
|
+
"request.queued",
|
|
170
|
+
"request.dequeued",
|
|
171
171
|
"output.delta",
|
|
172
172
|
]);
|
|
173
173
|
eventBus = new EventBus();
|
|
@@ -180,15 +180,15 @@ export class AgentHarnessRuntime {
|
|
|
180
180
|
vectorStores = new Map();
|
|
181
181
|
runtimeEntryBindings;
|
|
182
182
|
defaultRuntimeEntryBinding;
|
|
183
|
-
|
|
183
|
+
defaultRuntimeRootValue;
|
|
184
184
|
defaultStore;
|
|
185
185
|
runtimeMemoryStore;
|
|
186
186
|
runtimeMemoryPolicy;
|
|
187
187
|
runtimeMemoryMaintenanceConfig;
|
|
188
188
|
routingRules;
|
|
189
189
|
routingDefaultAgentId;
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
sessionMemorySync;
|
|
191
|
+
unregisterSessionMemorySync;
|
|
192
192
|
runtimeMemorySync;
|
|
193
193
|
unregisterRuntimeMemorySync;
|
|
194
194
|
mem0IngestionSync;
|
|
@@ -205,9 +205,9 @@ export class AgentHarnessRuntime {
|
|
|
205
205
|
concurrencyConfig;
|
|
206
206
|
backgroundTasks = new Set();
|
|
207
207
|
workerId = `worker-${createPersistentId()}`;
|
|
208
|
-
|
|
208
|
+
activeRequestSlots = 0;
|
|
209
209
|
pendingRunInsertionOrder = 0;
|
|
210
|
-
|
|
210
|
+
pendingRequestSlots = [];
|
|
211
211
|
runtimeEventSequence = 0;
|
|
212
212
|
initialized = false;
|
|
213
213
|
closed = false;
|
|
@@ -226,20 +226,20 @@ export class AgentHarnessRuntime {
|
|
|
226
226
|
return null;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
|
|
230
|
-
return this.
|
|
229
|
+
defaultRuntimeRoot() {
|
|
230
|
+
return this.defaultRuntimeRootValue;
|
|
231
231
|
}
|
|
232
232
|
getDefaultRuntimeEntryAgentId() {
|
|
233
233
|
return getDefaultRuntimeEntryAgentId(this.workspace, this.routingDefaultAgentId);
|
|
234
234
|
}
|
|
235
|
-
async resolveSelectedAgentId(input, requestedAgentId,
|
|
235
|
+
async resolveSelectedAgentId(input, requestedAgentId, sessionId) {
|
|
236
236
|
return resolveSelectedAgentId({
|
|
237
237
|
workspace: this.workspace,
|
|
238
238
|
input,
|
|
239
239
|
requestedAgentId,
|
|
240
|
-
|
|
240
|
+
sessionId,
|
|
241
241
|
preferredRuntimeEntryAgentId: this.routingDefaultAgentId,
|
|
242
|
-
|
|
242
|
+
getSessionSummary: (currentSessionId) => this.getSessionSummaryRecord(currentSessionId),
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
createPrepareRunStartRuntime() {
|
|
@@ -247,9 +247,9 @@ export class AgentHarnessRuntime {
|
|
|
247
247
|
workspace: this.workspace,
|
|
248
248
|
policyEngine: this.policyEngine,
|
|
249
249
|
persistence: this.persistence,
|
|
250
|
-
resolveSelectedAgentId: (input, requestedAgentId,
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
resolveSelectedAgentId: (input, requestedAgentId, sessionId) => this.resolveSelectedAgentId(input, requestedAgentId, sessionId),
|
|
251
|
+
emitRequestCreated: (sessionId, requestId, payload) => this.runtimeEventOperations.emitRequestCreated(sessionId, requestId, payload),
|
|
252
|
+
acquireRequestSlot: (sessionId, requestId, activeState, priority) => this.acquireRequestSlot(sessionId, requestId, activeState, priority),
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
constructor(workspace, runtimeAdapterOptions = {}) {
|
|
@@ -258,16 +258,16 @@ export class AgentHarnessRuntime {
|
|
|
258
258
|
normalizeProcessExecutablePath();
|
|
259
259
|
this.runtimeEntryBindings = inferRoutingBindings(this.workspace).runtimeEntryBindings;
|
|
260
260
|
this.defaultRuntimeEntryBinding = this.runtimeEntryBindings[0];
|
|
261
|
-
this.
|
|
262
|
-
const
|
|
263
|
-
this.persistence = new SqlitePersistence(
|
|
261
|
+
this.defaultRuntimeRootValue = this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeRoot ?? `${this.workspace.workspaceRoot}/.agent`;
|
|
262
|
+
const runtimeRoot = this.defaultRuntimeRoot();
|
|
263
|
+
this.persistence = new SqlitePersistence(runtimeRoot);
|
|
264
264
|
const defaultStoreConfig = this.defaultRuntimeEntryBinding?.harnessRuntime.store;
|
|
265
|
-
this.defaultStore = resolveStoreFromConfig(this.stores, defaultStoreConfig,
|
|
265
|
+
this.defaultStore = resolveStoreFromConfig(this.stores, defaultStoreConfig, runtimeRoot) ?? new SqliteBackedStore(resolveKnowledgeStorePath(runtimeRoot));
|
|
266
266
|
const runtimeMemoryStoreConfig = typeof this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory?.store === "object" &&
|
|
267
267
|
this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory?.store
|
|
268
268
|
? this.defaultRuntimeEntryBinding.harnessRuntime.runtimeMemory.store
|
|
269
269
|
: undefined;
|
|
270
|
-
this.runtimeMemoryStore = resolveStoreFromConfig(this.stores, runtimeMemoryStoreConfig,
|
|
270
|
+
this.runtimeMemoryStore = resolveStoreFromConfig(this.stores, runtimeMemoryStoreConfig, runtimeRoot) ?? this.defaultStore;
|
|
271
271
|
this.runtimeMemoryPolicy = readRuntimeMemoryPolicyConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory, this.workspace.workspaceRoot) ?? null;
|
|
272
272
|
this.runtimeMemoryMaintenanceConfig =
|
|
273
273
|
readRuntimeMemoryMaintenanceConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory) ?? null;
|
|
@@ -279,7 +279,7 @@ export class AgentHarnessRuntime {
|
|
|
279
279
|
defaultStore: this.defaultStore,
|
|
280
280
|
embeddingModels: this.embeddingModels,
|
|
281
281
|
vectorStores: this.vectorStores,
|
|
282
|
-
|
|
282
|
+
getDefaultRuntimeRoot: () => this.defaultRuntimeRoot(),
|
|
283
283
|
});
|
|
284
284
|
this.runtimeAdapter = new AgentRuntimeAdapter(this.resolvedRuntimeAdapterOptions);
|
|
285
285
|
this.backgroundEventRuntime = createBackgroundEventRuntime({
|
|
@@ -291,32 +291,33 @@ export class AgentHarnessRuntime {
|
|
|
291
291
|
this.runtimeEventOperations = createRuntimeEventOperations(this.backgroundEventRuntime);
|
|
292
292
|
this.routingRules = getRoutingRules(workspace.refs);
|
|
293
293
|
this.routingDefaultAgentId = getRoutingDefaultAgentId(workspace.refs);
|
|
294
|
-
if (
|
|
295
|
-
this.
|
|
296
|
-
|
|
294
|
+
if (isSessionMemorySyncEnabled(workspace)) {
|
|
295
|
+
this.sessionMemorySync = new SessionMemorySync(this.persistence, this.runtimeMemoryStore, {
|
|
296
|
+
resolveSessionNamespace: (sessionId) => {
|
|
297
297
|
const binding = this.defaultRuntimeEntryBinding;
|
|
298
298
|
if (!binding) {
|
|
299
299
|
return ["memories", "sessions", sessionId];
|
|
300
300
|
}
|
|
301
|
-
return this.resolveMemoryNamespace("
|
|
301
|
+
return this.resolveMemoryNamespace("session", binding, { sessionId });
|
|
302
302
|
},
|
|
303
303
|
});
|
|
304
|
-
this.
|
|
304
|
+
this.unregisterSessionMemorySync = this.eventBus.registerProjection(this.sessionMemorySync);
|
|
305
305
|
}
|
|
306
306
|
else {
|
|
307
|
-
this.
|
|
308
|
-
this.
|
|
307
|
+
this.sessionMemorySync = null;
|
|
308
|
+
this.unregisterSessionMemorySync = () => { };
|
|
309
309
|
}
|
|
310
310
|
const runtimeMemorySyncConfig = readRuntimeMemorySyncConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory);
|
|
311
311
|
if (runtimeMemorySyncConfig) {
|
|
312
312
|
this.runtimeMemorySync = new RuntimeMemorySync(this.persistence, this.runtimeMemoryStore, runtimeMemorySyncConfig, {
|
|
313
|
-
|
|
313
|
+
resolveSessionNamespace: (sessionId) => {
|
|
314
314
|
const binding = this.defaultRuntimeEntryBinding;
|
|
315
315
|
if (!binding) {
|
|
316
316
|
return ["memories", "sessions", sessionId];
|
|
317
317
|
}
|
|
318
|
-
return this.resolveMemoryNamespace("
|
|
318
|
+
return this.resolveMemoryNamespace("session", binding, { sessionId });
|
|
319
319
|
},
|
|
320
|
+
resolveRequestNamespace: (sessionId) => ["memories", "requests", sessionId],
|
|
320
321
|
});
|
|
321
322
|
this.unregisterRuntimeMemorySync = this.eventBus.registerProjection(this.runtimeMemorySync);
|
|
322
323
|
}
|
|
@@ -326,7 +327,7 @@ export class AgentHarnessRuntime {
|
|
|
326
327
|
}
|
|
327
328
|
const mem0RuntimeConfig = readMem0RuntimeConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory, this.workspace.workspaceRoot);
|
|
328
329
|
if (mem0RuntimeConfig) {
|
|
329
|
-
this.mem0IngestionSync = new Mem0IngestionSync(this.persistence, mem0RuntimeConfig,
|
|
330
|
+
this.mem0IngestionSync = new Mem0IngestionSync(this.persistence, mem0RuntimeConfig, runtimeRoot);
|
|
330
331
|
this.unregisterMem0IngestionSync = this.eventBus.registerProjection(this.mem0IngestionSync);
|
|
331
332
|
this.mem0SemanticRecall = new Mem0SemanticRecall(mem0RuntimeConfig);
|
|
332
333
|
}
|
|
@@ -353,7 +354,7 @@ export class AgentHarnessRuntime {
|
|
|
353
354
|
resolveNamespace: (scope, context) => {
|
|
354
355
|
const binding = this.defaultRuntimeEntryBinding;
|
|
355
356
|
if (!binding) {
|
|
356
|
-
const identifier = scope === "
|
|
357
|
+
const identifier = scope === "session"
|
|
357
358
|
? context.sessionId
|
|
358
359
|
: scope === "agent"
|
|
359
360
|
? context.agentId
|
|
@@ -376,8 +377,8 @@ export class AgentHarnessRuntime {
|
|
|
376
377
|
? ({ candidates, context, existingRecords }) => this.runtimeMemoryManager.transform({
|
|
377
378
|
candidates,
|
|
378
379
|
binding: this.defaultRuntimeEntryBinding,
|
|
379
|
-
|
|
380
|
-
|
|
380
|
+
sessionId: context.sessionId ?? `memory-api-${context.requestId ?? "unknown"}`,
|
|
381
|
+
requestId: context.requestId ?? createPersistentId(new Date(context.recordedAt ?? new Date().toISOString())),
|
|
381
382
|
recordedAt: context.recordedAt ?? new Date().toISOString(),
|
|
382
383
|
existingRecords,
|
|
383
384
|
})
|
|
@@ -386,14 +387,14 @@ export class AgentHarnessRuntime {
|
|
|
386
387
|
});
|
|
387
388
|
if (runtimeMemoryFormationConfig) {
|
|
388
389
|
this.runtimeMemoryFormationSync = new RuntimeMemoryFormationSync(this.persistence, runtimeMemoryFormationConfig, (input) => this.knowledgeModule.memorizeCandidates(input.candidates, {
|
|
389
|
-
sessionId: input.
|
|
390
|
-
requestId: input.
|
|
390
|
+
sessionId: input.sessionId,
|
|
391
|
+
requestId: input.requestId,
|
|
391
392
|
agentId: input.agentId,
|
|
392
393
|
workspaceId: this.getWorkspaceId(this.defaultRuntimeEntryBinding),
|
|
393
394
|
userId: input.userId,
|
|
394
395
|
projectId: input.projectId,
|
|
395
396
|
recordedAt: input.recordedAt,
|
|
396
|
-
}, { storeCandidateLog: false }).then(() => undefined),
|
|
397
|
+
}, { storeCandidateLog: false }).then(() => undefined), runtimeRoot);
|
|
397
398
|
this.unregisterRuntimeMemoryFormationSync = this.eventBus.registerProjection(this.runtimeMemoryFormationSync);
|
|
398
399
|
}
|
|
399
400
|
else {
|
|
@@ -409,8 +410,8 @@ export class AgentHarnessRuntime {
|
|
|
409
410
|
return new HealthMonitor({
|
|
410
411
|
workspace: this.workspace,
|
|
411
412
|
persistence: this.persistence,
|
|
412
|
-
|
|
413
|
-
|
|
413
|
+
getActiveRequestSlots: () => this.activeRequestSlots,
|
|
414
|
+
getPendingRequestSlots: () => this.pendingRequestSlots.length,
|
|
414
415
|
getCheckpointMaintenanceStatus: () => null,
|
|
415
416
|
getRuntimeRecordMaintenanceStatus: () => null,
|
|
416
417
|
publishEvent: async (payload) => {
|
|
@@ -436,7 +437,7 @@ export class AgentHarnessRuntime {
|
|
|
436
437
|
healthMonitor: this.healthMonitor,
|
|
437
438
|
scheduleBackgroundTask: (task) => this.scheduleBackgroundStartupTask(task),
|
|
438
439
|
});
|
|
439
|
-
this.scheduleBackgroundStartupTask(traceStartupStage("runtime.initialize.startupRecovery", () => this.
|
|
440
|
+
this.scheduleBackgroundStartupTask(traceStartupStage("runtime.initialize.startupRecovery", () => this.recoverStartupRequests()));
|
|
440
441
|
this.initialized = true;
|
|
441
442
|
}
|
|
442
443
|
subscribe(listener) {
|
|
@@ -446,17 +447,17 @@ export class AgentHarnessRuntime {
|
|
|
446
447
|
if (this.healthMonitor) {
|
|
447
448
|
return this.healthMonitor.getSnapshot();
|
|
448
449
|
}
|
|
449
|
-
return createDefaultHealthSnapshot(this.
|
|
450
|
+
return createDefaultHealthSnapshot(this.activeRequestSlots, this.pendingRequestSlots.length);
|
|
450
451
|
}
|
|
451
452
|
async getOperatorOverview(options) {
|
|
452
|
-
const [health,
|
|
453
|
+
const [health, requests, approvals] = await Promise.all([
|
|
453
454
|
this.getHealth(),
|
|
454
|
-
Promise.all(
|
|
455
|
+
Promise.all(ACTIVE_REQUEST_STATES.map((state) => this.listRequests({ state }))).then((groups) => groups.flat()),
|
|
455
456
|
this.listApprovals({ status: "pending" }),
|
|
456
457
|
]);
|
|
457
458
|
return projectOperatorOverview({
|
|
458
459
|
health,
|
|
459
|
-
|
|
460
|
+
requests,
|
|
460
461
|
approvals,
|
|
461
462
|
limit: options?.limit,
|
|
462
463
|
});
|
|
@@ -477,20 +478,17 @@ export class AgentHarnessRuntime {
|
|
|
477
478
|
const sessions = await this.persistence.listSessionSummaries(filter);
|
|
478
479
|
return sessions.map((session) => toSessionListSummary(session));
|
|
479
480
|
}
|
|
480
|
-
async listThreads(filter) {
|
|
481
|
-
return this.listSessions(filter);
|
|
482
|
-
}
|
|
483
481
|
async listRequests(filter) {
|
|
484
|
-
const requests = await this.persistence.
|
|
482
|
+
const requests = await this.persistence.listRequests({
|
|
485
483
|
agentId: filter?.agentId,
|
|
486
|
-
|
|
484
|
+
sessionId: filter?.sessionId,
|
|
487
485
|
state: filter?.state,
|
|
488
486
|
});
|
|
489
487
|
return requests.map((request) => ({
|
|
490
488
|
requestId: request.requestId,
|
|
491
489
|
sessionId: request.sessionId,
|
|
492
490
|
agentId: request.agentId,
|
|
493
|
-
|
|
491
|
+
parentRequestId: request.parentRequestId,
|
|
494
492
|
executionMode: request.executionMode,
|
|
495
493
|
adapterKind: request.adapterKind,
|
|
496
494
|
createdAt: request.createdAt,
|
|
@@ -506,13 +504,6 @@ export class AgentHarnessRuntime {
|
|
|
506
504
|
runtimeSnapshot: request.runtimeSnapshot,
|
|
507
505
|
}));
|
|
508
506
|
}
|
|
509
|
-
async listRuns(filter) {
|
|
510
|
-
return this.listRequests({
|
|
511
|
-
agentId: filter?.agentId,
|
|
512
|
-
sessionId: filter?.threadId,
|
|
513
|
-
state: filter?.state,
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
507
|
async memorize(input) {
|
|
517
508
|
const binding = this.defaultRuntimeEntryBinding;
|
|
518
509
|
if (!binding) {
|
|
@@ -578,12 +569,9 @@ export class AgentHarnessRuntime {
|
|
|
578
569
|
});
|
|
579
570
|
}
|
|
580
571
|
async getRequest(requestId) {
|
|
581
|
-
const request = await this.persistence.
|
|
572
|
+
const request = await this.persistence.getRequest(requestId);
|
|
582
573
|
return request ? buildRequestInspectionRecord(this.persistence, request) : null;
|
|
583
574
|
}
|
|
584
|
-
async getRun(runId) {
|
|
585
|
-
return this.getRequest(runId);
|
|
586
|
-
}
|
|
587
575
|
async getSessionSummary(sessionId) {
|
|
588
576
|
const session = await this.persistence.getSession(sessionId);
|
|
589
577
|
return session
|
|
@@ -598,8 +586,11 @@ export class AgentHarnessRuntime {
|
|
|
598
586
|
}
|
|
599
587
|
: null;
|
|
600
588
|
}
|
|
601
|
-
async
|
|
602
|
-
return this.getSessionSummary(
|
|
589
|
+
async getSessionSummaryRecord(sessionId) {
|
|
590
|
+
return this.getSessionSummary(sessionId);
|
|
591
|
+
}
|
|
592
|
+
async getSession(sessionId) {
|
|
593
|
+
return this.getSessionRecord(sessionId);
|
|
603
594
|
}
|
|
604
595
|
async getSessionRecord(sessionId) {
|
|
605
596
|
return buildSessionInspectionRecord({
|
|
@@ -607,16 +598,13 @@ export class AgentHarnessRuntime {
|
|
|
607
598
|
getSession: (currentSessionId) => this.getSessionSummary(currentSessionId),
|
|
608
599
|
}, sessionId);
|
|
609
600
|
}
|
|
610
|
-
async getThread(threadId) {
|
|
611
|
-
return this.getSessionRecord(threadId);
|
|
612
|
-
}
|
|
613
601
|
async listApprovals(filter) {
|
|
614
602
|
const approvals = await listPublicApprovals({
|
|
615
603
|
persistence: this.persistence,
|
|
616
604
|
}, {
|
|
617
605
|
status: filter?.status,
|
|
618
|
-
|
|
619
|
-
|
|
606
|
+
sessionId: filter?.sessionId,
|
|
607
|
+
requestId: filter?.requestId,
|
|
620
608
|
});
|
|
621
609
|
return approvals;
|
|
622
610
|
}
|
|
@@ -625,17 +613,14 @@ export class AgentHarnessRuntime {
|
|
|
625
613
|
persistence: this.persistence,
|
|
626
614
|
}, approvalId);
|
|
627
615
|
}
|
|
628
|
-
async
|
|
629
|
-
const listing = await this.persistence.
|
|
616
|
+
async listRequestArtifacts(sessionId, requestId) {
|
|
617
|
+
const listing = await this.persistence.listRequestArtifacts(sessionId, requestId);
|
|
630
618
|
return {
|
|
631
619
|
sessionId: listing.sessionId,
|
|
632
620
|
requestId: listing.requestId,
|
|
633
621
|
items: listing.items,
|
|
634
622
|
};
|
|
635
623
|
}
|
|
636
|
-
async readArtifact(threadId, runId, artifactPath) {
|
|
637
|
-
return this.persistence.readArtifact(threadId, runId, normalizeRecordedArtifactPath(artifactPath));
|
|
638
|
-
}
|
|
639
624
|
async recordArtifact(input) {
|
|
640
625
|
const session = await this.getSessionRecord(input.sessionId);
|
|
641
626
|
if (!session) {
|
|
@@ -655,27 +640,27 @@ export class AgentHarnessRuntime {
|
|
|
655
640
|
? input.createdAt.trim()
|
|
656
641
|
: new Date().toISOString(),
|
|
657
642
|
};
|
|
658
|
-
return this.persistence.
|
|
643
|
+
return this.persistence.createRequestArtifact(input.sessionId, input.requestId, artifact, input.content);
|
|
659
644
|
}
|
|
660
|
-
async
|
|
661
|
-
return this.persistence.
|
|
645
|
+
async readRequestArtifact(sessionId, requestId, artifactPath) {
|
|
646
|
+
return this.persistence.readRequestArtifact(sessionId, requestId, artifactPath);
|
|
662
647
|
}
|
|
663
|
-
async
|
|
664
|
-
return this.listRequestEvents(
|
|
648
|
+
async listRequestEvents(sessionId, requestId) {
|
|
649
|
+
return this.persistence.listRequestEvents(sessionId, requestId);
|
|
665
650
|
}
|
|
666
651
|
async exportRequestPackage(input) {
|
|
667
652
|
const session = await this.getSessionRecord(input.sessionId);
|
|
668
653
|
const request = await this.getRequest(input.requestId);
|
|
669
654
|
const approvals = await this.listApprovals({ sessionId: input.sessionId, requestId: input.requestId });
|
|
670
|
-
const transcript = await this.persistence.
|
|
655
|
+
const transcript = await this.persistence.listSessionMessages(input.sessionId, 500);
|
|
671
656
|
const events = await this.listRequestEvents(input.sessionId, input.requestId);
|
|
672
657
|
const artifactsListing = input.includeArtifacts === false
|
|
673
658
|
? { items: [] }
|
|
674
|
-
: await this.persistence.
|
|
659
|
+
: await this.persistence.listRequestArtifacts(input.sessionId, input.requestId);
|
|
675
660
|
const artifacts = await Promise.all(artifactsListing.items.map(async (artifact) => ({
|
|
676
661
|
...artifact,
|
|
677
662
|
...(input.includeArtifactContents === true
|
|
678
|
-
? { content: await this.persistence.
|
|
663
|
+
? { content: await this.persistence.readRequestArtifact(input.sessionId, input.requestId, artifact.path) }
|
|
679
664
|
: {}),
|
|
680
665
|
})));
|
|
681
666
|
const approvalSummary = summarizeApprovalEvidence(approvals);
|
|
@@ -708,7 +693,7 @@ export class AgentHarnessRuntime {
|
|
|
708
693
|
async exportSessionPackage(input) {
|
|
709
694
|
const session = await this.getSessionRecord(input.sessionId);
|
|
710
695
|
const requestIds = Array.from(new Set((session?.requests ?? []).map((item) => item.requestId)));
|
|
711
|
-
const
|
|
696
|
+
const requestPackages = await Promise.all(requestIds.map((requestId) => this.exportRequestPackage({
|
|
712
697
|
sessionId: input.sessionId,
|
|
713
698
|
requestId,
|
|
714
699
|
includeArtifacts: input.includeArtifacts,
|
|
@@ -717,7 +702,7 @@ export class AgentHarnessRuntime {
|
|
|
717
702
|
})));
|
|
718
703
|
const approvals = await this.listApprovals({ sessionId: input.sessionId });
|
|
719
704
|
const approvalSummary = summarizeApprovalEvidence(approvals);
|
|
720
|
-
const
|
|
705
|
+
const governanceRequests = requestPackages
|
|
721
706
|
.filter((item) => item.request?.requestId)
|
|
722
707
|
.map((item) => ({
|
|
723
708
|
requestId: item.request.requestId,
|
|
@@ -725,45 +710,45 @@ export class AgentHarnessRuntime {
|
|
|
725
710
|
}));
|
|
726
711
|
return {
|
|
727
712
|
session,
|
|
728
|
-
requests:
|
|
713
|
+
requests: requestPackages.map((item) => item.request).filter((item) => Boolean(item)),
|
|
729
714
|
approvals,
|
|
730
|
-
transcript: await this.persistence.
|
|
731
|
-
|
|
715
|
+
transcript: await this.persistence.listSessionMessages(input.sessionId, 500),
|
|
716
|
+
requestsPackages: requestPackages,
|
|
732
717
|
governance: {
|
|
733
|
-
|
|
718
|
+
requests: governanceRequests,
|
|
734
719
|
approvalSummary,
|
|
735
|
-
summary: `${
|
|
720
|
+
summary: `${governanceRequests.length} request evidence package(s), ${approvalSummary.total} approval record(s)`,
|
|
736
721
|
},
|
|
737
722
|
...(input.includeRuntimeHealth === false ? {} : { runtimeHealth: await this.getHealth() }),
|
|
738
723
|
};
|
|
739
724
|
}
|
|
740
725
|
async exportEvaluationBundle(input) {
|
|
741
|
-
const
|
|
742
|
-
const
|
|
743
|
-
const
|
|
726
|
+
const session = await this.getSessionRecord(input.sessionId);
|
|
727
|
+
const request = await this.getRequest(input.requestId);
|
|
728
|
+
const requestInput = await this.persistence.getRequestInput(input.sessionId, input.requestId);
|
|
744
729
|
const approvals = await this.listApprovals({ sessionId: input.sessionId, requestId: input.requestId });
|
|
745
|
-
const transcript = await this.persistence.
|
|
746
|
-
const events = await this.persistence.
|
|
730
|
+
const transcript = await this.persistence.listSessionMessages(input.sessionId, 500);
|
|
731
|
+
const events = await this.persistence.listRequestEvents(input.sessionId, input.requestId);
|
|
747
732
|
const runtimeHealth = await this.getHealth();
|
|
748
733
|
const artifactsListing = input.includeArtifacts === false
|
|
749
734
|
? { items: [] }
|
|
750
|
-
: await this.persistence.
|
|
735
|
+
: await this.persistence.listRequestArtifacts(input.sessionId, input.requestId);
|
|
751
736
|
const artifacts = await Promise.all(artifactsListing.items.map(async (artifact) => ({
|
|
752
737
|
...artifact,
|
|
753
738
|
...(input.includeArtifactContents === true
|
|
754
|
-
? { content: await this.persistence.
|
|
739
|
+
? { content: await this.persistence.readRequestArtifact(input.sessionId, input.requestId, artifact.path) }
|
|
755
740
|
: {}),
|
|
756
741
|
})));
|
|
757
742
|
return {
|
|
758
|
-
session:
|
|
759
|
-
request:
|
|
760
|
-
|
|
743
|
+
session: session ? toSessionRecord(session) : null,
|
|
744
|
+
request: request ? toRequestRecord(request) : null,
|
|
745
|
+
requestInput: requestInput
|
|
761
746
|
? {
|
|
762
|
-
input:
|
|
763
|
-
...(
|
|
764
|
-
...(typeof
|
|
747
|
+
input: requestInput.input,
|
|
748
|
+
...(requestInput.invocation ? { invocation: requestInput.invocation } : {}),
|
|
749
|
+
...(typeof requestInput.priority === "number" ? { priority: requestInput.priority } : {}),
|
|
765
750
|
}
|
|
766
|
-
: (
|
|
751
|
+
: (deriveRequestInputFromTranscript(transcript, input.requestId) ?? null),
|
|
767
752
|
approvals,
|
|
768
753
|
transcript,
|
|
769
754
|
events,
|
|
@@ -786,15 +771,15 @@ export class AgentHarnessRuntime {
|
|
|
786
771
|
if (!replayAgentId) {
|
|
787
772
|
throw new Error("Evaluation replay requires an agentId on the replay input or exported bundle.");
|
|
788
773
|
}
|
|
789
|
-
const replayRequest = input.bundle.
|
|
774
|
+
const replayRequest = input.bundle.requestInput ?? deriveRequestInputFromTranscript(input.bundle.transcript, input.bundle.request?.requestId);
|
|
790
775
|
if (!replayRequest) {
|
|
791
|
-
throw new Error("Evaluation replay requires bundle.
|
|
776
|
+
throw new Error("Evaluation replay requires bundle.requestInput from exportEvaluationBundle.");
|
|
792
777
|
}
|
|
793
778
|
const invocation = input.invocation ?? replayRequest.invocation;
|
|
794
779
|
const result = await this.run({
|
|
795
780
|
agentId: replayAgentId,
|
|
796
781
|
input: replayRequest.input,
|
|
797
|
-
...(input.sessionId ? {
|
|
782
|
+
...(input.sessionId ? { sessionId: input.sessionId } : {}),
|
|
798
783
|
...(invocation ? { invocation } : {}),
|
|
799
784
|
});
|
|
800
785
|
const expected = typeof input.bundle.expectedOutput === "string" ? input.bundle.expectedOutput.trim() : "";
|
|
@@ -829,7 +814,7 @@ export class AgentHarnessRuntime {
|
|
|
829
814
|
...options,
|
|
830
815
|
});
|
|
831
816
|
}
|
|
832
|
-
async
|
|
817
|
+
async deleteSessionCheckpoints(sessionId) {
|
|
833
818
|
const resolver = this.resolvedRuntimeAdapterOptions.checkpointerResolver;
|
|
834
819
|
if (!resolver) {
|
|
835
820
|
return;
|
|
@@ -841,29 +826,20 @@ export class AgentHarnessRuntime {
|
|
|
841
826
|
continue;
|
|
842
827
|
}
|
|
843
828
|
seen.add(saver);
|
|
844
|
-
const
|
|
845
|
-
if (typeof
|
|
846
|
-
await
|
|
829
|
+
const maybeDeleteSession = saver.deleteSession;
|
|
830
|
+
if (typeof maybeDeleteSession === "function") {
|
|
831
|
+
await maybeDeleteSession.call(saver, sessionId);
|
|
832
|
+
continue;
|
|
847
833
|
}
|
|
848
834
|
}
|
|
849
835
|
}
|
|
850
836
|
async deleteSession(sessionId) {
|
|
851
837
|
return deleteSessionRecord({
|
|
852
838
|
getSession: (currentSessionId) => this.getSessionRecord(currentSessionId),
|
|
853
|
-
deleteSession: (currentSessionId) => this.persistence.
|
|
854
|
-
deleteSessionCheckpoints: (currentSessionId) => this.
|
|
839
|
+
deleteSession: (currentSessionId) => this.persistence.deleteSession(currentSessionId),
|
|
840
|
+
deleteSessionCheckpoints: (currentSessionId) => this.deleteSessionCheckpoints(currentSessionId),
|
|
855
841
|
}, sessionId);
|
|
856
842
|
}
|
|
857
|
-
async deleteThread(threadId) {
|
|
858
|
-
return this.deleteSession(threadId);
|
|
859
|
-
}
|
|
860
|
-
async deleteThreadLegacy(threadId) {
|
|
861
|
-
return deleteThreadRecord({
|
|
862
|
-
getThread: (currentThreadId) => this.getThread(currentThreadId),
|
|
863
|
-
deleteThread: (currentThreadId) => this.persistence.deleteThread(currentThreadId),
|
|
864
|
-
deleteThreadCheckpoints: (currentThreadId) => this.deleteThreadCheckpoints(currentThreadId),
|
|
865
|
-
}, threadId);
|
|
866
|
-
}
|
|
867
843
|
async createToolMcpServer(options) {
|
|
868
844
|
const tools = this.resolveToolMcpServerTools(options.agentId);
|
|
869
845
|
return createToolMcpServerFromTools(tools, options);
|
|
@@ -884,16 +860,16 @@ export class AgentHarnessRuntime {
|
|
|
884
860
|
input,
|
|
885
861
|
routingRules: this.routingRules,
|
|
886
862
|
routingDefaultAgentId: this.routingDefaultAgentId,
|
|
887
|
-
|
|
863
|
+
sessionId: options.sessionId,
|
|
888
864
|
});
|
|
889
865
|
}
|
|
890
|
-
async emit(
|
|
866
|
+
async emit(sessionId, requestId, sequence, eventType, payload, source = "runtime") {
|
|
891
867
|
return emitHarnessEvent({
|
|
892
868
|
persistence: this.persistence,
|
|
893
869
|
publishEvent: (event) => this.eventBus.publish(event),
|
|
894
870
|
trackBackgroundTask: (task) => this.trackBackgroundTask(task),
|
|
895
871
|
backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
|
|
896
|
-
},
|
|
872
|
+
}, sessionId, requestId, sequence, eventType, payload, source);
|
|
897
873
|
}
|
|
898
874
|
trackBackgroundTask(task) {
|
|
899
875
|
this.backgroundTasks.add(task);
|
|
@@ -915,39 +891,39 @@ export class AgentHarnessRuntime {
|
|
|
915
891
|
sourceTool: this.workspace.tools.get(compiledTool.id),
|
|
916
892
|
}));
|
|
917
893
|
}
|
|
918
|
-
async loadPriorHistory(
|
|
919
|
-
const history = await this.persistence.
|
|
920
|
-
return history.filter((message) => message.requestId !==
|
|
894
|
+
async loadPriorHistory(sessionId, requestId) {
|
|
895
|
+
const history = await this.persistence.listSessionMessages(sessionId);
|
|
896
|
+
return history.filter((message) => message.requestId !== requestId);
|
|
921
897
|
}
|
|
922
|
-
async
|
|
923
|
-
const history = await this.persistence.
|
|
924
|
-
const userTurn = history.find((message) => message.requestId ===
|
|
898
|
+
async loadRequestInput(sessionId, requestId) {
|
|
899
|
+
const history = await this.persistence.listSessionMessages(sessionId, 100);
|
|
900
|
+
const userTurn = history.find((message) => message.requestId === requestId && message.role === "user");
|
|
925
901
|
return userTurn?.content ?? "";
|
|
926
902
|
}
|
|
927
|
-
async
|
|
928
|
-
const control = await this.persistence.
|
|
903
|
+
async getRequestCancellation(requestId) {
|
|
904
|
+
const control = await this.persistence.getRequestControl(requestId);
|
|
929
905
|
return {
|
|
930
906
|
requested: control?.cancelRequested === true,
|
|
931
907
|
...(control?.cancelReason ? { reason: control.cancelReason } : {}),
|
|
932
908
|
};
|
|
933
909
|
}
|
|
934
|
-
async
|
|
935
|
-
return
|
|
910
|
+
async finalizeCancelledRequest(sessionId, requestId, previousState, reason) {
|
|
911
|
+
return finalizeLifecycleCancelledRequest({
|
|
936
912
|
persistence: this.persistence,
|
|
937
|
-
emit: (
|
|
938
|
-
|
|
939
|
-
},
|
|
913
|
+
emit: (currentSessionId, currentRequestId, sequence, eventType, payload, source) => this.emit(currentSessionId, currentRequestId, sequence, eventType, payload, source),
|
|
914
|
+
setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, options) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, options),
|
|
915
|
+
}, sessionId, requestId, previousState, reason);
|
|
940
916
|
}
|
|
941
|
-
async invokeWithHistory(binding, input,
|
|
942
|
-
const history = priorHistory ?? await this.loadPriorHistory(
|
|
943
|
-
const memoryContext = options.memoryContext ?? await this.buildRuntimeMemoryContext(binding,
|
|
917
|
+
async invokeWithHistory(binding, input, sessionId, requestId, resumePayload, priorHistory, options = {}) {
|
|
918
|
+
const history = priorHistory ?? await this.loadPriorHistory(sessionId, requestId);
|
|
919
|
+
const memoryContext = options.memoryContext ?? await this.buildRuntimeMemoryContext(binding, sessionId, input);
|
|
944
920
|
const startedAt = Date.now();
|
|
945
921
|
try {
|
|
946
|
-
const result = await this.runtimeAdapter.invoke(binding, input,
|
|
922
|
+
const result = await this.runtimeAdapter.invoke(binding, input, sessionId, requestId, resumePayload, history, {
|
|
947
923
|
...options,
|
|
948
924
|
...(memoryContext ? { memoryContext } : {}),
|
|
949
925
|
});
|
|
950
|
-
await this.persistRuntimeMemoryCandidates(binding,
|
|
926
|
+
await this.persistRuntimeMemoryCandidates(binding, sessionId, requestId, result.metadata?.memoryCandidates);
|
|
951
927
|
this.recordLlmSuccess(startedAt);
|
|
952
928
|
return result;
|
|
953
929
|
}
|
|
@@ -971,18 +947,18 @@ export class AgentHarnessRuntime {
|
|
|
971
947
|
const workspaceRoot = binding.harnessRuntime.workspaceRoot ?? this.workspace.workspaceRoot;
|
|
972
948
|
return path.basename(workspaceRoot) || "default";
|
|
973
949
|
}
|
|
974
|
-
async buildRuntimeMemoryContext(binding,
|
|
950
|
+
async buildRuntimeMemoryContext(binding, sessionId, input) {
|
|
975
951
|
const query = typeof input === "string" ? input : JSON.stringify(input ?? "");
|
|
976
952
|
return this.knowledgeModule.buildPromptContext({
|
|
977
953
|
query,
|
|
978
954
|
topK: this.runtimeMemoryPolicy?.retrieval.maxPromptMemories ?? 8,
|
|
979
955
|
}, {
|
|
980
|
-
sessionId
|
|
956
|
+
sessionId,
|
|
981
957
|
agentId: binding.agent.id,
|
|
982
958
|
workspaceId: this.getWorkspaceId(binding),
|
|
983
959
|
});
|
|
984
960
|
}
|
|
985
|
-
async persistRuntimeMemoryCandidates(binding,
|
|
961
|
+
async persistRuntimeMemoryCandidates(binding, sessionId, requestId, value) {
|
|
986
962
|
if (!Array.isArray(value) || value.length === 0) {
|
|
987
963
|
return;
|
|
988
964
|
}
|
|
@@ -996,62 +972,62 @@ export class AgentHarnessRuntime {
|
|
|
996
972
|
return;
|
|
997
973
|
}
|
|
998
974
|
await this.knowledgeModule.memorizeCandidates(candidates, {
|
|
999
|
-
sessionId
|
|
1000
|
-
requestId
|
|
975
|
+
sessionId,
|
|
976
|
+
requestId,
|
|
1001
977
|
agentId: binding.agent.id,
|
|
1002
978
|
workspaceId: this.getWorkspaceId(binding),
|
|
1003
979
|
recordedAt: new Date().toISOString(),
|
|
1004
980
|
}, { storeCandidateLog: true });
|
|
1005
981
|
}
|
|
1006
|
-
async
|
|
1007
|
-
const persisted = await this.persistence.
|
|
1008
|
-
return
|
|
982
|
+
async resolvePersistedRequestPriority(sessionId, requestId) {
|
|
983
|
+
const persisted = await this.persistence.getRequestInput(sessionId, requestId);
|
|
984
|
+
return normalizeRequestPriority(persisted?.priority);
|
|
1009
985
|
}
|
|
1010
|
-
|
|
1011
|
-
return
|
|
986
|
+
enqueuePendingRequestSlot(entry) {
|
|
987
|
+
return enqueuePendingRequestSlot(this.pendingRequestSlots, entry, this.pendingRunInsertionOrder++);
|
|
1012
988
|
}
|
|
1013
|
-
async
|
|
1014
|
-
return
|
|
989
|
+
async executeQueuedRequest(binding, input, sessionId, requestId, agentId, options = {}) {
|
|
990
|
+
return executeQueuedRequestOperation({
|
|
1015
991
|
persistence: this.persistence,
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
emit: (
|
|
1019
|
-
if (eventType === "
|
|
1020
|
-
return this.emit(
|
|
992
|
+
getRequestCancellation: (currentRequestId) => this.getRequestCancellation(currentRequestId),
|
|
993
|
+
finalizeCancelledRequest: (currentSessionId, currentRequestId, previousRequestState, reason) => this.finalizeCancelledRequest(currentSessionId, currentRequestId, previousRequestState, reason),
|
|
994
|
+
emit: (currentSessionId, currentRequestId, sequence, eventType, payload) => {
|
|
995
|
+
if (eventType === "request.dequeued") {
|
|
996
|
+
return this.emit(currentSessionId, currentRequestId, sequence, eventType, {
|
|
1021
997
|
...payload,
|
|
1022
|
-
|
|
998
|
+
activeRequestCount: this.activeRequestSlots,
|
|
1023
999
|
maxConcurrentRuns: this.concurrencyConfig.maxConcurrentRuns,
|
|
1024
1000
|
});
|
|
1025
1001
|
}
|
|
1026
|
-
return this.emit(
|
|
1002
|
+
return this.emit(currentSessionId, currentRequestId, sequence, eventType, payload);
|
|
1027
1003
|
},
|
|
1028
|
-
|
|
1029
|
-
invokeWithHistory: (activeBinding, activeInput,
|
|
1030
|
-
|
|
1031
|
-
emitSyntheticFallback: (
|
|
1004
|
+
setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, stateOptions),
|
|
1005
|
+
invokeWithHistory: (activeBinding, activeInput, currentSessionId, currentRequestId, resumePayload, priorHistory, invokeOptions) => this.invokeWithHistory(activeBinding, activeInput, currentSessionId, currentRequestId, resumePayload, priorHistory, invokeOptions),
|
|
1006
|
+
finalizeContinuedRequest: (activeBinding, currentSessionId, currentRequestId, currentInput, actual, finalizeOptions) => this.finalizeContinuedRequest(activeBinding, currentSessionId, currentRequestId, currentInput, actual, finalizeOptions),
|
|
1007
|
+
emitSyntheticFallback: (currentSessionId, currentRequestId, currentAgentId, error) => this.runtimeEventOperations.emitSyntheticFallback(currentSessionId, currentRequestId, currentAgentId, error, 103),
|
|
1032
1008
|
renderRuntimeFailure,
|
|
1033
1009
|
}, {
|
|
1034
1010
|
binding,
|
|
1035
1011
|
message: input,
|
|
1036
|
-
|
|
1037
|
-
|
|
1012
|
+
sessionId,
|
|
1013
|
+
requestId,
|
|
1038
1014
|
agentId,
|
|
1039
1015
|
options,
|
|
1040
1016
|
});
|
|
1041
1017
|
}
|
|
1042
|
-
async
|
|
1043
|
-
return
|
|
1018
|
+
async finalizeContinuedRequest(binding, sessionId, requestId, input, actual, options) {
|
|
1019
|
+
return finalizeLifecycleContinuedRequest({
|
|
1044
1020
|
persistence: this.persistence,
|
|
1045
|
-
emit: (
|
|
1046
|
-
|
|
1047
|
-
requestApprovalAndEmit: (
|
|
1048
|
-
}, binding,
|
|
1021
|
+
emit: (currentSessionId, currentRequestId, sequence, eventType, payload, source) => this.emit(currentSessionId, currentRequestId, sequence, eventType, payload, source),
|
|
1022
|
+
setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, lifecycleOptions) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, lifecycleOptions),
|
|
1023
|
+
requestApprovalAndEmit: (currentSessionId, currentRequestId, lifecycleInput, interruptContent, checkpointRef, sequence) => this.requestApprovalAndEmit(currentSessionId, currentRequestId, lifecycleInput, interruptContent, checkpointRef, sequence),
|
|
1024
|
+
}, binding, sessionId, requestId, input, actual, options);
|
|
1049
1025
|
}
|
|
1050
|
-
async
|
|
1051
|
-
return this.runtimeEventOperations.
|
|
1026
|
+
async setRequestStateAndEmit(sessionId, requestId, sequence, state, options) {
|
|
1027
|
+
return this.runtimeEventOperations.setRequestStateAndEmit(sessionId, requestId, sequence, state, options);
|
|
1052
1028
|
}
|
|
1053
|
-
async requestApprovalAndEmit(
|
|
1054
|
-
return this.runtimeEventOperations.requestApprovalAndEmit(
|
|
1029
|
+
async requestApprovalAndEmit(sessionId, requestId, input, interruptContent, checkpointRef, sequence) {
|
|
1030
|
+
return this.runtimeEventOperations.requestApprovalAndEmit(sessionId, requestId, input, interruptContent, checkpointRef, sequence);
|
|
1055
1031
|
}
|
|
1056
1032
|
isDecisionRun(options) {
|
|
1057
1033
|
return "decision" in options;
|
|
@@ -1062,28 +1038,34 @@ export class AgentHarnessRuntime {
|
|
|
1062
1038
|
}
|
|
1063
1039
|
await listener(value);
|
|
1064
1040
|
}
|
|
1065
|
-
async
|
|
1041
|
+
async acquireRequestSlot(sessionId, requestId, activeState = "running", priority = 0) {
|
|
1066
1042
|
return acquireHarnessRunSlot({
|
|
1067
|
-
persistence:
|
|
1043
|
+
persistence: {
|
|
1044
|
+
claimQueuedRequest: ({ sessionId, requestId, workerId, claimedAt, leaseExpiresAt }) => this.persistence.claimQueuedRequest({ sessionId, requestId, workerId, claimedAt, leaseExpiresAt }),
|
|
1045
|
+
renewRequestLease: ({ requestId, workerId, heartbeatAt, leaseExpiresAt }) => this.persistence.renewRequestLease({ requestId, workerId, heartbeatAt, leaseExpiresAt }),
|
|
1046
|
+
releaseRequestClaim: (requestId) => this.persistence.releaseRequestClaim(requestId),
|
|
1047
|
+
enqueueRequest: ({ sessionId, requestId, priority }) => this.persistence.enqueueRequest({ sessionId, requestId, priority }),
|
|
1048
|
+
getRequest: (requestId) => this.persistence.getRequest(requestId),
|
|
1049
|
+
},
|
|
1068
1050
|
workerId: this.workerId,
|
|
1069
1051
|
concurrencyConfig: this.concurrencyConfig,
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
this.
|
|
1052
|
+
pendingRequestSlots: this.pendingRequestSlots,
|
|
1053
|
+
getActiveRequestSlots: () => this.activeRequestSlots,
|
|
1054
|
+
setActiveRequestSlots: (count) => {
|
|
1055
|
+
this.activeRequestSlots = count;
|
|
1074
1056
|
},
|
|
1075
|
-
|
|
1076
|
-
emit: (
|
|
1077
|
-
|
|
1057
|
+
enqueuePendingRequestSlot: (entry) => this.enqueuePendingRequestSlot(entry),
|
|
1058
|
+
emit: (currentSessionId, currentRequestId, sequence, eventType, payload) => this.emit(currentSessionId, currentRequestId, sequence, eventType, payload),
|
|
1059
|
+
setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, stateOptions),
|
|
1078
1060
|
}, {
|
|
1079
|
-
|
|
1080
|
-
|
|
1061
|
+
sessionId,
|
|
1062
|
+
requestId,
|
|
1081
1063
|
activeState,
|
|
1082
1064
|
priority,
|
|
1083
1065
|
});
|
|
1084
1066
|
}
|
|
1085
|
-
|
|
1086
|
-
return
|
|
1067
|
+
dropPendingRequestSlot(requestId) {
|
|
1068
|
+
return dropPendingRequestSlot(this.pendingRequestSlots, requestId);
|
|
1087
1069
|
}
|
|
1088
1070
|
async run(options) {
|
|
1089
1071
|
if (this.isDecisionRun(options)) {
|
|
@@ -1096,52 +1078,52 @@ export class AgentHarnessRuntime {
|
|
|
1096
1078
|
};
|
|
1097
1079
|
return this.resume(resumeOptions);
|
|
1098
1080
|
}
|
|
1099
|
-
const resolvedListeners =
|
|
1081
|
+
const resolvedListeners = resolveRequestListeners(options);
|
|
1100
1082
|
if (resolvedListeners) {
|
|
1101
1083
|
const result = await createListenerDispatchRuntime({
|
|
1102
1084
|
notifyListener: (listener, value) => this.notifyListener(listener, value),
|
|
1103
|
-
|
|
1104
|
-
const
|
|
1105
|
-
return
|
|
1085
|
+
getSession: async (sessionId) => {
|
|
1086
|
+
const session = await this.getSessionRecord(sessionId);
|
|
1087
|
+
return session
|
|
1106
1088
|
? {
|
|
1107
|
-
currentState:
|
|
1108
|
-
latestRequestId:
|
|
1109
|
-
entryAgentId:
|
|
1110
|
-
currentAgentId:
|
|
1111
|
-
requests:
|
|
1112
|
-
pendingDecision:
|
|
1089
|
+
currentState: session.currentState,
|
|
1090
|
+
latestRequestId: session.latestRequestId,
|
|
1091
|
+
entryAgentId: session.entryAgentId,
|
|
1092
|
+
currentAgentId: session.currentAgentId,
|
|
1093
|
+
requests: session.requests.map((request) => ({ agentId: request.agentId })),
|
|
1094
|
+
pendingDecision: session.pendingDecision,
|
|
1113
1095
|
}
|
|
1114
1096
|
: null;
|
|
1115
1097
|
},
|
|
1116
|
-
}).
|
|
1117
|
-
return
|
|
1098
|
+
}).dispatchRequestListeners(this.streamEvents(options), resolvedListeners);
|
|
1099
|
+
return toPublicRequestResultShape(result);
|
|
1118
1100
|
}
|
|
1119
1101
|
const invocation = normalizeInvocationEnvelope(options);
|
|
1120
|
-
const { binding, selectedAgentId,
|
|
1102
|
+
const { binding, selectedAgentId, sessionId, requestId, isNewSession, requestCreatedEventPromise, releaseRequestSlotPromise, } = await prepareRunStart(this.createPrepareRunStartRuntime(), {
|
|
1121
1103
|
options,
|
|
1122
1104
|
invocation,
|
|
1123
|
-
|
|
1105
|
+
requestCreatedPayload: (activeBinding, activeSelectedAgentId) => ({
|
|
1124
1106
|
agentId: activeBinding.agent.id,
|
|
1125
1107
|
requestedAgentId: defaultRequestedAgentId(options.agentId),
|
|
1126
1108
|
selectedAgentId: activeSelectedAgentId,
|
|
1127
1109
|
executionMode: getBindingRuntimeExecutionMode(activeBinding),
|
|
1128
1110
|
}),
|
|
1129
1111
|
});
|
|
1130
|
-
await
|
|
1131
|
-
const
|
|
1112
|
+
await requestCreatedEventPromise;
|
|
1113
|
+
const releaseRequestSlot = await releaseRequestSlotPromise;
|
|
1132
1114
|
try {
|
|
1133
|
-
return
|
|
1115
|
+
return toPublicRequestResultShape(await this.executeQueuedRequest(binding, options.input, sessionId, requestId, selectedAgentId, {
|
|
1134
1116
|
context: invocation.context,
|
|
1135
1117
|
state: invocation.state,
|
|
1136
1118
|
files: invocation.files,
|
|
1137
1119
|
previousState: "running",
|
|
1138
1120
|
stateSequence: 6,
|
|
1139
1121
|
approvalSequence: 7,
|
|
1140
|
-
priorHistory:
|
|
1122
|
+
priorHistory: isNewSession ? [] : undefined,
|
|
1141
1123
|
}));
|
|
1142
1124
|
}
|
|
1143
1125
|
finally {
|
|
1144
|
-
await
|
|
1126
|
+
await releaseRequestSlot();
|
|
1145
1127
|
}
|
|
1146
1128
|
}
|
|
1147
1129
|
async *streamEvents(options) {
|
|
@@ -1156,10 +1138,10 @@ export class AgentHarnessRuntime {
|
|
|
1156
1138
|
};
|
|
1157
1139
|
return;
|
|
1158
1140
|
}
|
|
1159
|
-
const {
|
|
1141
|
+
const { sessionId, requestId, isNewSession, requestCreatedEventPromise, releaseRequestSlotPromise, } = await prepareRunStart(this.createPrepareRunStartRuntime(), {
|
|
1160
1142
|
options,
|
|
1161
1143
|
invocation,
|
|
1162
|
-
|
|
1144
|
+
requestCreatedPayload: (_binding, activeSelectedAgentId) => ({
|
|
1163
1145
|
agentId: activeSelectedAgentId,
|
|
1164
1146
|
requestedAgentId: defaultRequestedAgentId(options.agentId),
|
|
1165
1147
|
selectedAgentId: activeSelectedAgentId,
|
|
@@ -1172,53 +1154,53 @@ export class AgentHarnessRuntime {
|
|
|
1172
1154
|
input: options.input,
|
|
1173
1155
|
invocation: {
|
|
1174
1156
|
...invocation,
|
|
1175
|
-
memoryContext: await this.buildRuntimeMemoryContext(binding,
|
|
1157
|
+
memoryContext: await this.buildRuntimeMemoryContext(binding, sessionId, options.input),
|
|
1176
1158
|
},
|
|
1177
|
-
|
|
1178
|
-
|
|
1159
|
+
sessionId,
|
|
1160
|
+
requestId,
|
|
1179
1161
|
selectedAgentId,
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1162
|
+
isNewSession: isNewSession,
|
|
1163
|
+
requestCreatedEventPromise,
|
|
1164
|
+
releaseRequestSlotPromise,
|
|
1183
1165
|
getBinding: (agentId) => getWorkspaceBinding(this.workspace, agentId),
|
|
1184
|
-
loadPriorHistory: (
|
|
1185
|
-
stream: (binding, message,
|
|
1186
|
-
invokeWithHistory: (binding, input,
|
|
1187
|
-
emit: (
|
|
1188
|
-
|
|
1189
|
-
requestApprovalAndEmit: (
|
|
1190
|
-
appendAssistantMessage: (
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
emitSyntheticFallback: (
|
|
1166
|
+
loadPriorHistory: (sessionId, requestId) => this.loadPriorHistory(sessionId, requestId),
|
|
1167
|
+
stream: (binding, message, sessionId, priorHistory, streamOptions) => this.runtimeAdapter.stream(binding, message, sessionId, priorHistory, streamOptions),
|
|
1168
|
+
invokeWithHistory: (binding, input, sessionId, requestId) => this.invokeWithHistory(binding, input, sessionId, requestId),
|
|
1169
|
+
emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
|
|
1170
|
+
setRequestStateAndEmit: (sessionId, requestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, stateOptions),
|
|
1171
|
+
requestApprovalAndEmit: (sessionId, requestId, input, interruptContent, checkpointRef, sequence) => this.requestApprovalAndEmit(sessionId, requestId, input, interruptContent, checkpointRef, sequence),
|
|
1172
|
+
appendAssistantMessage: (sessionId, requestId, content) => appendLifecycleAssistantMessage(this.persistence, sessionId, requestId, content),
|
|
1173
|
+
clearRequestInput: (sessionId, requestId) => this.persistence.clearRequestInput(sessionId, requestId),
|
|
1174
|
+
updateRequestInspection: (sessionId, requestId, patch) => this.persistence.updateRequestInspection(sessionId, requestId, patch),
|
|
1175
|
+
appendRequestTraceItem: (sessionId, requestId, item) => this.persistence.appendRequestTraceItem(sessionId, requestId, item),
|
|
1176
|
+
emitSyntheticFallback: (sessionId, requestId, selectedAgentId, error) => this.runtimeEventOperations.emitSyntheticFallback(sessionId, requestId, selectedAgentId, error),
|
|
1195
1177
|
});
|
|
1196
1178
|
for await (const item of stream) {
|
|
1197
1179
|
yield toPublicHarnessStreamItem(item);
|
|
1198
1180
|
}
|
|
1199
1181
|
}
|
|
1200
1182
|
async resume(options) {
|
|
1201
|
-
return
|
|
1183
|
+
return toPublicRequestResultShape(await resumeRequest({
|
|
1202
1184
|
getApprovalById: (approvalId) => this.persistence.getApproval(approvalId),
|
|
1203
|
-
getSession: (
|
|
1204
|
-
resolveApprovalRecord: (resumeOptions,
|
|
1185
|
+
getSession: (sessionId) => this.getSession(sessionId),
|
|
1186
|
+
resolveApprovalRecord: (resumeOptions, session) => resolveHarnessApprovalRecord(this.persistence, resumeOptions, session),
|
|
1205
1187
|
getBinding: (agentId) => getWorkspaceBinding(this.workspace, agentId),
|
|
1206
1188
|
buildResumePayload: (binding, approval, resumeOptions) => buildHarnessResumePayload(binding, approval, resumeOptions),
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
emit: (
|
|
1214
|
-
resolveApproval: (
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
invoke: (binding, input,
|
|
1189
|
+
getRequestCancellation: (requestId) => this.getRequestCancellation(requestId),
|
|
1190
|
+
finalizeCancelledRequest: (sessionId, requestId, previousState, reason) => this.finalizeCancelledRequest(sessionId, requestId, previousState, reason),
|
|
1191
|
+
setRequestState: (sessionId, requestId, state, checkpointRef) => this.persistence.setRequestState(sessionId, requestId, state, checkpointRef),
|
|
1192
|
+
acquireRequestSlot: (sessionId, requestId, activeState, priority) => this.acquireRequestSlot(sessionId, requestId, activeState, priority),
|
|
1193
|
+
resolvePersistedRequestPriority: (sessionId, requestId) => this.resolvePersistedRequestPriority(sessionId, requestId),
|
|
1194
|
+
saveRequestRecoveryIntent: (sessionId, requestId, payload) => this.persistence.saveRequestRecoveryIntent(sessionId, requestId, payload),
|
|
1195
|
+
emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
|
|
1196
|
+
resolveApproval: (sessionId, requestId, approvalId, resolution) => this.persistence.resolveApproval(sessionId, requestId, approvalId, resolution),
|
|
1197
|
+
listSessionMessages: (sessionId) => this.persistence.listSessionMessages(sessionId),
|
|
1198
|
+
loadRequestInput: (sessionId, requestId) => this.loadRequestInput(sessionId, requestId),
|
|
1199
|
+
invoke: (binding, input, sessionId, requestId, resumePayload, priorHistory) => this.runtimeAdapter.invoke(binding, input, sessionId, requestId, resumePayload, priorHistory),
|
|
1218
1200
|
recordLlmSuccess: (startedAt) => this.recordLlmSuccess(startedAt),
|
|
1219
1201
|
recordLlmFailure: (startedAt) => this.recordLlmFailure(startedAt),
|
|
1220
|
-
|
|
1221
|
-
|
|
1202
|
+
clearRequestRecoveryIntent: (sessionId, requestId) => this.persistence.clearRequestRecoveryIntent(sessionId, requestId),
|
|
1203
|
+
finalizeContinuedRequest: (binding, sessionId, requestId, input, actual, operationOptions) => this.finalizeContinuedRequest(binding, sessionId, requestId, input, actual, operationOptions),
|
|
1222
1204
|
}, {
|
|
1223
1205
|
...options,
|
|
1224
1206
|
}));
|
|
@@ -1229,11 +1211,11 @@ export class AgentHarnessRuntime {
|
|
|
1229
1211
|
throw new Error(`Unknown session ${options.sessionId}`);
|
|
1230
1212
|
}
|
|
1231
1213
|
const sourceRequestId = session.latestRequestId;
|
|
1232
|
-
const targetSessionId = options.mode === "restart-new-
|
|
1214
|
+
const targetSessionId = options.mode === "restart-new-session" ? createPersistentId() : options.sessionId;
|
|
1233
1215
|
const result = await this.run({
|
|
1234
|
-
agentId: session.
|
|
1216
|
+
agentId: session.currentAgentId ?? session.entryAgentId,
|
|
1235
1217
|
input: options.input,
|
|
1236
|
-
sessionId: options.mode === "restart-new-
|
|
1218
|
+
sessionId: options.mode === "restart-new-session" ? undefined : targetSessionId,
|
|
1237
1219
|
});
|
|
1238
1220
|
return {
|
|
1239
1221
|
...result,
|
|
@@ -1254,12 +1236,12 @@ export class AgentHarnessRuntime {
|
|
|
1254
1236
|
}
|
|
1255
1237
|
this.closed = true;
|
|
1256
1238
|
await this.healthMonitor?.stop();
|
|
1257
|
-
this.
|
|
1239
|
+
this.unregisterSessionMemorySync();
|
|
1258
1240
|
this.unregisterRuntimeMemorySync();
|
|
1259
1241
|
this.unregisterMem0IngestionSync();
|
|
1260
1242
|
this.unregisterRuntimeMemoryFormationSync();
|
|
1261
1243
|
await Promise.allSettled(Array.from(this.backgroundTasks));
|
|
1262
|
-
await this.
|
|
1244
|
+
await this.sessionMemorySync?.close();
|
|
1263
1245
|
await this.runtimeMemorySync?.close();
|
|
1264
1246
|
await this.mem0IngestionSync?.close();
|
|
1265
1247
|
await this.runtimeMemoryFormationSync?.close();
|
|
@@ -1269,17 +1251,17 @@ export class AgentHarnessRuntime {
|
|
|
1269
1251
|
async stop() {
|
|
1270
1252
|
await this.close();
|
|
1271
1253
|
}
|
|
1272
|
-
async
|
|
1273
|
-
return
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1254
|
+
async cancelRequest(options) {
|
|
1255
|
+
return toPublicRequestResultShape(await cancelRequestOperation({
|
|
1256
|
+
getRequest: (requestId) => this.persistence.getRequest(requestId),
|
|
1257
|
+
requestRequestCancel: (requestId, reason) => this.persistence.requestRequestCancel(requestId, reason),
|
|
1258
|
+
dropPendingRequestSlot: (requestId) => this.dropPendingRequestSlot(requestId),
|
|
1259
|
+
finalizeCancelledRequest: (sessionId, requestId, previousState, reason) => this.finalizeCancelledRequest(sessionId, requestId, previousState, reason),
|
|
1260
|
+
setRequestStateAndEmit: (sessionId, requestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, stateOptions),
|
|
1279
1261
|
}, options));
|
|
1280
1262
|
}
|
|
1281
|
-
async
|
|
1282
|
-
await
|
|
1263
|
+
async recoverStartupRequests() {
|
|
1264
|
+
await recoverHarnessStartupRequests({
|
|
1283
1265
|
recoveryConfig: this.recoveryConfig,
|
|
1284
1266
|
persistence: this.persistence,
|
|
1285
1267
|
createStartupRecoveryContext: () => ({
|
|
@@ -1289,34 +1271,34 @@ export class AgentHarnessRuntime {
|
|
|
1289
1271
|
recoveryConfig: this.recoveryConfig,
|
|
1290
1272
|
concurrencyConfig: this.concurrencyConfig,
|
|
1291
1273
|
getBinding: (agentId) => getWorkspaceBinding(this.workspace, agentId),
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
emit: (
|
|
1296
|
-
|
|
1297
|
-
|
|
1274
|
+
acquireRequestSlot: (sessionId, requestId, activeState, priority) => this.acquireRequestSlot(sessionId, requestId, activeState, priority),
|
|
1275
|
+
executeQueuedRequest: (binding, input, sessionId, requestId, agentId, options) => this.executeQueuedRequest(binding, input, sessionId, requestId, agentId, options),
|
|
1276
|
+
setRequestStateAndEmit: (sessionId, requestId, sequence, state, options) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, options),
|
|
1277
|
+
emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
|
|
1278
|
+
loadRequestInput: (sessionId, requestId) => this.loadRequestInput(sessionId, requestId),
|
|
1279
|
+
finalizeContinuedRequest: (binding, sessionId, requestId, input, actual, options) => this.finalizeContinuedRequest(binding, sessionId, requestId, input, actual, options),
|
|
1298
1280
|
supportsRunningReplay: (binding) => bindingSupportsRunningReplay(binding),
|
|
1299
|
-
|
|
1281
|
+
isStaleRunningRequest: (session, nowMs) => this.isStaleRunningRequest(session, nowMs),
|
|
1300
1282
|
recordLlmSuccess: (startedAt) => this.recordLlmSuccess(startedAt),
|
|
1301
1283
|
recordLlmFailure: (startedAt) => this.recordLlmFailure(startedAt),
|
|
1302
1284
|
}),
|
|
1303
|
-
|
|
1285
|
+
reclaimExpiredClaimedRequests: (nowIso) => this.reclaimExpiredClaimedRequests(nowIso),
|
|
1304
1286
|
});
|
|
1305
1287
|
}
|
|
1306
|
-
async
|
|
1307
|
-
await
|
|
1288
|
+
async reclaimExpiredClaimedRequests(nowIso = new Date().toISOString()) {
|
|
1289
|
+
await reclaimHarnessExpiredClaimedRequests({
|
|
1308
1290
|
persistence: this.persistence,
|
|
1309
|
-
|
|
1310
|
-
emit: (
|
|
1291
|
+
setRequestStateAndEmit: (sessionId, requestId, sequence, state, options) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, options),
|
|
1292
|
+
emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
|
|
1311
1293
|
concurrencyConfig: this.concurrencyConfig,
|
|
1312
|
-
|
|
1294
|
+
getActiveRequestSlots: () => this.activeRequestSlots,
|
|
1313
1295
|
}, nowIso);
|
|
1314
1296
|
}
|
|
1315
|
-
async
|
|
1316
|
-
return
|
|
1297
|
+
async isStaleRunningRequest(session, nowMs = Date.now()) {
|
|
1298
|
+
return isHarnessStaleRunningRequest({
|
|
1317
1299
|
persistence: this.persistence,
|
|
1318
1300
|
concurrencyConfig: this.concurrencyConfig,
|
|
1319
|
-
},
|
|
1301
|
+
}, session, nowMs);
|
|
1320
1302
|
}
|
|
1321
1303
|
}
|
|
1322
1304
|
function toRequestSummary(summary) {
|
|
@@ -1324,7 +1306,7 @@ function toRequestSummary(summary) {
|
|
|
1324
1306
|
requestId: summary.requestId,
|
|
1325
1307
|
sessionId: summary.sessionId,
|
|
1326
1308
|
agentId: summary.agentId,
|
|
1327
|
-
|
|
1309
|
+
parentRequestId: summary.parentRequestId,
|
|
1328
1310
|
executionMode: summary.executionMode,
|
|
1329
1311
|
adapterKind: summary.adapterKind,
|
|
1330
1312
|
createdAt: summary.createdAt,
|
|
@@ -1361,7 +1343,7 @@ function toRequestRecord(record) {
|
|
|
1361
1343
|
runtimeTimeline: record.runtimeTimeline,
|
|
1362
1344
|
};
|
|
1363
1345
|
}
|
|
1364
|
-
function
|
|
1346
|
+
function deriveRequestInputFromTranscript(transcript, requestId) {
|
|
1365
1347
|
const candidate = [...transcript]
|
|
1366
1348
|
.reverse()
|
|
1367
1349
|
.find((message) => message.role === "user" && (!requestId || message.requestId === requestId));
|