@cognipeer/agent-sdk 0.2.0 → 0.2.1
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.cjs +27 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +27 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1872,10 +1872,13 @@ function createAgent(opts) {
|
|
|
1872
1872
|
}
|
|
1873
1873
|
}
|
|
1874
1874
|
}
|
|
1875
|
-
let maxTok
|
|
1875
|
+
let maxTok;
|
|
1876
1876
|
if (opts.summarization && typeof opts.summarization === "object" && opts.summarization.maxTokens) {
|
|
1877
1877
|
maxTok = opts.summarization.maxTokens;
|
|
1878
1878
|
}
|
|
1879
|
+
if (maxTok === void 0) {
|
|
1880
|
+
maxTok = 5e4;
|
|
1881
|
+
}
|
|
1879
1882
|
if (maxTok) {
|
|
1880
1883
|
const allText = (state.messages || []).map((m) => typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((c) => typeof c === "string" ? c : c?.text ?? c?.content ?? "").join("") : "").join("\n");
|
|
1881
1884
|
const tokenCount = countApproxTokens(allText);
|
|
@@ -2242,6 +2245,10 @@ function createContextSummarizeNode(opts) {
|
|
|
2242
2245
|
if (!config.enabled) return {};
|
|
2243
2246
|
const model = opts.model;
|
|
2244
2247
|
const messages = state.messages || [];
|
|
2248
|
+
const compressableMessages = messages.filter((m) => m.role === "tool" && m.content !== "SUMMARIZED");
|
|
2249
|
+
if (compressableMessages.length === 0) {
|
|
2250
|
+
return {};
|
|
2251
|
+
}
|
|
2245
2252
|
const conversationText = messages.map((m) => {
|
|
2246
2253
|
let content = "";
|
|
2247
2254
|
if (typeof m.content === "string") content = m.content;
|
|
@@ -2404,10 +2411,16 @@ function createContextTools(stateRef, opts) {
|
|
|
2404
2411
|
|
|
2405
2412
|
// src/graph/decisions.ts
|
|
2406
2413
|
function needsSummarization(state, opts, summarizationEnabled) {
|
|
2407
|
-
|
|
2408
|
-
if (!maxTok || !summarizationEnabled) {
|
|
2414
|
+
if (!summarizationEnabled) {
|
|
2409
2415
|
return false;
|
|
2410
2416
|
}
|
|
2417
|
+
let maxTok;
|
|
2418
|
+
if (typeof opts.summarization === "object" && typeof opts.summarization.maxTokens === "number") {
|
|
2419
|
+
maxTok = opts.summarization.maxTokens;
|
|
2420
|
+
}
|
|
2421
|
+
if (maxTok === void 0) {
|
|
2422
|
+
maxTok = 5e4;
|
|
2423
|
+
}
|
|
2411
2424
|
try {
|
|
2412
2425
|
const allText = (state.messages || []).map((m) => typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((c) => typeof c === "string" ? c : c?.text ?? c?.content ?? "").join("") : "").join("\n");
|
|
2413
2426
|
const tokenCount = countApproxTokens(allText);
|
|
@@ -2474,8 +2487,10 @@ function createSmartAgent(opts) {
|
|
|
2474
2487
|
const next = summarizationEnabled ? decideBefore(state) : "agent";
|
|
2475
2488
|
if (next === "contextSummarize" && summarizer) {
|
|
2476
2489
|
const delta = await summarizer(state);
|
|
2477
|
-
|
|
2478
|
-
|
|
2490
|
+
if (!delta || Object.keys(delta).length === 0) ; else {
|
|
2491
|
+
state = { ...state, ...delta };
|
|
2492
|
+
continue;
|
|
2493
|
+
}
|
|
2479
2494
|
}
|
|
2480
2495
|
const res = await base.invoke(state, config);
|
|
2481
2496
|
lastResult = res;
|
|
@@ -2485,7 +2500,9 @@ function createSmartAgent(opts) {
|
|
|
2485
2500
|
delete ctx.__needsSummarization;
|
|
2486
2501
|
state = { ...state, ctx };
|
|
2487
2502
|
const delta = await summarizer(state);
|
|
2488
|
-
|
|
2503
|
+
if (delta && Object.keys(delta).length > 0) {
|
|
2504
|
+
state = { ...state, ...delta };
|
|
2505
|
+
}
|
|
2489
2506
|
continue;
|
|
2490
2507
|
}
|
|
2491
2508
|
if (state.ctx?.__finalizedDueToStructuredOutput) break;
|
|
@@ -2493,8 +2510,10 @@ function createSmartAgent(opts) {
|
|
|
2493
2510
|
const after = decideAfter(state);
|
|
2494
2511
|
if (after === "contextSummarize" && summarizer) {
|
|
2495
2512
|
const delta = await summarizer(state);
|
|
2496
|
-
|
|
2497
|
-
|
|
2513
|
+
if (delta && Object.keys(delta).length > 0) {
|
|
2514
|
+
state = { ...state, ...delta };
|
|
2515
|
+
continue;
|
|
2516
|
+
}
|
|
2498
2517
|
}
|
|
2499
2518
|
}
|
|
2500
2519
|
break;
|