Archived Tool Retrieval
This example focuses on the missing half of summarization: recovering raw tool output after the runtime has already compacted it.
Use this when
- tool outputs are too large to keep live forever
- the agent may need the exact raw payload later
- you want a retrieval path after archival rather than blind compression
What it shows
- context tools created through
createContextTools(...) - retrieval of archived tool outputs through
get_tool_response - a workflow where compact live context and raw evidence coexist
Run it
bash
cd examples
npm run example:summarize-contextCore code
ts
const heavyTool = createTool({
name: "heavy_tool",
description: "Returns heavy content",
schema: z.object({ id: z.number().min(1) }),
func: async ({ id }) => ({ data: "X".repeat(50000), id }),
});
const stateRef = { toolHistory: [], toolHistoryArchived: [] } as any;
const contextTools = createContextTools(stateRef);
const agent = createSmartAgent({
model,
tools: [heavyTool, ...contextTools],
limits: { maxToolCalls: 3, contextTokenLimit: 2000, summaryTokenLimit: 500 },
});End-to-end flow
- A
heavy_toolintentionally returns a massive payload. - Context tools are attached to the runtime.
- The smart runtime summarizes or archives the large tool result.
- The code locates the summarized tool message and extracts its
executionId. get_tool_responseretrieves the original raw payload.
Why it matters
Summarization is only operationally safe if the agent can recover raw evidence later. This example demonstrates that recovery path directly.
What to inspect
- the intentionally huge
heavy_toolpayload createContextTools(...)addingget_tool_response- the follow-up recovery path using
executionIdfrom the summarized tool message
Production takeaway
This pattern is what lets you keep live context compact without sacrificing auditability or evidence recovery.
Expected output
- the console shows shortened message metadata for the summarized run
- a recovered raw payload length is printed after
get_tool_responsesucceeds - the example demonstrates both compaction and post-compaction recovery in one pass
Common failure modes
- summarization does not trigger because token limits are misconfigured
- you look for
executionIdon the wrong message and never callget_tool_responsesuccessfully - the state reference used for
createContextTools(...)is not aligned with runtime history expectations