@axiom-lattice/core 10.0.0 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +127 -3
- package/dist/index.d.ts +127 -3
- package/dist/index.js +1521 -891
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1326 -694
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -249,6 +249,11 @@ var ModelLattice = class extends BaseChatModel {
|
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
+
// src/model_lattice/ModelLatticeManager.ts
|
|
253
|
+
import {
|
|
254
|
+
DEFAULT_MODEL_KEY
|
|
255
|
+
} from "@axiom-lattice/protocols";
|
|
256
|
+
|
|
252
257
|
// src/store_lattice/InMemoryThreadStore.ts
|
|
253
258
|
var InMemoryThreadStore = class {
|
|
254
259
|
constructor() {
|
|
@@ -1940,10 +1945,17 @@ var InMemoryModelProviderStore = class {
|
|
|
1940
1945
|
previous.map((model) => [model.modelId, model])
|
|
1941
1946
|
);
|
|
1942
1947
|
const incomingIds = new Set(models.map((model) => model.id));
|
|
1943
|
-
const
|
|
1944
|
-
|
|
1948
|
+
const namedDefaultKinds = /* @__PURE__ */ new Set();
|
|
1949
|
+
for (const model of models) {
|
|
1950
|
+
if (model.isDefault === true) {
|
|
1951
|
+
namedDefaultKinds.add(
|
|
1952
|
+
model.kind ?? previousById.get(model.id)?.kind ?? "chat"
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
if (namedDefaultKinds.size > 0) {
|
|
1945
1957
|
for (const [key5, entry] of this.models.entries()) {
|
|
1946
|
-
if (entry.tenantId === tenantId2 && entry.isDefault) {
|
|
1958
|
+
if (entry.tenantId === tenantId2 && entry.isDefault && namedDefaultKinds.has(entry.kind)) {
|
|
1947
1959
|
this.models.set(key5, { ...entry, isDefault: false });
|
|
1948
1960
|
}
|
|
1949
1961
|
}
|
|
@@ -1968,6 +1980,7 @@ var InMemoryModelProviderStore = class {
|
|
|
1968
1980
|
for (const model of models) {
|
|
1969
1981
|
const existing = previousById.get(model.id);
|
|
1970
1982
|
const carried = model.extra ?? existing?.extra;
|
|
1983
|
+
const kind = model.kind ?? existing?.kind ?? "chat";
|
|
1971
1984
|
const entry = {
|
|
1972
1985
|
id: `${providerId}:${model.id}`,
|
|
1973
1986
|
tenantId: tenantId2,
|
|
@@ -1984,10 +1997,8 @@ var InMemoryModelProviderStore = class {
|
|
|
1984
1997
|
// explicit flag marks one.
|
|
1985
1998
|
stale: model.stale ?? false,
|
|
1986
1999
|
extra: carried && Object.keys(carried).length > 0 ? carried : void 0,
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
kind: model.kind ?? existing?.kind ?? "chat",
|
|
1990
|
-
isDefault: model.isDefault ?? (namesDefault ? false : existing?.isDefault) ?? false,
|
|
2000
|
+
kind,
|
|
2001
|
+
isDefault: model.isDefault ?? (namedDefaultKinds.has(kind) ? false : existing?.isDefault) ?? false,
|
|
1991
2002
|
discoveredAt: now
|
|
1992
2003
|
};
|
|
1993
2004
|
this.models.set(this.getModelKey(tenantId2, providerId, model.id), entry);
|
|
@@ -6153,6 +6164,9 @@ var scheduleLatticeManager = ScheduleLatticeManager.getInstance();
|
|
|
6153
6164
|
var registerScheduleLattice = (key5, config, client) => scheduleLatticeManager.registerLattice(key5, config, client);
|
|
6154
6165
|
var getScheduleLattice = (key5) => scheduleLatticeManager.getScheduleLattice(key5);
|
|
6155
6166
|
|
|
6167
|
+
// src/vectorstore_lattice/VectorStoreProviderManager.ts
|
|
6168
|
+
import { EMBEDDING_DEFAULT_KEY as EMBEDDING_DEFAULT_KEY2 } from "@axiom-lattice/protocols";
|
|
6169
|
+
|
|
6156
6170
|
// src/collection_lattice/SimpleMemoryVectorStore.ts
|
|
6157
6171
|
import { VectorStore } from "@langchain/core/vectorstores";
|
|
6158
6172
|
function cosineSimilarity(a, b) {
|
|
@@ -6246,6 +6260,7 @@ var SimpleMemoryVectorStore = class extends VectorStore {
|
|
|
6246
6260
|
|
|
6247
6261
|
// src/embeddings_lattice/EmbeddingsLatticeManager.ts
|
|
6248
6262
|
import { OpenAIEmbeddings } from "@langchain/openai";
|
|
6263
|
+
import { EMBEDDING_DEFAULT_KEY } from "@axiom-lattice/protocols";
|
|
6249
6264
|
|
|
6250
6265
|
// src/model_lattice/buildModelLlmConfig.ts
|
|
6251
6266
|
var ALLOWED_LLM_PROVIDERS = /* @__PURE__ */ new Set(["openai"]);
|
|
@@ -6296,6 +6311,56 @@ function buildModelLlmConfig(provider2, model) {
|
|
|
6296
6311
|
}
|
|
6297
6312
|
|
|
6298
6313
|
// src/model_lattice/buildModelConfig.ts
|
|
6314
|
+
var DEFAULT_CONTENTS_EMBEDDING_PATH = "/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding";
|
|
6315
|
+
var DEFAULT_TEXTS_EMBEDDING_PATH = "/api/v1/services/embeddings/text-embedding/text-embedding";
|
|
6316
|
+
var EMBEDDING_SHAPES = [
|
|
6317
|
+
"openai",
|
|
6318
|
+
"contents",
|
|
6319
|
+
"texts"
|
|
6320
|
+
];
|
|
6321
|
+
function trimTrailingSlashes(value) {
|
|
6322
|
+
return value.replace(/\/+$/, "");
|
|
6323
|
+
}
|
|
6324
|
+
function isEmbeddingShape(value) {
|
|
6325
|
+
return typeof value === "string" && EMBEDDING_SHAPES.includes(value);
|
|
6326
|
+
}
|
|
6327
|
+
function isMultimodalEmbeddingId(modelId) {
|
|
6328
|
+
return /vl-embedding|multimodal-embedding/i.test(modelId);
|
|
6329
|
+
}
|
|
6330
|
+
function shapeImpliedByPath(path8) {
|
|
6331
|
+
if (/\/embeddings\/text-embedding\//.test(path8)) {
|
|
6332
|
+
return "texts";
|
|
6333
|
+
}
|
|
6334
|
+
return path8.includes("/services/embeddings/") ? "contents" : void 0;
|
|
6335
|
+
}
|
|
6336
|
+
function resolveEmbeddingShape(modelId, extra) {
|
|
6337
|
+
if (isEmbeddingShape(extra.embeddingShape)) {
|
|
6338
|
+
return extra.embeddingShape;
|
|
6339
|
+
}
|
|
6340
|
+
if (typeof extra.embeddingPath === "string") {
|
|
6341
|
+
const implied = shapeImpliedByPath(extra.embeddingPath);
|
|
6342
|
+
if (implied) {
|
|
6343
|
+
return implied;
|
|
6344
|
+
}
|
|
6345
|
+
}
|
|
6346
|
+
return isMultimodalEmbeddingId(modelId) ? "contents" : "openai";
|
|
6347
|
+
}
|
|
6348
|
+
function embeddingProbeCandidates(initial, modelId) {
|
|
6349
|
+
const nativeOrder = /text-embedding/i.test(modelId) ? ["texts", "contents"] : ["contents", "texts"];
|
|
6350
|
+
const alternates = initial === "openai" ? nativeOrder : initial === "contents" ? ["openai", "texts"] : ["openai", "contents"];
|
|
6351
|
+
return [initial, ...alternates];
|
|
6352
|
+
}
|
|
6353
|
+
function resolveEmbeddingEndpoint(baseURL, shape, extra) {
|
|
6354
|
+
if (shape === "openai") {
|
|
6355
|
+
return `${trimTrailingSlashes(baseURL)}/embeddings`;
|
|
6356
|
+
}
|
|
6357
|
+
const origin = new URL(baseURL).origin;
|
|
6358
|
+
const configuredPath = typeof extra.embeddingPath === "string" && extra.embeddingPath.startsWith("/") ? extra.embeddingPath : void 0;
|
|
6359
|
+
const implied = configuredPath ? shapeImpliedByPath(configuredPath) : void 0;
|
|
6360
|
+
const usablePath = configuredPath && (implied === void 0 || implied === shape) ? configuredPath : void 0;
|
|
6361
|
+
const fallback = shape === "texts" ? DEFAULT_TEXTS_EMBEDDING_PATH : DEFAULT_CONTENTS_EMBEDDING_PATH;
|
|
6362
|
+
return `${origin}${usablePath ?? fallback}`;
|
|
6363
|
+
}
|
|
6299
6364
|
function numberOrUndefined(value) {
|
|
6300
6365
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
6301
6366
|
}
|
|
@@ -6303,11 +6368,14 @@ function buildModelEmbeddingsConfig(provider2, model) {
|
|
|
6303
6368
|
const extra = { ...model.extra ?? {} };
|
|
6304
6369
|
delete extra.apiKeyEnvName;
|
|
6305
6370
|
const encodingFormat = extra.encodingFormat === "float" || extra.encodingFormat === "base64" ? extra.encodingFormat : void 0;
|
|
6371
|
+
const shape = resolveEmbeddingShape(model.modelId, extra);
|
|
6306
6372
|
return {
|
|
6307
6373
|
...extra,
|
|
6308
6374
|
model: model.modelId,
|
|
6309
6375
|
baseURL: provider2.baseURL,
|
|
6310
6376
|
apiKey: provider2.apiKey || "EMPTY",
|
|
6377
|
+
shape,
|
|
6378
|
+
endpoint: resolveEmbeddingEndpoint(provider2.baseURL, shape, extra),
|
|
6311
6379
|
dimensions: numberOrUndefined(extra.dimensions),
|
|
6312
6380
|
timeout: numberOrUndefined(extra.timeout),
|
|
6313
6381
|
batchSize: numberOrUndefined(extra.batchSize),
|
|
@@ -6374,6 +6442,131 @@ async function loadTenantModelRow(tenantId2, key5) {
|
|
|
6374
6442
|
return void 0;
|
|
6375
6443
|
}
|
|
6376
6444
|
}
|
|
6445
|
+
async function loadTenantDefaultModelRow(tenantId2, kind) {
|
|
6446
|
+
try {
|
|
6447
|
+
const { store: store2 } = getStoreLattice("default", "modelProvider");
|
|
6448
|
+
const models = await store2.listModels(tenantId2);
|
|
6449
|
+
const marked = models.find(
|
|
6450
|
+
(model) => model.isDefault === true && model.kind === kind
|
|
6451
|
+
);
|
|
6452
|
+
if (!marked || !marked.enabled) {
|
|
6453
|
+
return void 0;
|
|
6454
|
+
}
|
|
6455
|
+
const provider2 = await store2.getProviderById(tenantId2, marked.providerId);
|
|
6456
|
+
if (!provider2 || !provider2.enabled) {
|
|
6457
|
+
return void 0;
|
|
6458
|
+
}
|
|
6459
|
+
return { provider: provider2, model: marked };
|
|
6460
|
+
} catch (error) {
|
|
6461
|
+
console.error(
|
|
6462
|
+
`[model_lattice] Failed to load the ${kind} default for tenant "${tenantId2}":`,
|
|
6463
|
+
error
|
|
6464
|
+
);
|
|
6465
|
+
return void 0;
|
|
6466
|
+
}
|
|
6467
|
+
}
|
|
6468
|
+
|
|
6469
|
+
// src/embeddings_lattice/ServiceShapeEmbeddings.ts
|
|
6470
|
+
import { Embeddings } from "@langchain/core/embeddings";
|
|
6471
|
+
var ServiceShapeEmbeddings = class extends Embeddings {
|
|
6472
|
+
constructor(params) {
|
|
6473
|
+
super({});
|
|
6474
|
+
this.params = params;
|
|
6475
|
+
}
|
|
6476
|
+
async embedDocuments(documents) {
|
|
6477
|
+
if (documents.length === 0) {
|
|
6478
|
+
return [];
|
|
6479
|
+
}
|
|
6480
|
+
return this.request(documents);
|
|
6481
|
+
}
|
|
6482
|
+
async embedQuery(document) {
|
|
6483
|
+
const [first] = await this.request([document]);
|
|
6484
|
+
if (!first) {
|
|
6485
|
+
throw new Error(
|
|
6486
|
+
`Embedding response for "${this.params.model}" carried no vector`
|
|
6487
|
+
);
|
|
6488
|
+
}
|
|
6489
|
+
return first;
|
|
6490
|
+
}
|
|
6491
|
+
/**
|
|
6492
|
+
* Build the request body for this shape.
|
|
6493
|
+
*
|
|
6494
|
+
* Kept in one place so the probe in the gateway and the runtime client cannot
|
|
6495
|
+
* drift into testing a different body than the one actually sent.
|
|
6496
|
+
*/
|
|
6497
|
+
body(texts) {
|
|
6498
|
+
if (this.params.shape === "texts") {
|
|
6499
|
+
return JSON.stringify({
|
|
6500
|
+
model: this.params.model,
|
|
6501
|
+
input: { texts }
|
|
6502
|
+
});
|
|
6503
|
+
}
|
|
6504
|
+
return JSON.stringify({
|
|
6505
|
+
model: this.params.model,
|
|
6506
|
+
input: { contents: texts.map((text) => ({ text })) }
|
|
6507
|
+
});
|
|
6508
|
+
}
|
|
6509
|
+
async request(texts) {
|
|
6510
|
+
const controller = new AbortController();
|
|
6511
|
+
const timer = setTimeout(
|
|
6512
|
+
() => controller.abort(),
|
|
6513
|
+
this.params.timeout && this.params.timeout > 0 ? this.params.timeout : 3e4
|
|
6514
|
+
);
|
|
6515
|
+
try {
|
|
6516
|
+
const response = await fetch(this.params.endpoint, {
|
|
6517
|
+
method: "POST",
|
|
6518
|
+
headers: {
|
|
6519
|
+
Accept: "application/json",
|
|
6520
|
+
"Content-Type": "application/json",
|
|
6521
|
+
Authorization: `Bearer ${this.params.apiKey}`
|
|
6522
|
+
},
|
|
6523
|
+
body: this.body(texts),
|
|
6524
|
+
signal: controller.signal
|
|
6525
|
+
});
|
|
6526
|
+
const body = await response.text();
|
|
6527
|
+
if (!response.ok) {
|
|
6528
|
+
throw new Error(
|
|
6529
|
+
`Embedding upstream returned ${response.status}: ${body.slice(0, 300)}`
|
|
6530
|
+
);
|
|
6531
|
+
}
|
|
6532
|
+
let parsed;
|
|
6533
|
+
try {
|
|
6534
|
+
parsed = JSON.parse(body);
|
|
6535
|
+
} catch {
|
|
6536
|
+
throw new Error(
|
|
6537
|
+
`Embedding upstream returned invalid JSON: ${body.slice(0, 200)}`
|
|
6538
|
+
);
|
|
6539
|
+
}
|
|
6540
|
+
const embeddings = parsed.output?.embeddings;
|
|
6541
|
+
if (!Array.isArray(embeddings)) {
|
|
6542
|
+
throw new Error(
|
|
6543
|
+
`Embedding upstream response carried no "output.embeddings": ${body.slice(0, 200)}`
|
|
6544
|
+
);
|
|
6545
|
+
}
|
|
6546
|
+
if (embeddings.length !== texts.length) {
|
|
6547
|
+
throw new Error(
|
|
6548
|
+
`Embedding upstream returned ${embeddings.length} vectors for ${texts.length} inputs`
|
|
6549
|
+
);
|
|
6550
|
+
}
|
|
6551
|
+
return embeddings.map((entry, index) => {
|
|
6552
|
+
const vector = entry?.embedding;
|
|
6553
|
+
if (!Array.isArray(vector) || vector.some((value) => typeof value !== "number")) {
|
|
6554
|
+
throw new Error(`Embedding ${index} is not a numeric vector`);
|
|
6555
|
+
}
|
|
6556
|
+
return vector;
|
|
6557
|
+
});
|
|
6558
|
+
} catch (error) {
|
|
6559
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
6560
|
+
throw new Error(
|
|
6561
|
+
`Embedding request to "${this.params.endpoint}" timed out`
|
|
6562
|
+
);
|
|
6563
|
+
}
|
|
6564
|
+
throw error;
|
|
6565
|
+
} finally {
|
|
6566
|
+
clearTimeout(timer);
|
|
6567
|
+
}
|
|
6568
|
+
}
|
|
6569
|
+
};
|
|
6377
6570
|
|
|
6378
6571
|
// src/embeddings_lattice/EmbeddingsLatticeManager.ts
|
|
6379
6572
|
var EmbeddingsLatticeManager = class _EmbeddingsLatticeManager extends BaseLatticeManager {
|
|
@@ -6419,14 +6612,14 @@ var EmbeddingsLatticeManager = class _EmbeddingsLatticeManager extends BaseLatti
|
|
|
6419
6612
|
* @param key `${providerId}/${modelId}`
|
|
6420
6613
|
*/
|
|
6421
6614
|
async loadItemFromStore(tenantId2, key5) {
|
|
6422
|
-
const row = await loadTenantModelRow(tenantId2, key5);
|
|
6615
|
+
const row = key5 === EMBEDDING_DEFAULT_KEY ? await loadTenantDefaultModelRow(tenantId2, "embedding") : await loadTenantModelRow(tenantId2, key5);
|
|
6423
6616
|
if (!row || row.model.kind !== "embedding") {
|
|
6424
6617
|
return void 0;
|
|
6425
6618
|
}
|
|
6426
6619
|
const config = buildModelEmbeddingsConfig(row.provider, row.model);
|
|
6427
6620
|
return {
|
|
6428
6621
|
key: key5,
|
|
6429
|
-
client: new OpenAIEmbeddings({
|
|
6622
|
+
client: config.shape === "openai" ? new OpenAIEmbeddings({
|
|
6430
6623
|
model: config.model,
|
|
6431
6624
|
apiKey: config.apiKey,
|
|
6432
6625
|
dimensions: config.dimensions,
|
|
@@ -6434,6 +6627,12 @@ var EmbeddingsLatticeManager = class _EmbeddingsLatticeManager extends BaseLatti
|
|
|
6434
6627
|
batchSize: config.batchSize,
|
|
6435
6628
|
encodingFormat: config.encodingFormat,
|
|
6436
6629
|
configuration: { baseURL: config.baseURL }
|
|
6630
|
+
}) : new ServiceShapeEmbeddings({
|
|
6631
|
+
shape: config.shape,
|
|
6632
|
+
endpoint: config.endpoint,
|
|
6633
|
+
apiKey: config.apiKey,
|
|
6634
|
+
model: config.model,
|
|
6635
|
+
timeout: config.timeout
|
|
6437
6636
|
}),
|
|
6438
6637
|
label: row.model.displayName ?? row.model.modelId
|
|
6439
6638
|
};
|
|
@@ -6558,16 +6757,20 @@ var getEmbeddingsClient = (key5) => embeddingsLatticeManager.getEmbeddingsClient
|
|
|
6558
6757
|
var MemoryVectorStoreProvider = class {
|
|
6559
6758
|
async create(params) {
|
|
6560
6759
|
const tenantId2 = params.tenantId ?? "default";
|
|
6760
|
+
const requestedKey = params.embeddingKey || EMBEDDING_DEFAULT_KEY2;
|
|
6561
6761
|
const embeddings = await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
6562
6762
|
tenantId2,
|
|
6563
|
-
|
|
6564
|
-
) ?? await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
6763
|
+
requestedKey
|
|
6764
|
+
) ?? (requestedKey === EMBEDDING_DEFAULT_KEY2 ? void 0 : await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
6765
|
+
tenantId2,
|
|
6766
|
+
EMBEDDING_DEFAULT_KEY2
|
|
6767
|
+
)) ?? await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
6565
6768
|
tenantId2,
|
|
6566
6769
|
"default"
|
|
6567
6770
|
);
|
|
6568
6771
|
if (!embeddings) {
|
|
6569
6772
|
throw new Error(
|
|
6570
|
-
`No embedding model "${params.embeddingKey}" registered for tenant "${tenantId2}", and no deployment default. Configure one in the model
|
|
6773
|
+
`No embedding model "${params.embeddingKey}" registered for tenant "${tenantId2}", and no tenant or deployment default. Configure one in the model service panel.`
|
|
6571
6774
|
);
|
|
6572
6775
|
}
|
|
6573
6776
|
return new SimpleMemoryVectorStore(embeddings);
|
|
@@ -11847,7 +12050,6 @@ var InMemoryMenuStore = class {
|
|
|
11847
12050
|
};
|
|
11848
12051
|
|
|
11849
12052
|
// src/model_lattice/ModelLatticeManager.ts
|
|
11850
|
-
var DEFAULT_MODEL_KEY = "default";
|
|
11851
12053
|
var TENANT_DEFAULT_MISS_TTL_MS = 3e4;
|
|
11852
12054
|
var ModelLatticeManager = class _ModelLatticeManager extends BaseLatticeManager {
|
|
11853
12055
|
constructor() {
|
|
@@ -12180,6 +12382,60 @@ function listModelLatticesForTenant(tenantId2) {
|
|
|
12180
12382
|
return [...byKey.values()];
|
|
12181
12383
|
}
|
|
12182
12384
|
|
|
12385
|
+
// src/model_lattice/summarizationTrigger.ts
|
|
12386
|
+
var DEFAULT_SUMMARIZATION_TRIGGER_TOKENS = 17e4;
|
|
12387
|
+
var SUMMARIZATION_TRIGGER_RATIO = 0.85;
|
|
12388
|
+
function isPositiveNumber(value) {
|
|
12389
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
12390
|
+
}
|
|
12391
|
+
function unwrapBinding(model) {
|
|
12392
|
+
let current = model;
|
|
12393
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12394
|
+
while (typeof current === "object" && current !== null && !seen.has(current) && "bound" in current) {
|
|
12395
|
+
seen.add(current);
|
|
12396
|
+
const next = current.bound;
|
|
12397
|
+
if (next === void 0 || next === current) {
|
|
12398
|
+
break;
|
|
12399
|
+
}
|
|
12400
|
+
current = next;
|
|
12401
|
+
}
|
|
12402
|
+
return current;
|
|
12403
|
+
}
|
|
12404
|
+
function readContextWindow(model) {
|
|
12405
|
+
const unwrapped = unwrapBinding(model);
|
|
12406
|
+
if (typeof unwrapped !== "object" || unwrapped === null) {
|
|
12407
|
+
return void 0;
|
|
12408
|
+
}
|
|
12409
|
+
const getConfig = unwrapped.getConfig;
|
|
12410
|
+
if (typeof getConfig === "function") {
|
|
12411
|
+
const config = getConfig.call(unwrapped);
|
|
12412
|
+
if (typeof config === "object" && config !== null) {
|
|
12413
|
+
const declared = config.contextWindow;
|
|
12414
|
+
if (isPositiveNumber(declared)) {
|
|
12415
|
+
return declared;
|
|
12416
|
+
}
|
|
12417
|
+
}
|
|
12418
|
+
}
|
|
12419
|
+
const profile = unwrapped.profile;
|
|
12420
|
+
if (typeof profile === "object" && profile !== null) {
|
|
12421
|
+
const maxInputTokens = profile.maxInputTokens;
|
|
12422
|
+
if (isPositiveNumber(maxInputTokens)) {
|
|
12423
|
+
return maxInputTokens;
|
|
12424
|
+
}
|
|
12425
|
+
}
|
|
12426
|
+
return void 0;
|
|
12427
|
+
}
|
|
12428
|
+
function resolveSummarizationTriggerTokens(model) {
|
|
12429
|
+
const contextWindow = readContextWindow(model);
|
|
12430
|
+
if (contextWindow === void 0) {
|
|
12431
|
+
return DEFAULT_SUMMARIZATION_TRIGGER_TOKENS;
|
|
12432
|
+
}
|
|
12433
|
+
return Math.max(
|
|
12434
|
+
1,
|
|
12435
|
+
Math.floor(contextWindow * SUMMARIZATION_TRIGGER_RATIO)
|
|
12436
|
+
);
|
|
12437
|
+
}
|
|
12438
|
+
|
|
12183
12439
|
// src/tool_lattice/get_current_date_time/index.ts
|
|
12184
12440
|
import z from "zod";
|
|
12185
12441
|
|
|
@@ -16441,26 +16697,427 @@ function withToolCallLimitStateSchema(schema6) {
|
|
|
16441
16697
|
return schema6 ? schema6.extend(toolCallLimitStateSchema.shape) : toolCallLimitStateSchema;
|
|
16442
16698
|
}
|
|
16443
16699
|
|
|
16700
|
+
// src/middlewares/runGovernance.ts
|
|
16701
|
+
import {
|
|
16702
|
+
AIMessage as AIMessage2,
|
|
16703
|
+
SystemMessage,
|
|
16704
|
+
ToolMessage as ToolMessage2,
|
|
16705
|
+
createMiddleware as createMiddleware2
|
|
16706
|
+
} from "langchain";
|
|
16707
|
+
import { z as z42 } from "zod";
|
|
16708
|
+
|
|
16709
|
+
// src/middlewares/repeatedToolCallBreaker.ts
|
|
16710
|
+
import { AIMessage, HumanMessage, ToolMessage, createMiddleware } from "langchain";
|
|
16711
|
+
import { z as z41 } from "zod";
|
|
16712
|
+
var RepeatedToolCallError = class extends Error {
|
|
16713
|
+
constructor(toolName2, count, stopThreshold, argsPreview) {
|
|
16714
|
+
super(`Repeated identical tool call '${toolName2 ?? "unknown"}' ${count} times (stop threshold ${stopThreshold}).`);
|
|
16715
|
+
this.name = "RepeatedToolCallError";
|
|
16716
|
+
this.toolName = toolName2;
|
|
16717
|
+
this.count = count;
|
|
16718
|
+
this.stopThreshold = stopThreshold;
|
|
16719
|
+
this.argsPreview = argsPreview;
|
|
16720
|
+
}
|
|
16721
|
+
};
|
|
16722
|
+
function readLoopBreakerConfig(env = process.env) {
|
|
16723
|
+
const parse = (raw, fallback) => {
|
|
16724
|
+
if (raw === void 0 || raw.trim() === "") return fallback;
|
|
16725
|
+
const parsed = Number(raw);
|
|
16726
|
+
if (!Number.isFinite(parsed) || parsed < 0) return fallback;
|
|
16727
|
+
return Math.floor(parsed);
|
|
16728
|
+
};
|
|
16729
|
+
return {
|
|
16730
|
+
repeatWarn: parse(env.AGENT_REPEATED_TOOL_CALL_WARN, 20),
|
|
16731
|
+
repeatStop: parse(env.AGENT_REPEATED_TOOL_CALL_STOP, 25),
|
|
16732
|
+
runLimit: parse(env.AGENT_TOOL_CALL_RUN_LIMIT, 300),
|
|
16733
|
+
skillRunLimit: parse(env.AGENT_SKILL_CALL_RUN_LIMIT, 8)
|
|
16734
|
+
};
|
|
16735
|
+
}
|
|
16736
|
+
function stableStringify(value) {
|
|
16737
|
+
if (Array.isArray(value)) return "[" + value.map(stableStringify).join(",") + "]";
|
|
16738
|
+
if (value && typeof value === "object") {
|
|
16739
|
+
const body = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key5, item]) => JSON.stringify(key5) + ":" + stableStringify(item)).join(",");
|
|
16740
|
+
return "{" + body + "}";
|
|
16741
|
+
}
|
|
16742
|
+
return JSON.stringify(value) ?? "null";
|
|
16743
|
+
}
|
|
16744
|
+
function normalizeToolCalls(toolCalls) {
|
|
16745
|
+
return toolCalls.map((call) => ({ name: call.name ?? "", args: call.args ?? {} }));
|
|
16746
|
+
}
|
|
16747
|
+
var BREAKER_STATE_SCHEMA = z41.object({
|
|
16748
|
+
repeatedToolCallSignature: z41.string().default(""),
|
|
16749
|
+
repeatedToolCallCount: z41.number().default(0),
|
|
16750
|
+
repeatedToolCallRunMarker: z41.string().default(""),
|
|
16751
|
+
repeatedToolCallMemberSignatures: z41.array(z41.string()).default([])
|
|
16752
|
+
});
|
|
16753
|
+
function createRepeatedToolCallBreakerMiddleware(options = {}) {
|
|
16754
|
+
const rawWarn = options.warnThreshold ?? 20;
|
|
16755
|
+
const warnThreshold = rawWarn > 0 ? Math.max(2, rawWarn) : 0;
|
|
16756
|
+
const stopThreshold = Math.max(1, options.stopThreshold ?? 25);
|
|
16757
|
+
return createMiddleware({
|
|
16758
|
+
name: "RepeatedToolCallBreaker",
|
|
16759
|
+
stateSchema: BREAKER_STATE_SCHEMA,
|
|
16760
|
+
afterModel: {
|
|
16761
|
+
canJumpTo: ["end"],
|
|
16762
|
+
hook: (state) => {
|
|
16763
|
+
const lastAI = [...state.messages].reverse().find(AIMessage.isInstance);
|
|
16764
|
+
if (!lastAI || !lastAI.tool_calls?.length) return void 0;
|
|
16765
|
+
const lastHuman = [...state.messages].reverse().find(HumanMessage.isInstance);
|
|
16766
|
+
const runMarker = lastHuman?.id ?? "";
|
|
16767
|
+
const isNewRun = runMarker !== (state.repeatedToolCallRunMarker ?? "");
|
|
16768
|
+
const normalized = normalizeToolCalls(lastAI.tool_calls);
|
|
16769
|
+
const signature = stableStringify(normalized);
|
|
16770
|
+
const count = !isNewRun && signature === state.repeatedToolCallSignature ? (state.repeatedToolCallCount ?? 0) + 1 : 1;
|
|
16771
|
+
if (count >= stopThreshold) {
|
|
16772
|
+
const toolName2 = lastAI.tool_calls.length === 1 ? lastAI.tool_calls[0]?.name : void 0;
|
|
16773
|
+
throw new RepeatedToolCallError(toolName2, count, stopThreshold, signature.slice(0, 500));
|
|
16774
|
+
}
|
|
16775
|
+
return {
|
|
16776
|
+
repeatedToolCallSignature: signature,
|
|
16777
|
+
repeatedToolCallCount: count,
|
|
16778
|
+
repeatedToolCallRunMarker: runMarker,
|
|
16779
|
+
repeatedToolCallMemberSignatures: normalized.map((call) => stableStringify(call))
|
|
16780
|
+
};
|
|
16781
|
+
}
|
|
16782
|
+
},
|
|
16783
|
+
wrapToolCall: async (request, handler) => {
|
|
16784
|
+
const state = request.state;
|
|
16785
|
+
const count = state.repeatedToolCallCount ?? 0;
|
|
16786
|
+
const members = state.repeatedToolCallMemberSignatures ?? [];
|
|
16787
|
+
const current = stableStringify({ name: request.toolCall.name ?? "", args: request.toolCall.args ?? {} });
|
|
16788
|
+
if (warnThreshold > 0 && count >= warnThreshold && members.includes(current)) {
|
|
16789
|
+
return new ToolMessage({
|
|
16790
|
+
name: request.toolCall.name,
|
|
16791
|
+
tool_call_id: request.toolCall.id ?? "repeated-tool-call",
|
|
16792
|
+
status: "error",
|
|
16793
|
+
content: JSON.stringify({
|
|
16794
|
+
success: false,
|
|
16795
|
+
code: "REPEATED_TOOL_CALL",
|
|
16796
|
+
error: `You have already called '${request.toolCall.name}' with identical arguments ${count} times. The result will not change. Do not call it again \u2014 use the result already in context and take the next action (edit, re-run with different input, or finish).`
|
|
16797
|
+
})
|
|
16798
|
+
});
|
|
16799
|
+
}
|
|
16800
|
+
return handler(request);
|
|
16801
|
+
}
|
|
16802
|
+
});
|
|
16803
|
+
}
|
|
16804
|
+
|
|
16805
|
+
// src/middlewares/runGovernance.ts
|
|
16806
|
+
var runGovernanceStateSchema = z42.object({
|
|
16807
|
+
governRunId: z42.string().default(""),
|
|
16808
|
+
governModelCalls: z42.number().default(0),
|
|
16809
|
+
governToolRounds: z42.number().default(0),
|
|
16810
|
+
governToolCalls: z42.number().default(0),
|
|
16811
|
+
governSkillCalls: z42.number().default(0),
|
|
16812
|
+
governWarned: z42.boolean().default(false),
|
|
16813
|
+
governNotice: z42.string().default(""),
|
|
16814
|
+
governLastSignature: z42.string().default(""),
|
|
16815
|
+
governRepeatCount: z42.number().default(0),
|
|
16816
|
+
governTerminationReason: z42.string().default(""),
|
|
16817
|
+
governStopSummary: z42.string().default(""),
|
|
16818
|
+
governForceFinal: z42.boolean().default(false),
|
|
16819
|
+
governForcedRounds: z42.number().default(0)
|
|
16820
|
+
});
|
|
16821
|
+
function withRunGovernanceStateSchema(schema6) {
|
|
16822
|
+
return schema6 ? schema6.extend(runGovernanceStateSchema.shape) : runGovernanceStateSchema;
|
|
16823
|
+
}
|
|
16824
|
+
function positiveInt(raw, fallback) {
|
|
16825
|
+
if (raw === void 0 || raw.trim() === "") return fallback;
|
|
16826
|
+
const parsed = Number(raw);
|
|
16827
|
+
return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : fallback;
|
|
16828
|
+
}
|
|
16829
|
+
function readRunGovernanceConfig(env = process.env) {
|
|
16830
|
+
return {
|
|
16831
|
+
maxModelCalls: positiveInt(env.AGENT_RUN_MODEL_CALLS, 50),
|
|
16832
|
+
maxModelCallsMax: positiveInt(env.AGENT_RUN_MODEL_CALLS_MAX, 600),
|
|
16833
|
+
wrapUpReserve: positiveInt(env.AGENT_RUN_WRAP_UP_CALLS, 3),
|
|
16834
|
+
repeatWarn: positiveInt(env.AGENT_REPEATED_TOOL_CALL_WARN, 5),
|
|
16835
|
+
repeatStop: positiveInt(env.AGENT_REPEATED_TOOL_CALL_STOP, 8),
|
|
16836
|
+
maxToolCalls: positiveInt(env.AGENT_TOOL_CALL_RUN_LIMIT, 300),
|
|
16837
|
+
maxSkillCalls: positiveInt(env.AGENT_SKILL_CALL_RUN_LIMIT, 8)
|
|
16838
|
+
};
|
|
16839
|
+
}
|
|
16840
|
+
function isPlainRecord(value) {
|
|
16841
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
16842
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16843
|
+
return prototype === Object.prototype || prototype === null;
|
|
16844
|
+
}
|
|
16845
|
+
function resolveRequestedMaxModelCalls(requested, config = readRunGovernanceConfig()) {
|
|
16846
|
+
const raw = isPlainRecord(requested) && typeof requested.maxModelCalls === "number" ? requested.maxModelCalls : Number.NaN;
|
|
16847
|
+
if (!Number.isFinite(raw) || raw < 1) return config.maxModelCalls;
|
|
16848
|
+
return Math.min(config.maxModelCallsMax, Math.max(1, Math.floor(raw)));
|
|
16849
|
+
}
|
|
16850
|
+
function buildDeterministicSummary(messages, _reason) {
|
|
16851
|
+
const rows = messages;
|
|
16852
|
+
const toolNames = rows.filter((message) => ToolMessage2.isInstance(message)).slice(-5).map((message) => message.name).filter((name) => typeof name === "string" && name.length > 0);
|
|
16853
|
+
const lastAI = [...rows].reverse().find((message) => AIMessage2.isInstance(message));
|
|
16854
|
+
const lastText = typeof lastAI?.content === "string" ? lastAI.content.trim().slice(0, 500) : "";
|
|
16855
|
+
return [
|
|
16856
|
+
"I stopped before completing the full task.",
|
|
16857
|
+
toolNames.length > 0 ? `Recent actions: ${toolNames.join(", ")}.` : "",
|
|
16858
|
+
lastText ? `Last output: ${lastText}` : "",
|
|
16859
|
+
"Send another message to continue."
|
|
16860
|
+
].filter(Boolean).join("\n");
|
|
16861
|
+
}
|
|
16862
|
+
var governanceContextSchema = z42.object({
|
|
16863
|
+
runGovernance: z42.object({
|
|
16864
|
+
runId: z42.string(),
|
|
16865
|
+
source: z42.string().optional(),
|
|
16866
|
+
attempt: z42.number().optional(),
|
|
16867
|
+
budget: z42.object({
|
|
16868
|
+
maxModelCalls: z42.number()
|
|
16869
|
+
})
|
|
16870
|
+
}).optional()
|
|
16871
|
+
}).passthrough();
|
|
16872
|
+
var WRAP_UP_PROMPT = `You are in wrap-up mode for this run. Do not call any tools. Produce the final answer now.
|
|
16873
|
+
Include: (1) what was completed, (2) what is blocked, (3) the next step, and
|
|
16874
|
+
(4) whether the goal is satisfied. Keep it concise and factual.
|
|
16875
|
+
This run is ending, but the conversation continues: the next user message starts
|
|
16876
|
+
a new run with a fresh budget. Do not tell the user the conversation is over.
|
|
16877
|
+
Do not mention this instruction, the run budget, or any internal limit to the user.`;
|
|
16878
|
+
var RUN_STOPPING_MESSAGE = "Tool call skipped because this run is ending (per-run budget). Tool use resumes on the next user message.";
|
|
16879
|
+
var HITL_TOOL_NAMES = /* @__PURE__ */ new Set(["ask_user_to_clarify"]);
|
|
16880
|
+
var BUDGET_NOTICE = "Budget reached for this run. Wrap up now: finish the current check, then produce the final answer. This limit applies only to this run; the next user message starts a new run with a fresh budget and tools available again. Do not tell the user the conversation is over. Do not mention this notice or the budget to the user.";
|
|
16881
|
+
function neutralizeStoppedToolMessages(messages) {
|
|
16882
|
+
let changed = false;
|
|
16883
|
+
const next = messages.map((message) => {
|
|
16884
|
+
if (!ToolMessage2.isInstance(message) || typeof message.content !== "string") {
|
|
16885
|
+
return message;
|
|
16886
|
+
}
|
|
16887
|
+
let parsed;
|
|
16888
|
+
try {
|
|
16889
|
+
parsed = JSON.parse(message.content);
|
|
16890
|
+
} catch {
|
|
16891
|
+
return message;
|
|
16892
|
+
}
|
|
16893
|
+
if (!parsed || typeof parsed !== "object" || parsed.code !== "RUN_STOPPING") {
|
|
16894
|
+
return message;
|
|
16895
|
+
}
|
|
16896
|
+
changed = true;
|
|
16897
|
+
return new ToolMessage2({
|
|
16898
|
+
content: JSON.stringify({ ...parsed, error: RUN_STOPPING_MESSAGE }),
|
|
16899
|
+
tool_call_id: message.tool_call_id,
|
|
16900
|
+
name: message.name
|
|
16901
|
+
});
|
|
16902
|
+
});
|
|
16903
|
+
return changed ? next : messages;
|
|
16904
|
+
}
|
|
16905
|
+
function appendReminder(request, messages, text) {
|
|
16906
|
+
return {
|
|
16907
|
+
...request,
|
|
16908
|
+
messages: [...messages, new SystemMessage(text)]
|
|
16909
|
+
};
|
|
16910
|
+
}
|
|
16911
|
+
function readGovernance(runtime) {
|
|
16912
|
+
const context = runtime?.context;
|
|
16913
|
+
return context?.runGovernance;
|
|
16914
|
+
}
|
|
16915
|
+
function createRunGovernanceMiddleware(options = {}) {
|
|
16916
|
+
const defaultMax = Math.max(1, options.maxModelCalls ?? 50);
|
|
16917
|
+
const wrapUpReserve = Math.max(1, options.wrapUpReserve ?? 3);
|
|
16918
|
+
const repeatWarn = Math.max(1, options.repeatWarn ?? 5);
|
|
16919
|
+
const repeatStop = Math.max(repeatWarn, options.repeatStop ?? 8);
|
|
16920
|
+
const maxToolCalls = Math.max(1, options.maxToolCalls ?? 300);
|
|
16921
|
+
const maxSkillCalls = Math.max(1, options.maxSkillCalls ?? 8);
|
|
16922
|
+
const pollable = new Set(options.pollableTools ?? ["run_eval"]);
|
|
16923
|
+
return createMiddleware2({
|
|
16924
|
+
name: "RunGovernanceMiddleware",
|
|
16925
|
+
contextSchema: governanceContextSchema,
|
|
16926
|
+
stateSchema: runGovernanceStateSchema,
|
|
16927
|
+
beforeAgent: (state, runtime) => {
|
|
16928
|
+
const gov = readGovernance(runtime);
|
|
16929
|
+
if (!gov || state.governRunId === gov.runId) return void 0;
|
|
16930
|
+
return {
|
|
16931
|
+
governRunId: gov.runId,
|
|
16932
|
+
governModelCalls: 0,
|
|
16933
|
+
governToolRounds: 0,
|
|
16934
|
+
governToolCalls: 0,
|
|
16935
|
+
governSkillCalls: 0,
|
|
16936
|
+
governWarned: false,
|
|
16937
|
+
governNotice: "",
|
|
16938
|
+
governLastSignature: "",
|
|
16939
|
+
governRepeatCount: 0,
|
|
16940
|
+
governTerminationReason: "",
|
|
16941
|
+
governStopSummary: "",
|
|
16942
|
+
governForceFinal: false,
|
|
16943
|
+
governForcedRounds: 0
|
|
16944
|
+
};
|
|
16945
|
+
},
|
|
16946
|
+
beforeModel: {
|
|
16947
|
+
canJumpTo: ["end"],
|
|
16948
|
+
hook: (state, runtime) => {
|
|
16949
|
+
const gov = readGovernance(runtime);
|
|
16950
|
+
if (!gov) return void 0;
|
|
16951
|
+
const maxCalls = Math.max(1, gov.budget.maxModelCalls ?? defaultMax);
|
|
16952
|
+
const modelCalls = state.governModelCalls ?? 0;
|
|
16953
|
+
const hardCap = maxCalls + wrapUpReserve;
|
|
16954
|
+
const reason = state.governTerminationReason ?? "";
|
|
16955
|
+
if (modelCalls >= hardCap) {
|
|
16956
|
+
const summary = buildDeterministicSummary(
|
|
16957
|
+
state.messages ?? [],
|
|
16958
|
+
reason || "budget_exhausted"
|
|
16959
|
+
);
|
|
16960
|
+
return {
|
|
16961
|
+
governTerminationReason: reason || "budget_exhausted",
|
|
16962
|
+
governStopSummary: summary,
|
|
16963
|
+
governForceFinal: true,
|
|
16964
|
+
jumpTo: "end",
|
|
16965
|
+
messages: [new AIMessage2(summary)]
|
|
16966
|
+
};
|
|
16967
|
+
}
|
|
16968
|
+
if (modelCalls >= hardCap - 1) {
|
|
16969
|
+
return {
|
|
16970
|
+
governTerminationReason: reason || "budget_exhausted",
|
|
16971
|
+
governForceFinal: true,
|
|
16972
|
+
governWarned: true
|
|
16973
|
+
};
|
|
16974
|
+
}
|
|
16975
|
+
if (modelCalls >= maxCalls - 1) {
|
|
16976
|
+
return { governWarned: true };
|
|
16977
|
+
}
|
|
16978
|
+
return void 0;
|
|
16979
|
+
}
|
|
16980
|
+
},
|
|
16981
|
+
afterModel: {
|
|
16982
|
+
canJumpTo: ["end"],
|
|
16983
|
+
hook: (state, runtime) => {
|
|
16984
|
+
if (!readGovernance(runtime)) return void 0;
|
|
16985
|
+
const messages = state.messages ?? [];
|
|
16986
|
+
const lastAI = [...messages].reverse().find((message) => AIMessage2.isInstance(message));
|
|
16987
|
+
const toolCalls = lastAI?.tool_calls ?? [];
|
|
16988
|
+
const hasTools2 = toolCalls.length > 0;
|
|
16989
|
+
const modelCalls = (state.governModelCalls ?? 0) + 1;
|
|
16990
|
+
const toolRounds = (state.governToolRounds ?? 0) + (hasTools2 ? 1 : 0);
|
|
16991
|
+
const toolCallsThisRound = toolCalls.length;
|
|
16992
|
+
const skillCallsThisRound = toolCalls.filter((call) => call.name === "skill").length;
|
|
16993
|
+
const totalToolCalls = (state.governToolCalls ?? 0) + toolCallsThisRound;
|
|
16994
|
+
const totalSkillCalls = (state.governSkillCalls ?? 0) + skillCallsThisRound;
|
|
16995
|
+
let notice = "";
|
|
16996
|
+
const warned = state.governWarned ?? false;
|
|
16997
|
+
let reason = state.governTerminationReason ?? "";
|
|
16998
|
+
let forceFinal = state.governForceFinal ?? false;
|
|
16999
|
+
let signature = state.governLastSignature ?? "";
|
|
17000
|
+
let repeatCount = state.governRepeatCount ?? 0;
|
|
17001
|
+
const nonPollable = toolCalls.filter((call) => !pollable.has(call.name ?? ""));
|
|
17002
|
+
if (hasTools2 && nonPollable.length > 0) {
|
|
17003
|
+
const nextSignature = stableStringify(normalizeToolCalls(nonPollable));
|
|
17004
|
+
repeatCount = nextSignature === signature ? repeatCount + 1 : 1;
|
|
17005
|
+
signature = nextSignature;
|
|
17006
|
+
if (!reason && repeatCount === repeatWarn) {
|
|
17007
|
+
notice = `You have called the same tool with identical arguments ${repeatCount} times. The result will not change. Use the existing result or take a different action.`;
|
|
17008
|
+
}
|
|
17009
|
+
if (!reason && repeatCount >= repeatStop) {
|
|
17010
|
+
reason = "repeated_calls";
|
|
17011
|
+
forceFinal = true;
|
|
17012
|
+
}
|
|
17013
|
+
}
|
|
17014
|
+
if (!reason && (totalToolCalls >= maxToolCalls || totalSkillCalls >= maxSkillCalls)) {
|
|
17015
|
+
reason = "tool_limit";
|
|
17016
|
+
forceFinal = true;
|
|
17017
|
+
}
|
|
17018
|
+
let forcedRounds = state.governForcedRounds ?? 0;
|
|
17019
|
+
if (forceFinal && hasTools2) forcedRounds += 1;
|
|
17020
|
+
const counters = {
|
|
17021
|
+
governModelCalls: modelCalls,
|
|
17022
|
+
governToolRounds: toolRounds,
|
|
17023
|
+
governToolCalls: totalToolCalls,
|
|
17024
|
+
governSkillCalls: totalSkillCalls,
|
|
17025
|
+
governWarned: warned,
|
|
17026
|
+
governNotice: notice,
|
|
17027
|
+
governLastSignature: signature,
|
|
17028
|
+
governRepeatCount: repeatCount,
|
|
17029
|
+
governTerminationReason: reason,
|
|
17030
|
+
governForceFinal: forceFinal,
|
|
17031
|
+
governForcedRounds: forcedRounds
|
|
17032
|
+
};
|
|
17033
|
+
if (forceFinal && hasTools2 && forcedRounds >= 2) {
|
|
17034
|
+
const summary = buildDeterministicSummary(messages, reason);
|
|
17035
|
+
return {
|
|
17036
|
+
...counters,
|
|
17037
|
+
governStopSummary: summary,
|
|
17038
|
+
jumpTo: "end",
|
|
17039
|
+
messages: [new AIMessage2(summary)]
|
|
17040
|
+
};
|
|
17041
|
+
}
|
|
17042
|
+
return counters;
|
|
17043
|
+
}
|
|
17044
|
+
},
|
|
17045
|
+
wrapModelCall: async (request, handler) => {
|
|
17046
|
+
const state = request.state ?? {};
|
|
17047
|
+
const gov = readGovernance(request.runtime);
|
|
17048
|
+
const maxCalls = Math.max(1, gov?.budget.maxModelCalls ?? defaultMax);
|
|
17049
|
+
const used = state.governModelCalls ?? 0;
|
|
17050
|
+
const hardCap = maxCalls + wrapUpReserve;
|
|
17051
|
+
const forceByBudget = used >= hardCap - 1;
|
|
17052
|
+
const forceFinal = Boolean(state.governForceFinal) || forceByBudget;
|
|
17053
|
+
const budgetNotice = !forceByBudget && used >= maxCalls - 1 ? BUDGET_NOTICE : "";
|
|
17054
|
+
if (used >= hardCap) {
|
|
17055
|
+
return new AIMessage2(
|
|
17056
|
+
buildDeterministicSummary(request.messages ?? [], state.governTerminationReason)
|
|
17057
|
+
);
|
|
17058
|
+
}
|
|
17059
|
+
const messages = Array.isArray(request.messages) ? neutralizeStoppedToolMessages(request.messages) : request.messages;
|
|
17060
|
+
const nextRequest = messages === request.messages ? request : { ...request, messages };
|
|
17061
|
+
const pending = [state.governNotice, budgetNotice].filter((part) => typeof part === "string" && part.length > 0).join("\n\n");
|
|
17062
|
+
if (forceFinal) {
|
|
17063
|
+
const reminder = [pending, WRAP_UP_PROMPT].filter((part) => typeof part === "string" && part.length > 0).join("\n\n");
|
|
17064
|
+
return handler({
|
|
17065
|
+
...appendReminder(nextRequest, nextRequest.messages ?? [], reminder),
|
|
17066
|
+
tools: [],
|
|
17067
|
+
toolChoice: "none"
|
|
17068
|
+
});
|
|
17069
|
+
}
|
|
17070
|
+
if (pending) {
|
|
17071
|
+
return handler(
|
|
17072
|
+
appendReminder(nextRequest, nextRequest.messages ?? [], pending)
|
|
17073
|
+
);
|
|
17074
|
+
}
|
|
17075
|
+
return handler(nextRequest);
|
|
17076
|
+
},
|
|
17077
|
+
wrapToolCall: async (request, handler) => {
|
|
17078
|
+
const state = request.state ?? {};
|
|
17079
|
+
const gov = readGovernance(request.runtime);
|
|
17080
|
+
const maxCalls = Math.max(1, gov?.budget.maxModelCalls ?? defaultMax);
|
|
17081
|
+
const hardCap = maxCalls + wrapUpReserve;
|
|
17082
|
+
const forceByBudget = (state.governModelCalls ?? 0) >= hardCap;
|
|
17083
|
+
const isHitlTool = HITL_TOOL_NAMES.has(String(request.toolCall?.name ?? ""));
|
|
17084
|
+
if (!isHitlTool && (state.governForceFinal || forceByBudget)) {
|
|
17085
|
+
return new ToolMessage2({
|
|
17086
|
+
name: request.toolCall?.name,
|
|
17087
|
+
tool_call_id: request.toolCall?.id ?? "run-governance-blocked",
|
|
17088
|
+
status: "error",
|
|
17089
|
+
content: JSON.stringify({
|
|
17090
|
+
success: false,
|
|
17091
|
+
code: "RUN_STOPPING",
|
|
17092
|
+
error: RUN_STOPPING_MESSAGE
|
|
17093
|
+
})
|
|
17094
|
+
});
|
|
17095
|
+
}
|
|
17096
|
+
return handler(request);
|
|
17097
|
+
}
|
|
17098
|
+
});
|
|
17099
|
+
}
|
|
17100
|
+
|
|
16444
17101
|
// src/agent_lattice/builders/state.ts
|
|
16445
17102
|
var createReactAgentSchema = (schema6) => {
|
|
16446
|
-
return MessagesZodState.extend(schema6?.shape ?? {}).extend(toolCallLimitStateSchema.shape);
|
|
17103
|
+
return MessagesZodState.extend(schema6?.shape ?? {}).extend(toolCallLimitStateSchema.shape).extend(runGovernanceStateSchema.shape);
|
|
16447
17104
|
};
|
|
16448
17105
|
|
|
16449
17106
|
// src/agent_lattice/builders/ReActAgentGraphBuilder.ts
|
|
16450
17107
|
import { createAgent } from "langchain";
|
|
16451
17108
|
|
|
16452
17109
|
// src/middlewares/codeEvalMiddleware.ts
|
|
16453
|
-
import { createMiddleware } from "langchain";
|
|
17110
|
+
import { createMiddleware as createMiddleware3 } from "langchain";
|
|
16454
17111
|
|
|
16455
17112
|
// src/middlewares/contextSchema.ts
|
|
16456
|
-
import
|
|
16457
|
-
var contextSchema =
|
|
16458
|
-
runConfig:
|
|
17113
|
+
import z43 from "zod";
|
|
17114
|
+
var contextSchema = z43.object({
|
|
17115
|
+
runConfig: z43.any()
|
|
16459
17116
|
});
|
|
16460
17117
|
|
|
16461
17118
|
// src/middlewares/codeEvalMiddleware.ts
|
|
16462
17119
|
function createCodeEvalMiddleware(params = { vmIsolation: "agent" }) {
|
|
16463
|
-
return
|
|
17120
|
+
return createMiddleware3({
|
|
16464
17121
|
name: "codeEvalMiddleware",
|
|
16465
17122
|
contextSchema,
|
|
16466
17123
|
tools: [createShellExecTool({ vmIsolation: params.vmIsolation })]
|
|
@@ -16494,7 +17151,7 @@ var codeEvalPlugin = {
|
|
|
16494
17151
|
};
|
|
16495
17152
|
|
|
16496
17153
|
// src/middlewares/browserMiddleware.ts
|
|
16497
|
-
import { createMiddleware as
|
|
17154
|
+
import { createMiddleware as createMiddleware4 } from "langchain";
|
|
16498
17155
|
function createBrowserMiddleware(params = { vmIsolation: "agent" }) {
|
|
16499
17156
|
const vmIsolation = params.vmIsolation || "agent";
|
|
16500
17157
|
const tools = [
|
|
@@ -16521,7 +17178,7 @@ function createBrowserMiddleware(params = { vmIsolation: "agent" }) {
|
|
|
16521
17178
|
createBrowserGetDownloadListTool({ vmIsolation }),
|
|
16522
17179
|
createBrowserGetInfoTool({ vmIsolation })
|
|
16523
17180
|
];
|
|
16524
|
-
return
|
|
17181
|
+
return createMiddleware4({
|
|
16525
17182
|
name: "browserMiddleware",
|
|
16526
17183
|
contextSchema,
|
|
16527
17184
|
tools
|
|
@@ -16555,11 +17212,11 @@ var browserPlugin = {
|
|
|
16555
17212
|
};
|
|
16556
17213
|
|
|
16557
17214
|
// src/middlewares/sqlMiddleware.ts
|
|
16558
|
-
import { createMiddleware as
|
|
17215
|
+
import { createMiddleware as createMiddleware5 } from "langchain";
|
|
16559
17216
|
function createSqlMiddleware(params) {
|
|
16560
17217
|
const { databaseKeys = [], databaseDescriptions, compileStableCandidateTools = false } = params;
|
|
16561
17218
|
if (!compileStableCandidateTools && databaseKeys.length === 0) {
|
|
16562
|
-
return
|
|
17219
|
+
return createMiddleware5({
|
|
16563
17220
|
name: "sqlMiddleware",
|
|
16564
17221
|
tools: []
|
|
16565
17222
|
});
|
|
@@ -16568,7 +17225,7 @@ function createSqlMiddleware(params) {
|
|
|
16568
17225
|
databaseKeys,
|
|
16569
17226
|
databaseDescriptions
|
|
16570
17227
|
};
|
|
16571
|
-
return
|
|
17228
|
+
return createMiddleware5({
|
|
16572
17229
|
name: "sqlMiddleware",
|
|
16573
17230
|
contextSchema,
|
|
16574
17231
|
tools: [
|
|
@@ -16613,7 +17270,7 @@ var sqlPlugin = {
|
|
|
16613
17270
|
};
|
|
16614
17271
|
|
|
16615
17272
|
// src/deep_agent_new/middleware/fs.ts
|
|
16616
|
-
import { createMiddleware as
|
|
17273
|
+
import { createMiddleware as createMiddleware6, tool as tool38, ToolMessage as ToolMessage3 } from "langchain";
|
|
16617
17274
|
import { Command, isCommand, getCurrentTaskInput } from "@langchain/langgraph";
|
|
16618
17275
|
import { z as z310 } from "zod/v3";
|
|
16619
17276
|
import { withLangGraph as withLangGraph2 } from "@langchain/langgraph/zod";
|
|
@@ -17143,7 +17800,7 @@ function validateAudioSize(sizeBytes) {
|
|
|
17143
17800
|
}
|
|
17144
17801
|
|
|
17145
17802
|
// src/deep_agent_new/backends/describeImage.ts
|
|
17146
|
-
import { HumanMessage } from "@langchain/core/messages";
|
|
17803
|
+
import { HumanMessage as HumanMessage2 } from "@langchain/core/messages";
|
|
17147
17804
|
async function describeImage(options) {
|
|
17148
17805
|
const { modelKey, tenantId: tenantId2, mimeType, base64, prompt } = options;
|
|
17149
17806
|
const resolved = await resolveModelLatticeForTenant(
|
|
@@ -17158,7 +17815,7 @@ async function describeImage(options) {
|
|
|
17158
17815
|
throw new Error(`Model "${modelKey}" does not support vision.`);
|
|
17159
17816
|
}
|
|
17160
17817
|
const result = await client.invoke([
|
|
17161
|
-
new
|
|
17818
|
+
new HumanMessage2({
|
|
17162
17819
|
content: [
|
|
17163
17820
|
{
|
|
17164
17821
|
type: "text",
|
|
@@ -17174,6 +17831,9 @@ async function describeImage(options) {
|
|
|
17174
17831
|
return result.content || "";
|
|
17175
17832
|
}
|
|
17176
17833
|
|
|
17834
|
+
// src/stt_model_lattice/STTModelLatticeManager.ts
|
|
17835
|
+
import { ASR_DEFAULT_KEY } from "@axiom-lattice/protocols";
|
|
17836
|
+
|
|
17177
17837
|
// src/stt_model_lattice/STTModelLattice.ts
|
|
17178
17838
|
import { OpenAIClient, toFile } from "@langchain/openai";
|
|
17179
17839
|
var STTModelLattice = class {
|
|
@@ -17308,7 +17968,7 @@ var STTModelLatticeManager = class _STTModelLatticeManager extends BaseLatticeMa
|
|
|
17308
17968
|
* chat key must never resolve to a speech client.
|
|
17309
17969
|
*/
|
|
17310
17970
|
async loadItemFromStore(tenantId2, key5) {
|
|
17311
|
-
const row = await loadTenantModelRow(tenantId2, key5);
|
|
17971
|
+
const row = key5 === ASR_DEFAULT_KEY ? await loadTenantDefaultModelRow(tenantId2, "asr") : await loadTenantModelRow(tenantId2, key5);
|
|
17312
17972
|
if (!row || row.model.kind !== "asr") {
|
|
17313
17973
|
return void 0;
|
|
17314
17974
|
}
|
|
@@ -17432,15 +18092,23 @@ var getSTTClient = (key5) => sttModelLatticeManager.getSTTClient(key5);
|
|
|
17432
18092
|
var getSTTClientWithTenant = (tenantId2, key5) => sttModelLatticeManager.getSTTClientWithTenant(tenantId2, key5);
|
|
17433
18093
|
|
|
17434
18094
|
// src/deep_agent_new/backends/transcribeAudio.ts
|
|
18095
|
+
import { ASR_DEFAULT_KEY as ASR_DEFAULT_KEY2 } from "@axiom-lattice/protocols";
|
|
17435
18096
|
async function transcribeAudio(options) {
|
|
17436
|
-
const { audioBuffer, format, tenantId: tenantId2 = "default", modelKey
|
|
18097
|
+
const { audioBuffer, format, tenantId: tenantId2 = "default", modelKey } = options;
|
|
18098
|
+
const requestedKey = modelKey || ASR_DEFAULT_KEY2;
|
|
17437
18099
|
const client = await sttModelLatticeManager.getSTTClientWithTenantAsync(
|
|
17438
18100
|
tenantId2,
|
|
17439
|
-
|
|
18101
|
+
requestedKey
|
|
18102
|
+
) ?? (requestedKey === ASR_DEFAULT_KEY2 ? void 0 : await sttModelLatticeManager.getSTTClientWithTenantAsync(
|
|
18103
|
+
tenantId2,
|
|
18104
|
+
ASR_DEFAULT_KEY2
|
|
18105
|
+
)) ?? await sttModelLatticeManager.getSTTClientWithTenantAsync(
|
|
18106
|
+
tenantId2,
|
|
18107
|
+
"default"
|
|
17440
18108
|
);
|
|
17441
18109
|
if (!client) {
|
|
17442
18110
|
throw new Error(
|
|
17443
|
-
`No STT model "${
|
|
18111
|
+
`No STT model "${requestedKey}" registered for tenant "${tenantId2}", and no tenant or deployment default. Configure one in the model service panel.`
|
|
17444
18112
|
);
|
|
17445
18113
|
}
|
|
17446
18114
|
return await client.transcribe(audioBuffer, format);
|
|
@@ -17671,7 +18339,7 @@ function createWriteFileTool(backend, options) {
|
|
|
17671
18339
|
if (result.error) {
|
|
17672
18340
|
return result.error;
|
|
17673
18341
|
}
|
|
17674
|
-
const message = new
|
|
18342
|
+
const message = new ToolMessage3({
|
|
17675
18343
|
content: `Successfully wrote to '${file_path}'`,
|
|
17676
18344
|
tool_call_id: config.toolCall?.id,
|
|
17677
18345
|
name: "write_file",
|
|
@@ -17715,7 +18383,7 @@ function createEditFileTool(backend, options) {
|
|
|
17715
18383
|
if (result.error) {
|
|
17716
18384
|
return result.error;
|
|
17717
18385
|
}
|
|
17718
|
-
const message = new
|
|
18386
|
+
const message = new ToolMessage3({
|
|
17719
18387
|
content: `Successfully replaced ${result.occurrences} occurrence(s) in '${file_path}'`,
|
|
17720
18388
|
tool_call_id: config.toolCall?.id,
|
|
17721
18389
|
name: "edit_file",
|
|
@@ -17760,7 +18428,7 @@ function createDeleteFileTool(backend, options) {
|
|
|
17760
18428
|
if (result.error) {
|
|
17761
18429
|
return result.error;
|
|
17762
18430
|
}
|
|
17763
|
-
const message = new
|
|
18431
|
+
const message = new ToolMessage3({
|
|
17764
18432
|
content: `Successfully deleted '${file_path}'`,
|
|
17765
18433
|
tool_call_id: toolConfig.toolCall?.id ?? "",
|
|
17766
18434
|
name: "delete_file",
|
|
@@ -17883,7 +18551,7 @@ function createFilesystemMiddleware(options = {}) {
|
|
|
17883
18551
|
customDescription: customToolDescriptions?.grep
|
|
17884
18552
|
})
|
|
17885
18553
|
];
|
|
17886
|
-
return
|
|
18554
|
+
return createMiddleware6({
|
|
17887
18555
|
name: "FilesystemMiddleware",
|
|
17888
18556
|
contextSchema,
|
|
17889
18557
|
stateSchema: FilesystemStateSchema,
|
|
@@ -17915,7 +18583,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
17915
18583
|
if (writeResult.error) {
|
|
17916
18584
|
return { message: msg, filesUpdate: null };
|
|
17917
18585
|
}
|
|
17918
|
-
const truncatedMessage = new
|
|
18586
|
+
const truncatedMessage = new ToolMessage3({
|
|
17919
18587
|
content: `Tool result too large (${Math.round(
|
|
17920
18588
|
msg.content.length / 4
|
|
17921
18589
|
)} tokens). Content saved to ${evictPath}`,
|
|
@@ -17929,7 +18597,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
17929
18597
|
}
|
|
17930
18598
|
return { message: msg, filesUpdate: null };
|
|
17931
18599
|
}
|
|
17932
|
-
if (result instanceof
|
|
18600
|
+
if (result instanceof ToolMessage3) {
|
|
17933
18601
|
const processed = await processToolMessage(result);
|
|
17934
18602
|
if (processed.filesUpdate) {
|
|
17935
18603
|
return new Command({
|
|
@@ -17952,7 +18620,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
17952
18620
|
};
|
|
17953
18621
|
const processedMessages = [];
|
|
17954
18622
|
for (const msg of update.messages) {
|
|
17955
|
-
if (msg instanceof
|
|
18623
|
+
if (msg instanceof ToolMessage3) {
|
|
17956
18624
|
const processed = await processToolMessage(msg);
|
|
17957
18625
|
processedMessages.push(processed.message);
|
|
17958
18626
|
if (processed.filesUpdate) {
|
|
@@ -18005,11 +18673,11 @@ var filesystemPlugin = {
|
|
|
18005
18673
|
};
|
|
18006
18674
|
|
|
18007
18675
|
// src/middlewares/metricsMiddleware.ts
|
|
18008
|
-
import { createMiddleware as
|
|
18676
|
+
import { createMiddleware as createMiddleware7 } from "langchain";
|
|
18009
18677
|
function createMetricsMiddleware(params) {
|
|
18010
18678
|
const { serverKeys, serverDescriptions, connectAll, compileStableCandidateTools = false } = params;
|
|
18011
18679
|
if (!compileStableCandidateTools && (!serverKeys || serverKeys.length === 0)) {
|
|
18012
|
-
return
|
|
18680
|
+
return createMiddleware7({
|
|
18013
18681
|
name: "metricsMiddleware",
|
|
18014
18682
|
tools: []
|
|
18015
18683
|
});
|
|
@@ -18023,7 +18691,7 @@ function createMetricsMiddleware(params) {
|
|
|
18023
18691
|
getTenantId: void 0
|
|
18024
18692
|
// Tools will extract tenantId from _exeConfig.configurable.runConfig
|
|
18025
18693
|
};
|
|
18026
|
-
return
|
|
18694
|
+
return createMiddleware7({
|
|
18027
18695
|
name: "metricsMiddleware",
|
|
18028
18696
|
contextSchema,
|
|
18029
18697
|
tools: [
|
|
@@ -18080,9 +18748,9 @@ var metricsPlugin = {
|
|
|
18080
18748
|
};
|
|
18081
18749
|
|
|
18082
18750
|
// src/middlewares/modelSelectorMiddleware.ts
|
|
18083
|
-
import { createMiddleware as
|
|
18751
|
+
import { createMiddleware as createMiddleware8 } from "langchain";
|
|
18084
18752
|
function createModelSelectorMiddleware() {
|
|
18085
|
-
return
|
|
18753
|
+
return createMiddleware8({
|
|
18086
18754
|
name: "modelSelector",
|
|
18087
18755
|
wrapModelCall: async (request, handler) => {
|
|
18088
18756
|
const runConfig = request.runtime?.context?.runConfig;
|
|
@@ -18131,7 +18799,7 @@ function createModelSelectorMiddleware() {
|
|
|
18131
18799
|
}
|
|
18132
18800
|
|
|
18133
18801
|
// src/deep_agent_new/middleware/clawMiddleware.ts
|
|
18134
|
-
import { createMiddleware as
|
|
18802
|
+
import { createMiddleware as createMiddleware9 } from "langchain";
|
|
18135
18803
|
|
|
18136
18804
|
// src/deep_agent_new/middleware/AGENTS_MD.ts
|
|
18137
18805
|
var AGENTS_MD = `
|
|
@@ -18656,7 +19324,7 @@ function createClawMiddleware(options = {}) {
|
|
|
18656
19324
|
bootstrapFiles = {},
|
|
18657
19325
|
injectBootstrapFiles = true
|
|
18658
19326
|
} = options;
|
|
18659
|
-
return
|
|
19327
|
+
return createMiddleware9({
|
|
18660
19328
|
name: "ClawMiddleware",
|
|
18661
19329
|
contextSchema,
|
|
18662
19330
|
beforeAgent: async (state, runtime) => {
|
|
@@ -18724,8 +19392,8 @@ var clawPlugin = {
|
|
|
18724
19392
|
};
|
|
18725
19393
|
|
|
18726
19394
|
// src/middlewares/unknownToolHandlerMiddleware.ts
|
|
18727
|
-
import { createMiddleware as
|
|
18728
|
-
import { AIMessage, ToolMessage as
|
|
19395
|
+
import { createMiddleware as createMiddleware10 } from "langchain";
|
|
19396
|
+
import { AIMessage as AIMessage3, ToolMessage as ToolMessage4 } from "@langchain/core/messages";
|
|
18729
19397
|
function createUnknownToolHandlerMiddleware(config = {}) {
|
|
18730
19398
|
const {
|
|
18731
19399
|
strategy = "error",
|
|
@@ -18736,7 +19404,7 @@ Available tools:
|
|
|
18736
19404
|
|
|
18737
19405
|
Please select a valid tool from the list above.`
|
|
18738
19406
|
} = config;
|
|
18739
|
-
return
|
|
19407
|
+
return createMiddleware10({
|
|
18740
19408
|
name: "UnknownToolHandlerMiddleware",
|
|
18741
19409
|
/**
|
|
18742
19410
|
* wrapModelCall hook
|
|
@@ -18780,7 +19448,7 @@ Please select a valid tool from the list above.`
|
|
|
18780
19448
|
}));
|
|
18781
19449
|
const unknownToolIds = new Set(unknownToolCalls.map((toolCall) => toolCall.id));
|
|
18782
19450
|
const remainingToolCalls = aiResponse.tool_calls.filter((toolCall) => unknownToolIds.has(toolCall.id));
|
|
18783
|
-
const modifiedResponse = new
|
|
19451
|
+
const modifiedResponse = new AIMessage3({
|
|
18784
19452
|
content: aiResponse.content,
|
|
18785
19453
|
tool_calls: remainingToolCalls,
|
|
18786
19454
|
response_metadata: {
|
|
@@ -18810,7 +19478,7 @@ Please select a valid tool from the list above.`
|
|
|
18810
19478
|
return;
|
|
18811
19479
|
}
|
|
18812
19480
|
const lastMessage = messages[messages.length - 1];
|
|
18813
|
-
if (!
|
|
19481
|
+
if (!AIMessage3.isInstance(lastMessage)) {
|
|
18814
19482
|
return;
|
|
18815
19483
|
}
|
|
18816
19484
|
const unknownToolErrors = lastMessage.response_metadata?._unknownToolErrors;
|
|
@@ -18818,7 +19486,7 @@ Please select a valid tool from the list above.`
|
|
|
18818
19486
|
return;
|
|
18819
19487
|
}
|
|
18820
19488
|
const errorToolMessages = unknownToolErrors.map(
|
|
18821
|
-
(error) => new
|
|
19489
|
+
(error) => new ToolMessage4({
|
|
18822
19490
|
content: error.errorMessage,
|
|
18823
19491
|
name: error.toolName,
|
|
18824
19492
|
tool_call_id: error.toolCallId,
|
|
@@ -18837,13 +19505,13 @@ Please select a valid tool from the list above.`
|
|
|
18837
19505
|
|
|
18838
19506
|
// src/deep_agent_new/middleware/patch_tool_calls.ts
|
|
18839
19507
|
import {
|
|
18840
|
-
createMiddleware as
|
|
18841
|
-
ToolMessage as
|
|
18842
|
-
AIMessage as
|
|
19508
|
+
createMiddleware as createMiddleware11,
|
|
19509
|
+
ToolMessage as ToolMessage5,
|
|
19510
|
+
AIMessage as AIMessage4
|
|
18843
19511
|
} from "langchain";
|
|
18844
|
-
import { HumanMessage as
|
|
19512
|
+
import { HumanMessage as HumanMessage3 } from "@langchain/core/messages";
|
|
18845
19513
|
function createPatchToolCallsMiddleware() {
|
|
18846
|
-
return
|
|
19514
|
+
return createMiddleware11({
|
|
18847
19515
|
name: "patchToolCallsMiddleware",
|
|
18848
19516
|
wrapModelCall: async (request, handler) => {
|
|
18849
19517
|
const messages = repairToolMessages(request.messages);
|
|
@@ -18855,9 +19523,9 @@ function repairToolMessages(messages) {
|
|
|
18855
19523
|
const repaired = [];
|
|
18856
19524
|
for (let index = 0; index < messages.length; index += 1) {
|
|
18857
19525
|
const message = messages[index];
|
|
18858
|
-
if (!
|
|
18859
|
-
if (!
|
|
18860
|
-
if (!
|
|
19526
|
+
if (!AIMessage4.isInstance(message) || !message.tool_calls?.length) {
|
|
19527
|
+
if (!ToolMessage5.isInstance(message) || !hasMatchingToolCall(messages, index, message.tool_call_id)) {
|
|
19528
|
+
if (!ToolMessage5.isInstance(message)) repaired.push(message);
|
|
18861
19529
|
}
|
|
18862
19530
|
continue;
|
|
18863
19531
|
}
|
|
@@ -18872,17 +19540,17 @@ function repairToolMessages(messages) {
|
|
|
18872
19540
|
let cursor = index + 1;
|
|
18873
19541
|
for (; cursor < messages.length; cursor += 1) {
|
|
18874
19542
|
const following = messages[cursor];
|
|
18875
|
-
if (
|
|
18876
|
-
if (
|
|
19543
|
+
if (HumanMessage3.isInstance(following) || AIMessage4.isInstance(following)) break;
|
|
19544
|
+
if (ToolMessage5.isInstance(following) && !followingTools.has(following.tool_call_id)) {
|
|
18877
19545
|
followingTools.set(following.tool_call_id, following);
|
|
18878
|
-
} else if (!
|
|
19546
|
+
} else if (!ToolMessage5.isInstance(following)) {
|
|
18879
19547
|
followingMessages.push(following);
|
|
18880
19548
|
}
|
|
18881
19549
|
}
|
|
18882
19550
|
if (validCalls.length === message.tool_calls.length) {
|
|
18883
19551
|
repaired.push(message);
|
|
18884
19552
|
} else {
|
|
18885
|
-
repaired.push(new
|
|
19553
|
+
repaired.push(new AIMessage4({
|
|
18886
19554
|
id: message.id,
|
|
18887
19555
|
content: message.content,
|
|
18888
19556
|
name: message.name,
|
|
@@ -18894,7 +19562,7 @@ function repairToolMessages(messages) {
|
|
|
18894
19562
|
}));
|
|
18895
19563
|
}
|
|
18896
19564
|
for (const call of validCalls) {
|
|
18897
|
-
repaired.push(followingTools.get(call.id) ?? new
|
|
19565
|
+
repaired.push(followingTools.get(call.id) ?? new ToolMessage5({
|
|
18898
19566
|
id: `tool-result-repair:${call.id}`,
|
|
18899
19567
|
name: call.name,
|
|
18900
19568
|
tool_call_id: call.id,
|
|
@@ -18922,112 +19590,28 @@ function withoutToolCalls(additionalKwargs) {
|
|
|
18922
19590
|
function hasMatchingToolCall(messages, toolIndex, toolCallId) {
|
|
18923
19591
|
for (let index = toolIndex - 1; index >= 0; index -= 1) {
|
|
18924
19592
|
const message = messages[index];
|
|
18925
|
-
if (
|
|
18926
|
-
if (
|
|
19593
|
+
if (HumanMessage3.isInstance(message)) return false;
|
|
19594
|
+
if (AIMessage4.isInstance(message)) {
|
|
18927
19595
|
return message.tool_calls?.some((call) => call.id === toolCallId) ?? false;
|
|
18928
19596
|
}
|
|
18929
19597
|
}
|
|
18930
19598
|
return false;
|
|
18931
19599
|
}
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
18939
|
-
|
|
18940
|
-
|
|
18941
|
-
|
|
18942
|
-
this.stopThreshold = stopThreshold;
|
|
18943
|
-
this.argsPreview = argsPreview;
|
|
18944
|
-
}
|
|
18945
|
-
};
|
|
18946
|
-
function readLoopBreakerConfig(env = process.env) {
|
|
18947
|
-
const parse = (raw, fallback) => {
|
|
18948
|
-
if (raw === void 0 || raw.trim() === "") return fallback;
|
|
18949
|
-
const parsed = Number(raw);
|
|
18950
|
-
if (!Number.isFinite(parsed) || parsed < 0) return fallback;
|
|
18951
|
-
return Math.floor(parsed);
|
|
18952
|
-
};
|
|
18953
|
-
return {
|
|
18954
|
-
repeatWarn: parse(env.AGENT_REPEATED_TOOL_CALL_WARN, 20),
|
|
18955
|
-
repeatStop: parse(env.AGENT_REPEATED_TOOL_CALL_STOP, 25),
|
|
18956
|
-
runLimit: parse(env.AGENT_TOOL_CALL_RUN_LIMIT, 300),
|
|
18957
|
-
skillRunLimit: parse(env.AGENT_SKILL_CALL_RUN_LIMIT, 8)
|
|
18958
|
-
};
|
|
18959
|
-
}
|
|
18960
|
-
function stableStringify(value) {
|
|
18961
|
-
if (Array.isArray(value)) return "[" + value.map(stableStringify).join(",") + "]";
|
|
18962
|
-
if (value && typeof value === "object") {
|
|
18963
|
-
const body = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key5, item]) => JSON.stringify(key5) + ":" + stableStringify(item)).join(",");
|
|
18964
|
-
return "{" + body + "}";
|
|
18965
|
-
}
|
|
18966
|
-
return JSON.stringify(value) ?? "null";
|
|
18967
|
-
}
|
|
18968
|
-
function normalizeToolCalls(toolCalls) {
|
|
18969
|
-
return toolCalls.map((call) => ({ name: call.name ?? "", args: call.args ?? {} }));
|
|
18970
|
-
}
|
|
18971
|
-
var BREAKER_STATE_SCHEMA = z42.object({
|
|
18972
|
-
repeatedToolCallSignature: z42.string().default(""),
|
|
18973
|
-
repeatedToolCallCount: z42.number().default(0),
|
|
18974
|
-
repeatedToolCallRunMarker: z42.string().default(""),
|
|
18975
|
-
repeatedToolCallMemberSignatures: z42.array(z42.string()).default([])
|
|
18976
|
-
});
|
|
18977
|
-
function createRepeatedToolCallBreakerMiddleware(options = {}) {
|
|
18978
|
-
const rawWarn = options.warnThreshold ?? 20;
|
|
18979
|
-
const warnThreshold = rawWarn > 0 ? Math.max(2, rawWarn) : 0;
|
|
18980
|
-
const stopThreshold = Math.max(1, options.stopThreshold ?? 25);
|
|
18981
|
-
return createMiddleware10({
|
|
18982
|
-
name: "RepeatedToolCallBreaker",
|
|
18983
|
-
stateSchema: BREAKER_STATE_SCHEMA,
|
|
18984
|
-
afterModel: {
|
|
18985
|
-
canJumpTo: ["end"],
|
|
18986
|
-
hook: (state) => {
|
|
18987
|
-
const lastAI = [...state.messages].reverse().find(AIMessage3.isInstance);
|
|
18988
|
-
if (!lastAI || !lastAI.tool_calls?.length) return void 0;
|
|
18989
|
-
const lastHuman = [...state.messages].reverse().find(HumanMessage3.isInstance);
|
|
18990
|
-
const runMarker = lastHuman?.id ?? "";
|
|
18991
|
-
const isNewRun = runMarker !== (state.repeatedToolCallRunMarker ?? "");
|
|
18992
|
-
const normalized = normalizeToolCalls(lastAI.tool_calls);
|
|
18993
|
-
const signature = stableStringify(normalized);
|
|
18994
|
-
const count = !isNewRun && signature === state.repeatedToolCallSignature ? (state.repeatedToolCallCount ?? 0) + 1 : 1;
|
|
18995
|
-
if (count >= stopThreshold) {
|
|
18996
|
-
const toolName2 = lastAI.tool_calls.length === 1 ? lastAI.tool_calls[0]?.name : void 0;
|
|
18997
|
-
throw new RepeatedToolCallError(toolName2, count, stopThreshold, signature.slice(0, 500));
|
|
18998
|
-
}
|
|
18999
|
-
return {
|
|
19000
|
-
repeatedToolCallSignature: signature,
|
|
19001
|
-
repeatedToolCallCount: count,
|
|
19002
|
-
repeatedToolCallRunMarker: runMarker,
|
|
19003
|
-
repeatedToolCallMemberSignatures: normalized.map((call) => stableStringify(call))
|
|
19004
|
-
};
|
|
19005
|
-
}
|
|
19006
|
-
},
|
|
19007
|
-
wrapToolCall: async (request, handler) => {
|
|
19008
|
-
const state = request.state;
|
|
19009
|
-
const count = state.repeatedToolCallCount ?? 0;
|
|
19010
|
-
const members = state.repeatedToolCallMemberSignatures ?? [];
|
|
19011
|
-
const current = stableStringify({ name: request.toolCall.name ?? "", args: request.toolCall.args ?? {} });
|
|
19012
|
-
if (warnThreshold > 0 && count >= warnThreshold && members.includes(current)) {
|
|
19013
|
-
return new ToolMessage4({
|
|
19014
|
-
name: request.toolCall.name,
|
|
19015
|
-
tool_call_id: request.toolCall.id ?? "repeated-tool-call",
|
|
19016
|
-
status: "error",
|
|
19017
|
-
content: JSON.stringify({
|
|
19018
|
-
success: false,
|
|
19019
|
-
code: "REPEATED_TOOL_CALL",
|
|
19020
|
-
error: `You have already called '${request.toolCall.name}' with identical arguments ${count} times. The result will not change. Do not call it again \u2014 use the result already in context and take the next action (edit, re-run with different input, or finish).`
|
|
19021
|
-
})
|
|
19022
|
-
});
|
|
19023
|
-
}
|
|
19024
|
-
return handler(request);
|
|
19025
|
-
}
|
|
19600
|
+
function ensurePatchToolCallsMiddleware(middleware) {
|
|
19601
|
+
const matches = middleware.filter((candidate) => candidate.name === "patchToolCallsMiddleware");
|
|
19602
|
+
if (matches.length === 0) return [createPatchToolCallsMiddleware(), ...middleware];
|
|
19603
|
+
if (matches.length === 1) return middleware;
|
|
19604
|
+
let kept = false;
|
|
19605
|
+
return middleware.filter((candidate) => {
|
|
19606
|
+
if (candidate.name !== "patchToolCallsMiddleware") return true;
|
|
19607
|
+
if (kept) return false;
|
|
19608
|
+
kept = true;
|
|
19609
|
+
return true;
|
|
19026
19610
|
});
|
|
19027
19611
|
}
|
|
19028
19612
|
|
|
19029
19613
|
// src/agent_lattice/builders/commonMiddleware.ts
|
|
19030
|
-
import { summarizationMiddleware
|
|
19614
|
+
import { summarizationMiddleware } from "langchain";
|
|
19031
19615
|
|
|
19032
19616
|
// src/agent_lattice/builders/CustomMiddlewareRegistry.ts
|
|
19033
19617
|
var CustomMiddlewareRegistry = class {
|
|
@@ -19118,8 +19702,8 @@ function createSandboxResolver(getSandboxFromConfig) {
|
|
|
19118
19702
|
}
|
|
19119
19703
|
|
|
19120
19704
|
// src/middlewares/evalMiddleware.ts
|
|
19121
|
-
import { createMiddleware as
|
|
19122
|
-
import { z as
|
|
19705
|
+
import { createMiddleware as createMiddleware12, tool as tool39 } from "langchain";
|
|
19706
|
+
import { z as z44 } from "zod";
|
|
19123
19707
|
import { v4 as uuidv43 } from "uuid";
|
|
19124
19708
|
|
|
19125
19709
|
// src/eval_lattice/EvalRunnerHolder.ts
|
|
@@ -19298,24 +19882,6 @@ Use read_eval get_run_results (compact by default) for multiple runs and present
|
|
|
19298
19882
|
` }
|
|
19299
19883
|
};
|
|
19300
19884
|
|
|
19301
|
-
// src/tool_lattice/withToolTimeout.ts
|
|
19302
|
-
function withToolTimeout(executor, timeoutMs = 18e4) {
|
|
19303
|
-
return async (input, exeConfig) => {
|
|
19304
|
-
return new Promise((resolve4, reject) => {
|
|
19305
|
-
const timer = setTimeout(() => {
|
|
19306
|
-
reject(new Error(`Tool execution timed out after ${timeoutMs}ms`));
|
|
19307
|
-
}, timeoutMs);
|
|
19308
|
-
executor(input, exeConfig).then((result) => {
|
|
19309
|
-
clearTimeout(timer);
|
|
19310
|
-
resolve4(result);
|
|
19311
|
-
}).catch((err) => {
|
|
19312
|
-
clearTimeout(timer);
|
|
19313
|
-
reject(err);
|
|
19314
|
-
});
|
|
19315
|
-
});
|
|
19316
|
-
};
|
|
19317
|
-
}
|
|
19318
|
-
|
|
19319
19885
|
// src/middlewares/evalMiddleware.ts
|
|
19320
19886
|
var RUN_EVAL_SYNC_WAIT_MS = 15e4;
|
|
19321
19887
|
function getStore() {
|
|
@@ -19364,8 +19930,8 @@ async function runWithResults(tid, store2, svc, run, runnerAlive) {
|
|
|
19364
19930
|
return { ...run, runnerAlive, results };
|
|
19365
19931
|
}
|
|
19366
19932
|
function createReadEvalTool() {
|
|
19367
|
-
const schema6 =
|
|
19368
|
-
action:
|
|
19933
|
+
const schema6 = z44.object({
|
|
19934
|
+
action: z44.enum([
|
|
19369
19935
|
"list_projects",
|
|
19370
19936
|
"get_project",
|
|
19371
19937
|
"list_suites",
|
|
@@ -19377,13 +19943,13 @@ function createReadEvalTool() {
|
|
|
19377
19943
|
"get_run_results",
|
|
19378
19944
|
"get_project_report"
|
|
19379
19945
|
]).describe("Operation"),
|
|
19380
|
-
projectId:
|
|
19381
|
-
name:
|
|
19382
|
-
suiteId:
|
|
19383
|
-
caseId:
|
|
19384
|
-
runId:
|
|
19385
|
-
verbose:
|
|
19386
|
-
status:
|
|
19946
|
+
projectId: z44.string().optional(),
|
|
19947
|
+
name: z44.string().optional().describe("For list_projects \u2014 exact project name filter (names are unique per tenant). Use this instead of listing all projects."),
|
|
19948
|
+
suiteId: z44.string().optional(),
|
|
19949
|
+
caseId: z44.string().optional(),
|
|
19950
|
+
runId: z44.string().optional(),
|
|
19951
|
+
verbose: z44.boolean().optional().describe("For get_run_results \u2014 return full per-case results. Omit for a compact summary (counts + failing cases only)."),
|
|
19952
|
+
status: z44.string().optional().describe("Filter: running|completed|failed|aborted")
|
|
19387
19953
|
});
|
|
19388
19954
|
return tool39(
|
|
19389
19955
|
async (input, exeConfig) => {
|
|
@@ -19500,8 +20066,8 @@ function requireEvalVerifyDeclaration(evalVerifyLoaded) {
|
|
|
19500
20066
|
return void 0;
|
|
19501
20067
|
}
|
|
19502
20068
|
function createManageEvalTool() {
|
|
19503
|
-
const schema6 =
|
|
19504
|
-
action:
|
|
20069
|
+
const schema6 = z44.object({
|
|
20070
|
+
action: z44.enum([
|
|
19505
20071
|
"create_project",
|
|
19506
20072
|
"update_project",
|
|
19507
20073
|
"delete_project",
|
|
@@ -19512,24 +20078,24 @@ function createManageEvalTool() {
|
|
|
19512
20078
|
"update_case",
|
|
19513
20079
|
"delete_case"
|
|
19514
20080
|
]).describe("Operation"),
|
|
19515
|
-
projectId:
|
|
19516
|
-
name:
|
|
19517
|
-
description:
|
|
19518
|
-
judgeModelKey:
|
|
19519
|
-
concurrency:
|
|
19520
|
-
evalVerifyLoaded:
|
|
19521
|
-
targetAgentId:
|
|
19522
|
-
suiteId:
|
|
19523
|
-
caseId:
|
|
19524
|
-
inputMessage:
|
|
19525
|
-
inputFiles:
|
|
19526
|
-
steps:
|
|
19527
|
-
outputType:
|
|
19528
|
-
contentAssertion:
|
|
19529
|
-
rubrics:
|
|
19530
|
-
interruptPolicy:
|
|
19531
|
-
mode:
|
|
19532
|
-
value:
|
|
20081
|
+
projectId: z44.string().optional(),
|
|
20082
|
+
name: z44.string().optional(),
|
|
20083
|
+
description: z44.string().optional(),
|
|
20084
|
+
judgeModelKey: z44.string().optional(),
|
|
20085
|
+
concurrency: z44.number().optional(),
|
|
20086
|
+
evalVerifyLoaded: z44.boolean().optional().describe("Required on create_project: load the 'eval-verify' skill first via the skill tool (skill_name 'eval-verify'), then pass evalVerifyLoaded: true. Calls without evalVerifyLoaded: true fail. Never omit or pass false."),
|
|
20087
|
+
targetAgentId: z44.string().optional().describe("Optional for create_project \u2014 the agent this eval project verifies. Recorded in targetServerConfig so the agent's detail page can find its eval data without relying on project naming."),
|
|
20088
|
+
suiteId: z44.string().optional(),
|
|
20089
|
+
caseId: z44.string().optional(),
|
|
20090
|
+
inputMessage: z44.string().optional(),
|
|
20091
|
+
inputFiles: z44.record(z44.string()).optional(),
|
|
20092
|
+
steps: z44.array(z44.object({ agent_id: z44.string(), override_message: z44.string().optional() })).optional(),
|
|
20093
|
+
outputType: z44.enum(["file_content", "message_content"]).optional(),
|
|
20094
|
+
contentAssertion: z44.string().optional(),
|
|
20095
|
+
rubrics: z44.array(z44.object({ name: z44.string(), weight: z44.number(), description: z44.string() })).optional(),
|
|
20096
|
+
interruptPolicy: z44.object({
|
|
20097
|
+
mode: z44.enum(["stop", "auto-approve", "auto-reject", "canned-response"]).describe("stop=judge the pause; auto-approve/auto-reject/canned-response=resume the agent to test the flow after the human input"),
|
|
20098
|
+
value: z44.string().optional().describe("Response to inject (defaults: \u540C\u610F / \u62D2\u7EDD; required for canned-response)")
|
|
19533
20099
|
}).optional().describe("Optional for create_case/update_case \u2014 how HITL interrupts are handled")
|
|
19534
20100
|
});
|
|
19535
20101
|
return tool39(
|
|
@@ -19665,107 +20231,105 @@ Case: create_case(suiteId, inputMessage, steps, outputType, contentAssertion, in
|
|
|
19665
20231
|
);
|
|
19666
20232
|
}
|
|
19667
20233
|
function createRunEvalTool() {
|
|
19668
|
-
const schema6 =
|
|
19669
|
-
action:
|
|
19670
|
-
projectId:
|
|
19671
|
-
suiteIds:
|
|
19672
|
-
caseIds:
|
|
19673
|
-
runId:
|
|
19674
|
-
taskId:
|
|
19675
|
-
sleepMs:
|
|
19676
|
-
wait:
|
|
20234
|
+
const schema6 = z44.object({
|
|
20235
|
+
action: z44.enum(["start", "status", "resume", "abort"]).describe("Operation"),
|
|
20236
|
+
projectId: z44.string().optional().describe("Required for start"),
|
|
20237
|
+
suiteIds: z44.array(z44.string()).optional().describe("Optional for start \u2014 only run these suites (e.g. dev set only). Omit to run all."),
|
|
20238
|
+
caseIds: z44.array(z44.string()).optional().describe("Optional for start \u2014 only run these cases across the selected suites. Omit to run all cases in those suites."),
|
|
20239
|
+
runId: z44.string().optional().describe("Required for status, resume, abort"),
|
|
20240
|
+
taskId: z44.string().optional().describe("Optional for start \u2014 training task ID this run belongs to (round association)"),
|
|
20241
|
+
sleepMs: z44.number().int().min(0).max(12e4).optional().describe("Optional for status \u2014 sleep this many ms BEFORE checking the run, to pace polling (e.g. 15000 \u2192 30000 \u2192 60000 \u2192 120000). Omit to check immediately."),
|
|
20242
|
+
wait: z44.boolean().optional().describe("Optional for start \u2014 defaults to true: block synchronously (up to ~150s) and return final results in one call. Set false to return the runId immediately and poll.")
|
|
19677
20243
|
});
|
|
19678
20244
|
return tool39(
|
|
19679
|
-
|
|
19680
|
-
|
|
19681
|
-
|
|
19682
|
-
|
|
19683
|
-
|
|
19684
|
-
|
|
19685
|
-
|
|
19686
|
-
|
|
19687
|
-
|
|
19688
|
-
|
|
19689
|
-
|
|
19690
|
-
|
|
19691
|
-
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
data = sanitize({ runId, message: "Run started. Poll with run_eval status (backoff: 15s\u219230s\u219260s\u2192max 120s)." });
|
|
19695
|
-
break;
|
|
19696
|
-
}
|
|
19697
|
-
let timer;
|
|
19698
|
-
try {
|
|
19699
|
-
await Promise.race([
|
|
19700
|
-
svc.waitForRun(runId).catch(() => {
|
|
19701
|
-
}),
|
|
19702
|
-
new Promise((resolve4) => {
|
|
19703
|
-
timer = setTimeout(resolve4, RUN_EVAL_SYNC_WAIT_MS);
|
|
19704
|
-
})
|
|
19705
|
-
]);
|
|
19706
|
-
} finally {
|
|
19707
|
-
if (timer) clearTimeout(timer);
|
|
19708
|
-
}
|
|
19709
|
-
const run = await store2.getRunById(tid, runId);
|
|
19710
|
-
if (!run) return JSON.stringify({ success: false, error: "Run not found" });
|
|
19711
|
-
if (run.status === "running") {
|
|
19712
|
-
data = sanitize({
|
|
19713
|
-
runId,
|
|
19714
|
-
status: "running",
|
|
19715
|
-
runnerAlive: svc.isRunning(runId),
|
|
19716
|
-
message: `Run not finished within ${RUN_EVAL_SYNC_WAIT_MS / 1e3}s \u2014 poll with run_eval status(runId, sleepMs) (e.g. 15000, doubling up to 120000), or abort with run_eval abort.`
|
|
19717
|
-
});
|
|
19718
|
-
break;
|
|
19719
|
-
}
|
|
19720
|
-
data = sanitize({ synced: true, ...await runWithResults(tid, store2, svc, run, svc.isRunning(runId)) });
|
|
20245
|
+
async (input, exeConfig) => {
|
|
20246
|
+
const tid = tenantId(exeConfig);
|
|
20247
|
+
if (!tid) {
|
|
20248
|
+
return JSON.stringify({ success: false, error: "No tenant context. Agent must be invoked through gateway." });
|
|
20249
|
+
}
|
|
20250
|
+
try {
|
|
20251
|
+
const store2 = getStore();
|
|
20252
|
+
const svc = getEvalRunService();
|
|
20253
|
+
let data;
|
|
20254
|
+
switch (input.action) {
|
|
20255
|
+
case "start": {
|
|
20256
|
+
const ctx = workspaceContext(exeConfig);
|
|
20257
|
+
const runId = await svc.startRun(tid, input.projectId, input.suiteIds, input.caseIds, ctx, input.taskId);
|
|
20258
|
+
if (input.wait === false) {
|
|
20259
|
+
data = sanitize({ runId, message: "Run started. Poll with run_eval status (backoff: 15s\u219230s\u219260s\u2192max 120s)." });
|
|
19721
20260
|
break;
|
|
19722
20261
|
}
|
|
19723
|
-
|
|
19724
|
-
|
|
19725
|
-
|
|
19726
|
-
|
|
19727
|
-
|
|
19728
|
-
|
|
19729
|
-
|
|
19730
|
-
|
|
20262
|
+
let timer;
|
|
20263
|
+
try {
|
|
20264
|
+
await Promise.race([
|
|
20265
|
+
svc.waitForRun(runId).catch(() => {
|
|
20266
|
+
}),
|
|
20267
|
+
new Promise((resolve4) => {
|
|
20268
|
+
timer = setTimeout(resolve4, RUN_EVAL_SYNC_WAIT_MS);
|
|
20269
|
+
})
|
|
20270
|
+
]);
|
|
20271
|
+
} finally {
|
|
20272
|
+
if (timer) clearTimeout(timer);
|
|
19731
20273
|
}
|
|
19732
|
-
|
|
19733
|
-
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
});
|
|
19742
|
-
data = sanitize({
|
|
19743
|
-
...run,
|
|
19744
|
-
status: "failed",
|
|
19745
|
-
runnerAlive: false,
|
|
19746
|
-
message: "Run was orphaned \u2014 marked failed. Start a new run."
|
|
19747
|
-
});
|
|
19748
|
-
break;
|
|
19749
|
-
}
|
|
19750
|
-
data = sanitize(await runWithResults(tid, store2, svc, run, runnerAlive));
|
|
20274
|
+
const run = await store2.getRunById(tid, runId);
|
|
20275
|
+
if (!run) return JSON.stringify({ success: false, error: "Run not found" });
|
|
20276
|
+
if (run.status === "running") {
|
|
20277
|
+
data = sanitize({
|
|
20278
|
+
runId,
|
|
20279
|
+
status: "running",
|
|
20280
|
+
runnerAlive: svc.isRunning(runId),
|
|
20281
|
+
message: `Run not finished within ${RUN_EVAL_SYNC_WAIT_MS / 1e3}s \u2014 poll with run_eval status(runId, sleepMs) (e.g. 15000, doubling up to 120000), or abort with run_eval abort.`
|
|
20282
|
+
});
|
|
19751
20283
|
break;
|
|
19752
20284
|
}
|
|
19753
|
-
|
|
19754
|
-
|
|
19755
|
-
|
|
19756
|
-
|
|
19757
|
-
|
|
20285
|
+
data = sanitize({ synced: true, ...await runWithResults(tid, store2, svc, run, svc.isRunning(runId)) });
|
|
20286
|
+
break;
|
|
20287
|
+
}
|
|
20288
|
+
case "status": {
|
|
20289
|
+
if (input.sleepMs && input.sleepMs > 0) {
|
|
20290
|
+
await new Promise((resolve4) => setTimeout(resolve4, input.sleepMs));
|
|
20291
|
+
}
|
|
20292
|
+
const run = await store2.getRunById(tid, input.runId);
|
|
20293
|
+
if (!run) return JSON.stringify({ success: false, error: "Run not found" });
|
|
20294
|
+
data = sanitize({ ...run, runnerAlive: svc.isRunning(input.runId) });
|
|
20295
|
+
break;
|
|
20296
|
+
}
|
|
20297
|
+
case "resume": {
|
|
20298
|
+
const run = await store2.getRunById(tid, input.runId);
|
|
20299
|
+
if (!run) return JSON.stringify({ success: false, error: "Run not found" });
|
|
20300
|
+
const runnerAlive = svc.isRunning(input.runId);
|
|
20301
|
+
if (run.status === "running" && !runnerAlive) {
|
|
20302
|
+
await store2.updateRunStatus(tid, run.id, {
|
|
20303
|
+
status: "failed",
|
|
20304
|
+
error: "Gateway restarted \u2014 run orphaned",
|
|
20305
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
20306
|
+
});
|
|
20307
|
+
data = sanitize({
|
|
20308
|
+
...run,
|
|
20309
|
+
status: "failed",
|
|
20310
|
+
runnerAlive: false,
|
|
20311
|
+
message: "Run was orphaned \u2014 marked failed. Start a new run."
|
|
20312
|
+
});
|
|
19758
20313
|
break;
|
|
19759
20314
|
}
|
|
19760
|
-
|
|
19761
|
-
|
|
20315
|
+
data = sanitize(await runWithResults(tid, store2, svc, run, runnerAlive));
|
|
20316
|
+
break;
|
|
19762
20317
|
}
|
|
19763
|
-
|
|
19764
|
-
|
|
19765
|
-
|
|
20318
|
+
case "abort": {
|
|
20319
|
+
const run = await store2.getRunById(tid, input.runId);
|
|
20320
|
+
if (!run) return JSON.stringify({ success: false, error: "Run not found" });
|
|
20321
|
+
const ok = await svc.abortRun(input.runId);
|
|
20322
|
+
data = sanitize({ aborted: ok });
|
|
20323
|
+
break;
|
|
20324
|
+
}
|
|
20325
|
+
default:
|
|
20326
|
+
return JSON.stringify({ success: false, error: `Unknown action: ${input.action}` });
|
|
19766
20327
|
}
|
|
20328
|
+
return JSON.stringify({ success: true, data });
|
|
20329
|
+
} catch (e) {
|
|
20330
|
+
return JSON.stringify({ success: false, error: e.message });
|
|
19767
20331
|
}
|
|
19768
|
-
|
|
20332
|
+
},
|
|
19769
20333
|
{
|
|
19770
20334
|
name: "run_eval",
|
|
19771
20335
|
description: `Execute and manage evaluation runs.
|
|
@@ -19806,7 +20370,7 @@ var evalPlugin = {
|
|
|
19806
20370
|
defaultConfig: {}
|
|
19807
20371
|
},
|
|
19808
20372
|
skills: EVAL_SKILLS,
|
|
19809
|
-
middleware: () =>
|
|
20373
|
+
middleware: () => createMiddleware12({
|
|
19810
20374
|
name: "EvalMiddleware",
|
|
19811
20375
|
tools: [createReadEvalTool(), createManageEvalTool(), createRunEvalTool()]
|
|
19812
20376
|
})
|
|
@@ -20348,7 +20912,7 @@ function getPluginDeploymentService() {
|
|
|
20348
20912
|
import { createHash as createHash3 } from "crypto";
|
|
20349
20913
|
|
|
20350
20914
|
// src/sandbox_plugin/jsonSchemaToZod.ts
|
|
20351
|
-
import { z as
|
|
20915
|
+
import { z as z45 } from "zod";
|
|
20352
20916
|
function isRecord6(value) {
|
|
20353
20917
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20354
20918
|
}
|
|
@@ -20368,25 +20932,25 @@ function jsonSchemaToZod(schema6) {
|
|
|
20368
20932
|
const child = jsonSchemaToZod(sub);
|
|
20369
20933
|
shape[key5] = required.includes(key5) ? child : child.optional();
|
|
20370
20934
|
}
|
|
20371
|
-
return withDescription(
|
|
20935
|
+
return withDescription(z45.object(shape), schema6);
|
|
20372
20936
|
}
|
|
20373
20937
|
case "array": {
|
|
20374
|
-
const item = schema6.items === void 0 ?
|
|
20375
|
-
return withDescription(
|
|
20938
|
+
const item = schema6.items === void 0 ? z45.unknown() : jsonSchemaToZod(schema6.items);
|
|
20939
|
+
return withDescription(z45.array(item), schema6);
|
|
20376
20940
|
}
|
|
20377
20941
|
case "string": {
|
|
20378
20942
|
if (Array.isArray(schema6.enum) && schema6.enum.length > 0) {
|
|
20379
20943
|
const values = schema6.enum.filter((x) => typeof x === "string");
|
|
20380
|
-
return withDescription(
|
|
20944
|
+
return withDescription(z45.enum(values), schema6);
|
|
20381
20945
|
}
|
|
20382
|
-
return withDescription(
|
|
20946
|
+
return withDescription(z45.string(), schema6);
|
|
20383
20947
|
}
|
|
20384
20948
|
case "number":
|
|
20385
|
-
return withDescription(
|
|
20949
|
+
return withDescription(z45.number(), schema6);
|
|
20386
20950
|
case "integer":
|
|
20387
|
-
return withDescription(
|
|
20951
|
+
return withDescription(z45.number().int(), schema6);
|
|
20388
20952
|
case "boolean":
|
|
20389
|
-
return withDescription(
|
|
20953
|
+
return withDescription(z45.boolean(), schema6);
|
|
20390
20954
|
default:
|
|
20391
20955
|
throw new Error(`unsupported JSON Schema type: ${String(type)}`);
|
|
20392
20956
|
}
|
|
@@ -20666,7 +21230,7 @@ function validateSandboxPluginManifest(args) {
|
|
|
20666
21230
|
}
|
|
20667
21231
|
|
|
20668
21232
|
// src/sandbox_plugin/SandboxPluginCompiler.ts
|
|
20669
|
-
import { createMiddleware as
|
|
21233
|
+
import { createMiddleware as createMiddleware13, tool as tool40 } from "langchain";
|
|
20670
21234
|
|
|
20671
21235
|
// src/connection/PluginConnectionResolver.ts
|
|
20672
21236
|
async function resolvePluginConnections(type, config, scope) {
|
|
@@ -21021,7 +21585,7 @@ function compileSandboxPlugin(args) {
|
|
|
21021
21585
|
{ name: t.name, description: t.description, schema: jsonSchemaToZod(t.schema) }
|
|
21022
21586
|
)
|
|
21023
21587
|
);
|
|
21024
|
-
return
|
|
21588
|
+
return createMiddleware13({ name: `SandboxPlugin:${manifest.type}`, tools });
|
|
21025
21589
|
},
|
|
21026
21590
|
skills: manifest.skills,
|
|
21027
21591
|
agents: manifest.agents
|
|
@@ -21897,8 +22461,8 @@ var CapabilityToolRegistry = class {
|
|
|
21897
22461
|
};
|
|
21898
22462
|
|
|
21899
22463
|
// src/middlewares/capabilityGuardMiddleware.ts
|
|
21900
|
-
import { ToolMessage as
|
|
21901
|
-
import { createMiddleware as
|
|
22464
|
+
import { ToolMessage as ToolMessage6 } from "@langchain/core/messages";
|
|
22465
|
+
import { createMiddleware as createMiddleware14 } from "langchain";
|
|
21902
22466
|
function isRecord11(value) {
|
|
21903
22467
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21904
22468
|
}
|
|
@@ -21956,7 +22520,7 @@ async function standardConnectionAllowed(request, capabilityType, config) {
|
|
|
21956
22520
|
}
|
|
21957
22521
|
}
|
|
21958
22522
|
function denialMessage(toolCall, denial) {
|
|
21959
|
-
return new
|
|
22523
|
+
return new ToolMessage6({
|
|
21960
22524
|
content: JSON.stringify({ success: false, ...denial }),
|
|
21961
22525
|
name: toolCall.name,
|
|
21962
22526
|
tool_call_id: toolCall.id ?? "",
|
|
@@ -21964,7 +22528,7 @@ function denialMessage(toolCall, denial) {
|
|
|
21964
22528
|
});
|
|
21965
22529
|
}
|
|
21966
22530
|
function createCapabilityGuardMiddleware(registry4) {
|
|
21967
|
-
return
|
|
22531
|
+
return createMiddleware14({
|
|
21968
22532
|
name: "CapabilityGuardMiddleware",
|
|
21969
22533
|
wrapToolCall: async (request, handler) => {
|
|
21970
22534
|
const toolName2 = request.toolCall.name;
|
|
@@ -22199,24 +22763,21 @@ async function createCommonMiddlewares(middlewareConfigs, filesystemBackend, fsI
|
|
|
22199
22763
|
middlewares.push(createCapabilityGuardMiddleware(capabilityTools));
|
|
22200
22764
|
middlewares.push(createModelSelectorMiddleware());
|
|
22201
22765
|
middlewares.push(createPatchToolCallsMiddleware());
|
|
22202
|
-
const
|
|
22203
|
-
|
|
22204
|
-
|
|
22205
|
-
|
|
22206
|
-
|
|
22207
|
-
|
|
22208
|
-
|
|
22209
|
-
|
|
22210
|
-
|
|
22211
|
-
}
|
|
22212
|
-
if (loopBreaker.skillRunLimit > 0) {
|
|
22213
|
-
middlewares.push(toolCallLimitMiddleware({ toolName: "skill", runLimit: loopBreaker.skillRunLimit, exitBehavior: "error" }));
|
|
22214
|
-
}
|
|
22766
|
+
const governance = readRunGovernanceConfig();
|
|
22767
|
+
middlewares.push(createRunGovernanceMiddleware({
|
|
22768
|
+
maxModelCalls: governance.maxModelCalls,
|
|
22769
|
+
wrapUpReserve: governance.wrapUpReserve,
|
|
22770
|
+
repeatWarn: governance.repeatWarn,
|
|
22771
|
+
repeatStop: governance.repeatStop,
|
|
22772
|
+
maxToolCalls: governance.maxToolCalls,
|
|
22773
|
+
maxSkillCalls: governance.maxSkillCalls,
|
|
22774
|
+
pollableTools: ["run_eval"]
|
|
22775
|
+
}));
|
|
22215
22776
|
if (model) {
|
|
22216
22777
|
middlewares.push(
|
|
22217
22778
|
summarizationMiddleware({
|
|
22218
22779
|
model,
|
|
22219
|
-
trigger: { tokens:
|
|
22780
|
+
trigger: { tokens: resolveSummarizationTriggerTokens(model) },
|
|
22220
22781
|
keep: { messages: 6 }
|
|
22221
22782
|
})
|
|
22222
22783
|
);
|
|
@@ -22586,12 +23147,12 @@ import {
|
|
|
22586
23147
|
} from "langchain";
|
|
22587
23148
|
|
|
22588
23149
|
// src/deep_agent_new/middleware/subagents.ts
|
|
22589
|
-
import { z as
|
|
23150
|
+
import { z as z47 } from "zod/v3";
|
|
22590
23151
|
import {
|
|
22591
|
-
createMiddleware as
|
|
23152
|
+
createMiddleware as createMiddleware15,
|
|
22592
23153
|
createAgent as createAgent2,
|
|
22593
23154
|
tool as tool41,
|
|
22594
|
-
ToolMessage as
|
|
23155
|
+
ToolMessage as ToolMessage8,
|
|
22595
23156
|
humanInTheLoopMiddleware
|
|
22596
23157
|
} from "langchain";
|
|
22597
23158
|
import { Command as Command3, getCurrentTaskInput as getCurrentTaskInput2, GraphInterrupt } from "@langchain/langgraph";
|
|
@@ -23290,7 +23851,7 @@ function normalizeAgentInterrupts(state, threadId) {
|
|
|
23290
23851
|
}
|
|
23291
23852
|
|
|
23292
23853
|
// src/services/Agent.ts
|
|
23293
|
-
import { AIMessage as
|
|
23854
|
+
import { AIMessage as AIMessage5, filterMessages, HumanMessage as HumanMessage4, SystemMessage as SystemMessage2, ToolMessage as ToolMessage7 } from "langchain";
|
|
23294
23855
|
|
|
23295
23856
|
// src/chunk_buffer_lattice/types.ts
|
|
23296
23857
|
var ThreadEndError = class extends Error {
|
|
@@ -24284,7 +24845,7 @@ registerChunkBuffer("default", buffer);
|
|
|
24284
24845
|
import { v4 as v42 } from "uuid";
|
|
24285
24846
|
|
|
24286
24847
|
// src/capability/CapabilityRuntimeResolver.ts
|
|
24287
|
-
import { z as
|
|
24848
|
+
import { z as z46 } from "zod";
|
|
24288
24849
|
|
|
24289
24850
|
// src/capability/CapabilityBundleMerger.ts
|
|
24290
24851
|
import { createHash as createHash4 } from "crypto";
|
|
@@ -25077,9 +25638,9 @@ var CapabilityRuntimeResolutionError = class extends Error {
|
|
|
25077
25638
|
this.actualRevision = context.actualRevision;
|
|
25078
25639
|
}
|
|
25079
25640
|
};
|
|
25080
|
-
var bundleIdsSchema =
|
|
25641
|
+
var bundleIdsSchema = z46.array(z46.string().uuid()).superRefine((ids, context) => {
|
|
25081
25642
|
if (new Set(ids).size !== ids.length) {
|
|
25082
|
-
context.addIssue({ code:
|
|
25643
|
+
context.addIssue({ code: z46.ZodIssueCode.custom, message: "Bundle IDs must be unique" });
|
|
25083
25644
|
}
|
|
25084
25645
|
});
|
|
25085
25646
|
function projectBundleIds(config) {
|
|
@@ -25386,12 +25947,12 @@ function stripDelegatedWorkerContext(target) {
|
|
|
25386
25947
|
// src/services/DelegationContext.ts
|
|
25387
25948
|
var DELEGATION_CONTEXT_TOKEN = Symbol("delegation-context");
|
|
25388
25949
|
var delegationContextSecret = Object.freeze({});
|
|
25389
|
-
function
|
|
25950
|
+
function positiveInt2(value, fallback) {
|
|
25390
25951
|
const parsed = Number(value);
|
|
25391
25952
|
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
25392
25953
|
}
|
|
25393
|
-
var DELEGATION_MAX_DEPTH =
|
|
25394
|
-
var DELEGATION_MAX_CHILDREN_PER_ROOT =
|
|
25954
|
+
var DELEGATION_MAX_DEPTH = positiveInt2(process.env.DELEGATION_MAX_DEPTH, 3);
|
|
25955
|
+
var DELEGATION_MAX_CHILDREN_PER_ROOT = positiveInt2(
|
|
25395
25956
|
process.env.DELEGATION_MAX_CHILDREN_PER_ROOT,
|
|
25396
25957
|
20
|
|
25397
25958
|
);
|
|
@@ -25727,7 +26288,7 @@ var RESERVED_CALLER_RUN_KEYS = /* @__PURE__ */ new Set([
|
|
|
25727
26288
|
"delegatedTaskId",
|
|
25728
26289
|
"taskExecutionRole"
|
|
25729
26290
|
]);
|
|
25730
|
-
function
|
|
26291
|
+
function isPlainRecord2(value) {
|
|
25731
26292
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
25732
26293
|
const prototype = Object.getPrototypeOf(value);
|
|
25733
26294
|
return prototype === Object.prototype || prototype === null;
|
|
@@ -25928,7 +26489,7 @@ function trustedCapabilityRevision(value) {
|
|
|
25928
26489
|
return requireTrustedCapabilityRevision(value);
|
|
25929
26490
|
}
|
|
25930
26491
|
function finalAiMessageMarker(state) {
|
|
25931
|
-
if (!
|
|
26492
|
+
if (!isPlainRecord2(state) || !isPlainRecord2(state.values) || !Array.isArray(state.values.messages)) {
|
|
25932
26493
|
return void 0;
|
|
25933
26494
|
}
|
|
25934
26495
|
const messages = state.values.messages;
|
|
@@ -25950,44 +26511,44 @@ function finalAiMessageMarker(state) {
|
|
|
25950
26511
|
return { index, totalMessageCount: messages.length, id, text };
|
|
25951
26512
|
}
|
|
25952
26513
|
function checkpointIdFromSnapshot(state) {
|
|
25953
|
-
if (!
|
|
26514
|
+
if (!isPlainRecord2(state)) return void 0;
|
|
25954
26515
|
const config = state.config;
|
|
25955
|
-
if (
|
|
26516
|
+
if (isPlainRecord2(config)) {
|
|
25956
26517
|
const configurable = config.configurable;
|
|
25957
|
-
if (
|
|
26518
|
+
if (isPlainRecord2(configurable)) {
|
|
25958
26519
|
const checkpointId = configurable.checkpoint_id;
|
|
25959
26520
|
if (typeof checkpointId === "string" && checkpointId.length > 0) return checkpointId;
|
|
25960
26521
|
}
|
|
25961
26522
|
}
|
|
25962
26523
|
const checkpoint = state.checkpoint;
|
|
25963
|
-
if (
|
|
26524
|
+
if (isPlainRecord2(checkpoint)) {
|
|
25964
26525
|
const checkpointId = checkpoint.checkpoint_id;
|
|
25965
26526
|
if (typeof checkpointId === "string" && checkpointId.length > 0) return checkpointId;
|
|
25966
26527
|
}
|
|
25967
26528
|
return void 0;
|
|
25968
26529
|
}
|
|
25969
26530
|
function checkpointRunIdFromSnapshot(state) {
|
|
25970
|
-
if (!
|
|
26531
|
+
if (!isPlainRecord2(state)) return void 0;
|
|
25971
26532
|
const config = state.config;
|
|
25972
|
-
if (
|
|
26533
|
+
if (isPlainRecord2(config)) {
|
|
25973
26534
|
const configurable = config.configurable;
|
|
25974
|
-
if (
|
|
26535
|
+
if (isPlainRecord2(configurable)) {
|
|
25975
26536
|
const runId = configurable.run_id;
|
|
25976
26537
|
if (typeof runId === "string" && runId.length > 0) return runId;
|
|
25977
26538
|
}
|
|
25978
26539
|
const configMetadata = config.metadata;
|
|
25979
|
-
if (
|
|
26540
|
+
if (isPlainRecord2(configMetadata)) {
|
|
25980
26541
|
const runId = configMetadata.run_id;
|
|
25981
26542
|
if (typeof runId === "string" && runId.length > 0) return runId;
|
|
25982
26543
|
}
|
|
25983
26544
|
}
|
|
25984
26545
|
const metadata = state.metadata;
|
|
25985
|
-
if (
|
|
26546
|
+
if (isPlainRecord2(metadata)) {
|
|
25986
26547
|
const runId = metadata.run_id;
|
|
25987
26548
|
if (typeof runId === "string" && runId.length > 0) return runId;
|
|
25988
26549
|
}
|
|
25989
26550
|
const checkpoint = state.checkpoint;
|
|
25990
|
-
if (
|
|
26551
|
+
if (isPlainRecord2(checkpoint)) {
|
|
25991
26552
|
const runId = checkpoint.run_id;
|
|
25992
26553
|
if (typeof runId === "string" && runId.length > 0) return runId;
|
|
25993
26554
|
}
|
|
@@ -25999,7 +26560,7 @@ function normalizeBaseCheckpointId(value) {
|
|
|
25999
26560
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
26000
26561
|
}
|
|
26001
26562
|
function isInterruptResumeMap(value) {
|
|
26002
|
-
if (!
|
|
26563
|
+
if (!isPlainRecord2(value)) return false;
|
|
26003
26564
|
const keys = Object.keys(value);
|
|
26004
26565
|
return keys.length > 0 && keys.every((key5) => isOfficialInterruptId(key5));
|
|
26005
26566
|
}
|
|
@@ -26070,11 +26631,11 @@ function executeRunInputMessages(input, fallbackMessageId) {
|
|
|
26070
26631
|
};
|
|
26071
26632
|
switch (message.role) {
|
|
26072
26633
|
case "system":
|
|
26073
|
-
return new
|
|
26634
|
+
return new SystemMessage2(fields);
|
|
26074
26635
|
case "assistant":
|
|
26075
|
-
return new
|
|
26636
|
+
return new AIMessage5(fields);
|
|
26076
26637
|
case "tool":
|
|
26077
|
-
return new
|
|
26638
|
+
return new ToolMessage7({
|
|
26078
26639
|
...fields,
|
|
26079
26640
|
tool_call_id: typeof message.metadata?.tool_call_id === "string" ? message.metadata.tool_call_id : ""
|
|
26080
26641
|
});
|
|
@@ -26090,19 +26651,19 @@ function executeRunInputMessages(input, fallbackMessageId) {
|
|
|
26090
26651
|
return [new HumanMessage4({ id, content: input.message })];
|
|
26091
26652
|
}
|
|
26092
26653
|
function statusFromSnapshot(state) {
|
|
26093
|
-
if (!
|
|
26094
|
-
if (Array.isArray(state.tasks) && state.tasks.some((task) =>
|
|
26095
|
-
if (Array.isArray(state.tasks) && state.tasks.some((task) =>
|
|
26654
|
+
if (!isPlainRecord2(state)) return "error" /* ERROR */;
|
|
26655
|
+
if (Array.isArray(state.tasks) && state.tasks.some((task) => isPlainRecord2(task) && Array.isArray(task.interrupts) && task.interrupts.length > 0)) return "interrupted" /* INTERRUPTED */;
|
|
26656
|
+
if (Array.isArray(state.tasks) && state.tasks.some((task) => isPlainRecord2(task) && task.error !== void 0)) return "error" /* ERROR */;
|
|
26096
26657
|
if (Array.isArray(state.next) && state.next.length > 0) return "busy" /* BUSY */;
|
|
26097
26658
|
return "idle" /* IDLE */;
|
|
26098
26659
|
}
|
|
26099
26660
|
var MAX_EXECUTION_ERROR_LENGTH = 2e3;
|
|
26100
26661
|
function executionErrorFromSnapshot(state) {
|
|
26101
|
-
if (!
|
|
26662
|
+
if (!isPlainRecord2(state) || !Array.isArray(state.tasks)) return void 0;
|
|
26102
26663
|
for (const task of state.tasks) {
|
|
26103
|
-
if (!
|
|
26664
|
+
if (!isPlainRecord2(task) || task.error === void 0 || task.error === null) continue;
|
|
26104
26665
|
const raw = task.error;
|
|
26105
|
-
const message = typeof raw === "string" ? raw : raw instanceof Error ? raw.message :
|
|
26666
|
+
const message = typeof raw === "string" ? raw : raw instanceof Error ? raw.message : isPlainRecord2(raw) && typeof raw.message === "string" ? raw.message : (() => {
|
|
26106
26667
|
try {
|
|
26107
26668
|
return JSON.stringify(raw);
|
|
26108
26669
|
} catch {
|
|
@@ -26235,7 +26796,8 @@ var Agent = class {
|
|
|
26235
26796
|
command ? new Command2(command) : { ...stateInput, "x-tenant-id": this.tenant_id },
|
|
26236
26797
|
{
|
|
26237
26798
|
context: {
|
|
26238
|
-
runConfig: executionRunConfig
|
|
26799
|
+
runConfig: executionRunConfig,
|
|
26800
|
+
runGovernance: this.runGovernanceContext(runId, executionRunConfig)
|
|
26239
26801
|
},
|
|
26240
26802
|
configurable: {
|
|
26241
26803
|
...executionRunConfig,
|
|
@@ -26318,7 +26880,8 @@ var Agent = class {
|
|
|
26318
26880
|
},
|
|
26319
26881
|
{
|
|
26320
26882
|
context: {
|
|
26321
|
-
runConfig: executionRunConfig
|
|
26883
|
+
runConfig: executionRunConfig,
|
|
26884
|
+
runGovernance: this.runGovernanceContext(runId, executionRunConfig)
|
|
26322
26885
|
},
|
|
26323
26886
|
configurable: {
|
|
26324
26887
|
...executionRunConfig,
|
|
@@ -26769,7 +27332,7 @@ var Agent = class {
|
|
|
26769
27332
|
*/
|
|
26770
27333
|
async [TRUSTED_AGENT_DISPATCH](queueMessage, options) {
|
|
26771
27334
|
this.rejectDelegatedQueueAuthority(queueMessage);
|
|
26772
|
-
if (!
|
|
27335
|
+
if (!isPlainRecord2(options) || !hasExactKeys(options, ["trustedRunContext", "executionMode"]) || options.executionMode !== "followup") {
|
|
26773
27336
|
throw invalidTrustedRunContext();
|
|
26774
27337
|
}
|
|
26775
27338
|
this.validateTrustedRunContext(options.trustedRunContext, queueMessage.input.id);
|
|
@@ -26803,14 +27366,14 @@ var Agent = class {
|
|
|
26803
27366
|
const markedRows = rows.filter((row2) => row2.trusted_run_context !== void 0 || row2.execution_mode !== void 0);
|
|
26804
27367
|
if (markedRows.length === 0) {
|
|
26805
27368
|
const revisions = rows.map((row2) => {
|
|
26806
|
-
const config =
|
|
27369
|
+
const config = isPlainRecord2(row2.custom_run_config) ? row2.custom_run_config : {};
|
|
26807
27370
|
return typeof config.capabilityRuntimeRevision === "string" ? config.capabilityRuntimeRevision : void 0;
|
|
26808
27371
|
});
|
|
26809
27372
|
if (new Set(revisions).size > 1) {
|
|
26810
27373
|
throw new Error("Processing rows have inconsistent capability runtime revisions");
|
|
26811
27374
|
}
|
|
26812
27375
|
return {
|
|
26813
|
-
customRunConfig:
|
|
27376
|
+
customRunConfig: isPlainRecord2(rows[0].custom_run_config) ? rows[0].custom_run_config : {},
|
|
26814
27377
|
inputMessageId: rows[0].id,
|
|
26815
27378
|
consumedInputMessageIds: rows.map(({ id }) => id)
|
|
26816
27379
|
};
|
|
@@ -26831,7 +27394,7 @@ var Agent = class {
|
|
|
26831
27394
|
throw new TrustedRunContextRecoveryError("Trusted processing context is invalid");
|
|
26832
27395
|
}
|
|
26833
27396
|
return {
|
|
26834
|
-
customRunConfig:
|
|
27397
|
+
customRunConfig: isPlainRecord2(row.custom_run_config) ? row.custom_run_config : {},
|
|
26835
27398
|
trustedRunContext,
|
|
26836
27399
|
inputMessageId: row.id,
|
|
26837
27400
|
consumedInputMessageIds: [row.id]
|
|
@@ -26886,8 +27449,21 @@ var Agent = class {
|
|
|
26886
27449
|
}
|
|
26887
27450
|
return base;
|
|
26888
27451
|
}
|
|
27452
|
+
runGovernanceContext(runId, executionRunConfig) {
|
|
27453
|
+
const config = readRunGovernanceConfig();
|
|
27454
|
+
const execution = isPlainRecord2(executionRunConfig.execution) ? executionRunConfig.execution : void 0;
|
|
27455
|
+
const taskId = typeof executionRunConfig.taskId === "string" ? executionRunConfig.taskId : typeof execution?.taskId === "string" ? execution.taskId : "";
|
|
27456
|
+
const isTask = taskId.length > 0;
|
|
27457
|
+
return {
|
|
27458
|
+
runId,
|
|
27459
|
+
source: isTask ? "task" : "chat",
|
|
27460
|
+
budget: {
|
|
27461
|
+
maxModelCalls: resolveRequestedMaxModelCalls(executionRunConfig.budget, config)
|
|
27462
|
+
}
|
|
27463
|
+
};
|
|
27464
|
+
}
|
|
26889
27465
|
observabilityCallbacks(runConfig, runId, source) {
|
|
26890
|
-
const execution =
|
|
27466
|
+
const execution = isPlainRecord2(runConfig.execution) ? runConfig.execution : void 0;
|
|
26891
27467
|
const taskId = typeof runConfig.taskId === "string" ? runConfig.taskId : execution && typeof execution.taskId === "string" ? execution.taskId : void 0;
|
|
26892
27468
|
const callbacks = resolveObservabilityCallbacks({
|
|
26893
27469
|
tenantId: this.tenant_id,
|
|
@@ -26928,11 +27504,11 @@ var Agent = class {
|
|
|
26928
27504
|
};
|
|
26929
27505
|
switch (message.role) {
|
|
26930
27506
|
case "system":
|
|
26931
|
-
return new
|
|
27507
|
+
return new SystemMessage2(fields);
|
|
26932
27508
|
case "assistant":
|
|
26933
|
-
return new
|
|
27509
|
+
return new AIMessage5(fields);
|
|
26934
27510
|
case "tool":
|
|
26935
|
-
return new
|
|
27511
|
+
return new ToolMessage7({
|
|
26936
27512
|
...fields,
|
|
26937
27513
|
tool_call_id: typeof message.metadata?.tool_call_id === "string" ? message.metadata.tool_call_id : ""
|
|
26938
27514
|
});
|
|
@@ -27137,7 +27713,10 @@ var Agent = class {
|
|
|
27137
27713
|
const result = await runnable_agent.invoke(
|
|
27138
27714
|
inputMessage.command ? new Command2(inputMessage.command) : { ...rest, messages, "x-tenant-id": this.tenant_id },
|
|
27139
27715
|
{
|
|
27140
|
-
context: {
|
|
27716
|
+
context: {
|
|
27717
|
+
runConfig: executionRunConfig,
|
|
27718
|
+
runGovernance: this.runGovernanceContext(runId, executionRunConfig)
|
|
27719
|
+
},
|
|
27141
27720
|
configurable: {
|
|
27142
27721
|
...executionRunConfig,
|
|
27143
27722
|
run_id: runId,
|
|
@@ -27550,7 +28129,8 @@ var Agent = class {
|
|
|
27550
28129
|
null,
|
|
27551
28130
|
{
|
|
27552
28131
|
context: {
|
|
27553
|
-
runConfig: executionRunConfig
|
|
28132
|
+
runConfig: executionRunConfig,
|
|
28133
|
+
runGovernance: this.runGovernanceContext(runId, executionRunConfig)
|
|
27554
28134
|
},
|
|
27555
28135
|
configurable: {
|
|
27556
28136
|
...executionRunConfig,
|
|
@@ -29269,11 +29849,24 @@ var EXCLUDED_STATE_KEYS = [
|
|
|
29269
29849
|
"repeatedToolCallSignature",
|
|
29270
29850
|
"repeatedToolCallCount",
|
|
29271
29851
|
"repeatedToolCallRunMarker",
|
|
29272
|
-
"repeatedToolCallMemberSignatures"
|
|
29852
|
+
"repeatedToolCallMemberSignatures",
|
|
29853
|
+
"governRunId",
|
|
29854
|
+
"governModelCalls",
|
|
29855
|
+
"governToolRounds",
|
|
29856
|
+
"governToolCalls",
|
|
29857
|
+
"governSkillCalls",
|
|
29858
|
+
"governWarned",
|
|
29859
|
+
"governNotice",
|
|
29860
|
+
"governLastSignature",
|
|
29861
|
+
"governRepeatCount",
|
|
29862
|
+
"governTerminationReason",
|
|
29863
|
+
"governStopSummary",
|
|
29864
|
+
"governForceFinal",
|
|
29865
|
+
"governForcedRounds"
|
|
29273
29866
|
];
|
|
29274
29867
|
var DEFAULT_GENERAL_PURPOSE_DESCRIPTION = "General-purpose agent for researching complex questions, searching for files and content, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you. This agent has access to all tools as the main agent.";
|
|
29275
29868
|
function createGeneralPurposeAgent(options) {
|
|
29276
|
-
const middleware = [...options.middleware];
|
|
29869
|
+
const middleware = ensurePatchToolCallsMiddleware([...options.middleware]);
|
|
29277
29870
|
if (options.interruptOn) {
|
|
29278
29871
|
middleware.push(humanInTheLoopMiddleware({ interruptOn: options.interruptOn }));
|
|
29279
29872
|
}
|
|
@@ -29282,7 +29875,7 @@ function createGeneralPurposeAgent(options) {
|
|
|
29282
29875
|
systemPrompt: DEFAULT_SUBAGENT_PROMPT,
|
|
29283
29876
|
tools: options.tools,
|
|
29284
29877
|
middleware,
|
|
29285
|
-
stateSchema: withToolCallLimitStateSchema(),
|
|
29878
|
+
stateSchema: withRunGovernanceStateSchema(withToolCallLimitStateSchema()),
|
|
29286
29879
|
checkpointer: getCheckpointSaver("default"),
|
|
29287
29880
|
name: "general-purpose"
|
|
29288
29881
|
});
|
|
@@ -29444,7 +30037,7 @@ function returnCommandWithStateUpdate(result, toolCallId) {
|
|
|
29444
30037
|
update: {
|
|
29445
30038
|
...stateUpdate,
|
|
29446
30039
|
messages: [
|
|
29447
|
-
new
|
|
30040
|
+
new ToolMessage8({
|
|
29448
30041
|
content: lastMessage?.content || "Task Failed to complete",
|
|
29449
30042
|
tool_call_id: toolCallId,
|
|
29450
30043
|
name: "task"
|
|
@@ -29483,7 +30076,9 @@ function getSubagents(options) {
|
|
|
29483
30076
|
if ("runnable" in agentParams) {
|
|
29484
30077
|
agents[agentParams.key] = agentParams.runnable;
|
|
29485
30078
|
} else {
|
|
29486
|
-
const middleware =
|
|
30079
|
+
const middleware = ensurePatchToolCallsMiddleware(
|
|
30080
|
+
agentParams.middleware ? [...defaultSubagentMiddleware, ...agentParams.middleware] : [...defaultSubagentMiddleware]
|
|
30081
|
+
);
|
|
29487
30082
|
const interruptOn = agentParams.interruptOn || defaultInterruptOn;
|
|
29488
30083
|
if (interruptOn)
|
|
29489
30084
|
middleware.push(humanInTheLoopMiddleware({ interruptOn }));
|
|
@@ -29492,7 +30087,7 @@ function getSubagents(options) {
|
|
|
29492
30087
|
systemPrompt: agentParams.systemPrompt,
|
|
29493
30088
|
tools: agentParams.tools ?? defaultTools,
|
|
29494
30089
|
middleware,
|
|
29495
|
-
stateSchema: withToolCallLimitStateSchema(),
|
|
30090
|
+
stateSchema: withRunGovernanceStateSchema(withToolCallLimitStateSchema()),
|
|
29496
30091
|
checkpointer: getCheckpointSaver("default")
|
|
29497
30092
|
});
|
|
29498
30093
|
}
|
|
@@ -29532,7 +30127,7 @@ function createTaskTool(options) {
|
|
|
29532
30127
|
return new Command3({
|
|
29533
30128
|
update: {
|
|
29534
30129
|
messages: [
|
|
29535
|
-
new
|
|
30130
|
+
new ToolMessage8({
|
|
29536
30131
|
content: JSON.stringify({
|
|
29537
30132
|
success: false,
|
|
29538
30133
|
code: "TASK_MIDDLEWARE_REQUIRED",
|
|
@@ -29612,7 +30207,7 @@ You are executing a persistent task (ID: ${input.taskId}). Use manage_task.updat
|
|
|
29612
30207
|
return new Command3({
|
|
29613
30208
|
update: {
|
|
29614
30209
|
messages: [
|
|
29615
|
-
new
|
|
30210
|
+
new ToolMessage8({
|
|
29616
30211
|
content: error instanceof Error ? error.message : "Task Failed to complete",
|
|
29617
30212
|
tool_call_id: config.toolCall.id,
|
|
29618
30213
|
name: "task"
|
|
@@ -29625,14 +30220,14 @@ You are executing a persistent task (ID: ${input.taskId}). Use manage_task.updat
|
|
|
29625
30220
|
{
|
|
29626
30221
|
name: "task",
|
|
29627
30222
|
description: finalTaskDescription,
|
|
29628
|
-
schema:
|
|
29629
|
-
description:
|
|
29630
|
-
subagent_type:
|
|
30223
|
+
schema: z47.object({
|
|
30224
|
+
description: z47.string().describe("The task to execute with the selected agent"),
|
|
30225
|
+
subagent_type: z47.string().describe(
|
|
29631
30226
|
`Name of the agent to use. Available: ${Object.keys(
|
|
29632
30227
|
subagentGraphs
|
|
29633
30228
|
).join(", ")}`
|
|
29634
30229
|
),
|
|
29635
|
-
taskId:
|
|
30230
|
+
taskId: z47.string().optional().describe(
|
|
29636
30231
|
"Optional: ID of a TaskItem created via manage_task. When set, the subagent will update this task's status as it works. Use this when executing a persistent task from the task board."
|
|
29637
30232
|
)
|
|
29638
30233
|
})
|
|
@@ -29661,7 +30256,7 @@ function createSubAgentMiddleware(options) {
|
|
|
29661
30256
|
});
|
|
29662
30257
|
const allTools = [taskTool];
|
|
29663
30258
|
const effectiveSystemPrompt = systemPrompt;
|
|
29664
|
-
return
|
|
30259
|
+
return createMiddleware15({
|
|
29665
30260
|
name: "subAgentMiddleware",
|
|
29666
30261
|
tools: allTools,
|
|
29667
30262
|
wrapModelCall: async (request, handler) => {
|
|
@@ -29681,8 +30276,8 @@ ${effectiveSystemPrompt}` : effectiveSystemPrompt;
|
|
|
29681
30276
|
}
|
|
29682
30277
|
|
|
29683
30278
|
// src/deep_agent_new/middleware/date.ts
|
|
29684
|
-
import { createMiddleware as
|
|
29685
|
-
import { z as
|
|
30279
|
+
import { createMiddleware as createMiddleware16, tool as tool42 } from "langchain";
|
|
30280
|
+
import { z as z48 } from "zod";
|
|
29686
30281
|
function formatCurrentDate(timezone = "UTC") {
|
|
29687
30282
|
const now = /* @__PURE__ */ new Date();
|
|
29688
30283
|
let validTimezone = timezone;
|
|
@@ -29710,7 +30305,7 @@ function generateDateContext(timezone = "UTC") {
|
|
|
29710
30305
|
function createDateMiddleware(options = {}) {
|
|
29711
30306
|
const timezone = options.timezone || "UTC";
|
|
29712
30307
|
const dateContext = generateDateContext(timezone);
|
|
29713
|
-
return
|
|
30308
|
+
return createMiddleware16({
|
|
29714
30309
|
name: "DateMiddleware",
|
|
29715
30310
|
tools: [
|
|
29716
30311
|
tool42(
|
|
@@ -29743,7 +30338,7 @@ function createDateMiddleware(options = {}) {
|
|
|
29743
30338
|
{
|
|
29744
30339
|
name: "get_current_date_time",
|
|
29745
30340
|
description: "Get the exact current date and time at the moment of invocation. Use this when the user asks about the current time (e.g., 'what time is it', '\u51E0\u70B9\u4E86', '\u73B0\u5728\u51E0\u70B9'), or when you need to know the precise time for scheduling, deadlines, or time-sensitive operations.",
|
|
29746
|
-
schema:
|
|
30341
|
+
schema: z48.object({})
|
|
29747
30342
|
}
|
|
29748
30343
|
)
|
|
29749
30344
|
],
|
|
@@ -29809,8 +30404,8 @@ var datePlugin = {
|
|
|
29809
30404
|
};
|
|
29810
30405
|
|
|
29811
30406
|
// src/deep_agent_new/middleware/scheduler.ts
|
|
29812
|
-
import { tool as tool43, createMiddleware as
|
|
29813
|
-
import { z as
|
|
30407
|
+
import { tool as tool43, createMiddleware as createMiddleware17 } from "langchain";
|
|
30408
|
+
import { z as z49 } from "zod";
|
|
29814
30409
|
import { v4 as uuidv44 } from "uuid";
|
|
29815
30410
|
import { ScheduledTaskStatus as ScheduledTaskStatus3, ScheduleExecutionType as ScheduleExecutionType3 } from "@axiom-lattice/protocols";
|
|
29816
30411
|
var SCHEDULE_LATTICE_KEY = "default";
|
|
@@ -29891,7 +30486,7 @@ function registerAgentAddMessageHandler() {
|
|
|
29891
30486
|
function createSchedulerMiddleware(options = {}) {
|
|
29892
30487
|
const defaultMaxRetries = options.defaultMaxRetries ?? 0;
|
|
29893
30488
|
registerAgentAddMessageHandler();
|
|
29894
|
-
return
|
|
30489
|
+
return createMiddleware17({
|
|
29895
30490
|
name: "SchedulerMiddleware",
|
|
29896
30491
|
tools: [
|
|
29897
30492
|
tool43(
|
|
@@ -29922,10 +30517,10 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
29922
30517
|
{
|
|
29923
30518
|
name: "schedule_at",
|
|
29924
30519
|
description: "Schedule a system message for an absolute future timestamp",
|
|
29925
|
-
schema:
|
|
29926
|
-
executeAt:
|
|
29927
|
-
maxRetries:
|
|
29928
|
-
message:
|
|
30520
|
+
schema: z49.object({
|
|
30521
|
+
executeAt: z49.number(),
|
|
30522
|
+
maxRetries: z49.number().int().min(0).optional(),
|
|
30523
|
+
message: z49.string()
|
|
29929
30524
|
})
|
|
29930
30525
|
}
|
|
29931
30526
|
),
|
|
@@ -29957,10 +30552,10 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
29957
30552
|
{
|
|
29958
30553
|
name: "schedule_after",
|
|
29959
30554
|
description: "Schedule a system message after a relative delay",
|
|
29960
|
-
schema:
|
|
29961
|
-
delayMs:
|
|
29962
|
-
maxRetries:
|
|
29963
|
-
message:
|
|
30555
|
+
schema: z49.object({
|
|
30556
|
+
delayMs: z49.number().positive(),
|
|
30557
|
+
maxRetries: z49.number().int().min(0).optional(),
|
|
30558
|
+
message: z49.string()
|
|
29964
30559
|
})
|
|
29965
30560
|
}
|
|
29966
30561
|
),
|
|
@@ -29999,12 +30594,12 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
29999
30594
|
{
|
|
30000
30595
|
name: "schedule_recurring",
|
|
30001
30596
|
description: "Schedule a recurring system message with a cron expression",
|
|
30002
|
-
schema:
|
|
30003
|
-
cronExpression:
|
|
30004
|
-
maxRuns:
|
|
30005
|
-
expiresAt:
|
|
30006
|
-
maxRetries:
|
|
30007
|
-
message:
|
|
30597
|
+
schema: z49.object({
|
|
30598
|
+
cronExpression: z49.string(),
|
|
30599
|
+
maxRuns: z49.number().int().positive().optional(),
|
|
30600
|
+
expiresAt: z49.number().optional(),
|
|
30601
|
+
maxRetries: z49.number().int().min(0).optional(),
|
|
30602
|
+
message: z49.string()
|
|
30008
30603
|
})
|
|
30009
30604
|
}
|
|
30010
30605
|
),
|
|
@@ -30017,8 +30612,8 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
30017
30612
|
{
|
|
30018
30613
|
name: "cancel_scheduled_task",
|
|
30019
30614
|
description: "Cancel a scheduled task by task id",
|
|
30020
|
-
schema:
|
|
30021
|
-
taskId:
|
|
30615
|
+
schema: z49.object({
|
|
30616
|
+
taskId: z49.string()
|
|
30022
30617
|
})
|
|
30023
30618
|
}
|
|
30024
30619
|
),
|
|
@@ -30044,11 +30639,11 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
30044
30639
|
{
|
|
30045
30640
|
name: "list_scheduled_tasks",
|
|
30046
30641
|
description: "List scheduled tasks for the current agent context",
|
|
30047
|
-
schema:
|
|
30048
|
-
status:
|
|
30049
|
-
executionType:
|
|
30050
|
-
limit:
|
|
30051
|
-
offset:
|
|
30642
|
+
schema: z49.object({
|
|
30643
|
+
status: z49.enum(["pending", "running", "completed", "failed", "cancelled", "paused"]).optional(),
|
|
30644
|
+
executionType: z49.enum(["once", "cron"]).optional(),
|
|
30645
|
+
limit: z49.number().int().positive().optional(),
|
|
30646
|
+
offset: z49.number().int().min(0).optional()
|
|
30052
30647
|
})
|
|
30053
30648
|
}
|
|
30054
30649
|
)
|
|
@@ -31305,8 +31900,8 @@ var MemoryBackend = class {
|
|
|
31305
31900
|
|
|
31306
31901
|
// src/deep_agent_new/middleware/todos.ts
|
|
31307
31902
|
import { Command as Command4 } from "@langchain/langgraph";
|
|
31308
|
-
import { z as
|
|
31309
|
-
import { createMiddleware as
|
|
31903
|
+
import { z as z50 } from "zod";
|
|
31904
|
+
import { createMiddleware as createMiddleware18, tool as tool44, ToolMessage as ToolMessage9 } from "langchain";
|
|
31310
31905
|
var WRITE_TODOS_DESCRIPTION = `Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
31311
31906
|
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
31312
31907
|
Only use this tool if you think it will be helpful in staying organized. If the user's request is trivial and takes less than 3 steps, it is better to NOT use this tool and just do the taks directly.
|
|
@@ -31533,12 +32128,12 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
|
|
|
31533
32128
|
## Important To-Do List Usage Notes to Remember
|
|
31534
32129
|
- The \`write_todos\` tool should never be called multiple times in parallel.
|
|
31535
32130
|
- Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.`;
|
|
31536
|
-
var TodoStatus =
|
|
31537
|
-
var TodoSchema =
|
|
31538
|
-
content:
|
|
32131
|
+
var TodoStatus = z50.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
|
|
32132
|
+
var TodoSchema = z50.object({
|
|
32133
|
+
content: z50.string().describe("Content of the todo item"),
|
|
31539
32134
|
status: TodoStatus
|
|
31540
32135
|
});
|
|
31541
|
-
var stateSchema =
|
|
32136
|
+
var stateSchema = z50.object({ todos: z50.array(TodoSchema).default([]) });
|
|
31542
32137
|
function todoListMiddleware(options) {
|
|
31543
32138
|
const writeTodos = tool44(
|
|
31544
32139
|
({ todos }, config) => {
|
|
@@ -31546,7 +32141,7 @@ function todoListMiddleware(options) {
|
|
|
31546
32141
|
update: {
|
|
31547
32142
|
todos,
|
|
31548
32143
|
messages: [
|
|
31549
|
-
new
|
|
32144
|
+
new ToolMessage9({
|
|
31550
32145
|
content: genUIMarkdown("todo_list", todos),
|
|
31551
32146
|
tool_call_id: config.toolCall?.id
|
|
31552
32147
|
})
|
|
@@ -31557,12 +32152,12 @@ function todoListMiddleware(options) {
|
|
|
31557
32152
|
{
|
|
31558
32153
|
name: "write_todos",
|
|
31559
32154
|
description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
|
|
31560
|
-
schema:
|
|
31561
|
-
todos:
|
|
32155
|
+
schema: z50.object({
|
|
32156
|
+
todos: z50.array(TodoSchema).describe("List of todo items to update")
|
|
31562
32157
|
})
|
|
31563
32158
|
}
|
|
31564
32159
|
);
|
|
31565
|
-
return
|
|
32160
|
+
return createMiddleware18({
|
|
31566
32161
|
name: "todoListMiddleware",
|
|
31567
32162
|
stateSchema,
|
|
31568
32163
|
tools: [writeTodos],
|
|
@@ -31610,7 +32205,7 @@ function createDeepAgent(params = {}) {
|
|
|
31610
32205
|
${BASE_PROMPT}` : BASE_PROMPT;
|
|
31611
32206
|
const filesystemBackend = backend ? backend : async (config) => new StateBackend(config);
|
|
31612
32207
|
const postDelegationMiddleware = interruptOn ? [humanInTheLoopMiddleware2({ interruptOn })] : [];
|
|
31613
|
-
const middleware = assembleDeepAgentMiddleware(
|
|
32208
|
+
const middleware = ensurePatchToolCallsMiddleware(assembleDeepAgentMiddleware(
|
|
31614
32209
|
customMiddleware,
|
|
31615
32210
|
[
|
|
31616
32211
|
// Provides todo list management capabilities for tracking tasks
|
|
@@ -31623,7 +32218,7 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
31623
32218
|
createSubAgentMiddleware({
|
|
31624
32219
|
defaultModel: model,
|
|
31625
32220
|
defaultTools: tools,
|
|
31626
|
-
defaultMiddleware: [
|
|
32221
|
+
defaultMiddleware: ensurePatchToolCallsMiddleware([
|
|
31627
32222
|
// Subagent middleware: Todo list management
|
|
31628
32223
|
todoListMiddleware(),
|
|
31629
32224
|
// Subagent middleware: Filesystem operations
|
|
@@ -31635,7 +32230,7 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
31635
32230
|
unsupportedModelBehavior: "ignore"
|
|
31636
32231
|
}),
|
|
31637
32232
|
...customMiddleware
|
|
31638
|
-
],
|
|
32233
|
+
]),
|
|
31639
32234
|
defaultInterruptOn: interruptOn,
|
|
31640
32235
|
subagents,
|
|
31641
32236
|
generalPurposeAgent: true
|
|
@@ -31646,7 +32241,7 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
31646
32241
|
// unsupportedModelBehavior: "ignore",
|
|
31647
32242
|
// })
|
|
31648
32243
|
postDelegationMiddleware
|
|
31649
|
-
);
|
|
32244
|
+
));
|
|
31650
32245
|
return createAgent3({
|
|
31651
32246
|
model,
|
|
31652
32247
|
systemPrompt: finalSystemPrompt,
|
|
@@ -31654,7 +32249,7 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
31654
32249
|
middleware,
|
|
31655
32250
|
responseFormat,
|
|
31656
32251
|
contextSchema: contextSchema2,
|
|
31657
|
-
stateSchema: withToolCallLimitStateSchema(),
|
|
32252
|
+
stateSchema: withRunGovernanceStateSchema(withToolCallLimitStateSchema()),
|
|
31658
32253
|
checkpointer,
|
|
31659
32254
|
store: store2,
|
|
31660
32255
|
name
|
|
@@ -31740,7 +32335,7 @@ var DeepAgentGraphBuilder = class {
|
|
|
31740
32335
|
|
|
31741
32336
|
// src/agent_lattice/builders/RemoteAgentGraphBuilder.ts
|
|
31742
32337
|
import { StateGraph as StateGraph2, MessagesAnnotation } from "@langchain/langgraph";
|
|
31743
|
-
import { AIMessage as
|
|
32338
|
+
import { AIMessage as AIMessage6 } from "@langchain/core/messages";
|
|
31744
32339
|
|
|
31745
32340
|
// src/services/a2a-client.ts
|
|
31746
32341
|
import { v4 as uuidv45 } from "uuid";
|
|
@@ -32079,7 +32674,7 @@ var RemoteAgentGraphBuilder = class {
|
|
|
32079
32674
|
if (!text) {
|
|
32080
32675
|
return {
|
|
32081
32676
|
messages: [
|
|
32082
|
-
new
|
|
32677
|
+
new AIMessage6("No text input provided to remote agent.")
|
|
32083
32678
|
]
|
|
32084
32679
|
};
|
|
32085
32680
|
}
|
|
@@ -32091,13 +32686,13 @@ ${text}` : text;
|
|
|
32091
32686
|
const threadId = langGraphConfig?.configurable?.thread_id;
|
|
32092
32687
|
const response = await client.sendMessage(fullPrompt, threadId);
|
|
32093
32688
|
return {
|
|
32094
|
-
messages: [new
|
|
32689
|
+
messages: [new AIMessage6(response)]
|
|
32095
32690
|
};
|
|
32096
32691
|
} catch (error) {
|
|
32097
32692
|
const msg = error.message ?? String(error);
|
|
32098
32693
|
return {
|
|
32099
32694
|
messages: [
|
|
32100
|
-
new
|
|
32695
|
+
new AIMessage6(`Remote A2A agent error: ${msg}`)
|
|
32101
32696
|
]
|
|
32102
32697
|
};
|
|
32103
32698
|
}
|
|
@@ -32128,9 +32723,10 @@ import { createAgent as createAgent4 } from "langchain";
|
|
|
32128
32723
|
import { isWorkflowAgentConfig } from "@axiom-lattice/protocols";
|
|
32129
32724
|
|
|
32130
32725
|
// src/agent_lattice/builders/middlewareSanitize.ts
|
|
32131
|
-
function stripWrapModelCallHook(middlewares) {
|
|
32726
|
+
function stripWrapModelCallHook(middlewares, preserveNames = []) {
|
|
32727
|
+
const preserved = new Set(preserveNames);
|
|
32132
32728
|
return middlewares.map((m) => {
|
|
32133
|
-
if (typeof m.wrapModelCall !== "function") {
|
|
32729
|
+
if (preserved.has(m.name) || typeof m.wrapModelCall !== "function") {
|
|
32134
32730
|
return m;
|
|
32135
32731
|
}
|
|
32136
32732
|
const clone3 = { ...m };
|
|
@@ -32185,8 +32781,11 @@ var WorkflowAgentGraphBuilder = class {
|
|
|
32185
32781
|
config: {}
|
|
32186
32782
|
}
|
|
32187
32783
|
], void 0, false, void 0, params.model);
|
|
32188
|
-
const
|
|
32189
|
-
|
|
32784
|
+
const preservedMiddlewareNames = [
|
|
32785
|
+
"patchToolCallsMiddleware"
|
|
32786
|
+
];
|
|
32787
|
+
const noWrapMiddlewares = stripWrapModelCallHook(middlewares, preservedMiddlewareNames);
|
|
32788
|
+
const noWrapAskMiddlewares = stripWrapModelCallHook(askMiddlewares, preservedMiddlewareNames);
|
|
32190
32789
|
console.log(`[WF BUILDER] building default agent | toolCount=${tools.length} | middlewareCount=${middlewares.length}`);
|
|
32191
32790
|
const defaultAgent = createAgent4({
|
|
32192
32791
|
model: params.model,
|
|
@@ -32195,7 +32794,7 @@ var WorkflowAgentGraphBuilder = class {
|
|
|
32195
32794
|
name: agentName,
|
|
32196
32795
|
checkpointer,
|
|
32197
32796
|
middleware: middlewares,
|
|
32198
|
-
stateSchema: withToolCallLimitStateSchema()
|
|
32797
|
+
stateSchema: withRunGovernanceStateSchema(withToolCallLimitStateSchema())
|
|
32199
32798
|
});
|
|
32200
32799
|
console.log(`[WF BUILDER] default agent built`);
|
|
32201
32800
|
const agentCache = /* @__PURE__ */ new Map();
|
|
@@ -32217,7 +32816,7 @@ var WorkflowAgentGraphBuilder = class {
|
|
|
32217
32816
|
name: agentName,
|
|
32218
32817
|
checkpointer,
|
|
32219
32818
|
middleware: isAsk ? noWrapAskMiddlewares : noWrapMiddlewares,
|
|
32220
|
-
stateSchema: withToolCallLimitStateSchema(),
|
|
32819
|
+
stateSchema: withRunGovernanceStateSchema(withToolCallLimitStateSchema()),
|
|
32221
32820
|
responseFormat
|
|
32222
32821
|
});
|
|
32223
32822
|
agentCache.set(key5, agent);
|
|
@@ -32413,7 +33012,7 @@ function mergeAgentConfig(parent, child) {
|
|
|
32413
33012
|
}
|
|
32414
33013
|
|
|
32415
33014
|
// src/agent_lattice/agentArchitectTools.ts
|
|
32416
|
-
import
|
|
33015
|
+
import z51 from "zod";
|
|
32417
33016
|
import { v4 as v43 } from "uuid";
|
|
32418
33017
|
import { AgentType as AgentType4 } from "@axiom-lattice/protocols";
|
|
32419
33018
|
function getTenantId2(exeConfig) {
|
|
@@ -32527,7 +33126,7 @@ registerToolLattice(
|
|
|
32527
33126
|
{
|
|
32528
33127
|
name: "list_agents",
|
|
32529
33128
|
description: "List all agents for the current workspace. Returns a summary with id, name, description, and type for each agent.",
|
|
32530
|
-
schema:
|
|
33129
|
+
schema: z51.object({})
|
|
32531
33130
|
},
|
|
32532
33131
|
async (_input, exeConfig) => {
|
|
32533
33132
|
try {
|
|
@@ -32553,9 +33152,9 @@ registerToolLattice(
|
|
|
32553
33152
|
"get_agent",
|
|
32554
33153
|
{
|
|
32555
33154
|
name: "get_agent",
|
|
32556
|
-
description: "Get the full configuration of a specific agent by its ID. Returns the complete AgentConfig including prompt, middleware, tools, and sub-agents.",
|
|
32557
|
-
schema:
|
|
32558
|
-
id:
|
|
33155
|
+
description: "Get the full configuration of a specific agent by its ID. Returns the complete AgentConfig including prompt, middleware, tools, and sub-agents. Pass only { id: string }; this tool has no action, collection, or other parameters.",
|
|
33156
|
+
schema: z51.object({
|
|
33157
|
+
id: z51.string().describe("The agent ID to retrieve")
|
|
32559
33158
|
})
|
|
32560
33159
|
},
|
|
32561
33160
|
async (input, exeConfig) => {
|
|
@@ -32572,27 +33171,27 @@ registerToolLattice(
|
|
|
32572
33171
|
}
|
|
32573
33172
|
}
|
|
32574
33173
|
);
|
|
32575
|
-
var middlewareConfigSchema =
|
|
32576
|
-
id:
|
|
32577
|
-
type:
|
|
32578
|
-
name:
|
|
32579
|
-
description:
|
|
32580
|
-
enabled:
|
|
32581
|
-
allowedTools:
|
|
32582
|
-
config:
|
|
33174
|
+
var middlewareConfigSchema = z51.object({
|
|
33175
|
+
id: z51.string(),
|
|
33176
|
+
type: z51.string(),
|
|
33177
|
+
name: z51.string(),
|
|
33178
|
+
description: z51.string(),
|
|
33179
|
+
enabled: z51.boolean(),
|
|
33180
|
+
allowedTools: z51.array(z51.string()).optional().describe("Optional tool-name allowlist. Omit it or pass [] to enable all tools from this middleware. A non-empty task middleware allowlist must include both manage_task and task."),
|
|
33181
|
+
config: z51.record(z51.any()).optional()
|
|
32583
33182
|
});
|
|
32584
|
-
var createAgentSchema =
|
|
32585
|
-
skillLoaded:
|
|
32586
|
-
name:
|
|
32587
|
-
description:
|
|
32588
|
-
type:
|
|
32589
|
-
prompt:
|
|
32590
|
-
tools:
|
|
32591
|
-
middleware:
|
|
32592
|
-
subAgents:
|
|
32593
|
-
internalSubAgents:
|
|
32594
|
-
modelKey:
|
|
32595
|
-
metadata:
|
|
33183
|
+
var createAgentSchema = z51.object({
|
|
33184
|
+
skillLoaded: z51.boolean().optional().describe("Required on every call: load the 'agent-architecture' skill first via the skill tool (skill_name 'agent-architecture'), then pass skillLoaded: true. Calls without skillLoaded: true fail. Never omit or pass false."),
|
|
33185
|
+
name: z51.string().describe("Human-friendly display name for the agent. The machine ID (used in other tools) is auto-generated as a slug from this name (e.g. 'My Cool Agent' \u2192 'my-cool-agent')."),
|
|
33186
|
+
description: z51.string().optional().describe("Short description"),
|
|
33187
|
+
type: z51.enum(["react", "deep_agent"]).describe("Agent type. Use 'react' for simple single-responsibility agents, 'deep_agent' for complex open-ended agents. For PROCESSING agents (workflow orchestration), use create_processing_agent instead."),
|
|
33188
|
+
prompt: z51.string().describe("System prompt for the agent"),
|
|
33189
|
+
tools: z51.array(z51.string()).optional().describe("Tool keys (strings) to assign. Call list_tools first to see available keys. Each element is a plain string like 'sap_api_search'. IMPORTANT: tools is a FLAT string array of tool names. Do NOT put middleware-like objects here \u2014 middleware goes in the separate 'middleware' field."),
|
|
33190
|
+
middleware: z51.array(middlewareConfigSchema).optional().describe("Middleware configuration objects. Each has {id, type, name, description, enabled, config}. IMPORTANT: middleware objects are NOT tools. Do NOT put tool keys (strings) here \u2014 tool names go in the separate 'tools' array. For user approval/confirmation scenarios, use type: 'ask_user_to_clarify' with config: {}."),
|
|
33191
|
+
subAgents: z51.array(z51.string()).optional().describe("Sub-agent IDs (deep_agent only)"),
|
|
33192
|
+
internalSubAgents: z51.array(z51.any()).optional().describe("Inline sub-agent configs (deep_agent only)"),
|
|
33193
|
+
modelKey: z51.string().optional().describe("Model key to use"),
|
|
33194
|
+
metadata: z51.record(z51.string(), z51.string()).optional().describe("Arbitrary metadata key-value pairs (e.g. verified: 'human-reviewed', version: '1.0', source: 'PO-Format-SAP.pdf')")
|
|
32596
33195
|
});
|
|
32597
33196
|
registerToolLattice(
|
|
32598
33197
|
"create_agent",
|
|
@@ -32637,14 +33236,14 @@ registerToolLattice(
|
|
|
32637
33236
|
}
|
|
32638
33237
|
}
|
|
32639
33238
|
);
|
|
32640
|
-
var createWorkflowSchema =
|
|
32641
|
-
name:
|
|
32642
|
-
description:
|
|
32643
|
-
skillLoaded:
|
|
32644
|
-
yaml:
|
|
32645
|
-
tools:
|
|
32646
|
-
middleware:
|
|
32647
|
-
modelKey:
|
|
33239
|
+
var createWorkflowSchema = z51.object({
|
|
33240
|
+
name: z51.string().describe("Display name for the workflow agent"),
|
|
33241
|
+
description: z51.string().optional().describe("Short description"),
|
|
33242
|
+
skillLoaded: z51.boolean().optional().describe("Required on every call: load the 'agent-architecture' skill first via the skill tool (skill_name 'agent-architecture'), then pass skillLoaded: true. Calls without skillLoaded: true fail. Never omit or pass false."),
|
|
33243
|
+
yaml: z51.string().describe("The YAML workflow definition in linear DSL format (steps execute top-to-bottom, use parallel: for concurrency)"),
|
|
33244
|
+
tools: z51.array(z51.string()).optional().describe("Tool keys for the workflow agent"),
|
|
33245
|
+
middleware: z51.array(middlewareConfigSchema).optional().describe("Middleware configs"),
|
|
33246
|
+
modelKey: z51.string().optional().describe("Model key")
|
|
32648
33247
|
});
|
|
32649
33248
|
registerToolLattice(
|
|
32650
33249
|
"create_workflow",
|
|
@@ -32697,8 +33296,8 @@ registerToolLattice(
|
|
|
32697
33296
|
{
|
|
32698
33297
|
name: "validate_workflow",
|
|
32699
33298
|
description: "Validate a workflow agent's DSL for correctness by compiling it.",
|
|
32700
|
-
schema:
|
|
32701
|
-
id:
|
|
33299
|
+
schema: z51.object({
|
|
33300
|
+
id: z51.string().describe("The workflow agent ID to validate")
|
|
32702
33301
|
})
|
|
32703
33302
|
},
|
|
32704
33303
|
async (input, exeConfig) => {
|
|
@@ -32795,15 +33394,15 @@ registerToolLattice(
|
|
|
32795
33394
|
}
|
|
32796
33395
|
}
|
|
32797
33396
|
);
|
|
32798
|
-
var updateWorkflowSchema =
|
|
32799
|
-
id:
|
|
32800
|
-
skillLoaded:
|
|
32801
|
-
name:
|
|
32802
|
-
description:
|
|
32803
|
-
yaml:
|
|
32804
|
-
tools:
|
|
32805
|
-
middleware:
|
|
32806
|
-
modelKey:
|
|
33397
|
+
var updateWorkflowSchema = z51.object({
|
|
33398
|
+
id: z51.string().describe("The workflow agent ID to update"),
|
|
33399
|
+
skillLoaded: z51.boolean().optional().describe("Required on every call: load the 'agent-architecture' skill first via the skill tool (skill_name 'agent-architecture'), then pass skillLoaded: true. Calls without skillLoaded: true fail. Never omit or pass false."),
|
|
33400
|
+
name: z51.string().optional().describe("New display name"),
|
|
33401
|
+
description: z51.string().optional().describe("New description"),
|
|
33402
|
+
yaml: z51.string().optional().describe("Replacement YAML workflow DSL. Omit to keep existing."),
|
|
33403
|
+
tools: z51.array(z51.string()).optional().describe("Replacement tool keys"),
|
|
33404
|
+
middleware: z51.array(middlewareConfigSchema).optional().describe("Replacement middleware configs"),
|
|
33405
|
+
modelKey: z51.string().optional().describe("Replacement model key")
|
|
32807
33406
|
});
|
|
32808
33407
|
registerToolLattice(
|
|
32809
33408
|
"update_workflow",
|
|
@@ -32909,20 +33508,20 @@ registerToolLattice(
|
|
|
32909
33508
|
}
|
|
32910
33509
|
}
|
|
32911
33510
|
);
|
|
32912
|
-
var updateAgentSchema =
|
|
32913
|
-
id:
|
|
32914
|
-
skillLoaded:
|
|
32915
|
-
config:
|
|
32916
|
-
name:
|
|
32917
|
-
description:
|
|
32918
|
-
type:
|
|
32919
|
-
prompt:
|
|
32920
|
-
tools:
|
|
32921
|
-
middleware:
|
|
32922
|
-
subAgents:
|
|
32923
|
-
internalSubAgents:
|
|
32924
|
-
modelKey:
|
|
32925
|
-
metadata:
|
|
33511
|
+
var updateAgentSchema = z51.object({
|
|
33512
|
+
id: z51.string().describe("The agent ID to update"),
|
|
33513
|
+
skillLoaded: z51.boolean().optional().describe("Required on every call: load the 'agent-architecture' skill first via the skill tool (skill_name 'agent-architecture'), then pass skillLoaded: true. Calls without skillLoaded: true fail. Never omit or pass false."),
|
|
33514
|
+
config: z51.object({
|
|
33515
|
+
name: z51.string().optional().describe("New display name for the agent"),
|
|
33516
|
+
description: z51.string().optional().describe("New short description"),
|
|
33517
|
+
type: z51.enum(["react", "deep_agent"]).optional().describe("Agent type"),
|
|
33518
|
+
prompt: z51.string().optional().describe("New system prompt for the agent"),
|
|
33519
|
+
tools: z51.array(z51.string()).optional().describe("Tool keys to assign to this agent. These are registered tool names (strings), NOT middleware objects."),
|
|
33520
|
+
middleware: z51.array(middlewareConfigSchema).optional().describe("Middleware configurations. NOTE: middleware objects have type/name/description/enabled/config fields and are NOT the same as tools. Tool keys go in the 'tools' array. For user approval/confirmation scenarios, use type: 'ask_user_to_clarify' with config: {}."),
|
|
33521
|
+
subAgents: z51.array(z51.string()).optional().describe("Sub-agent IDs (deep_agent only)"),
|
|
33522
|
+
internalSubAgents: z51.array(z51.any()).optional().describe("Inline sub-agent configs (deep_agent only)"),
|
|
33523
|
+
modelKey: z51.string().optional().describe("Model key to use"),
|
|
33524
|
+
metadata: z51.record(z51.string(), z51.string()).optional().describe("Arbitrary metadata key-value pairs (e.g. verified: 'machine-confirmed', version: '1.1'). Replaces the whole map when provided.")
|
|
32926
33525
|
}).describe("Configuration fields to update. Only include the fields you want to change.")
|
|
32927
33526
|
});
|
|
32928
33527
|
registerToolLattice(
|
|
@@ -33044,8 +33643,8 @@ registerToolLattice(
|
|
|
33044
33643
|
{
|
|
33045
33644
|
name: "delete_agent",
|
|
33046
33645
|
description: "Permanently delete an agent by its ID. This action cannot be undone.",
|
|
33047
|
-
schema:
|
|
33048
|
-
id:
|
|
33646
|
+
schema: z51.object({
|
|
33647
|
+
id: z51.string().describe("The agent ID to delete")
|
|
33049
33648
|
})
|
|
33050
33649
|
},
|
|
33051
33650
|
async (input, exeConfig) => {
|
|
@@ -33071,7 +33670,7 @@ registerToolLattice(
|
|
|
33071
33670
|
{
|
|
33072
33671
|
name: "list_tools",
|
|
33073
33672
|
description: "List all available tools that can be assigned to agents. Returns each tool's registry key (use this string value in the 'tools' array), name, description, and whether it requires user approval.",
|
|
33074
|
-
schema:
|
|
33673
|
+
schema: z51.object({})
|
|
33075
33674
|
},
|
|
33076
33675
|
async (_input, _exeConfig) => {
|
|
33077
33676
|
try {
|
|
@@ -33095,7 +33694,7 @@ registerToolLattice(
|
|
|
33095
33694
|
{
|
|
33096
33695
|
name: "list_models",
|
|
33097
33696
|
description: "List all registered models. Returns each model's key (use this string as modelKey when creating eval projects via manage_eval create_project, or as an agent's modelKey in create_agent/update_agent) and its display name.",
|
|
33098
|
-
schema:
|
|
33697
|
+
schema: z51.object({})
|
|
33099
33698
|
},
|
|
33100
33699
|
async (_input, exeConfig) => {
|
|
33101
33700
|
try {
|
|
@@ -33116,9 +33715,9 @@ registerToolLattice(
|
|
|
33116
33715
|
{
|
|
33117
33716
|
name: "invoke_agent",
|
|
33118
33717
|
description: "Invoke an agent with a test message and return its response. Use this to verify an agent works correctly after creating or modifying it. The agent must be compiled (already created and valid).",
|
|
33119
|
-
schema:
|
|
33120
|
-
id:
|
|
33121
|
-
message:
|
|
33718
|
+
schema: z51.object({
|
|
33719
|
+
id: z51.string().describe("The agent ID to invoke"),
|
|
33720
|
+
message: z51.string().describe("The test message to send to the agent")
|
|
33122
33721
|
})
|
|
33123
33722
|
},
|
|
33124
33723
|
async (input, exeConfig) => {
|
|
@@ -33154,7 +33753,7 @@ registerToolLattice(
|
|
|
33154
33753
|
{
|
|
33155
33754
|
name: "list_middleware_types",
|
|
33156
33755
|
description: "\u5217\u51FA\u5F53\u524D\u7CFB\u7EDF\u4E2D\u6240\u6709\u53EF\u7528\u7684\u4E2D\u95F4\u4EF6\u7C7B\u578B\uFF08Middlewares\uFF09\uFF0C\u5305\u62EC\u5185\u7F6E\u548C\u81EA\u5B9A\u4E49\u63D2\u4EF6\u3002\u8FD4\u56DE\u6BCF\u4E2A\u4E2D\u95F4\u4EF6\u7684 type\u3001name\u3001description\u3001tools \u6E05\u5355\uFF08\u652F\u6301 allowedTools \u8FC7\u6EE4\uFF09\u3001configSchema\uFF08\u914D\u7F6E\u9762\u677F\u9700\u8981\u54EA\u4E9B\u5B57\u6BB5\uFF09\u548C connectionSchema\uFF08\u662F\u5426\u652F\u6301\u8FDE\u63A5\u6D4B\u8BD5\u548C\u8D44\u6E90\u53D1\u73B0\uFF09\u3002\n\n\u4F7F\u7528\u573A\u666F\uFF1A\n1. \u5728\u521B\u5EFA agent \u524D\uFF0C\u5148\u8C03\u6B64\u5DE5\u5177\u4E86\u89E3\u6709\u54EA\u4E9B\u4E2D\u95F4\u4EF6\u53EF\u914D\u7F6E\n2. \u6839\u636E configSchema \u51B3\u5B9A\u9700\u8981\u63D0\u4F9B\u54EA\u4E9B\u914D\u7F6E\u5B57\u6BB5\uFF1B\u65B0\u8FDE\u63A5\u578B\u63D2\u4EF6\u4F7F\u7528 connections \u548C connectAll\uFF0C\u5185\u7F6E\u65E7\u63D2\u4EF6\u7684 selector \u5B57\u6BB5\u7531 core \u7684 legacy compatibility map \u5B9A\u4E49\n3. \u5982\u679C\u67D0\u4E2A\u4E2D\u95F4\u4EF6\u7684 connectionSchema \u5B58\u5728\uFF0C\u8BF4\u660E\u5B83\u662F\u8FDE\u63A5\u578B\u4E2D\u95F4\u4EF6\uFF0C\u9700\u8981\u518D\u8C03 list_connections \u83B7\u53D6\u53EF\u7528\u8FDE\u63A5\n4. \u7528\u8FD4\u56DE\u7684 type \u5B57\u6BB5\u6784\u5EFA middleware \u6570\u7EC4\u4F20\u7ED9 create_agent / update_agent",
|
|
33157
|
-
schema:
|
|
33756
|
+
schema: z51.object({})
|
|
33158
33757
|
},
|
|
33159
33758
|
async (_input, exeConfig) => {
|
|
33160
33759
|
const tenantId2 = getTenantId2(exeConfig);
|
|
@@ -33168,8 +33767,8 @@ registerToolLattice(
|
|
|
33168
33767
|
{
|
|
33169
33768
|
name: "list_connections",
|
|
33170
33769
|
description: "\u5217\u51FA\u6307\u5B9A\u63D2\u4EF6\u7C7B\u578B\u7684\u6240\u6709\u5DF2\u914D\u7F6E\u8FDE\u63A5\u3002\u7528\u4E8E\u67E5\u8BE2\u6709\u54EA\u4E9B\u53EF\u7528\u7684\u8FDE\u63A5\u5B9E\u4F8B\uFF08\u5982 'sap-prod', 'sap-dev'\uFF09\uFF0C\u65B9\u4FBF\u5728 agent \u914D\u7F6E\u4E2D\u9009\u62E9\u5177\u4F53\u8FDE\u63A5\u3002\n\n\u4F7F\u7528\u573A\u666F\uFF1A\n1. \u5148\u8C03 list_middleware_types \u786E\u5B9A\u67D0\u4E2A\u4E2D\u95F4\u4EF6\u662F\u8FDE\u63A5\u578B\uFF08\u6709 connectionSchema\uFF09\n2. \u8C03\u6B64\u5DE5\u5177\u4F20\u5165 type\uFF08\u5982 'erp'\uFF09\uFF0C\u83B7\u53D6\u8BE5\u7C7B\u578B\u4E0B\u5DF2\u914D\u597D\u7684\u8FDE\u63A5\u5217\u8868\n3. \u5728 create_agent \u7684 middleware[i].config.connections \u4E2D\u586B\u5165\u5BF9\u5E94\u7684 key \u503C\n\n\u8FD4\u56DE\u683C\u5F0F\uFF1A{ success: true, data: { records: [{ key, name, ... }] } }",
|
|
33171
|
-
schema:
|
|
33172
|
-
type:
|
|
33770
|
+
schema: z51.object({
|
|
33771
|
+
type: z51.string().describe("\u63D2\u4EF6\u7C7B\u578B\u6807\u8BC6\uFF0C\u5982 'erp'\u3002\u4ECE list_middleware_types \u7684\u8FD4\u56DE\u4E2D\u83B7\u53D6")
|
|
33173
33772
|
}),
|
|
33174
33773
|
needUserApprove: false
|
|
33175
33774
|
},
|
|
@@ -44200,10 +44799,10 @@ async function assertSafeUpstreamUrl(raw) {
|
|
|
44200
44799
|
}
|
|
44201
44800
|
|
|
44202
44801
|
// src/middlewares/skillMiddleware.ts
|
|
44203
|
-
import { createMiddleware as
|
|
44802
|
+
import { createMiddleware as createMiddleware19 } from "langchain";
|
|
44204
44803
|
|
|
44205
44804
|
// src/tool_lattice/skill/load_skills.ts
|
|
44206
|
-
import
|
|
44805
|
+
import z52 from "zod";
|
|
44207
44806
|
import { tool as tool45 } from "langchain";
|
|
44208
44807
|
var LOAD_SKILLS_DESCRIPTION = `Load all available skills and return their metadata (name, description, license, compatibility, metadata, and subSkills) without the content. This tool returns skill information including hierarchical relationships (subSkills). Use this to discover what skills are available and their structure.`;
|
|
44209
44808
|
function getSandboxFromExeConfig(_exe_config) {
|
|
@@ -44285,7 +44884,7 @@ var createLoadSkillsTool = ({ skills, readAll, pluginSkills, pluginSkillOwners }
|
|
|
44285
44884
|
{
|
|
44286
44885
|
name: "load_skills",
|
|
44287
44886
|
description: LOAD_SKILLS_DESCRIPTION,
|
|
44288
|
-
schema:
|
|
44887
|
+
schema: z52.object({})
|
|
44289
44888
|
}
|
|
44290
44889
|
);
|
|
44291
44890
|
};
|
|
@@ -44295,7 +44894,7 @@ function isSkillAllowed(skillName, staticSkills, staticReadAll) {
|
|
|
44295
44894
|
}
|
|
44296
44895
|
|
|
44297
44896
|
// src/tool_lattice/skill/load_skill_content.ts
|
|
44298
|
-
import
|
|
44897
|
+
import z53 from "zod";
|
|
44299
44898
|
import { tool as tool46 } from "langchain";
|
|
44300
44899
|
|
|
44301
44900
|
// src/sandbox_plugin/pluginSkillResolution.ts
|
|
@@ -44445,8 +45044,8 @@ var createLoadSkillContentTool = (pluginSkills, pluginSkillOwnersOrStaticSelecti
|
|
|
44445
45044
|
{
|
|
44446
45045
|
name: "skill",
|
|
44447
45046
|
description: LOAD_SKILL_CONTENT_DESCRIPTION,
|
|
44448
|
-
schema:
|
|
44449
|
-
skill_name:
|
|
45047
|
+
schema: z53.object({
|
|
45048
|
+
skill_name: z53.string().describe("The name of the skill to load")
|
|
44450
45049
|
})
|
|
44451
45050
|
}
|
|
44452
45051
|
);
|
|
@@ -44465,7 +45064,7 @@ function isSkillAllowed2(skillName, staticSelection) {
|
|
|
44465
45064
|
}
|
|
44466
45065
|
|
|
44467
45066
|
// src/tool_lattice/skill/load_skill_resource.ts
|
|
44468
|
-
import
|
|
45067
|
+
import z54 from "zod";
|
|
44469
45068
|
import { tool as tool47 } from "langchain";
|
|
44470
45069
|
var LOAD_SKILL_RESOURCE_DESCRIPTION = `Load a specific resource file from a skill's resources directory. Use this tool when you need to access template files, example data, or other resources bundled with a skill. The resource paths are listed in the skill content when using the load_skill_content tool.`;
|
|
44471
45070
|
function getSandboxFromExeConfig3(_exe_config) {
|
|
@@ -44509,16 +45108,16 @@ var createLoadSkillResourceTool = (pluginSkills, pluginSkillOwners) => {
|
|
|
44509
45108
|
{
|
|
44510
45109
|
name: "load_skill_resource",
|
|
44511
45110
|
description: LOAD_SKILL_RESOURCE_DESCRIPTION,
|
|
44512
|
-
schema:
|
|
44513
|
-
skill_name:
|
|
44514
|
-
resource_path:
|
|
45111
|
+
schema: z54.object({
|
|
45112
|
+
skill_name: z54.string().describe("The name of the skill containing the resource"),
|
|
45113
|
+
resource_path: z54.string().describe("The path to the resource relative to the skill's resources/ directory")
|
|
44515
45114
|
})
|
|
44516
45115
|
}
|
|
44517
45116
|
);
|
|
44518
45117
|
};
|
|
44519
45118
|
|
|
44520
45119
|
// src/tool_lattice/skill/delete_skill.ts
|
|
44521
|
-
import
|
|
45120
|
+
import z55 from "zod";
|
|
44522
45121
|
import { tool as tool48 } from "langchain";
|
|
44523
45122
|
var DELETE_SKILL_DESCRIPTION = `
|
|
44524
45123
|
Delete a skill by name from the skill system.
|
|
@@ -44578,8 +45177,8 @@ var createDeleteSkillTool = (staticSelection = {}) => {
|
|
|
44578
45177
|
{
|
|
44579
45178
|
name: "delete_skill",
|
|
44580
45179
|
description: DELETE_SKILL_DESCRIPTION,
|
|
44581
|
-
schema:
|
|
44582
|
-
skill_name:
|
|
45180
|
+
schema: z55.object({
|
|
45181
|
+
skill_name: z55.string().describe("The name of the skill to delete")
|
|
44583
45182
|
})
|
|
44584
45183
|
}
|
|
44585
45184
|
);
|
|
@@ -44603,7 +45202,7 @@ function createSkillMiddleware(params = {}) {
|
|
|
44603
45202
|
} = params;
|
|
44604
45203
|
const skills = params.skills;
|
|
44605
45204
|
let latestSkills = [];
|
|
44606
|
-
return
|
|
45205
|
+
return createMiddleware19({
|
|
44607
45206
|
name: "skillMiddleware",
|
|
44608
45207
|
contextSchema,
|
|
44609
45208
|
tools: [
|
|
@@ -44753,10 +45352,10 @@ var skillPlugin = {
|
|
|
44753
45352
|
};
|
|
44754
45353
|
|
|
44755
45354
|
// src/middlewares/collectionMiddleware.ts
|
|
44756
|
-
import { createMiddleware as
|
|
45355
|
+
import { createMiddleware as createMiddleware20 } from "langchain";
|
|
44757
45356
|
|
|
44758
45357
|
// src/tool_lattice/collection/list_collections.ts
|
|
44759
|
-
import
|
|
45358
|
+
import z56 from "zod";
|
|
44760
45359
|
import { tool as tool49 } from "langchain";
|
|
44761
45360
|
|
|
44762
45361
|
// src/tool_lattice/collection/utils.ts
|
|
@@ -44815,20 +45414,21 @@ var createListCollectionsTool = ({
|
|
|
44815
45414
|
{
|
|
44816
45415
|
name: "list_collections",
|
|
44817
45416
|
description: LIST_COLLECTIONS_DESCRIPTION,
|
|
44818
|
-
schema:
|
|
45417
|
+
schema: z56.object({})
|
|
44819
45418
|
}
|
|
44820
45419
|
);
|
|
44821
45420
|
};
|
|
44822
45421
|
|
|
44823
45422
|
// src/tool_lattice/collection/search_collection.ts
|
|
44824
|
-
import
|
|
45423
|
+
import z57 from "zod";
|
|
44825
45424
|
import { tool as tool50 } from "langchain";
|
|
45425
|
+
import { EMBEDDING_DEFAULT_KEY as EMBEDDING_DEFAULT_KEY3 } from "@axiom-lattice/protocols";
|
|
44826
45426
|
var SEARCH_COLLECTION_DESCRIPTION = `Search for content within a specific collection using semantic (vector) similarity. Use the 'filter' parameter to narrow results by metadata fields (e.g., {"category": "cardiovascular"}). Returns the most relevant content entries with similarity scores.`;
|
|
44827
|
-
var searchSchema =
|
|
44828
|
-
collection:
|
|
44829
|
-
query:
|
|
44830
|
-
filter:
|
|
44831
|
-
top_k:
|
|
45427
|
+
var searchSchema = z57.object({
|
|
45428
|
+
collection: z57.string().describe("The collection name to search in"),
|
|
45429
|
+
query: z57.string().describe("The search query text"),
|
|
45430
|
+
filter: z57.record(z57.unknown()).optional().describe("Metadata filter conditions"),
|
|
45431
|
+
top_k: z57.number().optional().default(5).describe("Number of results to return")
|
|
44832
45432
|
});
|
|
44833
45433
|
var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => {
|
|
44834
45434
|
return tool50(
|
|
@@ -44842,7 +45442,7 @@ var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
44842
45442
|
if (!metadata) {
|
|
44843
45443
|
return `Collection "${collection}" not found. Use list_collections to see available collections.`;
|
|
44844
45444
|
}
|
|
44845
|
-
const embeddingKey = metadata.embeddingKey ||
|
|
45445
|
+
const embeddingKey = metadata.embeddingKey || EMBEDDING_DEFAULT_KEY3;
|
|
44846
45446
|
let vectorStore;
|
|
44847
45447
|
try {
|
|
44848
45448
|
const storeKey = `${tenantId2}:${collection}`;
|
|
@@ -44857,7 +45457,10 @@ var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
44857
45457
|
const embeddingsClient = await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
44858
45458
|
tenantId2,
|
|
44859
45459
|
embeddingKey
|
|
44860
|
-
) ?? await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
45460
|
+
) ?? (embeddingKey === EMBEDDING_DEFAULT_KEY3 ? void 0 : await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
45461
|
+
tenantId2,
|
|
45462
|
+
EMBEDDING_DEFAULT_KEY3
|
|
45463
|
+
)) ?? await embeddingsLatticeManager.getEmbeddingsClientWithTenant(
|
|
44861
45464
|
tenantId2,
|
|
44862
45465
|
"default"
|
|
44863
45466
|
);
|
|
@@ -44901,7 +45504,7 @@ var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
44901
45504
|
};
|
|
44902
45505
|
|
|
44903
45506
|
// src/tool_lattice/collection/get_collection.ts
|
|
44904
|
-
import
|
|
45507
|
+
import z58 from "zod";
|
|
44905
45508
|
import { tool as tool51 } from "langchain";
|
|
44906
45509
|
var GET_COLLECTION_DESCRIPTION = `Get a collection's full definition including its custom fields schema. Use this to discover what metadata fields are available before adding entries.`;
|
|
44907
45510
|
var createGetCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool51(
|
|
@@ -44929,21 +45532,21 @@ Embedding: ${c.embeddingKey}${fieldsDesc}`;
|
|
|
44929
45532
|
return `Error: ${error.message}`;
|
|
44930
45533
|
}
|
|
44931
45534
|
},
|
|
44932
|
-
{ name: "get_collection", description: GET_COLLECTION_DESCRIPTION, schema:
|
|
45535
|
+
{ name: "get_collection", description: GET_COLLECTION_DESCRIPTION, schema: z58.object({ name: z58.string().describe("Collection name") }) }
|
|
44933
45536
|
);
|
|
44934
45537
|
|
|
44935
45538
|
// src/tool_lattice/collection/create_collection.ts
|
|
44936
|
-
import
|
|
45539
|
+
import z59 from "zod";
|
|
44937
45540
|
import { tool as tool52 } from "langchain";
|
|
44938
|
-
var createSchema =
|
|
44939
|
-
name:
|
|
44940
|
-
label:
|
|
44941
|
-
embeddingKey:
|
|
44942
|
-
fields:
|
|
44943
|
-
key:
|
|
44944
|
-
type:
|
|
44945
|
-
enumValues:
|
|
44946
|
-
required:
|
|
45541
|
+
var createSchema = z59.object({
|
|
45542
|
+
name: z59.string().describe("Collection name (lowercase, underscores only)"),
|
|
45543
|
+
label: z59.string().describe("Display name"),
|
|
45544
|
+
embeddingKey: z59.string().describe("Embedding model key"),
|
|
45545
|
+
fields: z59.array(z59.object({
|
|
45546
|
+
key: z59.string().describe("Field key name"),
|
|
45547
|
+
type: z59.enum(["string", "number", "enum"]).describe("Field data type"),
|
|
45548
|
+
enumValues: z59.array(z59.string()).optional().describe("Valid values for enum type"),
|
|
45549
|
+
required: z59.boolean().optional().default(false).describe("Whether field is required")
|
|
44947
45550
|
})).optional().describe("Custom field definitions for entries in this collection")
|
|
44948
45551
|
});
|
|
44949
45552
|
var createCreateCollectionTool = (scope = {}) => tool52(
|
|
@@ -44972,17 +45575,17 @@ var createCreateCollectionTool = (scope = {}) => tool52(
|
|
|
44972
45575
|
);
|
|
44973
45576
|
|
|
44974
45577
|
// src/tool_lattice/collection/update_collection.ts
|
|
44975
|
-
import
|
|
45578
|
+
import z60 from "zod";
|
|
44976
45579
|
import { tool as tool53 } from "langchain";
|
|
44977
|
-
var schema =
|
|
44978
|
-
name:
|
|
44979
|
-
label:
|
|
44980
|
-
embeddingKey:
|
|
44981
|
-
fields:
|
|
44982
|
-
key:
|
|
44983
|
-
type:
|
|
44984
|
-
enumValues:
|
|
44985
|
-
required:
|
|
45580
|
+
var schema = z60.object({
|
|
45581
|
+
name: z60.string().describe("Collection name"),
|
|
45582
|
+
label: z60.string().optional().describe("New display name"),
|
|
45583
|
+
embeddingKey: z60.string().optional().describe("New embedding model key"),
|
|
45584
|
+
fields: z60.array(z60.object({
|
|
45585
|
+
key: z60.string().describe("Field key name"),
|
|
45586
|
+
type: z60.enum(["string", "number", "enum"]).describe("Field data type"),
|
|
45587
|
+
enumValues: z60.array(z60.string()).optional().describe("Valid values for enum type"),
|
|
45588
|
+
required: z60.boolean().optional().default(false).describe("Whether field is required")
|
|
44986
45589
|
})).optional().describe("Custom field definitions for entries (replaces existing schema)")
|
|
44987
45590
|
});
|
|
44988
45591
|
var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool53(
|
|
@@ -45006,7 +45609,7 @@ var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
45006
45609
|
);
|
|
45007
45610
|
|
|
45008
45611
|
// src/tool_lattice/collection/delete_collection.ts
|
|
45009
|
-
import
|
|
45612
|
+
import z61 from "zod";
|
|
45010
45613
|
import { tool as tool54 } from "langchain";
|
|
45011
45614
|
var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool54(
|
|
45012
45615
|
async (input, _exeConfig) => {
|
|
@@ -45020,14 +45623,14 @@ var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
45020
45623
|
return `Error: ${e.message}`;
|
|
45021
45624
|
}
|
|
45022
45625
|
},
|
|
45023
|
-
{ name: "delete_collection", description: `Delete a collection and all its entries. This cannot be undone.`, schema:
|
|
45626
|
+
{ name: "delete_collection", description: `Delete a collection and all its entries. This cannot be undone.`, schema: z61.object({ name: z61.string().describe("Collection name") }) }
|
|
45024
45627
|
);
|
|
45025
45628
|
|
|
45026
45629
|
// src/tool_lattice/collection/list_entries.ts
|
|
45027
|
-
import
|
|
45630
|
+
import z62 from "zod";
|
|
45028
45631
|
import { tool as tool55 } from "langchain";
|
|
45029
|
-
var schema2 =
|
|
45030
|
-
collection:
|
|
45632
|
+
var schema2 = z62.object({
|
|
45633
|
+
collection: z62.string().describe("Collection name")
|
|
45031
45634
|
});
|
|
45032
45635
|
function buildKey2(tenantId2, name) {
|
|
45033
45636
|
return `${tenantId2}:${name}`;
|
|
@@ -45061,14 +45664,14 @@ var createListEntriesTool = (scope = { collectionKeys: [], connectAll: true }) =
|
|
|
45061
45664
|
);
|
|
45062
45665
|
|
|
45063
45666
|
// src/tool_lattice/collection/add_entry.ts
|
|
45064
|
-
import
|
|
45667
|
+
import z63 from "zod";
|
|
45065
45668
|
import { tool as tool56 } from "langchain";
|
|
45066
45669
|
import { Document } from "@langchain/core/documents";
|
|
45067
45670
|
import { v4 as uuidv47 } from "uuid";
|
|
45068
|
-
var schema3 =
|
|
45069
|
-
collection:
|
|
45070
|
-
content:
|
|
45071
|
-
metadata:
|
|
45671
|
+
var schema3 = z63.object({
|
|
45672
|
+
collection: z63.string().describe("Collection name"),
|
|
45673
|
+
content: z63.string().describe("Entry content text"),
|
|
45674
|
+
metadata: z63.record(z63.unknown()).optional().describe("Metadata fields matching the collection schema")
|
|
45072
45675
|
});
|
|
45073
45676
|
function key2(t, n) {
|
|
45074
45677
|
return `${t}:${n}`;
|
|
@@ -45105,13 +45708,13 @@ var createAddEntryTool = (scope = { collectionKeys: [], connectAll: true }) => t
|
|
|
45105
45708
|
);
|
|
45106
45709
|
|
|
45107
45710
|
// src/tool_lattice/collection/update_entry.ts
|
|
45108
|
-
import
|
|
45711
|
+
import z64 from "zod";
|
|
45109
45712
|
import { tool as tool57 } from "langchain";
|
|
45110
|
-
var schema4 =
|
|
45111
|
-
collection:
|
|
45112
|
-
entryId:
|
|
45113
|
-
content:
|
|
45114
|
-
metadata:
|
|
45713
|
+
var schema4 = z64.object({
|
|
45714
|
+
collection: z64.string().describe("Collection name"),
|
|
45715
|
+
entryId: z64.string().describe("Entry ID to update"),
|
|
45716
|
+
content: z64.string().optional().describe("New content"),
|
|
45717
|
+
metadata: z64.record(z64.unknown()).optional().describe("New metadata")
|
|
45115
45718
|
});
|
|
45116
45719
|
function key3(t, n) {
|
|
45117
45720
|
return `${t}:${n}`;
|
|
@@ -45137,11 +45740,11 @@ var createUpdateEntryTool = (scope = { collectionKeys: [], connectAll: true }) =
|
|
|
45137
45740
|
);
|
|
45138
45741
|
|
|
45139
45742
|
// src/tool_lattice/collection/delete_entry.ts
|
|
45140
|
-
import
|
|
45743
|
+
import z65 from "zod";
|
|
45141
45744
|
import { tool as tool58 } from "langchain";
|
|
45142
|
-
var schema5 =
|
|
45143
|
-
collection:
|
|
45144
|
-
entryId:
|
|
45745
|
+
var schema5 = z65.object({
|
|
45746
|
+
collection: z65.string().describe("Collection name"),
|
|
45747
|
+
entryId: z65.string().describe("Entry ID to delete")
|
|
45145
45748
|
});
|
|
45146
45749
|
function key4(t, n) {
|
|
45147
45750
|
return `${t}:${n}`;
|
|
@@ -45166,7 +45769,7 @@ var createDeleteEntryTool = (scope = { collectionKeys: [], connectAll: true }) =
|
|
|
45166
45769
|
function createCollectionMiddleware(params) {
|
|
45167
45770
|
const { collectionKeys, connectAll, compileStableCandidateTools = false } = params;
|
|
45168
45771
|
if (!compileStableCandidateTools && !connectAll && (!collectionKeys || collectionKeys.length === 0)) {
|
|
45169
|
-
return
|
|
45772
|
+
return createMiddleware20({
|
|
45170
45773
|
name: "collectionMiddleware",
|
|
45171
45774
|
contextSchema,
|
|
45172
45775
|
tools: [
|
|
@@ -45176,7 +45779,7 @@ function createCollectionMiddleware(params) {
|
|
|
45176
45779
|
});
|
|
45177
45780
|
}
|
|
45178
45781
|
const toolParams = { collectionKeys, connectAll };
|
|
45179
|
-
return
|
|
45782
|
+
return createMiddleware20({
|
|
45180
45783
|
name: "collectionMiddleware",
|
|
45181
45784
|
contextSchema,
|
|
45182
45785
|
tools: [
|
|
@@ -45239,21 +45842,21 @@ var collectionPlugin = {
|
|
|
45239
45842
|
};
|
|
45240
45843
|
|
|
45241
45844
|
// src/middlewares/askUserClarifyMiddleware.ts
|
|
45242
|
-
import { createMiddleware as
|
|
45845
|
+
import { createMiddleware as createMiddleware21, ToolMessage as ToolMessage10 } from "langchain";
|
|
45243
45846
|
import { interrupt as interrupt3 } from "@langchain/langgraph";
|
|
45244
45847
|
|
|
45245
45848
|
// src/tool_lattice/ask_user_to_clarify/index.ts
|
|
45246
45849
|
import { tool as tool59 } from "langchain";
|
|
45247
|
-
import
|
|
45248
|
-
var questionSchema =
|
|
45249
|
-
question:
|
|
45250
|
-
options:
|
|
45251
|
-
type:
|
|
45252
|
-
required:
|
|
45253
|
-
allowOther:
|
|
45850
|
+
import z66 from "zod";
|
|
45851
|
+
var questionSchema = z66.object({
|
|
45852
|
+
question: z66.string().describe("The question text to ask the user. MUST include the specific context, options, or details being clarified \u2014 never use a bare generic label. Good: 'Confirm the plan: use Redis cache + PostgreSQL primary, split microservices as needed?' Bad: 'Confirm the plan?'"),
|
|
45853
|
+
options: z66.array(z66.string()).optional().default([]).describe("List of EXACT, selectable values. Maximum 3 options allowed. DO NOT include placeholder values like 'Other' or 'Enter manually'. For free-text with predefined choices, use allowOther=true (works with 'single' and 'multiple'). For pure free-text without choices, use type='input' instead. For file_upload and input, pass an empty array."),
|
|
45854
|
+
type: z66.enum(["single", "multiple", "file_upload", "input"]).describe("The question format. 'single' = pick one from options (default, see tool description for guidance). 'multiple' = pick several from options. 'input' = free-text field (only when options cannot express the answer). 'file_upload' = file picker."),
|
|
45855
|
+
required: z66.boolean().optional().default(false).describe("Whether this question must be answered"),
|
|
45856
|
+
allowOther: z66.boolean().optional().default(true).describe("Set to true to append an 'Other' checkbox with a free-text input field. Works with 'single' and 'multiple' types. Use for open-ended answers or when the options cannot cover all possibilities. Not applicable for 'input' or 'file_upload' types.")
|
|
45254
45857
|
});
|
|
45255
|
-
var inputSchema =
|
|
45256
|
-
questions:
|
|
45858
|
+
var inputSchema = z66.object({
|
|
45859
|
+
questions: z66.array(questionSchema).min(1, "At least one question is required").describe("A structured sequence of clarification questions. Use these to gather missing parameters or disambiguate user intent before proceeding.")
|
|
45257
45860
|
});
|
|
45258
45861
|
function createAskUserToClarifyTool() {
|
|
45259
45862
|
return tool59(
|
|
@@ -45281,7 +45884,7 @@ function isProjectRoomRun(request) {
|
|
|
45281
45884
|
return isRecord13(runConfig?.projectRoom);
|
|
45282
45885
|
}
|
|
45283
45886
|
function createAskUserClarifyMiddleware() {
|
|
45284
|
-
return
|
|
45887
|
+
return createMiddleware21({
|
|
45285
45888
|
name: "AskUserClarifyMiddleware",
|
|
45286
45889
|
tools: [createAskUserToClarifyTool()],
|
|
45287
45890
|
wrapToolCall: async (request, handler) => {
|
|
@@ -45291,7 +45894,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
45291
45894
|
return handler(request);
|
|
45292
45895
|
}
|
|
45293
45896
|
if (isProjectRoomRun(request)) {
|
|
45294
|
-
return new
|
|
45897
|
+
return new ToolMessage10({
|
|
45295
45898
|
content: "You are replying inside a project room, which has no interactive clarification UI. Ask your clarifying questions directly in your reply text and stop; the user's next room message will continue the conversation.",
|
|
45296
45899
|
tool_call_id: toolCall?.id,
|
|
45297
45900
|
name: toolName2
|
|
@@ -45299,7 +45902,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
45299
45902
|
}
|
|
45300
45903
|
const parsed = inputSchema.safeParse(toolCall?.args);
|
|
45301
45904
|
if (!parsed.success) {
|
|
45302
|
-
return new
|
|
45905
|
+
return new ToolMessage10({
|
|
45303
45906
|
content: `Invalid clarify tool arguments: ${parsed.error.message}`,
|
|
45304
45907
|
tool_call_id: toolCall?.id,
|
|
45305
45908
|
name: toolName2
|
|
@@ -45319,7 +45922,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
45319
45922
|
const result = await interrupt3(md);
|
|
45320
45923
|
const response = result.data;
|
|
45321
45924
|
if (!response?.answers || response.answers.length === 0) {
|
|
45322
|
-
return new
|
|
45925
|
+
return new ToolMessage10({
|
|
45323
45926
|
content: "No clarification questions were answered.",
|
|
45324
45927
|
tool_call_id: toolCall?.id,
|
|
45325
45928
|
name: toolName2
|
|
@@ -45329,7 +45932,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
45329
45932
|
(answer) => (answer.selectedOptions?.length ?? 0) > 0 || answer.otherText && answer.otherText.trim() !== "" || answer.filePath && answer.filePath.trim() !== ""
|
|
45330
45933
|
);
|
|
45331
45934
|
if (answeredQuestions.length === 0) {
|
|
45332
|
-
return new
|
|
45935
|
+
return new ToolMessage10({
|
|
45333
45936
|
content: "No clarification questions were answered.",
|
|
45334
45937
|
tool_call_id: toolCall?.id,
|
|
45335
45938
|
name: toolName2
|
|
@@ -45359,7 +45962,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
45359
45962
|
}
|
|
45360
45963
|
lines.push("");
|
|
45361
45964
|
}
|
|
45362
|
-
return new
|
|
45965
|
+
return new ToolMessage10({
|
|
45363
45966
|
content: lines.join("\n"),
|
|
45364
45967
|
tool_call_id: toolCall?.id,
|
|
45365
45968
|
name: toolName2
|
|
@@ -45385,11 +45988,11 @@ var askUserClarifyPlugin = {
|
|
|
45385
45988
|
};
|
|
45386
45989
|
|
|
45387
45990
|
// src/middlewares/widgetMiddleware.ts
|
|
45388
|
-
import { createMiddleware as
|
|
45991
|
+
import { createMiddleware as createMiddleware22 } from "langchain";
|
|
45389
45992
|
|
|
45390
45993
|
// src/tool_lattice/widget/loadGuidelines.ts
|
|
45391
45994
|
import { tool as tool60 } from "langchain";
|
|
45392
|
-
import { z as
|
|
45995
|
+
import { z as z67 } from "zod";
|
|
45393
45996
|
|
|
45394
45997
|
// src/middlewares/guidelines/index.ts
|
|
45395
45998
|
var CORE = `# Imagine \u2014 Visual Creation Suite
|
|
@@ -46256,8 +46859,8 @@ function getGuidelines(modules) {
|
|
|
46256
46859
|
var AVAILABLE_MODULES = Object.keys(MODULE_SECTIONS);
|
|
46257
46860
|
|
|
46258
46861
|
// src/tool_lattice/widget/loadGuidelines.ts
|
|
46259
|
-
var LoadGuidelinesInputSchema =
|
|
46260
|
-
modules:
|
|
46862
|
+
var LoadGuidelinesInputSchema = z67.object({
|
|
46863
|
+
modules: z67.array(z67.string()).describe(
|
|
46261
46864
|
"Which design modules to load. Choose all that apply. Available modules: [" + AVAILABLE_MODULES.join(",") + "]"
|
|
46262
46865
|
)
|
|
46263
46866
|
});
|
|
@@ -46277,7 +46880,7 @@ function createLoadGuidelinesTool() {
|
|
|
46277
46880
|
|
|
46278
46881
|
// src/tool_lattice/widget/showWidget.ts
|
|
46279
46882
|
import { tool as tool61 } from "langchain";
|
|
46280
|
-
import { z as
|
|
46883
|
+
import { z as z68 } from "zod";
|
|
46281
46884
|
function containsForbiddenTags(code) {
|
|
46282
46885
|
const forbiddenPatterns = [
|
|
46283
46886
|
/<!DOCTYPE/i,
|
|
@@ -46299,15 +46902,15 @@ function validateWidgetCode(code) {
|
|
|
46299
46902
|
}
|
|
46300
46903
|
return { valid: true };
|
|
46301
46904
|
}
|
|
46302
|
-
var ShowWidgetInputSchema =
|
|
46303
|
-
i_have_seen_guidelines:
|
|
46905
|
+
var ShowWidgetInputSchema = z68.object({
|
|
46906
|
+
i_have_seen_guidelines: z68.boolean().describe(
|
|
46304
46907
|
"Must be true. Confirm you have called load_guidelines first."
|
|
46305
46908
|
),
|
|
46306
|
-
title:
|
|
46307
|
-
loading_messages:
|
|
46909
|
+
title: z68.string().describe("Title displayed above the widget"),
|
|
46910
|
+
loading_messages: z68.array(z68.string()).optional().describe(
|
|
46308
46911
|
"1-4 short strings shown while the widget renders"
|
|
46309
46912
|
),
|
|
46310
|
-
widget_code:
|
|
46913
|
+
widget_code: z68.string().describe(
|
|
46311
46914
|
"HTML fragment to render. Rules: 1. No DOCTYPE, <html>, <head>, or <body> tags. 2. Order: <style> block first, then HTML content, then <script> last. 3. Use only CSS variables for colors (e.g. var(--color-accent)). 4. No gradients, shadows, or blur effects. For SVG: start directly with <svg> tag."
|
|
46312
46915
|
)
|
|
46313
46916
|
});
|
|
@@ -46343,7 +46946,7 @@ function createWidgetMiddleware() {
|
|
|
46343
46946
|
createLoadGuidelinesTool(),
|
|
46344
46947
|
createShowWidgetTool()
|
|
46345
46948
|
];
|
|
46346
|
-
return
|
|
46949
|
+
return createMiddleware22({
|
|
46347
46950
|
name: "widgetMiddleware",
|
|
46348
46951
|
contextSchema,
|
|
46349
46952
|
tools
|
|
@@ -46367,8 +46970,8 @@ var widgetPlugin = {
|
|
|
46367
46970
|
};
|
|
46368
46971
|
|
|
46369
46972
|
// src/middlewares/taskMiddleware.ts
|
|
46370
|
-
import { createMiddleware as
|
|
46371
|
-
import { z as
|
|
46973
|
+
import { createMiddleware as createMiddleware23, tool as tool62, ToolMessage as ToolMessage11 } from "langchain";
|
|
46974
|
+
import { z as z69 } from "zod";
|
|
46372
46975
|
import { GraphInterrupt as GraphInterrupt3, interrupt as interrupt4 } from "@langchain/langgraph";
|
|
46373
46976
|
import { resolveRunScope as resolveRunScope3 } from "@axiom-lattice/protocols";
|
|
46374
46977
|
|
|
@@ -47253,72 +47856,72 @@ function buildReviewMarkdown(task) {
|
|
|
47253
47856
|
result: task.result
|
|
47254
47857
|
});
|
|
47255
47858
|
}
|
|
47256
|
-
var manageTaskSchema =
|
|
47257
|
-
action:
|
|
47258
|
-
id:
|
|
47259
|
-
title:
|
|
47260
|
-
description:
|
|
47261
|
-
priority:
|
|
47262
|
-
status:
|
|
47263
|
-
dueDate:
|
|
47264
|
-
metadata:
|
|
47265
|
-
metadataFilter:
|
|
47266
|
-
|
|
47859
|
+
var manageTaskSchema = z69.object({
|
|
47860
|
+
action: z69.enum(["create", "get", "list", "update", "set_status", "add_activity", "delete"]).describe("Action to perform. Available: create, get, list, update, set_status, add_activity, delete. To change status, use set_status. To change content fields, use update."),
|
|
47861
|
+
id: z69.string().optional().describe("Task ID (required for get, update, add_activity; required for delete unless ids is given)"),
|
|
47862
|
+
title: z69.string().optional().describe("Task title (required for create)"),
|
|
47863
|
+
description: z69.string().optional().describe("Task description in Markdown"),
|
|
47864
|
+
priority: z69.enum(["low", "medium", "high"]).optional().describe("Priority level"),
|
|
47865
|
+
status: z69.enum(["pending", "in_progress", "review", "failed", "interrupted", "completed", "cancelled"]).optional().describe("Task status. For status-only changes, prefer set_status action. Set 'in_progress' only for a task THIS run executes (a delegated task is claimed by `task` dispatch); 'completed'/'failed' require the task to be 'in_progress'. Agent summary-only interrupted updates default to missing_input"),
|
|
47866
|
+
dueDate: z69.string().optional().describe("Due date (ISO 8601 format)"),
|
|
47867
|
+
metadata: z69.record(z69.unknown()).optional().describe("Structured metadata (e.g. projectId, module)"),
|
|
47868
|
+
metadataFilter: z69.record(
|
|
47869
|
+
z69.union([z69.string(), z69.number(), z69.boolean()])
|
|
47267
47870
|
).optional().describe("List-only filter. Every key must equal the task metadata value, e.g. {projectId:'p1', retries:2}. Multiple keys AND together."),
|
|
47268
|
-
parentId:
|
|
47269
|
-
sourceId:
|
|
47270
|
-
context:
|
|
47271
|
-
ownerType:
|
|
47272
|
-
ownerId:
|
|
47273
|
-
requireReview:
|
|
47274
|
-
dependencies:
|
|
47275
|
-
result:
|
|
47276
|
-
failureReason:
|
|
47277
|
-
files:
|
|
47278
|
-
uri:
|
|
47279
|
-
name:
|
|
47280
|
-
addedBy:
|
|
47871
|
+
parentId: z69.string().optional().describe("Parent task ID for grouping subtasks"),
|
|
47872
|
+
sourceId: z69.string().optional().describe("Source session/thread ID"),
|
|
47873
|
+
context: z69.record(z69.unknown()).optional().describe("Additional context data"),
|
|
47874
|
+
ownerType: z69.enum(["user", "agent"]).optional().describe("Owner type. Defaults to the runtime actor: agent runtime (no user identity) -> 'agent', user runtime -> 'user'."),
|
|
47875
|
+
ownerId: z69.string().optional().describe("Owner ID. Auto-filled from current user/agent if omitted"),
|
|
47876
|
+
requireReview: z69.boolean().optional().describe("If true, agent completion pauses as interrupted(review_required) for HITL approval"),
|
|
47877
|
+
dependencies: z69.array(z69.string()).optional().describe("List of task IDs that must be completed before this task can start"),
|
|
47878
|
+
result: z69.string().optional().describe("Result summary. Used with set_status status='completed' or update status='completed'"),
|
|
47879
|
+
failureReason: z69.string().optional().describe("Failure reason. Used with set_status status='failed' or update status='failed'"),
|
|
47880
|
+
files: z69.array(z69.object({
|
|
47881
|
+
uri: z69.string().describe("Uniquely locates the resource: http(s):// URL, /s/:token share, or sandbox path"),
|
|
47882
|
+
name: z69.string().optional().describe("Display name"),
|
|
47883
|
+
addedBy: z69.enum(["user", "agent"]).optional().describe("Who attached the file")
|
|
47281
47884
|
})).optional().describe("File references attached to this task"),
|
|
47282
|
-
beliefImpact:
|
|
47283
|
-
key:
|
|
47284
|
-
after:
|
|
47285
|
-
basis:
|
|
47286
|
-
isNew:
|
|
47885
|
+
beliefImpact: z69.array(z69.object({
|
|
47886
|
+
key: z69.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
47887
|
+
after: z69.number().int().min(0).max(100),
|
|
47888
|
+
basis: z69.string().trim().min(1).max(1e3),
|
|
47889
|
+
isNew: z69.boolean().optional().describe("Set true only to add a belief key that is absent from the belief owner's Belief State; omit for keys that already exist")
|
|
47287
47890
|
})).optional().describe("Structured belief reports required when an agent-owned task completes; existing keys update the belief owner's table, and a brand-new key must be declared with isNew: true"),
|
|
47288
|
-
content:
|
|
47289
|
-
summary:
|
|
47290
|
-
executionResultId:
|
|
47891
|
+
content: z69.string().optional().describe("Markdown content required for add_activity"),
|
|
47892
|
+
summary: z69.string().optional().describe("Brief summary of the operation"),
|
|
47893
|
+
executionResultId: z69.string().refine(isExecutionResultEventKey3, {
|
|
47291
47894
|
message: "executionResultId must be the execution-result:<threadId> event key returned by task()"
|
|
47292
47895
|
}).optional().describe(
|
|
47293
47896
|
"Canonical ASCII `execution-result:<suffix>` event key returned by task(); the nonempty suffix allows only A-Z, a-z, 0-9, period, underscore, colon, and hyphen, and is not a database row ID"
|
|
47294
47897
|
),
|
|
47295
|
-
ids:
|
|
47898
|
+
ids: z69.array(z69.string().trim().min(1)).optional().describe("Task IDs to delete in one batch (delete action only). Use with or instead of id.")
|
|
47296
47899
|
}).superRefine((input, context) => {
|
|
47297
47900
|
if (input.executionResultId && input.action !== "update" && input.action !== "set_status" && input.action !== "add_activity") {
|
|
47298
47901
|
context.addIssue({
|
|
47299
|
-
code:
|
|
47902
|
+
code: z69.ZodIssueCode.custom,
|
|
47300
47903
|
path: ["executionResultId"],
|
|
47301
47904
|
message: "executionResultId is valid only for update, set_status, or add_activity"
|
|
47302
47905
|
});
|
|
47303
47906
|
}
|
|
47304
47907
|
if (input.metadataFilter && input.action !== "list") {
|
|
47305
47908
|
context.addIssue({
|
|
47306
|
-
code:
|
|
47909
|
+
code: z69.ZodIssueCode.custom,
|
|
47307
47910
|
path: ["metadataFilter"],
|
|
47308
47911
|
message: "metadataFilter is valid only for list"
|
|
47309
47912
|
});
|
|
47310
47913
|
}
|
|
47311
47914
|
if (input.ids && input.action !== "delete") {
|
|
47312
47915
|
context.addIssue({
|
|
47313
|
-
code:
|
|
47916
|
+
code: z69.ZodIssueCode.custom,
|
|
47314
47917
|
path: ["ids"],
|
|
47315
47918
|
message: "ids is valid only for delete"
|
|
47316
47919
|
});
|
|
47317
47920
|
}
|
|
47318
47921
|
});
|
|
47319
|
-
var startTaskSchema =
|
|
47320
|
-
taskId:
|
|
47321
|
-
agentId:
|
|
47922
|
+
var startTaskSchema = z69.object({
|
|
47923
|
+
taskId: z69.string().trim().min(1).describe("ID of the persisted TaskItem to start"),
|
|
47924
|
+
agentId: z69.string().trim().min(1).describe(
|
|
47322
47925
|
`ID of the Agent that should execute the task. Use "general-purpose" to run the caller's own capabilities as an isolated worker.`
|
|
47323
47926
|
)
|
|
47324
47927
|
});
|
|
@@ -48708,12 +49311,12 @@ function createTaskMiddleware(options = {}) {
|
|
|
48708
49311
|
...trustedCaller ? { callerMembershipId: trustedCaller.membershipId, callerAssistantId: trustedCaller.assistantId } : rc.assistant_id ? { callerAssistantId: rc.assistant_id } : {}
|
|
48709
49312
|
}));
|
|
48710
49313
|
};
|
|
48711
|
-
return
|
|
49314
|
+
return createMiddleware23({
|
|
48712
49315
|
name: "TaskMiddleware",
|
|
48713
49316
|
contextSchema,
|
|
48714
49317
|
// Persisted between invocations (ADRs: the run↔task binding survives turns).
|
|
48715
|
-
stateSchema:
|
|
48716
|
-
taskId:
|
|
49318
|
+
stateSchema: z69.object({
|
|
49319
|
+
taskId: z69.string().default("")
|
|
48717
49320
|
}),
|
|
48718
49321
|
// CLAIM: a run that holds a task moves it to in_progress (idempotent).
|
|
48719
49322
|
beforeAgent: async (state, runtime) => {
|
|
@@ -48778,6 +49381,26 @@ function createTaskMiddleware(options = {}) {
|
|
|
48778
49381
|
taskRunRegistry.unregister(taskId);
|
|
48779
49382
|
return {};
|
|
48780
49383
|
},
|
|
49384
|
+
wrapToolCall: async (request, handler) => {
|
|
49385
|
+
if (request.toolCall?.name === "task") {
|
|
49386
|
+
const args = request.toolCall.args;
|
|
49387
|
+
const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
|
|
49388
|
+
const agentId = typeof args?.agentId === "string" ? args.agentId.trim() : "";
|
|
49389
|
+
if (!taskId || !agentId) {
|
|
49390
|
+
return new ToolMessage11({
|
|
49391
|
+
name: "task",
|
|
49392
|
+
tool_call_id: request.toolCall.id ?? "task-dispatch",
|
|
49393
|
+
status: "error",
|
|
49394
|
+
content: JSON.stringify({
|
|
49395
|
+
success: false,
|
|
49396
|
+
code: "TASK_DISPATCH_REQUIRES_TASK_ID",
|
|
49397
|
+
error: '`task` only dispatches an existing TaskItem. Create the task first with `manage_task` action="create" (title + description), then call `task { taskId, agentId }`. Do not pass action/description/title to `task`.'
|
|
49398
|
+
})
|
|
49399
|
+
});
|
|
49400
|
+
}
|
|
49401
|
+
}
|
|
49402
|
+
return handler(request);
|
|
49403
|
+
},
|
|
48781
49404
|
wrapModelCall: async (request, handler) => {
|
|
48782
49405
|
const taskPrompt = `## Task Management
|
|
48783
49406
|
|
|
@@ -48878,7 +49501,7 @@ to an expert \u2014 never re-dispatch the task you are processing.`,
|
|
|
48878
49501
|
),
|
|
48879
49502
|
tool62(handleStartTask, {
|
|
48880
49503
|
name: "task",
|
|
48881
|
-
description: `Start a persisted TaskItem with any existing Agent in a fresh isolated thread. Use this to delegate work \u2014 dispatch a subtask you created to the agent that should execute it; never re-dispatch the task you are currently processing (give the expert a child task instead). Pass agentId "general-purpose" for the general-purpose worker \u2014 ${DEFAULT_GENERAL_PURPOSE_DESCRIPTION} It has access to all the caller's tools, model, and middleware, so use it for general-purpose subtasks, to isolate context and token usage, and whenever no specialized agent fits. The target does NOT need task-management tools: it runs and returns an observation, an executionResultId, and the task's taskStatus (re-read after the worker settled). Check taskStatus before completing: if it is already 'completed' the worker finished it \u2014 do NOT complete again (use manage_task add_activity); if it is still 'in_progress' you are the single completer and pass the executionResultId to manage_task set_status completed; if it is 'failed' or 'interrupted', act on that. The caller reconciles via manage_task, which interprets the result and records the outcome. A project task instead returns a managed result (success:true, managed:true) because the project-lifecycle queue owns execution.`,
|
|
49504
|
+
description: `Start a persisted TaskItem with any existing Agent in a fresh isolated thread. This tool CANNOT create a task: create it first with \`manage_task\` action="create" (title + description), then dispatch it with \`task { taskId, agentId }\`. Do not pass action/description/title to this tool. Use this to delegate work \u2014 dispatch a subtask you created to the agent that should execute it; never re-dispatch the task you are currently processing (give the expert a child task instead). Pass agentId "general-purpose" for the general-purpose worker \u2014 ${DEFAULT_GENERAL_PURPOSE_DESCRIPTION} It has access to all the caller's tools, model, and middleware, so use it for general-purpose subtasks, to isolate context and token usage, and whenever no specialized agent fits. The target does NOT need task-management tools: it runs and returns an observation, an executionResultId, and the task's taskStatus (re-read after the worker settled). Check taskStatus before completing: if it is already 'completed' the worker finished it \u2014 do NOT complete again (use manage_task add_activity); if it is still 'in_progress' you are the single completer and pass the executionResultId to manage_task set_status completed; if it is 'failed' or 'interrupted', act on that. The caller reconciles via manage_task, which interprets the result and records the outcome. A project task instead returns a managed result (success:true, managed:true) because the project-lifecycle queue owns execution.`,
|
|
48882
49505
|
schema: startTaskSchema
|
|
48883
49506
|
})
|
|
48884
49507
|
]
|
|
@@ -49020,7 +49643,7 @@ canonical Belief State:
|
|
|
49020
49643
|
};
|
|
49021
49644
|
|
|
49022
49645
|
// src/middlewares/documentLearningMiddleware.ts
|
|
49023
|
-
import { createMiddleware as
|
|
49646
|
+
import { createMiddleware as createMiddleware24 } from "langchain";
|
|
49024
49647
|
|
|
49025
49648
|
// src/middlewares/documentLearningSkills.ts
|
|
49026
49649
|
var LEARN_CAPABILITY_SKILL = `---
|
|
@@ -49259,7 +49882,7 @@ patterns discovered, recommendations. Include validation coverage: user-sample N
|
|
|
49259
49882
|
`;
|
|
49260
49883
|
|
|
49261
49884
|
// src/middlewares/documentLearningMiddleware.ts
|
|
49262
|
-
var createDocumentLearningMiddleware = () =>
|
|
49885
|
+
var createDocumentLearningMiddleware = () => createMiddleware24({
|
|
49263
49886
|
name: "DocumentLearningMiddleware",
|
|
49264
49887
|
contextSchema,
|
|
49265
49888
|
tools: []
|
|
@@ -49282,11 +49905,11 @@ var documentLearningPlugin = {
|
|
|
49282
49905
|
};
|
|
49283
49906
|
|
|
49284
49907
|
// src/middlewares/documentParserMiddleware.ts
|
|
49285
|
-
import { createMiddleware as
|
|
49908
|
+
import { createMiddleware as createMiddleware25 } from "langchain";
|
|
49286
49909
|
|
|
49287
49910
|
// src/tool_lattice/document_parser/index.ts
|
|
49288
49911
|
import * as path7 from "path";
|
|
49289
|
-
import
|
|
49912
|
+
import z70 from "zod";
|
|
49290
49913
|
import { tool as tool63 } from "langchain";
|
|
49291
49914
|
var PARSE_DOCUMENT_DESCRIPTION = `Parse a document file (docx, pdf) into structured Markdown using a remote document parsing service.
|
|
49292
49915
|
This tool handles the full pipeline internally: file upload \u2192 document parsing \u2192 polling until complete \u2192 download result \u2192 save to filesystem.
|
|
@@ -49481,17 +50104,17 @@ function createParseDocumentTool({
|
|
|
49481
50104
|
{
|
|
49482
50105
|
name: "parse_document",
|
|
49483
50106
|
description: PARSE_DOCUMENT_DESCRIPTION,
|
|
49484
|
-
schema:
|
|
49485
|
-
file_path:
|
|
50107
|
+
schema: z70.object({
|
|
50108
|
+
file_path: z70.string().describe(
|
|
49486
50109
|
'Absolute path to the document file. Must point to an existing .docx or .pdf file. Example: "/project/reports/contract.docx". The file must be accessible from the current workspace.'
|
|
49487
50110
|
),
|
|
49488
|
-
engine:
|
|
50111
|
+
engine: z70.string().describe(
|
|
49489
50112
|
'Parsing engine to use. Available options: "textin" (recommended, works with local files, supports docx/pdf), "datalab" (alternative engine for docx/pdf), "mineru" (requires public URL, use only if textin/datalab fail), "paddleocr_remote" (PaddleOCR, good for scanned documents), "qwen_ocr" (OCR-focused, best for image-heavy PDFs).'
|
|
49490
50113
|
),
|
|
49491
|
-
output_path:
|
|
50114
|
+
output_path: z70.string().optional().describe(
|
|
49492
50115
|
'Path to save the parsed result. If not specified, the input extension is replaced with .md. Example: "/project/report.docx" becomes "/project/report.md". Parent directories are created automatically.'
|
|
49493
50116
|
),
|
|
49494
|
-
output_format:
|
|
50117
|
+
output_format: z70.enum(["markdown", "json"]).optional().default("markdown").describe(
|
|
49495
50118
|
'Output format. "markdown": structured Markdown with tables, headers, formatting preserved (recommended). "json": raw JSON output from the parsing engine (for programmatic use).'
|
|
49496
50119
|
)
|
|
49497
50120
|
})
|
|
@@ -49947,7 +50570,7 @@ function createDocumentParserMiddleware(config) {
|
|
|
49947
50570
|
const baseUrl = config.baseUrl || "";
|
|
49948
50571
|
const apiKey = config.apiKey || "";
|
|
49949
50572
|
const connections = Array.isArray(config.connections) ? config.connections.filter((key5) => typeof key5 === "string") : [];
|
|
49950
|
-
return
|
|
50573
|
+
return createMiddleware25({
|
|
49951
50574
|
name: "DocumentParser",
|
|
49952
50575
|
contextSchema,
|
|
49953
50576
|
tools: [createParseDocumentTool({ connectAll, connections, baseUrl, apiKey })]
|
|
@@ -50135,8 +50758,8 @@ import {
|
|
|
50135
50758
|
snapshotExactArray as snapshotExactArray2,
|
|
50136
50759
|
snapshotExactRecord as snapshotExactRecord7
|
|
50137
50760
|
} from "@axiom-lattice/protocols";
|
|
50138
|
-
import { createMiddleware as
|
|
50139
|
-
import { z as
|
|
50761
|
+
import { createMiddleware as createMiddleware26, tool as tool64 } from "langchain";
|
|
50762
|
+
import { z as z71 } from "zod";
|
|
50140
50763
|
var PROJECT_ROOM_CONTEXT_REQUIRED = "PROJECT_ROOM_CONTEXT_REQUIRED";
|
|
50141
50764
|
var PROJECT_ROOM_POST_FAILED = "PROJECT_ROOM_POST_FAILED";
|
|
50142
50765
|
var PROJECT_ROOM_ROSTER_FAILED = "PROJECT_ROOM_ROSTER_FAILED";
|
|
@@ -50156,10 +50779,10 @@ var ROSTER_FAILED = JSON.stringify({
|
|
|
50156
50779
|
error: PROJECT_ROOM_ROSTER_FAILED,
|
|
50157
50780
|
message: PROJECT_ROOM_ROSTER_FAILED_MESSAGE
|
|
50158
50781
|
});
|
|
50159
|
-
var postSchema =
|
|
50160
|
-
text:
|
|
50782
|
+
var postSchema = z71.object({
|
|
50783
|
+
text: z71.string().trim().min(1).max(2e4)
|
|
50161
50784
|
}).strict();
|
|
50162
|
-
var listSchema =
|
|
50785
|
+
var listSchema = z71.object({}).strict();
|
|
50163
50786
|
function ownDataValue2(record, key5) {
|
|
50164
50787
|
if (typeof record !== "object" || record === null || Array.isArray(record)) return void 0;
|
|
50165
50788
|
try {
|
|
@@ -50244,7 +50867,7 @@ async function hasActiveCurrentMembership(scope) {
|
|
|
50244
50867
|
return true;
|
|
50245
50868
|
}
|
|
50246
50869
|
function createProjectRoomMiddleware() {
|
|
50247
|
-
return
|
|
50870
|
+
return createMiddleware26({
|
|
50248
50871
|
name: "ProjectRoomMiddleware",
|
|
50249
50872
|
tools: [
|
|
50250
50873
|
tool64(async (input, config) => {
|
|
@@ -50339,8 +50962,8 @@ var projectRoomPlugin = {
|
|
|
50339
50962
|
};
|
|
50340
50963
|
|
|
50341
50964
|
// src/middlewares/sandboxPluginsMiddleware.ts
|
|
50342
|
-
import { createMiddleware as
|
|
50343
|
-
import { z as
|
|
50965
|
+
import { createMiddleware as createMiddleware27, tool as tool65 } from "langchain";
|
|
50966
|
+
import { z as z72 } from "zod";
|
|
50344
50967
|
import { AgentType as AgentType10 } from "@axiom-lattice/protocols";
|
|
50345
50968
|
|
|
50346
50969
|
// src/connection/connectionSecretFields.ts
|
|
@@ -51583,8 +52206,8 @@ function redactSecretValues(payload, secrets) {
|
|
|
51583
52206
|
};
|
|
51584
52207
|
return walk(payload);
|
|
51585
52208
|
}
|
|
51586
|
-
var managePluginSchema =
|
|
51587
|
-
action:
|
|
52209
|
+
var managePluginSchema = z72.object({
|
|
52210
|
+
action: z72.enum([
|
|
51588
52211
|
"list",
|
|
51589
52212
|
"get",
|
|
51590
52213
|
"validate",
|
|
@@ -51599,15 +52222,15 @@ var managePluginSchema = z71.object({
|
|
|
51599
52222
|
"status",
|
|
51600
52223
|
"deployments"
|
|
51601
52224
|
]),
|
|
51602
|
-
type:
|
|
51603
|
-
name:
|
|
51604
|
-
description:
|
|
51605
|
-
mode:
|
|
51606
|
-
target:
|
|
51607
|
-
kind:
|
|
51608
|
-
name:
|
|
51609
|
-
input:
|
|
51610
|
-
connectionKey:
|
|
52225
|
+
type: z72.string().optional(),
|
|
52226
|
+
name: z72.string().optional(),
|
|
52227
|
+
description: z72.string().optional(),
|
|
52228
|
+
mode: z72.enum(["onDemand", "alwaysOn"]).optional(),
|
|
52229
|
+
target: z72.object({
|
|
52230
|
+
kind: z72.enum(["tool", "connection-test", "connection-discover"]),
|
|
52231
|
+
name: z72.string().optional(),
|
|
52232
|
+
input: z72.unknown().optional(),
|
|
52233
|
+
connectionKey: z72.string().optional()
|
|
51611
52234
|
}).optional()
|
|
51612
52235
|
});
|
|
51613
52236
|
var sandboxPluginsPlugin = {
|
|
@@ -51702,7 +52325,7 @@ var sandboxPluginsPlugin = {
|
|
|
51702
52325
|
]
|
|
51703
52326
|
}
|
|
51704
52327
|
},
|
|
51705
|
-
middleware: () =>
|
|
52328
|
+
middleware: () => createMiddleware27({
|
|
51706
52329
|
name: "SandboxPluginsMiddleware",
|
|
51707
52330
|
tools: [
|
|
51708
52331
|
tool65(
|
|
@@ -51993,8 +52616,8 @@ var sandboxPluginsPlugin = {
|
|
|
51993
52616
|
};
|
|
51994
52617
|
|
|
51995
52618
|
// src/middlewares/longTermStoreMiddleware.ts
|
|
51996
|
-
import { createMiddleware as
|
|
51997
|
-
import { z as
|
|
52619
|
+
import { createMiddleware as createMiddleware28, tool as tool66 } from "langchain";
|
|
52620
|
+
import { z as z73 } from "zod";
|
|
51998
52621
|
import {
|
|
51999
52622
|
STORE_IDENTITY_SEPARATOR as STORE_IDENTITY_SEPARATOR2,
|
|
52000
52623
|
StoreValidationError
|
|
@@ -52093,34 +52716,34 @@ function store() {
|
|
|
52093
52716
|
return void 0;
|
|
52094
52717
|
}
|
|
52095
52718
|
}
|
|
52096
|
-
var namespaceSchema =
|
|
52719
|
+
var namespaceSchema = z73.array(z73.string()).optional().describe(
|
|
52097
52720
|
"Optional relative namespace segments for organization (appended to the scoped prefix)."
|
|
52098
52721
|
);
|
|
52099
|
-
var keySchema =
|
|
52100
|
-
var valueSchema =
|
|
52101
|
-
var putSchema =
|
|
52722
|
+
var keySchema = z73.string().min(1).describe("Stable item key within the resolved namespace.");
|
|
52723
|
+
var valueSchema = z73.record(z73.unknown()).describe("JSON object value to persist.");
|
|
52724
|
+
var putSchema = z73.object({
|
|
52102
52725
|
key: keySchema,
|
|
52103
52726
|
value: valueSchema,
|
|
52104
52727
|
namespace: namespaceSchema,
|
|
52105
|
-
ttlMinutes:
|
|
52728
|
+
ttlMinutes: z73.number().positive().optional().describe("Optional TTL in minutes; omit to use the plugin default.")
|
|
52106
52729
|
});
|
|
52107
|
-
var getSchema =
|
|
52730
|
+
var getSchema = z73.object({
|
|
52108
52731
|
key: keySchema,
|
|
52109
52732
|
namespace: namespaceSchema
|
|
52110
52733
|
});
|
|
52111
|
-
var searchSchema2 =
|
|
52112
|
-
query:
|
|
52113
|
-
filter:
|
|
52734
|
+
var searchSchema2 = z73.object({
|
|
52735
|
+
query: z73.string().optional().describe("Case-insensitive substring match over serialized values."),
|
|
52736
|
+
filter: z73.record(z73.unknown()).optional().describe("Deep partial-equality filter over the value object."),
|
|
52114
52737
|
namespace: namespaceSchema,
|
|
52115
|
-
limit:
|
|
52738
|
+
limit: z73.number().int().min(1).max(MAX_SEARCH_LIMIT).optional()
|
|
52116
52739
|
});
|
|
52117
|
-
var deleteSchema =
|
|
52740
|
+
var deleteSchema = z73.object({
|
|
52118
52741
|
key: keySchema,
|
|
52119
52742
|
namespace: namespaceSchema
|
|
52120
52743
|
});
|
|
52121
|
-
var namespacesSchema =
|
|
52744
|
+
var namespacesSchema = z73.object({
|
|
52122
52745
|
namespace: namespaceSchema,
|
|
52123
|
-
limit:
|
|
52746
|
+
limit: z73.number().int().min(1).max(MAX_SEARCH_LIMIT).optional()
|
|
52124
52747
|
});
|
|
52125
52748
|
var STORE_SKILL_HINT = "Load long_term_store-usage for namespace/TTL guidance.";
|
|
52126
52749
|
var STORE_DESCRIPTION = [
|
|
@@ -52373,7 +52996,7 @@ function createLongTermStoreMiddleware(config = {}) {
|
|
|
52373
52996
|
schema: namespacesSchema
|
|
52374
52997
|
}
|
|
52375
52998
|
);
|
|
52376
|
-
return
|
|
52999
|
+
return createMiddleware28({
|
|
52377
53000
|
name: "LongTermStoreMiddleware",
|
|
52378
53001
|
tools: readOnly ? [getTool, searchTool, namespacesTool] : [putTool, getTool, searchTool, deleteTool, namespacesTool]
|
|
52379
53002
|
});
|
|
@@ -53454,11 +54077,14 @@ export {
|
|
|
53454
54077
|
CustomMiddlewareRegistry,
|
|
53455
54078
|
DEFAULT_CALIBRATION_PROBES,
|
|
53456
54079
|
DEFAULT_CONNECT_TIMEOUT_MS,
|
|
54080
|
+
DEFAULT_CONTENTS_EMBEDDING_PATH,
|
|
53457
54081
|
DEFAULT_DELAY_MS,
|
|
53458
54082
|
DEFAULT_HANDLER_TIMEOUT_MS,
|
|
53459
54083
|
DEFAULT_MAX_ATTEMPTS,
|
|
53460
54084
|
DEFAULT_MODEL_EXTRA,
|
|
53461
54085
|
DEFAULT_RESIDENT_INVOKE_TIMEOUT_MS,
|
|
54086
|
+
DEFAULT_SUMMARIZATION_TRIGGER_TOKENS,
|
|
54087
|
+
DEFAULT_TEXTS_EMBEDDING_PATH,
|
|
53462
54088
|
DaytonaInstance,
|
|
53463
54089
|
DaytonaProvider,
|
|
53464
54090
|
DefaultScheduleClient,
|
|
@@ -53575,6 +54201,7 @@ export {
|
|
|
53575
54201
|
SANDBOX_OPEN_TOKEN_ENV,
|
|
53576
54202
|
STTModelLattice,
|
|
53577
54203
|
STTModelLatticeManager,
|
|
54204
|
+
SUMMARIZATION_TRIGGER_RATIO,
|
|
53578
54205
|
SandboxFilesystem,
|
|
53579
54206
|
SandboxLatticeManager,
|
|
53580
54207
|
SandboxPluginExecutor,
|
|
@@ -53698,6 +54325,7 @@ export {
|
|
|
53698
54325
|
disconnectAllChannels,
|
|
53699
54326
|
documentLearningPlugin,
|
|
53700
54327
|
documentParserPlugin,
|
|
54328
|
+
embeddingProbeCandidates,
|
|
53701
54329
|
embeddingsLatticeManager,
|
|
53702
54330
|
encodeInput,
|
|
53703
54331
|
encrypt,
|
|
@@ -53835,6 +54463,7 @@ export {
|
|
|
53835
54463
|
publishCollectionChanged,
|
|
53836
54464
|
publishPluginCatalogChanged,
|
|
53837
54465
|
queueLatticeManager,
|
|
54466
|
+
readContextWindow,
|
|
53838
54467
|
readLoopBreakerConfig,
|
|
53839
54468
|
reconcileAllTenantTaskRuns,
|
|
53840
54469
|
reconcileStaleTaskRuns,
|
|
@@ -53864,6 +54493,8 @@ export {
|
|
|
53864
54493
|
removeCollectionVectorStore,
|
|
53865
54494
|
renderTemplate,
|
|
53866
54495
|
resetReplicaIdForTests,
|
|
54496
|
+
resolveEmbeddingEndpoint,
|
|
54497
|
+
resolveEmbeddingShape,
|
|
53867
54498
|
resolveEnabledPluginSkill,
|
|
53868
54499
|
resolveHandlerTimeoutMs,
|
|
53869
54500
|
resolveJudgeModelKey,
|
|
@@ -53873,6 +54504,7 @@ export {
|
|
|
53873
54504
|
resolvePluginConnections,
|
|
53874
54505
|
resolveSandboxPluginConnections,
|
|
53875
54506
|
resolveStartIndex,
|
|
54507
|
+
resolveSummarizationTriggerTokens,
|
|
53876
54508
|
resolveTenantPluginSkill,
|
|
53877
54509
|
roomCoordinatorConfig,
|
|
53878
54510
|
runAsLeader,
|