@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.cjs
CHANGED
|
@@ -1881,10 +1881,13 @@ function createAgent(opts) {
|
|
|
1881
1881
|
}
|
|
1882
1882
|
}
|
|
1883
1883
|
}
|
|
1884
|
-
let maxTok
|
|
1884
|
+
let maxTok;
|
|
1885
1885
|
if (opts.summarization && typeof opts.summarization === "object" && opts.summarization.maxTokens) {
|
|
1886
1886
|
maxTok = opts.summarization.maxTokens;
|
|
1887
1887
|
}
|
|
1888
|
+
if (maxTok === void 0) {
|
|
1889
|
+
maxTok = 5e4;
|
|
1890
|
+
}
|
|
1888
1891
|
if (maxTok) {
|
|
1889
1892
|
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");
|
|
1890
1893
|
const tokenCount = countApproxTokens(allText);
|
|
@@ -2251,6 +2254,10 @@ function createContextSummarizeNode(opts) {
|
|
|
2251
2254
|
if (!config.enabled) return {};
|
|
2252
2255
|
const model = opts.model;
|
|
2253
2256
|
const messages = state.messages || [];
|
|
2257
|
+
const compressableMessages = messages.filter((m) => m.role === "tool" && m.content !== "SUMMARIZED");
|
|
2258
|
+
if (compressableMessages.length === 0) {
|
|
2259
|
+
return {};
|
|
2260
|
+
}
|
|
2254
2261
|
const conversationText = messages.map((m) => {
|
|
2255
2262
|
let content = "";
|
|
2256
2263
|
if (typeof m.content === "string") content = m.content;
|
|
@@ -2413,10 +2420,16 @@ function createContextTools(stateRef, opts) {
|
|
|
2413
2420
|
|
|
2414
2421
|
// src/graph/decisions.ts
|
|
2415
2422
|
function needsSummarization(state, opts, summarizationEnabled) {
|
|
2416
|
-
|
|
2417
|
-
if (!maxTok || !summarizationEnabled) {
|
|
2423
|
+
if (!summarizationEnabled) {
|
|
2418
2424
|
return false;
|
|
2419
2425
|
}
|
|
2426
|
+
let maxTok;
|
|
2427
|
+
if (typeof opts.summarization === "object" && typeof opts.summarization.maxTokens === "number") {
|
|
2428
|
+
maxTok = opts.summarization.maxTokens;
|
|
2429
|
+
}
|
|
2430
|
+
if (maxTok === void 0) {
|
|
2431
|
+
maxTok = 5e4;
|
|
2432
|
+
}
|
|
2420
2433
|
try {
|
|
2421
2434
|
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");
|
|
2422
2435
|
const tokenCount = countApproxTokens(allText);
|
|
@@ -2483,8 +2496,10 @@ function createSmartAgent(opts) {
|
|
|
2483
2496
|
const next = summarizationEnabled ? decideBefore(state) : "agent";
|
|
2484
2497
|
if (next === "contextSummarize" && summarizer) {
|
|
2485
2498
|
const delta = await summarizer(state);
|
|
2486
|
-
|
|
2487
|
-
|
|
2499
|
+
if (!delta || Object.keys(delta).length === 0) ; else {
|
|
2500
|
+
state = { ...state, ...delta };
|
|
2501
|
+
continue;
|
|
2502
|
+
}
|
|
2488
2503
|
}
|
|
2489
2504
|
const res = await base.invoke(state, config);
|
|
2490
2505
|
lastResult = res;
|
|
@@ -2494,7 +2509,9 @@ function createSmartAgent(opts) {
|
|
|
2494
2509
|
delete ctx.__needsSummarization;
|
|
2495
2510
|
state = { ...state, ctx };
|
|
2496
2511
|
const delta = await summarizer(state);
|
|
2497
|
-
|
|
2512
|
+
if (delta && Object.keys(delta).length > 0) {
|
|
2513
|
+
state = { ...state, ...delta };
|
|
2514
|
+
}
|
|
2498
2515
|
continue;
|
|
2499
2516
|
}
|
|
2500
2517
|
if (state.ctx?.__finalizedDueToStructuredOutput) break;
|
|
@@ -2502,8 +2519,10 @@ function createSmartAgent(opts) {
|
|
|
2502
2519
|
const after = decideAfter(state);
|
|
2503
2520
|
if (after === "contextSummarize" && summarizer) {
|
|
2504
2521
|
const delta = await summarizer(state);
|
|
2505
|
-
|
|
2506
|
-
|
|
2522
|
+
if (delta && Object.keys(delta).length > 0) {
|
|
2523
|
+
state = { ...state, ...delta };
|
|
2524
|
+
continue;
|
|
2525
|
+
}
|
|
2507
2526
|
}
|
|
2508
2527
|
}
|
|
2509
2528
|
break;
|