@cognipeer/agent-sdk 0.2.1 → 0.2.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.cjs +26 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +26 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -183,6 +183,8 @@ type SmartAgentOptions = {
|
|
|
183
183
|
summarization?: boolean | {
|
|
184
184
|
enable: boolean;
|
|
185
185
|
maxTokens: number;
|
|
186
|
+
/** Max tokens to include in the summarization prompt itself (to avoid sending huge context to summarizer). Default: 8000 */
|
|
187
|
+
summaryPromptMaxTokens?: number;
|
|
186
188
|
};
|
|
187
189
|
systemPrompt?: string;
|
|
188
190
|
useTodoList?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,8 @@ type SmartAgentOptions = {
|
|
|
183
183
|
summarization?: boolean | {
|
|
184
184
|
enable: boolean;
|
|
185
185
|
maxTokens: number;
|
|
186
|
+
/** Max tokens to include in the summarization prompt itself (to avoid sending huge context to summarizer). Default: 8000 */
|
|
187
|
+
summaryPromptMaxTokens?: number;
|
|
186
188
|
};
|
|
187
189
|
systemPrompt?: string;
|
|
188
190
|
useTodoList?: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -2231,12 +2231,16 @@ function getSummarizationConfig(opts) {
|
|
|
2231
2231
|
if (typeof opts.summarization === "object") {
|
|
2232
2232
|
return {
|
|
2233
2233
|
enabled: opts.summarization.enable !== false,
|
|
2234
|
-
maxTokens: opts.summarization.maxTokens
|
|
2234
|
+
maxTokens: opts.summarization.maxTokens ?? 5e4,
|
|
2235
|
+
// Max tokens we can send to the model for summarization prompt itself
|
|
2236
|
+
// This should be well under the model's context limit
|
|
2237
|
+
summaryPromptMaxTokens: opts.summarization.summaryPromptMaxTokens ?? 8e3
|
|
2235
2238
|
};
|
|
2236
2239
|
}
|
|
2237
2240
|
return {
|
|
2238
2241
|
enabled: opts.summarization !== false,
|
|
2239
|
-
maxTokens: 5e4
|
|
2242
|
+
maxTokens: 5e4,
|
|
2243
|
+
summaryPromptMaxTokens: 8e3
|
|
2240
2244
|
};
|
|
2241
2245
|
}
|
|
2242
2246
|
function createContextSummarizeNode(opts) {
|
|
@@ -2249,16 +2253,33 @@ function createContextSummarizeNode(opts) {
|
|
|
2249
2253
|
if (compressableMessages.length === 0) {
|
|
2250
2254
|
return {};
|
|
2251
2255
|
}
|
|
2252
|
-
const
|
|
2256
|
+
const summaryPromptMaxTokens = config.summaryPromptMaxTokens;
|
|
2257
|
+
const availableTokensForConversation = summaryPromptMaxTokens - 500;
|
|
2258
|
+
const messageTexts = [];
|
|
2259
|
+
let accumulatedTokens = 0;
|
|
2260
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2261
|
+
const m = messages[i];
|
|
2253
2262
|
let content = "";
|
|
2254
2263
|
if (typeof m.content === "string") content = m.content;
|
|
2255
2264
|
else if (Array.isArray(m.content)) {
|
|
2256
2265
|
content = m.content.map((c) => c.text || JSON.stringify(c)).join(" ");
|
|
2257
2266
|
}
|
|
2267
|
+
const maxContentLength = 2e3;
|
|
2268
|
+
if (content.length > maxContentLength) {
|
|
2269
|
+
content = content.substring(0, maxContentLength) + "... [TRUNCATED]";
|
|
2270
|
+
}
|
|
2258
2271
|
let prefix = `${m.role.toUpperCase()}`;
|
|
2259
2272
|
if (m.name) prefix += ` (${m.name})`;
|
|
2260
|
-
|
|
2261
|
-
|
|
2273
|
+
const messageText = `${prefix}: ${content}`;
|
|
2274
|
+
const messageTokens = countApproxTokens(messageText);
|
|
2275
|
+
if (accumulatedTokens + messageTokens > availableTokensForConversation) {
|
|
2276
|
+
messageTexts.unshift("[Earlier conversation history omitted for brevity]");
|
|
2277
|
+
break;
|
|
2278
|
+
}
|
|
2279
|
+
messageTexts.unshift(messageText);
|
|
2280
|
+
accumulatedTokens += messageTokens;
|
|
2281
|
+
}
|
|
2282
|
+
const conversationText = messageTexts.join("\n\n");
|
|
2262
2283
|
const summaryPrompt = [
|
|
2263
2284
|
systemMessage("You are a helpful assistant that summarizes conversation history efficiently."),
|
|
2264
2285
|
humanMessage(
|