@cognipeer/agent-sdk 0.4.0 → 0.4.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 +18 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +18 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2149,10 +2149,13 @@ function countMessagesTokens(messages) {
|
|
|
2149
2149
|
function safeStringify(value) {
|
|
2150
2150
|
if (typeof value === "string") return value;
|
|
2151
2151
|
try {
|
|
2152
|
-
|
|
2152
|
+
const serialized = JSON.stringify(value);
|
|
2153
|
+
if (typeof serialized === "string") {
|
|
2154
|
+
return serialized;
|
|
2155
|
+
}
|
|
2153
2156
|
} catch {
|
|
2154
|
-
return String(value);
|
|
2155
2157
|
}
|
|
2158
|
+
return String(value);
|
|
2156
2159
|
}
|
|
2157
2160
|
function summarizeObject(value) {
|
|
2158
2161
|
if (value == null) return "null";
|
|
@@ -2196,10 +2199,11 @@ function resolveToolResponsePolicy(toolName, output, config) {
|
|
|
2196
2199
|
} else if (classification === "redundant") {
|
|
2197
2200
|
retentionPolicy = byTool || "drop";
|
|
2198
2201
|
}
|
|
2199
|
-
const summary = summarizeObject(output);
|
|
2200
2202
|
if (retentionPolicy === "keep_full") {
|
|
2201
|
-
|
|
2203
|
+
const summary2 = "";
|
|
2204
|
+
return { classification, retentionPolicy, content: serialized, rawOutput: output, summary: summary2, tokenCount };
|
|
2202
2205
|
}
|
|
2206
|
+
const summary = summarizeObject(output);
|
|
2203
2207
|
if (retentionPolicy === "keep_structured") {
|
|
2204
2208
|
return { classification, retentionPolicy, content: summary, rawOutput: output, summary, tokenCount };
|
|
2205
2209
|
}
|
|
@@ -2502,7 +2506,15 @@ function createToolsNode(initialTools, opts) {
|
|
|
2502
2506
|
status: "success"
|
|
2503
2507
|
});
|
|
2504
2508
|
}
|
|
2505
|
-
|
|
2509
|
+
let toolMessageContent = responsePolicy.content;
|
|
2510
|
+
if (responsePolicy.retentionPolicy === "summarize_archive") {
|
|
2511
|
+
toolMessageContent = `ARCHIVED_TOOL_RESPONSE [executionId=${executionId}]: ${responsePolicy.summary}
|
|
2512
|
+
Use get_tool_response with executionId "${executionId}" to retrieve the full output.`;
|
|
2513
|
+
} else if (responsePolicy.retentionPolicy === "drop") {
|
|
2514
|
+
toolMessageContent = `DROPPED_TOOL_RESPONSE [executionId=${executionId}]: ${responsePolicy.summary}
|
|
2515
|
+
Use get_tool_response with executionId "${executionId}" to retrieve the full output.`;
|
|
2516
|
+
}
|
|
2517
|
+
appended.push({ role: "tool", content: toolMessageContent, tool_call_id: tc.id || `${tc.name}_${appended.length}`, name: tc.name });
|
|
2506
2518
|
onEvent?.({ type: "tool_call", phase: "success", name: toolName, id: tc.id, args, result: output, durationMs });
|
|
2507
2519
|
onProgress?.({ stage: "tools", message: `Tool ${tc.name} completed`, detail: { durationMs } });
|
|
2508
2520
|
if (needsApproval && approvalEntry) {
|
|
@@ -4211,7 +4223,7 @@ function createContextTools(stateRef, opts) {
|
|
|
4211
4223
|
}
|
|
4212
4224
|
const getTool = createTool({
|
|
4213
4225
|
name: "get_tool_response",
|
|
4214
|
-
description: "RETRIEVE tool execution response
|
|
4226
|
+
description: "RETRIEVE the full output of a tool execution whose response was archived or dropped. When a tool response appears as 'ARCHIVED_TOOL_RESPONSE [executionId=xxx]' or 'DROPPED_TOOL_RESPONSE [executionId=xxx]', pass that exact executionId to this tool to get the complete data. You can also pass the tool_call_id from your original tool call.",
|
|
4215
4227
|
schema: zod.z.object({ executionId: zod.z.string().describe("Tool execution id") }),
|
|
4216
4228
|
func: async ({ executionId }) => {
|
|
4217
4229
|
const matchesExecution = (t) => t?.executionId === executionId || t?.tool_call_id === executionId;
|