npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

n8n-nodes-context-optimizer

v1.0.1

Published

Provider-neutral n8n nodes that reduce AI Agent input tokens with quality guards and exact retrieval.

Downloads

611

Readme

Context Saver for n8n

Provider-neutral community nodes that reduce AI Agent input tokens while preserving exact facts, active tool calls, structured output, and recoverable originals.

Five-minute setup

Any n8n Chat Model -> Context Saver / Agent Model -> AI Agent
                                                       |-> Context Saver / Exact Lookup

AI Agent -> Savings Report
  1. Insert Context Saver / Agent Model between the Chat Model and AI Agent.
  2. Choose Save Tokens and Balanced.
  3. Keep Adaptive Quality Protection enabled.
  4. Add Savings Report after the agent response.
  5. Use Maximum Savings only with Exact Lookup and shared storage.

No model provider is required by Context Saver. It wraps compatible n8n chat models from Gemini, OpenAI, Anthropic, OpenRouter, Ollama, and other LangChain-compatible nodes.

Nodes

| Node | Use it for | Where it connects | |---|---|---| | Agent Model | Every call of one AI Agent: prompt, history, tools, and large tool results | Chat Model -> Context Saver / Agent Model -> AI Agent | | Data Optimizer | Large JSON, API, RAG, HTML, logs, text, or tool output | Before the AI Agent input | | Agent Handoff | Compact evidence passed between multiple agents | Agent A -> Agent Handoff -> Agent B | | Session Memory | Current facts, state, protected events, recent window, and archive | Main workflow path before the Agent | | Context Storage | Exact original content outside the prompt | Before Agent Handoff or as a data branch | | Exact Lookup | Bounded exact retrieval from Context Storage | AI Tool port of the Agent | | Savings Report | Current-execution totals and diagnostics | After the optimized agent path |

Use only the features needed by the workflow. Agent Model alone is the normal starting point.

Profiles

| Profile | Typical eligible reduction | Safety behavior | |---|---:|---| | Quality First | 15-35% | Lossless transforms, 12 recent messages, all tools | | Balanced | 35-60% | Reversible packing, six recent messages, conservative selection | | Maximum Savings | 60-85% | Three recent messages, lazy tools, recoverable previews | | Custom | User-defined | Manual budgets and experimental semantic stages |

Ranges describe synthetic eligible content, not guaranteed provider billing. Adaptive protection can automatically downgrade a risky call. Code, exact quotations, forced tools, active tool sequences, ambiguous structured output, or missing retrieval produce a safer effective profile.

What actually saves tokens

  • Exact paragraph and message deduplication; stable System Prompt compilation.
  • Reversible JSON packing, shared schemas, field projection, and log collapsing.
  • Recent-window memory, replaced-fact versioning, and compact multi-agent handoffs.
  • High-confidence lazy tool schemas; ambiguity and low confidence retain all tools.
  • Large-result virtualization with hash reuse and bounded exact recovery.

The current user message is never summarized. Active tool-call IDs, result IDs, order, and pairing remain intact. Non-positive optimization and failed quality checks return a safer candidate or the original.

Cache and direct reduction

Automatic Hybrid is the default. It preserves repeated stable prefixes when provider caching is valuable and reduces dynamic content. The fingerprint registry stores hashes and timing/count metadata, never prompt text.

  • Filesystem registry: simplest local setup.
  • Redis registry: shared observations across queue workers.
  • Provider-reported cached tokens are used when available.
  • Savings Report separates estimates from provider measurements.

Shared and secure storage

Filesystem remains the zero-credential option. Redis is recommended for queue mode and many simultaneous users. Optional AES-256-GCM encryption protects compressed resources and sessions at rest.

Set the same values in producers and Exact Lookup:

Storage Provider
Scope
Session ID
Owner ID
Redis Prefix or Filesystem Directory
Encryption setting and credential

Resource access is rejected when workflow, session, owner, TTL, hash, encryption authentication, field policy, call budget, or token budget fails.

Measurement

Savings Report / Current Execution automatically collects Agent Model calls plus Data Optimizer, Agent Handoff, Session Memory, Context Storage, and Exact Lookup telemetry. It subtracts compression, verification, and retrieval overhead from net savings. Provider usage is never invented.

Local validation

npm install
npm run check:local
npm pack

check:local uses generated fictional data only. It runs unit, compatibility, security, concurrency, profile, long-context, 14-tool, multi-agent, build, and lint gates without external LLM calls.

Importable local workflows:

Documentation

The package publishes one Context Saver picker entry. Version 1.0.1 workflow examples use only this unified type. Legacy profile aliases and stored resources remain readable; legacy workflow JSON must be migrated to the unified type before import.