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

@context-router/langgraph-adapter

v0.5.0

Published

LangGraph adapter for Context Router - brings structured state to LangGraph workflows

Readme

@context-router/langgraph-adapter

Bridge LangGraph workflows with Context Router's structured state management for persistent, resumable, and scalable agent orchestration.

Installation

npm install @context-router/langgraph-adapter

Requirements:

  • Node.js >= 20
  • @context-router/sdk (installed as a dependency)
  • @langchain/langgraph (optional peer — install separately when wiring a graph)

Quick Example

import { createContextRouterChecker } from '@context-router/langgraph-adapter';
import { StateGraph, MANDATORY_CHANNELS } from '@langchain/langgraph';

const checker = createContextRouterChecker();

const graph = new StateGraph({ channels: MANDATORY_CHANNELS })
  .addNode('research', researchNode)
  .addNode('write', writeNode)
  .addEdge('research', 'write')
  .addConditionalEdges('write', shouldContinue)
  .compile({ checkpointer: checker });

// Run with persistence across sessions
const result = await graph.invoke(
  { messages: [] },
  { configurable: { thread_id: 'user-123-session-1' } }
);

Why This Adapter?

Built-in LangGraph Checkpointers

| Feature | Memory | Postgres | SQLite | Context Router | |---------|--------|----------|--------|----------------| | Persistence | Session only | Permanent | File-based | Permanent | | Multi-tenancy | No | Yes | No | Yes (workspaces) | | Selective reads | No | Manual SQL | Manual SQL | Built-in (handoffs) | | Serverless ready | No | External DB | File issues | SQLite auto-created | | State schema | Any | Any | Any | Typed + validated | | Version history | No | Basic | No | Full checkpoints |

Context Router combines workspace isolation, typed state, selective context (handoffs), and automatic checkpointing in one package.

API Reference

createContextRouterChecker(config?)

Creates a LangGraph-compatible checkpointer backed by Context Router.

const checker = createContextRouterChecker({
  workspaceName: 'my-app',  // Optional: isolates workflows
  autoCheckpoint: true,     // Default: true
  router?: ContextRouter,   // Optional: share existing instance
});

ContextRouterChecker

The main checkpointer class with these methods:

get(config)

Retrieve saved state for a thread. Returns null if no checkpoint exists.

const checkpoint = await checker.get({ thread_id: 'session-1' });
// Returns: { data: {...}, config: { thread_id, checkpoint_id } } | null

put(config, data)

Save state to Context Router with automatic checkpointing.

await checker.put({ thread_id: 'session-1' }, { count: 42, items: [...] });

list(config)

List all checkpoints for a thread.

const checkpoints = await checker.list({ thread_id: 'session-1' });
// [{ id: 'cp-1', metadata: { label, createdAt } }, ...]

restore(config)

Restore workflow state from a specific checkpoint.

await checker.restore({
  thread_id: 'session-1',
  checkpoint_id: 'cp-1'
});

close()

Clean up all sessions and connections. Call when done.

await checker.close();

contextRouterNode(graphState, config, options)

LangGraph node helper that reads selected keys from Context Router.

const researchNode = async (state, config) => {
  const ctxState = await contextRouterNode(state, config, {
    keys: ['search_query', 'filters'],  // Selective context
    nodeName: 'research'
  });

  const results = await search(ctxState.search_query);
  return { ...state, results };
};

writeContextRouterNode(graphState, config, options)

LangGraph node helper that writes state to Context Router with checkpointing.

const writeNode = async (state, config) => {
  const updated = { ...state, draft: 'Generated content...' };
  await writeContextRouterNode(updated, config, { nodeName: 'write' });
  return updated;
};

generateHandoff(graphState, config, options)

Generate a structured summary for the next agent in a pipeline. Uses Context Router's built-in handoff summarization.

const supervisorNode = async (state, config) => {
  const handoff = await generateHandoff(state, config, {
    keys: ['analysis', 'findings', 'next_steps'],
    maxTokens: 500,
    nextGoals: ['Review findings', 'Draft recommendations']
  });

  return { ...state, handoff_summary: handoff.summary };
};

Returns:

  • summary: AI-generated context summary
  • keysIncluded: Which keys were included
  • packet: Optional structured payload

contextRouterChannel(threadId)

Create a LangGraph state channel that syncs bidirectionally with Context Router.

const graph = new StateGraph({
  channels: {
    ...MANDATORY_CHANNELS,
    context_router: contextRouterChannel('thread_id_123'),
  }
});

Advanced Usage

Multi-Tenant Workflows

Use workspace isolation for multi-tenant deployments:

const checker = createContextRouterChecker({
  workspaceName: req.tenantId,  // Each tenant gets isolated storage
});

Shared Router Instance

For better connection pooling in server environments:

const router = await ContextRouter.local();
const checker = createContextRouterChecker({ router });

// Use same router across multiple graph instances
const graph1 = new StateGraph(...).compile({ checkpointer: checker });
const graph2 = new StateGraph(...).compile({ checkpointer: checker });

// Clean up once at the end
await checker.close();

Selective Context with Handoffs

Only pass relevant data between agents:

// In research node
await writeContextRouterNode(state, config, { nodeName: 'research' });

// In write node - only read what you need
const { query, results } = await contextRouterNode(state, config, {
  keys: ['query', 'results'],
});

License

Apache-2.0 - see LICENSE