@botbotgo/agent-harness 0.0.474 → 0.0.476
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 +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +2 -2
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -411
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1089
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,613 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { compileModel, compileTool } from "./resource-compilers.js";
|
|
5
|
-
import { inferAgentCapabilities } from "./support/agent-capabilities.js";
|
|
6
|
-
import { getAgentExecutionConfigValue, getAgentExecutionObject, getAgentExecutionString } from "./support/agent-execution-config.js";
|
|
7
|
-
import { discoverSkillPaths } from "./support/discovery.js";
|
|
8
|
-
import { compileAgentMemories, getProceduralMemoryDefaults, getResilienceConfig, getRuntimeAgentDefaults, getRuntimeDefaults, getRuntimeMemoryDefaults, getRuntimeStorageRoots, getWorkspaceObject, resolvePromptValue, resolveRefId, } from "./support/workspace-ref-utils.js";
|
|
9
|
-
import { WORKSPACE_BOUNDARY_GUIDANCE } from "../runtime/prompts/runtime-prompts.js";
|
|
10
|
-
function requireSkills(pathEntries, workspaceRoot) {
|
|
11
|
-
return Array.from(new Set(discoverSkillPaths(pathEntries, workspaceRoot)));
|
|
12
|
-
}
|
|
13
|
-
function resolveInheritancePolicy(agent) {
|
|
14
|
-
return getAgentExecutionString(agent, "skillInheritancePolicy") ?? "default";
|
|
15
|
-
}
|
|
16
|
-
export function compileAgentSkills(workspaceRoot, agent, parentSkills = []) {
|
|
17
|
-
const policyName = resolveInheritancePolicy(agent);
|
|
18
|
-
const policy = getSkillInheritancePolicy(policyName);
|
|
19
|
-
if (!policy) {
|
|
20
|
-
throw new Error(`Agent ${agent.id} skill inheritance policy ${policyName} is not registered`);
|
|
21
|
-
}
|
|
22
|
-
return Array.from(new Set(policy.apply({
|
|
23
|
-
agent,
|
|
24
|
-
ownSkills: requireSkills(agent.skillPathRefs, workspaceRoot),
|
|
25
|
-
parentSkills,
|
|
26
|
-
})));
|
|
27
|
-
}
|
|
28
|
-
function requireModel(models, ref, ownerId) {
|
|
29
|
-
const model = models.get(resolveRefId(ref));
|
|
30
|
-
if (!model) {
|
|
31
|
-
throw new Error(`Agent ${ownerId} references missing model ${ref}`);
|
|
32
|
-
}
|
|
33
|
-
return compileModel(model);
|
|
34
|
-
}
|
|
35
|
-
function compileMiddlewareConfigs(middleware, models, ownerId) {
|
|
36
|
-
if (!middleware || middleware.length === 0) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
return middleware.map((config) => {
|
|
40
|
-
const compiled = { ...config };
|
|
41
|
-
if (compiled.kind === "summarization" && typeof compiled.modelRef === "string") {
|
|
42
|
-
compiled.model = requireModel(models, compiled.modelRef, ownerId);
|
|
43
|
-
delete compiled.modelRef;
|
|
44
|
-
}
|
|
45
|
-
if (compiled.kind === "llmToolSelector" && typeof compiled.modelRef === "string") {
|
|
46
|
-
compiled.model = requireModel(models, compiled.modelRef, ownerId);
|
|
47
|
-
delete compiled.modelRef;
|
|
48
|
-
}
|
|
49
|
-
if (compiled.kind === "modelFallback") {
|
|
50
|
-
const fallbackModelRefs = Array.isArray(compiled.fallbackModelRefs)
|
|
51
|
-
? compiled.fallbackModelRefs
|
|
52
|
-
: Array.isArray(compiled.modelRefs)
|
|
53
|
-
? compiled.modelRefs
|
|
54
|
-
: [];
|
|
55
|
-
if (fallbackModelRefs.length > 0) {
|
|
56
|
-
compiled.fallbackModels = fallbackModelRefs.map((modelRef) => requireModel(models, String(modelRef), ownerId));
|
|
57
|
-
delete compiled.fallbackModelRefs;
|
|
58
|
-
delete compiled.modelRefs;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return compiled;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
function resolveAgentRuntimeName(agent) {
|
|
65
|
-
const baseName = agent.id;
|
|
66
|
-
if (baseName.includes(".")) {
|
|
67
|
-
return baseName;
|
|
68
|
-
}
|
|
69
|
-
const normalizedSourcePath = agent.sourcePath.split(path.sep).join("/");
|
|
70
|
-
if (normalizedSourcePath.includes("/packages/framework/")) {
|
|
71
|
-
return `core.${baseName}`;
|
|
72
|
-
}
|
|
73
|
-
return baseName;
|
|
74
|
-
}
|
|
75
|
-
function asObject(value) {
|
|
76
|
-
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
77
|
-
? value
|
|
78
|
-
: undefined;
|
|
79
|
-
}
|
|
80
|
-
function mergeConfigValue(base, override) {
|
|
81
|
-
if (override === undefined) {
|
|
82
|
-
return base;
|
|
83
|
-
}
|
|
84
|
-
if (Array.isArray(base) && Array.isArray(override)) {
|
|
85
|
-
return override;
|
|
86
|
-
}
|
|
87
|
-
if (typeof base === "object" && base && typeof override === "object" && override && !Array.isArray(base) && !Array.isArray(override)) {
|
|
88
|
-
const merged = { ...base };
|
|
89
|
-
for (const [key, value] of Object.entries(override)) {
|
|
90
|
-
merged[key] = key in merged ? mergeConfigValue(merged[key], value) : value;
|
|
91
|
-
}
|
|
92
|
-
return merged;
|
|
93
|
-
}
|
|
94
|
-
return override;
|
|
95
|
-
}
|
|
96
|
-
function mergeConfigObjects(base, override) {
|
|
97
|
-
const merged = mergeConfigValue(base, override);
|
|
98
|
-
return typeof merged === "object" && merged && !Array.isArray(merged)
|
|
99
|
-
? merged
|
|
100
|
-
: undefined;
|
|
101
|
-
}
|
|
102
|
-
function parseHitlOverride(value) {
|
|
103
|
-
const record = asObject(value);
|
|
104
|
-
if (!record) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
const enabled = record.enabled === true;
|
|
108
|
-
const allow = Array.isArray(record.allow)
|
|
109
|
-
? record.allow.filter((item) => item === "approve" || item === "edit" || item === "reject")
|
|
110
|
-
: undefined;
|
|
111
|
-
return {
|
|
112
|
-
enabled,
|
|
113
|
-
allow: allow && allow.length > 0 ? allow : undefined,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function applyToolBindingOverrides(tool, binding) {
|
|
117
|
-
const overrides = binding.overrides;
|
|
118
|
-
if (!overrides || Object.keys(overrides).length === 0) {
|
|
119
|
-
return tool;
|
|
120
|
-
}
|
|
121
|
-
const overrideConfig = mergeConfigObjects(asObject(overrides.config), asObject(overrides.execution)
|
|
122
|
-
? {
|
|
123
|
-
execution: asObject(overrides.execution),
|
|
124
|
-
}
|
|
125
|
-
: undefined);
|
|
126
|
-
return {
|
|
127
|
-
...tool,
|
|
128
|
-
...(typeof overrides.name === "string" ? { name: overrides.name } : {}),
|
|
129
|
-
...(typeof overrides.description === "string" ? { description: overrides.description } : {}),
|
|
130
|
-
...(typeof overrides.implementationName === "string" ? { implementationName: overrides.implementationName } : {}),
|
|
131
|
-
...(typeof overrides.inputSchemaRef === "string" ? { inputSchemaRef: overrides.inputSchemaRef } : {}),
|
|
132
|
-
...(typeof overrides.embeddingModelRef === "string"
|
|
133
|
-
? { embeddingModelRef: overrides.embeddingModelRef }
|
|
134
|
-
: typeof overrides.embeddingModel === "string"
|
|
135
|
-
? {
|
|
136
|
-
embeddingModelRef: overrides.embeddingModel.startsWith("embedding-model/")
|
|
137
|
-
? overrides.embeddingModel
|
|
138
|
-
: `embedding-model/${overrides.embeddingModel}`,
|
|
139
|
-
}
|
|
140
|
-
: {}),
|
|
141
|
-
...(typeof overrides.backendOperation === "string" ? { backendOperation: overrides.backendOperation } : {}),
|
|
142
|
-
...(typeof overrides.mcpRef === "string" ? { mcpRef: overrides.mcpRef } : {}),
|
|
143
|
-
...(typeof overrides.subprocess === "boolean" ? { subprocess: overrides.subprocess } : {}),
|
|
144
|
-
...(typeof overrides.retryable === "boolean" ? { retryable: overrides.retryable } : {}),
|
|
145
|
-
...(overrides.hitl !== undefined ? { hitl: parseHitlOverride(overrides.hitl) } : {}),
|
|
146
|
-
...(overrideConfig ? { config: mergeConfigObjects(tool.config, overrideConfig) } : {}),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function getAgentToolBindings(agent) {
|
|
150
|
-
if (agent.toolBindings && agent.toolBindings.length > 0) {
|
|
151
|
-
return agent.toolBindings;
|
|
152
|
-
}
|
|
153
|
-
return agent.toolRefs.map((ref) => ({ ref }));
|
|
154
|
-
}
|
|
155
|
-
export function requireTools(tools, bindings, ownerId) {
|
|
156
|
-
const compiled = bindings.flatMap((binding) => {
|
|
157
|
-
const targets = resolveToolTargets(tools, binding.ref);
|
|
158
|
-
if (targets.length === 0) {
|
|
159
|
-
throw new Error(`Agent ${ownerId} references missing tool ${binding.ref}`);
|
|
160
|
-
}
|
|
161
|
-
return targets.flatMap((tool) => compileTool(applyToolBindingOverrides(tool, binding), tools));
|
|
162
|
-
});
|
|
163
|
-
const deduped = new Map();
|
|
164
|
-
for (const tool of compiled) {
|
|
165
|
-
deduped.set(tool.name, tool);
|
|
166
|
-
}
|
|
167
|
-
return Array.from(deduped.values());
|
|
168
|
-
}
|
|
169
|
-
function buildSubagent(agent, workspaceRoot, refs, models, tools, parentSkills, parentModel) {
|
|
170
|
-
const execution = compileExecutionCore(agent, workspaceRoot, refs, models, tools);
|
|
171
|
-
return {
|
|
172
|
-
agentId: agent.id,
|
|
173
|
-
name: resolveAgentRuntimeName(agent),
|
|
174
|
-
description: agent.description,
|
|
175
|
-
systemPrompt: execution.systemPrompt ?? WORKSPACE_BOUNDARY_GUIDANCE,
|
|
176
|
-
tools: execution.tools,
|
|
177
|
-
model: agent.modelRef ? execution.model : parentModel,
|
|
178
|
-
interruptOn: resolveInterruptOn(agent),
|
|
179
|
-
skills: compileAgentSkills(workspaceRoot, agent, parentSkills),
|
|
180
|
-
responseFormat: execution.responseFormat,
|
|
181
|
-
middleware: execution.middleware,
|
|
182
|
-
builtinTools: getAgentExecutionObject(agent, "builtinTools"),
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function resolveSystemPrompt(agent, workspaceRoot) {
|
|
186
|
-
const promptBaseDir = path.dirname(agent.sourcePath || workspaceRoot);
|
|
187
|
-
const prompt = resolvePromptValue(getAgentExecutionConfigValue(agent, "systemPrompt"), promptBaseDir);
|
|
188
|
-
if (agent.executionMode !== "deepagent") {
|
|
189
|
-
return prompt;
|
|
190
|
-
}
|
|
191
|
-
return [prompt, WORKSPACE_BOUNDARY_GUIDANCE].filter(Boolean).join("\n\n");
|
|
192
|
-
}
|
|
193
|
-
function resolveInterruptOn(agent) {
|
|
194
|
-
return getAgentExecutionObject(agent, "interruptOn");
|
|
195
|
-
}
|
|
196
|
-
function resolveResponseFormat(agent) {
|
|
197
|
-
return getAgentExecutionConfigValue(agent, "responseFormat");
|
|
198
|
-
}
|
|
199
|
-
function normalizeResponseFormatRef(ref) {
|
|
200
|
-
return ref.startsWith("response-format/") ? ref : `response-format/${ref}`;
|
|
201
|
-
}
|
|
202
|
-
function resolveResponseFormatObject(refs, ref, ownerLabel) {
|
|
203
|
-
if (!ref) {
|
|
204
|
-
return undefined;
|
|
205
|
-
}
|
|
206
|
-
const object = getWorkspaceObject(refs, normalizeResponseFormatRef(ref));
|
|
207
|
-
if (!object) {
|
|
208
|
-
throw new Error(`${ownerLabel} responseFormatRef references missing object ${ref}`);
|
|
209
|
-
}
|
|
210
|
-
if (object.kind !== "response-format") {
|
|
211
|
-
throw new Error(`${ownerLabel} responseFormatRef references ${ref}, but expected response-format`);
|
|
212
|
-
}
|
|
213
|
-
if (!("format" in object.value)) {
|
|
214
|
-
throw new Error(`${ownerLabel} responseFormatRef ${ref} must define format`);
|
|
215
|
-
}
|
|
216
|
-
return object.value.format;
|
|
217
|
-
}
|
|
218
|
-
function mergeResponseFormats(base, override) {
|
|
219
|
-
if (override === undefined) {
|
|
220
|
-
return base;
|
|
221
|
-
}
|
|
222
|
-
if (typeof base === "object" &&
|
|
223
|
-
base &&
|
|
224
|
-
typeof override === "object" &&
|
|
225
|
-
override &&
|
|
226
|
-
!Array.isArray(base) &&
|
|
227
|
-
!Array.isArray(override)) {
|
|
228
|
-
const merged = { ...base };
|
|
229
|
-
for (const [key, value] of Object.entries(override)) {
|
|
230
|
-
if (key === "required" && Array.isArray(merged.required) && Array.isArray(value)) {
|
|
231
|
-
merged.required = Array.from(new Set([...merged.required, ...value]));
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
if (key === "properties" &&
|
|
235
|
-
typeof merged.properties === "object" &&
|
|
236
|
-
merged.properties &&
|
|
237
|
-
!Array.isArray(merged.properties) &&
|
|
238
|
-
typeof value === "object" &&
|
|
239
|
-
value &&
|
|
240
|
-
!Array.isArray(value)) {
|
|
241
|
-
merged.properties = {
|
|
242
|
-
...merged.properties,
|
|
243
|
-
...value,
|
|
244
|
-
};
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
merged[key] = key in merged ? mergeResponseFormats(merged[key], value) : value;
|
|
248
|
-
}
|
|
249
|
-
return merged;
|
|
250
|
-
}
|
|
251
|
-
return override;
|
|
252
|
-
}
|
|
253
|
-
function resolveInheritedResponseFormat(agent, refs) {
|
|
254
|
-
const defaults = getRuntimeAgentDefaults(refs);
|
|
255
|
-
if (defaults && "responseFormat" in defaults) {
|
|
256
|
-
return defaults.responseFormat === null ? undefined : defaults.responseFormat;
|
|
257
|
-
}
|
|
258
|
-
const defaultRef = typeof defaults?.responseFormatRef === "string" ? defaults.responseFormatRef.trim() : "";
|
|
259
|
-
if (defaultRef) {
|
|
260
|
-
return resolveResponseFormatObject(refs, defaultRef, "Runtime defaults.agent.config");
|
|
261
|
-
}
|
|
262
|
-
return undefined;
|
|
263
|
-
}
|
|
264
|
-
function resolveEffectiveResponseFormat(agent, refs) {
|
|
265
|
-
const explicitResponseFormat = resolveResponseFormat(agent);
|
|
266
|
-
if (explicitResponseFormat !== undefined) {
|
|
267
|
-
return explicitResponseFormat === null
|
|
268
|
-
? undefined
|
|
269
|
-
: mergeResponseFormats(resolveInheritedResponseFormat(agent, refs), explicitResponseFormat);
|
|
270
|
-
}
|
|
271
|
-
const explicitRef = getAgentExecutionConfigValue(agent, "responseFormatRef");
|
|
272
|
-
if (typeof explicitRef === "string" && explicitRef.trim().length > 0) {
|
|
273
|
-
return resolveResponseFormatObject(refs, explicitRef.trim(), `Agent ${agent.id}`);
|
|
274
|
-
}
|
|
275
|
-
return resolveInheritedResponseFormat(agent, refs);
|
|
276
|
-
}
|
|
277
|
-
function resolveContextSchema(agent) {
|
|
278
|
-
return getAgentExecutionConfigValue(agent, "contextSchema");
|
|
279
|
-
}
|
|
280
|
-
function resolveExecutionContract(agent) {
|
|
281
|
-
const value = getAgentExecutionObject(agent, "executionContract");
|
|
282
|
-
if (!value) {
|
|
283
|
-
return undefined;
|
|
284
|
-
}
|
|
285
|
-
const recoveryEvidenceTool = typeof value.recoveryEvidenceTool === "string" && value.recoveryEvidenceTool.trim().length > 0
|
|
286
|
-
? { name: value.recoveryEvidenceTool.trim() }
|
|
287
|
-
: typeof value.recoveryEvidenceTool === "object" && value.recoveryEvidenceTool && !Array.isArray(value.recoveryEvidenceTool)
|
|
288
|
-
? value.recoveryEvidenceTool
|
|
289
|
-
: undefined;
|
|
290
|
-
const recoveryEvidenceToolName = recoveryEvidenceTool && typeof recoveryEvidenceTool.name === "string" && recoveryEvidenceTool.name.trim().length > 0
|
|
291
|
-
? recoveryEvidenceTool.name.trim()
|
|
292
|
-
: undefined;
|
|
293
|
-
const recoveryEvidenceToolArgs = recoveryEvidenceTool
|
|
294
|
-
&& typeof recoveryEvidenceTool.args === "object"
|
|
295
|
-
&& recoveryEvidenceTool.args
|
|
296
|
-
&& !Array.isArray(recoveryEvidenceTool.args)
|
|
297
|
-
? recoveryEvidenceTool.args
|
|
298
|
-
: undefined;
|
|
299
|
-
return {
|
|
300
|
-
...(value.requiresPlan === true ? { requiresPlan: true } : {}),
|
|
301
|
-
...(recoveryEvidenceToolName
|
|
302
|
-
? {
|
|
303
|
-
recoveryEvidenceTool: {
|
|
304
|
-
name: recoveryEvidenceToolName,
|
|
305
|
-
...(recoveryEvidenceToolArgs ? { args: recoveryEvidenceToolArgs } : {}),
|
|
306
|
-
},
|
|
307
|
-
}
|
|
308
|
-
: {}),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
function resolveCompiledMiddleware(agent, models) {
|
|
312
|
-
const middleware = getAgentExecutionConfigValue(agent, "middleware");
|
|
313
|
-
return compileMiddlewareConfigs(middleware, models, agent.id);
|
|
314
|
-
}
|
|
315
|
-
function resolvePassthrough(agent) {
|
|
316
|
-
const passthrough = getAgentExecutionObject(agent, "passthrough");
|
|
317
|
-
return passthrough ? { ...passthrough } : undefined;
|
|
318
|
-
}
|
|
319
|
-
function compileSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel) {
|
|
320
|
-
return agent.subagentRefs.map((ref) => {
|
|
321
|
-
const subagent = agents.get(resolveRefId(ref));
|
|
322
|
-
if (!subagent) {
|
|
323
|
-
throw new Error(`Missing subagent ${ref} for agent ${agent.id}`);
|
|
324
|
-
}
|
|
325
|
-
return buildSubagent(subagent, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
function compileAsyncSubagents(agent) {
|
|
329
|
-
return (agent.asyncSubagents ?? []).map((subagent) => ({
|
|
330
|
-
name: subagent.name,
|
|
331
|
-
description: subagent.description,
|
|
332
|
-
graphId: subagent.graphId,
|
|
333
|
-
...(subagent.url ? { url: subagent.url } : {}),
|
|
334
|
-
...(subagent.headers ? { headers: { ...subagent.headers } } : {}),
|
|
335
|
-
}));
|
|
336
|
-
}
|
|
337
|
-
function compileDeepAgentSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel) {
|
|
338
|
-
return [
|
|
339
|
-
...compileSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel),
|
|
340
|
-
...compileAsyncSubagents(agent),
|
|
341
|
-
];
|
|
342
|
-
}
|
|
343
|
-
function compileExecutionCore(agent, workspaceRoot, refs, models, tools) {
|
|
344
|
-
return {
|
|
345
|
-
model: requireModel(models, agent.modelRef, agent.id),
|
|
346
|
-
tools: requireTools(tools, getAgentToolBindings(agent), agent.id),
|
|
347
|
-
systemPrompt: resolveSystemPrompt(agent, workspaceRoot),
|
|
348
|
-
responseFormat: resolveEffectiveResponseFormat(agent, refs),
|
|
349
|
-
contextSchema: resolveContextSchema(agent),
|
|
350
|
-
middleware: resolveCompiledMiddleware(agent, models),
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
function resolveBackendConfig(agent, refs) {
|
|
354
|
-
if (agent.executionMode !== "deepagent") {
|
|
355
|
-
return undefined;
|
|
356
|
-
}
|
|
357
|
-
const backendConfig = getAgentExecutionObject(agent, "backend");
|
|
358
|
-
if (!backendConfig) {
|
|
359
|
-
return undefined;
|
|
360
|
-
}
|
|
361
|
-
if (isRefConfig(backendConfig)) {
|
|
362
|
-
return {
|
|
363
|
-
config: materializeWorkspaceObjectConfig(refs, backendConfig.ref, ["backend"], `Agent ${agent.id} backend`),
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
return { config: backendConfig };
|
|
367
|
-
}
|
|
368
|
-
function isRefConfig(value) {
|
|
369
|
-
if (typeof value?.ref !== "string" || value.ref.trim().length === 0) {
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
return Object.keys(value).every((key) => key === "ref");
|
|
373
|
-
}
|
|
374
|
-
function mergeOpaqueConfig(base, extra) {
|
|
375
|
-
if (!base && !extra) {
|
|
376
|
-
return undefined;
|
|
377
|
-
}
|
|
378
|
-
return {
|
|
379
|
-
...(base ?? {}),
|
|
380
|
-
...(extra ?? {}),
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
function materializeWorkspaceObjectConfig(refs, ref, allowedKinds, ownerLabel) {
|
|
384
|
-
const object = getWorkspaceObject(refs, ref);
|
|
385
|
-
if (!object) {
|
|
386
|
-
throw new Error(`${ownerLabel} references missing object ${ref}`);
|
|
387
|
-
}
|
|
388
|
-
if (!allowedKinds.includes(object.kind)) {
|
|
389
|
-
throw new Error(`${ownerLabel} references ${ref}, but expected one of: ${allowedKinds.join(", ")}`);
|
|
390
|
-
}
|
|
391
|
-
const { id: _id, kind: _kind, ...config } = object.value;
|
|
392
|
-
if (object.kind === "store") {
|
|
393
|
-
const storeKind = typeof config.storeKind === "string" ? config.storeKind : undefined;
|
|
394
|
-
const { storeKind: _storeKind, ...rest } = config;
|
|
395
|
-
return storeKind ? { kind: storeKind, ...rest } : config;
|
|
396
|
-
}
|
|
397
|
-
if (object.kind === "checkpointer" || object.kind === "file-checkpointer" || object.kind === "sqlite-saver") {
|
|
398
|
-
const checkpointerKind = typeof config.checkpointerKind === "string" ? config.checkpointerKind : undefined;
|
|
399
|
-
const { checkpointerKind: _checkpointerKind, ...rest } = config;
|
|
400
|
-
return checkpointerKind ? { kind: checkpointerKind, ...rest } : config;
|
|
401
|
-
}
|
|
402
|
-
if (object.kind === "backend") {
|
|
403
|
-
const backendKind = typeof config.backendKind === "string" ? config.backendKind : undefined;
|
|
404
|
-
const { backendKind: _backendKind, ...rest } = config;
|
|
405
|
-
return backendKind ? { kind: backendKind, ...rest } : config;
|
|
406
|
-
}
|
|
407
|
-
return config;
|
|
408
|
-
}
|
|
409
|
-
function materializeRuntimeMemoryConfig(refs, config, ownerLabel) {
|
|
410
|
-
const runtimeMemory = { ...config };
|
|
411
|
-
const nestedStore = asObject(runtimeMemory.store);
|
|
412
|
-
if (nestedStore && isRefConfig(nestedStore)) {
|
|
413
|
-
runtimeMemory.store = materializeWorkspaceObjectConfig(refs, nestedStore.ref, ["store"], `${ownerLabel} runtimeMemory.store`);
|
|
414
|
-
}
|
|
415
|
-
return runtimeMemory;
|
|
416
|
-
}
|
|
417
|
-
function materializeProceduralMemoryConfig(refs, config, ownerLabel) {
|
|
418
|
-
const proceduralMemory = { ...config };
|
|
419
|
-
const nestedStore = asObject(proceduralMemory.store);
|
|
420
|
-
if (nestedStore && isRefConfig(nestedStore)) {
|
|
421
|
-
proceduralMemory.store = materializeWorkspaceObjectConfig(refs, nestedStore.ref, ["store"], `${ownerLabel} proceduralMemory.store`);
|
|
422
|
-
}
|
|
423
|
-
const nestedVectorStore = asObject(proceduralMemory.vectorStore);
|
|
424
|
-
if (nestedVectorStore && isRefConfig(nestedVectorStore)) {
|
|
425
|
-
proceduralMemory.vectorStore = materializeWorkspaceObjectConfig(refs, nestedVectorStore.ref, ["vector-store"], `${ownerLabel} proceduralMemory.vectorStore`);
|
|
426
|
-
}
|
|
427
|
-
const nestedEmbeddingModel = asObject(proceduralMemory.embeddingModel);
|
|
428
|
-
if (nestedEmbeddingModel && isRefConfig(nestedEmbeddingModel)) {
|
|
429
|
-
proceduralMemory.embeddingModel = materializeWorkspaceObjectConfig(refs, nestedEmbeddingModel.ref, ["embedding-model"], `${ownerLabel} proceduralMemory.embeddingModel`);
|
|
430
|
-
}
|
|
431
|
-
return proceduralMemory;
|
|
432
|
-
}
|
|
433
|
-
function resolveStoreConfig(agent, refs) {
|
|
434
|
-
const inlineStore = getAgentExecutionObject(agent, "store");
|
|
435
|
-
if (!inlineStore) {
|
|
436
|
-
return undefined;
|
|
437
|
-
}
|
|
438
|
-
if (isRefConfig(inlineStore)) {
|
|
439
|
-
return {
|
|
440
|
-
config: materializeWorkspaceObjectConfig(refs, inlineStore.ref, ["store"], `Agent ${agent.id} store`),
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
return { config: inlineStore };
|
|
444
|
-
}
|
|
445
|
-
function resolveCheckpointerConfig(agent, refs) {
|
|
446
|
-
const inlineAgentCheckpointer = getAgentExecutionConfigValue(agent, "checkpointer");
|
|
447
|
-
if (inlineAgentCheckpointer === undefined) {
|
|
448
|
-
return undefined;
|
|
449
|
-
}
|
|
450
|
-
if (typeof inlineAgentCheckpointer === "boolean") {
|
|
451
|
-
return { config: inlineAgentCheckpointer };
|
|
452
|
-
}
|
|
453
|
-
if (isRefConfig(inlineAgentCheckpointer)) {
|
|
454
|
-
return {
|
|
455
|
-
config: materializeWorkspaceObjectConfig(refs, inlineAgentCheckpointer.ref, ["checkpointer", "file-checkpointer", "sqlite-saver"], `Agent ${agent.id} checkpointer`),
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
return { config: inlineAgentCheckpointer };
|
|
459
|
-
}
|
|
460
|
-
function resolveRuntimeMemoryConfig(agent, refs) {
|
|
461
|
-
const inlineRuntimeMemory = agent.runtimeMemory ?? getAgentExecutionObject(agent, "runtimeMemory");
|
|
462
|
-
if (inlineRuntimeMemory) {
|
|
463
|
-
if (isRefConfig(inlineRuntimeMemory)) {
|
|
464
|
-
return {
|
|
465
|
-
config: materializeRuntimeMemoryConfig(refs, materializeWorkspaceObjectConfig(refs, inlineRuntimeMemory.ref, ["runtime-memory"], `Agent ${agent.id} runtimeMemory`), `Agent ${agent.id}`),
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
return { config: materializeRuntimeMemoryConfig(refs, inlineRuntimeMemory, `Agent ${agent.id}`) };
|
|
469
|
-
}
|
|
470
|
-
const runtimeMemoryDefaults = getRuntimeMemoryDefaults(refs);
|
|
471
|
-
return runtimeMemoryDefaults ? { config: materializeRuntimeMemoryConfig(refs, runtimeMemoryDefaults, `Agent ${agent.id}`) } : undefined;
|
|
472
|
-
}
|
|
473
|
-
function resolveProceduralMemoryConfig(agent, refs) {
|
|
474
|
-
const inlineProceduralMemory = agent.proceduralMemory ?? getAgentExecutionObject(agent, "proceduralMemory");
|
|
475
|
-
if (inlineProceduralMemory) {
|
|
476
|
-
if (isRefConfig(inlineProceduralMemory)) {
|
|
477
|
-
return {
|
|
478
|
-
config: materializeProceduralMemoryConfig(refs, materializeWorkspaceObjectConfig(refs, inlineProceduralMemory.ref, ["procedural-memory"], `Agent ${agent.id} proceduralMemory`), `Agent ${agent.id}`),
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
return { config: materializeProceduralMemoryConfig(refs, inlineProceduralMemory, `Agent ${agent.id}`) };
|
|
482
|
-
}
|
|
483
|
-
const proceduralMemoryDefaults = getProceduralMemoryDefaults(refs);
|
|
484
|
-
return proceduralMemoryDefaults
|
|
485
|
-
? { config: materializeProceduralMemoryConfig(refs, proceduralMemoryDefaults, `Agent ${agent.id}`) }
|
|
486
|
-
: undefined;
|
|
487
|
-
}
|
|
488
|
-
export function compileBinding(workspaceRoot, agent, agents, referencedSubagentIds, refs, models, tools) {
|
|
489
|
-
const internalSubagent = referencedSubagentIds.has(agent.id);
|
|
490
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
491
|
-
const runtimeStorage = getRuntimeStorageRoots(refs, workspaceRoot);
|
|
492
|
-
const resilience = getResilienceConfig(refs);
|
|
493
|
-
const compiledAgentSkills = compileAgentSkills(workspaceRoot, agent);
|
|
494
|
-
const compiledAgentMemory = compileAgentMemories(workspaceRoot, agent.memorySources);
|
|
495
|
-
const executionCore = compileExecutionCore({
|
|
496
|
-
...agent,
|
|
497
|
-
modelRef: agent.modelRef || (internalSubagent ? "model/default" : ""),
|
|
498
|
-
}, workspaceRoot, refs, models, tools);
|
|
499
|
-
const passthrough = resolvePassthrough(agent);
|
|
500
|
-
const compiledAgentModel = executionCore.model;
|
|
501
|
-
const backend = resolveBackendConfig(agent, refs);
|
|
502
|
-
const store = resolveStoreConfig(agent, refs);
|
|
503
|
-
const checkpointer = resolveCheckpointerConfig(agent, refs);
|
|
504
|
-
const runtimeMemory = resolveRuntimeMemoryConfig(agent, refs);
|
|
505
|
-
const proceduralMemory = resolveProceduralMemoryConfig(agent, refs);
|
|
506
|
-
const runtimeFilesystemDefaults = agent.executionMode === "langchain-v1"
|
|
507
|
-
? asObject(runtimeDefaults?.filesystem)
|
|
508
|
-
: undefined;
|
|
509
|
-
const runtimeGovernanceDefaults = asObject(runtimeDefaults?.governance);
|
|
510
|
-
const runtimeObservabilityDefaults = asObject(runtimeDefaults?.observability);
|
|
511
|
-
const executionContract = resolveExecutionContract(agent);
|
|
512
|
-
const compiledFilesystemConfig = agent.executionMode === "langchain-v1"
|
|
513
|
-
? mergeConfigObjects(runtimeFilesystemDefaults, getAgentExecutionObject(agent, "filesystem", { executionMode: "langchain-v1" }))
|
|
514
|
-
: undefined;
|
|
515
|
-
const runtimeRoot = typeof agent.runtimeRoot === "string" && agent.runtimeRoot.trim().length > 0
|
|
516
|
-
? (path.isAbsolute(agent.runtimeRoot) ? agent.runtimeRoot : path.resolve(runtimeStorage.dataRoot, agent.runtimeRoot))
|
|
517
|
-
: runtimeStorage.dataRoot;
|
|
518
|
-
const base = {
|
|
519
|
-
agent,
|
|
520
|
-
harnessRuntime: {
|
|
521
|
-
applicationRoot: runtimeStorage.applicationRoot,
|
|
522
|
-
dataRoot: runtimeStorage.dataRoot,
|
|
523
|
-
runtimeProfile: runtimeStorage.runtimeProfile,
|
|
524
|
-
runtimeRoot,
|
|
525
|
-
workspaceRoot: runtimeStorage.applicationRoot,
|
|
526
|
-
capabilities: inferAgentCapabilities(agent),
|
|
527
|
-
resilience,
|
|
528
|
-
...(runtimeGovernanceDefaults ? { governance: runtimeGovernanceDefaults } : {}),
|
|
529
|
-
...(runtimeObservabilityDefaults ? { observability: runtimeObservabilityDefaults } : {}),
|
|
530
|
-
...(executionContract ? { executionContract } : {}),
|
|
531
|
-
...(agent.executionMode === "deepagent"
|
|
532
|
-
? {
|
|
533
|
-
deepagent: {
|
|
534
|
-
description: agent.description,
|
|
535
|
-
passthrough,
|
|
536
|
-
},
|
|
537
|
-
}
|
|
538
|
-
: {}),
|
|
539
|
-
...(agent.executionMode === "langchain-v1"
|
|
540
|
-
? {
|
|
541
|
-
langchain: {
|
|
542
|
-
passthrough,
|
|
543
|
-
interruptOn: resolveInterruptOn(agent),
|
|
544
|
-
filesystem: compiledFilesystemConfig,
|
|
545
|
-
subagents: compileSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel),
|
|
546
|
-
memory: compiledAgentMemory,
|
|
547
|
-
skills: compiledAgentSkills,
|
|
548
|
-
generalPurposeAgent: getAgentExecutionConfigValue(agent, "generalPurposeAgent", { executionMode: "langchain-v1" }),
|
|
549
|
-
taskDescription: getAgentExecutionString(agent, "taskDescription", { executionMode: "langchain-v1" }),
|
|
550
|
-
},
|
|
551
|
-
}
|
|
552
|
-
: {}),
|
|
553
|
-
...(checkpointer ? { checkpointer: checkpointer.config } : {}),
|
|
554
|
-
...(store ? { store: store.config } : {}),
|
|
555
|
-
...(runtimeMemory ? { runtimeMemory: runtimeMemory.config } : {}),
|
|
556
|
-
...(proceduralMemory ? { proceduralMemory: proceduralMemory.config } : {}),
|
|
557
|
-
},
|
|
558
|
-
};
|
|
559
|
-
if (agent.executionMode !== "deepagent") {
|
|
560
|
-
const langchainVersion = getAgentExecutionConfigValue(agent, "version", { executionMode: "langchain-v1" });
|
|
561
|
-
const executionBinding = {
|
|
562
|
-
kind: "langchain-v1",
|
|
563
|
-
params: {
|
|
564
|
-
model: executionCore.model,
|
|
565
|
-
tools: executionCore.tools,
|
|
566
|
-
systemPrompt: executionCore.systemPrompt,
|
|
567
|
-
stateSchema: getAgentExecutionConfigValue(agent, "stateSchema", { executionMode: "langchain-v1" }),
|
|
568
|
-
responseFormat: executionCore.responseFormat,
|
|
569
|
-
contextSchema: executionCore.contextSchema,
|
|
570
|
-
middleware: executionCore.middleware,
|
|
571
|
-
includeAgentName: getAgentExecutionConfigValue(agent, "includeAgentName", { executionMode: "langchain-v1" }) === "inline" ? "inline" : undefined,
|
|
572
|
-
version: langchainVersion === "v1" || langchainVersion === "v2"
|
|
573
|
-
? langchainVersion
|
|
574
|
-
: undefined,
|
|
575
|
-
name: resolveAgentRuntimeName(agent),
|
|
576
|
-
description: agent.description,
|
|
577
|
-
builtinTools: getAgentExecutionObject(agent, "builtinTools"),
|
|
578
|
-
},
|
|
579
|
-
};
|
|
580
|
-
return attachLegacyExecutionAliases({
|
|
581
|
-
...base,
|
|
582
|
-
execution: executionBinding,
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
const executionBinding = {
|
|
586
|
-
kind: "deepagent",
|
|
587
|
-
params: {
|
|
588
|
-
model: executionCore.model,
|
|
589
|
-
tools: executionCore.tools,
|
|
590
|
-
systemPrompt: executionCore.systemPrompt,
|
|
591
|
-
responseFormat: executionCore.responseFormat,
|
|
592
|
-
contextSchema: executionCore.contextSchema,
|
|
593
|
-
middleware: executionCore.middleware,
|
|
594
|
-
subagents: compileDeepAgentSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel),
|
|
595
|
-
interruptOn: resolveInterruptOn(agent),
|
|
596
|
-
...(backend ? { backend: backend.config } : {}),
|
|
597
|
-
...(store ? { store: store.config } : {}),
|
|
598
|
-
name: resolveAgentRuntimeName(agent),
|
|
599
|
-
memory: compiledAgentMemory,
|
|
600
|
-
skills: compiledAgentSkills,
|
|
601
|
-
interactionMode: getAgentExecutionConfigValue(agent, "interactionMode", { executionMode: "deepagent" }) === "invoke"
|
|
602
|
-
? "invoke"
|
|
603
|
-
: getAgentExecutionConfigValue(agent, "interactionMode", { executionMode: "deepagent" }) === "stream"
|
|
604
|
-
? "stream"
|
|
605
|
-
: undefined,
|
|
606
|
-
builtinTools: getAgentExecutionObject(agent, "builtinTools"),
|
|
607
|
-
},
|
|
608
|
-
};
|
|
609
|
-
return attachLegacyExecutionAliases({
|
|
610
|
-
...base,
|
|
611
|
-
execution: executionBinding,
|
|
612
|
-
});
|
|
613
|
-
}
|
|
1
|
+
import A from"node:path";import{getSkillInheritancePolicy as ne,resolveToolTargets as oe}from"../tooling/extensions.js";import{attachLegacyExecutionAliases as B}from"../utils/compiled-binding.js";import{compileModel as re,compileTool as te}from"./resource-compilers.js";import{inferAgentCapabilities as ie}from"./support/agent-capabilities.js";import{getAgentExecutionConfigValue as f,getAgentExecutionObject as m,getAgentExecutionString as N}from"./support/agent-execution-config.js";import{discoverSkillPaths as ce}from"./support/discovery.js";import{compileAgentMemories as se,getProceduralMemoryDefaults as de,getResilienceConfig as ue,getRuntimeAgentDefaults as le,getRuntimeDefaults as fe,getRuntimeMemoryDefaults as me,getRuntimeStorageRoots as ae,getWorkspaceObject as I,resolvePromptValue as pe,resolveRefId as z}from"./support/workspace-ref-utils.js";import{WORKSPACE_BOUNDARY_GUIDANCE as _}from"../runtime/prompts/runtime-prompts.js";function ye(n,e){return Array.from(new Set(ce(n,e)))}function ge(n){return N(n,"skillInheritancePolicy")??"default"}function V(n,e,o=[]){const t=ge(e),r=ne(t);if(!r)throw new Error(`Agent ${e.id} skill inheritance policy ${t} is not registered`);return Array.from(new Set(r.apply({agent:e,ownSkills:ye(e.skillPathRefs,n),parentSkills:o})))}function k(n,e,o){const t=n.get(z(e));if(!t)throw new Error(`Agent ${o} references missing model ${e}`);return re(t)}function he(n,e,o){if(!(!n||n.length===0))return n.map(t=>{const r={...t};if(r.kind==="summarization"&&typeof r.modelRef=="string"&&(r.model=k(e,r.modelRef,o),delete r.modelRef),r.kind==="llmToolSelector"&&typeof r.modelRef=="string"&&(r.model=k(e,r.modelRef,o),delete r.modelRef),r.kind==="modelFallback"){const c=Array.isArray(r.fallbackModelRefs)?r.fallbackModelRefs:Array.isArray(r.modelRefs)?r.modelRefs:[];c.length>0&&(r.fallbackModels=c.map(s=>k(e,String(s),o)),delete r.fallbackModelRefs,delete r.modelRefs)}return r})}function v(n){const e=n.id;return e.includes(".")?e:n.sourcePath.split(A.sep).join("/").includes("/packages/framework/")?`core.${e}`:e}function a(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)?n:void 0}function W(n,e){if(e===void 0)return n;if(Array.isArray(n)&&Array.isArray(e))return e;if(typeof n=="object"&&n&&typeof e=="object"&&e&&!Array.isArray(n)&&!Array.isArray(e)){const o={...n};for(const[t,r]of Object.entries(e))o[t]=t in o?W(o[t],r):r;return o}return e}function R(n,e){const o=W(n,e);return typeof o=="object"&&o&&!Array.isArray(o)?o:void 0}function be(n){const e=a(n);if(!e)return;const o=e.enabled===!0,t=Array.isArray(e.allow)?e.allow.filter(r=>r==="approve"||r==="edit"||r==="reject"):void 0;return{enabled:o,allow:t&&t.length>0?t:void 0}}function Ae(n,e){const o=e.overrides;if(!o||Object.keys(o).length===0)return n;const t=R(a(o.config),a(o.execution)?{execution:a(o.execution)}:void 0);return{...n,...typeof o.name=="string"?{name:o.name}:{},...typeof o.description=="string"?{description:o.description}:{},...typeof o.implementationName=="string"?{implementationName:o.implementationName}:{},...typeof o.inputSchemaRef=="string"?{inputSchemaRef:o.inputSchemaRef}:{},...typeof o.embeddingModelRef=="string"?{embeddingModelRef:o.embeddingModelRef}:typeof o.embeddingModel=="string"?{embeddingModelRef:o.embeddingModel.startsWith("embedding-model/")?o.embeddingModel:`embedding-model/${o.embeddingModel}`}:{},...typeof o.backendOperation=="string"?{backendOperation:o.backendOperation}:{},...typeof o.mcpRef=="string"?{mcpRef:o.mcpRef}:{},...typeof o.subprocess=="boolean"?{subprocess:o.subprocess}:{},...typeof o.retryable=="boolean"?{retryable:o.retryable}:{},...o.hitl!==void 0?{hitl:be(o.hitl)}:{},...t?{config:R(n.config,t)}:{}}}function ke(n){return n.toolBindings&&n.toolBindings.length>0?n.toolBindings:n.toolRefs.map(e=>({ref:e}))}function Me(n,e,o){const t=e.flatMap(c=>{const s=oe(n,c.ref);if(s.length===0)throw new Error(`Agent ${o} references missing tool ${c.ref}`);return s.flatMap(i=>te(Ae(i,c),n))}),r=new Map;for(const c of t)r.set(c.name,c);return Array.from(r.values())}function ve(n,e,o,t,r,c,s){const i=J(n,e,o,t,r);return{agentId:n.id,name:v(n),description:n.description,systemPrompt:i.systemPrompt??_,tools:i.tools,model:n.modelRef?i.model:s,interruptOn:x(n),skills:V(e,n,c),responseFormat:i.responseFormat,middleware:i.middleware,builtinTools:m(n,"builtinTools")}}function Re(n,e){const o=A.dirname(n.sourcePath||e),t=pe(f(n,"systemPrompt"),o);return n.executionMode!=="deepagent"?t:[t,_].filter(Boolean).join(`
|
|
2
|
+
|
|
3
|
+
`)}function x(n){return m(n,"interruptOn")}function xe(n){return f(n,"responseFormat")}function Se(n){return n.startsWith("response-format/")?n:`response-format/${n}`}function G(n,e,o){if(!e)return;const t=I(n,Se(e));if(!t)throw new Error(`${o} responseFormatRef references missing object ${e}`);if(t.kind!=="response-format")throw new Error(`${o} responseFormatRef references ${e}, but expected response-format`);if(!("format"in t.value))throw new Error(`${o} responseFormatRef ${e} must define format`);return t.value.format}function U(n,e){if(e===void 0)return n;if(typeof n=="object"&&n&&typeof e=="object"&&e&&!Array.isArray(n)&&!Array.isArray(e)){const o={...n};for(const[t,r]of Object.entries(e)){if(t==="required"&&Array.isArray(o.required)&&Array.isArray(r)){o.required=Array.from(new Set([...o.required,...r]));continue}if(t==="properties"&&typeof o.properties=="object"&&o.properties&&!Array.isArray(o.properties)&&typeof r=="object"&&r&&!Array.isArray(r)){o.properties={...o.properties,...r};continue}o[t]=t in o?U(o[t],r):r}return o}return e}function H(n,e){const o=le(e);if(o&&"responseFormat"in o)return o.responseFormat===null?void 0:o.responseFormat;const t=typeof o?.responseFormatRef=="string"?o.responseFormatRef.trim():"";if(t)return G(e,t,"Runtime defaults.agent.config")}function $e(n,e){const o=xe(n);if(o!==void 0)return o===null?void 0:U(H(n,e),o);const t=f(n,"responseFormatRef");return typeof t=="string"&&t.trim().length>0?G(e,t.trim(),`Agent ${n.id}`):H(n,e)}function Pe(n){return f(n,"contextSchema")}function Ce(n){const e=m(n,"executionContract");if(!e)return;const o=typeof e.recoveryEvidenceTool=="string"&&e.recoveryEvidenceTool.trim().length>0?{name:e.recoveryEvidenceTool.trim()}:typeof e.recoveryEvidenceTool=="object"&&e.recoveryEvidenceTool&&!Array.isArray(e.recoveryEvidenceTool)?e.recoveryEvidenceTool:void 0,t=o&&typeof o.name=="string"&&o.name.trim().length>0?o.name.trim():void 0,r=o&&typeof o.args=="object"&&o.args&&!Array.isArray(o.args)?o.args:void 0;return{...e.requiresPlan===!0?{requiresPlan:!0}:{},...t?{recoveryEvidenceTool:{name:t,...r?{args:r}:{}}}:{}}}function Ee(n,e){const o=f(n,"middleware");return he(o,e,n.id)}function je(n){const e=m(n,"passthrough");return e?{...e}:void 0}function Y(n,e,o,t,r,c,s,i){return n.subagentRefs.map(d=>{const l=e.get(z(d));if(!l)throw new Error(`Missing subagent ${d} for agent ${n.id}`);return ve(l,o,t,r,c,s,i)})}function Fe(n){return(n.asyncSubagents??[]).map(e=>({name:e.name,description:e.description,graphId:e.graphId,...e.url?{url:e.url}:{},...e.headers?{headers:{...e.headers}}:{}}))}function we(n,e,o,t,r,c,s,i){return[...Y(n,e,o,t,r,c,s,i),...Fe(n)]}function J(n,e,o,t,r){return{model:k(t,n.modelRef,n.id),tools:Me(r,ke(n),n.id),systemPrompt:Re(n,e),responseFormat:$e(n,o),contextSchema:Pe(n),middleware:Ee(n,t)}}function Oe(n,e){if(n.executionMode!=="deepagent")return;const o=m(n,"backend");if(o)return p(o)?{config:y(e,o.ref,["backend"],`Agent ${n.id} backend`)}:{config:o}}function p(n){return typeof n?.ref!="string"||n.ref.trim().length===0?!1:Object.keys(n).every(e=>e==="ref")}function He(n,e){if(!(!n&&!e))return{...n??{},...e??{}}}function y(n,e,o,t){const r=I(n,e);if(!r)throw new Error(`${t} references missing object ${e}`);if(!o.includes(r.kind))throw new Error(`${t} references ${e}, but expected one of: ${o.join(", ")}`);const{id:c,kind:s,...i}=r.value;if(r.kind==="store"){const d=typeof i.storeKind=="string"?i.storeKind:void 0,{storeKind:l,...g}=i;return d?{kind:d,...g}:i}if(r.kind==="checkpointer"||r.kind==="file-checkpointer"||r.kind==="sqlite-saver"){const d=typeof i.checkpointerKind=="string"?i.checkpointerKind:void 0,{checkpointerKind:l,...g}=i;return d?{kind:d,...g}:i}if(r.kind==="backend"){const d=typeof i.backendKind=="string"?i.backendKind:void 0,{backendKind:l,...g}=i;return d?{kind:d,...g}:i}return i}function S(n,e,o){const t={...e},r=a(t.store);return r&&p(r)&&(t.store=y(n,r.ref,["store"],`${o} runtimeMemory.store`)),t}function $(n,e,o){const t={...e},r=a(t.store);r&&p(r)&&(t.store=y(n,r.ref,["store"],`${o} proceduralMemory.store`));const c=a(t.vectorStore);c&&p(c)&&(t.vectorStore=y(n,c.ref,["vector-store"],`${o} proceduralMemory.vectorStore`));const s=a(t.embeddingModel);return s&&p(s)&&(t.embeddingModel=y(n,s.ref,["embedding-model"],`${o} proceduralMemory.embeddingModel`)),t}function Te(n,e){const o=m(n,"store");if(o)return p(o)?{config:y(e,o.ref,["store"],`Agent ${n.id} store`)}:{config:o}}function De(n,e){const o=f(n,"checkpointer");if(o!==void 0)return typeof o=="boolean"?{config:o}:p(o)?{config:y(e,o.ref,["checkpointer","file-checkpointer","sqlite-saver"],`Agent ${n.id} checkpointer`)}:{config:o}}function Ke(n,e){const o=n.runtimeMemory??m(n,"runtimeMemory");if(o)return p(o)?{config:S(e,y(e,o.ref,["runtime-memory"],`Agent ${n.id} runtimeMemory`),`Agent ${n.id}`)}:{config:S(e,o,`Agent ${n.id}`)};const t=me(e);return t?{config:S(e,t,`Agent ${n.id}`)}:void 0}function qe(n,e){const o=n.proceduralMemory??m(n,"proceduralMemory");if(o)return p(o)?{config:$(e,y(e,o.ref,["procedural-memory"],`Agent ${n.id} proceduralMemory`),`Agent ${n.id}`)}:{config:$(e,o,`Agent ${n.id}`)};const t=de(e);return t?{config:$(e,t,`Agent ${n.id}`)}:void 0}function Ye(n,e,o,t,r,c,s){const i=t.has(e.id),d=fe(r),l=ae(r,n),g=ue(r),h=V(n,e),P=se(n,e.memorySources),u=J({...e,modelRef:e.modelRef||(i?"model/default":"")},n,r,c,s),C=je(e),E=u.model,j=Oe(e,r),b=Te(e,r),F=De(e,r),w=Ke(e,r),O=qe(e,r),Q=e.executionMode==="langchain-v1"?a(d?.filesystem):void 0,T=a(d?.governance),D=a(d?.observability),K=Ce(e),X=e.executionMode==="langchain-v1"?R(Q,m(e,"filesystem",{executionMode:"langchain-v1"})):void 0,Z=typeof e.runtimeRoot=="string"&&e.runtimeRoot.trim().length>0?A.isAbsolute(e.runtimeRoot)?e.runtimeRoot:A.resolve(l.dataRoot,e.runtimeRoot):l.dataRoot,q={agent:e,harnessRuntime:{applicationRoot:l.applicationRoot,dataRoot:l.dataRoot,runtimeProfile:l.runtimeProfile,runtimeRoot:Z,workspaceRoot:l.applicationRoot,capabilities:ie(e),resilience:g,...T?{governance:T}:{},...D?{observability:D}:{},...K?{executionContract:K}:{},...e.executionMode==="deepagent"?{deepagent:{description:e.description,passthrough:C}}:{},...e.executionMode==="langchain-v1"?{langchain:{passthrough:C,interruptOn:x(e),filesystem:X,subagents:Y(e,o,n,r,c,s,h,E),memory:P,skills:h,generalPurposeAgent:f(e,"generalPurposeAgent",{executionMode:"langchain-v1"}),taskDescription:N(e,"taskDescription",{executionMode:"langchain-v1"})}}:{},...F?{checkpointer:F.config}:{},...b?{store:b.config}:{},...w?{runtimeMemory:w.config}:{},...O?{proceduralMemory:O.config}:{}}};if(e.executionMode!=="deepagent"){const M=f(e,"version",{executionMode:"langchain-v1"}),ee={kind:"langchain-v1",params:{model:u.model,tools:u.tools,systemPrompt:u.systemPrompt,stateSchema:f(e,"stateSchema",{executionMode:"langchain-v1"}),responseFormat:u.responseFormat,contextSchema:u.contextSchema,middleware:u.middleware,includeAgentName:f(e,"includeAgentName",{executionMode:"langchain-v1"})==="inline"?"inline":void 0,version:M==="v1"||M==="v2"?M:void 0,name:v(e),description:e.description,builtinTools:m(e,"builtinTools")}};return B({...q,execution:ee})}const L={kind:"deepagent",params:{model:u.model,tools:u.tools,systemPrompt:u.systemPrompt,responseFormat:u.responseFormat,contextSchema:u.contextSchema,middleware:u.middleware,subagents:we(e,o,n,r,c,s,h,E),interruptOn:x(e),...j?{backend:j.config}:{},...b?{store:b.config}:{},name:v(e),memory:P,skills:h,interactionMode:f(e,"interactionMode",{executionMode:"deepagent"})==="invoke"?"invoke":f(e,"interactionMode",{executionMode:"deepagent"})==="stream"?"stream":void 0,builtinTools:m(e,"builtinTools")}};return B({...q,execution:L})}export{V as compileAgentSkills,Ye as compileBinding,Me as requireTools};
|