@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.mjs CHANGED
@@ -2139,10 +2139,13 @@ function countMessagesTokens(messages) {
2139
2139
  function safeStringify(value) {
2140
2140
  if (typeof value === "string") return value;
2141
2141
  try {
2142
- return JSON.stringify(value);
2142
+ const serialized = JSON.stringify(value);
2143
+ if (typeof serialized === "string") {
2144
+ return serialized;
2145
+ }
2143
2146
  } catch {
2144
- return String(value);
2145
2147
  }
2148
+ return String(value);
2146
2149
  }
2147
2150
  function summarizeObject(value) {
2148
2151
  if (value == null) return "null";
@@ -2186,10 +2189,11 @@ function resolveToolResponsePolicy(toolName, output, config) {
2186
2189
  } else if (classification === "redundant") {
2187
2190
  retentionPolicy = byTool || "drop";
2188
2191
  }
2189
- const summary = summarizeObject(output);
2190
2192
  if (retentionPolicy === "keep_full") {
2191
- return { classification, retentionPolicy, content: serialized, rawOutput: output, summary, tokenCount };
2193
+ const summary2 = "";
2194
+ return { classification, retentionPolicy, content: serialized, rawOutput: output, summary: summary2, tokenCount };
2192
2195
  }
2196
+ const summary = summarizeObject(output);
2193
2197
  if (retentionPolicy === "keep_structured") {
2194
2198
  return { classification, retentionPolicy, content: summary, rawOutput: output, summary, tokenCount };
2195
2199
  }
@@ -2492,7 +2496,15 @@ function createToolsNode(initialTools, opts) {
2492
2496
  status: "success"
2493
2497
  });
2494
2498
  }
2495
- appended.push({ role: "tool", content: responsePolicy.content, tool_call_id: tc.id || `${tc.name}_${appended.length}`, name: tc.name });
2499
+ let toolMessageContent = responsePolicy.content;
2500
+ if (responsePolicy.retentionPolicy === "summarize_archive") {
2501
+ toolMessageContent = `ARCHIVED_TOOL_RESPONSE [executionId=${executionId}]: ${responsePolicy.summary}
2502
+ Use get_tool_response with executionId "${executionId}" to retrieve the full output.`;
2503
+ } else if (responsePolicy.retentionPolicy === "drop") {
2504
+ toolMessageContent = `DROPPED_TOOL_RESPONSE [executionId=${executionId}]: ${responsePolicy.summary}
2505
+ Use get_tool_response with executionId "${executionId}" to retrieve the full output.`;
2506
+ }
2507
+ appended.push({ role: "tool", content: toolMessageContent, tool_call_id: tc.id || `${tc.name}_${appended.length}`, name: tc.name });
2496
2508
  onEvent?.({ type: "tool_call", phase: "success", name: toolName, id: tc.id, args, result: output, durationMs });
2497
2509
  onProgress?.({ stage: "tools", message: `Tool ${tc.name} completed`, detail: { durationMs } });
2498
2510
  if (needsApproval && approvalEntry) {
@@ -4201,7 +4213,7 @@ function createContextTools(stateRef, opts) {
4201
4213
  }
4202
4214
  const getTool = createTool({
4203
4215
  name: "get_tool_response",
4204
- description: "RETRIEVE tool execution response: Use this to access the full output of a tool execution that shows as 'SUMMARIZED' in the tool history. Accepts either the internal executionId or the provider tool call id shown in prior tool traces.",
4216
+ 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.",
4205
4217
  schema: z.object({ executionId: z.string().describe("Tool execution id") }),
4206
4218
  func: async ({ executionId }) => {
4207
4219
  const matchesExecution = (t) => t?.executionId === executionId || t?.tool_call_id === executionId;