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

@librechat/agents

v4.0.6

Published

TypeScript utilities for building LibreChat agent workflows. The package provides graph orchestration, streaming event handling, tool execution, provider adapters, and message formatting for single-agent and multi-agent runs.

Readme

@librechat/agents

TypeScript utilities for building LibreChat agent workflows. The package provides graph orchestration, streaming event handling, tool execution, provider adapters, and message formatting for single-agent and multi-agent runs.

Features

  • LangGraph-based single-agent and multi-agent workflows
  • Streaming content aggregation and run-step event handlers
  • Tool calling, tool search, subagent handoffs, and programmatic tool execution
  • Provider adapters for Anthropic, Bedrock, Vertex AI, OpenAI-compatible providers, Google, Mistral, DeepSeek, and xAI
  • Message formatting, context pruning, summarization, and cache-control helpers

Installation

npm install @librechat/agents

Basic Usage

import { HumanMessage } from '@langchain/core/messages';
import { Providers, Run } from '@librechat/agents';

const run = await Run.create({
  runId: crypto.randomUUID(),
  graphConfig: {
    type: 'standard',
    instructions: 'You are a helpful assistant.',
    llmConfig: {
      provider: Providers.OPENAI,
      model: 'gpt-4o-mini',
      apiKey: process.env.OPENAI_API_KEY,
    },
  },
  returnContent: true,
});

const content = await run.processStream(
  { messages: [new HumanMessage('Hello')] },
  {
    runId: crypto.randomUUID(),
    streamMode: 'values',
    version: 'v2',
  }
);

Runtime Provider Registration

Hosts can register a compatible LangChain chat model before creating a run, without adding the provider to this package. The provider registration carries the model constructor plus the shared message and streaming behavior the model needs.

import { registerProvider } from '@librechat/agents/provider-registration';
import type { LLMConfig } from '@librechat/agents';

interface AcmeOptions {
  apiKey: string;
  model: string;
}

declare module '@librechat/agents/provider-registration' {
  interface CustomProviderOptionsMap {
    acme: AcmeOptions;
  }
}

const unregister = registerProvider({
  provider: 'acme',
  model: AcmeChatModel,
  family: 'openai',
});

const llmConfig: LLMConfig = {
  provider: 'acme',
  apiKey: process.env.ACME_API_KEY!,
  model: 'acme-chat',
};

Register once per process before the provider is used. Duplicate names are rejected, and unregister() removes only that registration. Set manualToolStream or strictAlternation only when the provider contract needs those behaviors. Declaration-merged required options are enforced for direct model initialization, graph agents, primary graph configs, and fallbacks.

Programmatic Sessions

For scripts, CI, and programmatic integrations, use the session facade. It keeps a JSONL session tree by default, so runs can be resumed, cloned, forked, branched in place, compacted, and inspected later.

import { Providers, createAgentSession } from '@librechat/agents';

const session = await createAgentSession({
  checkpointing: true,
  graphConfig: {
    type: 'standard',
    instructions: 'You are a concise coding assistant.',
    llmConfig: {
      provider: Providers.OPENAI,
      model: 'gpt-4o-mini',
      apiKey: process.env.OPENAI_API_KEY,
    },
  },
});

const result = await session.run('Summarize this repository.');
console.log(result.text);
console.log(session.sessionPath); // durable .jsonl session file

When checkpointing is enabled, the session injects a shared LangGraph checkpointer into compileOptions, records checkpoint IDs in JSONL, and uses checkpoint state for later turns on the same thread_id. When HITL is enabled (humanInTheLoop: { enabled: true }), sessions also get a MemorySaver by default so resumeInterrupt() can reuse the same saver instead of relying on a per-run fallback. JSONL still owns portable replay, clone, fork, and audit records.

Sessions expose tree operations inspired by Pi-style workflows:

const store = session.getSessionStore();
const forkPoint = store?.getForkPoints()[0];

if (forkPoint) {
  const forked = await session.fork(forkPoint.id, { position: 'before' });
  await forked.run('Try a different approach from here.');
}

const cloned = await session.clone();
await cloned.compact({ instructions: 'Keep only implementation decisions.' });

session.stream() projects the SDK's existing graph events, and session.compact() uses the same summarization node, hooks, and provider logic as normal runs. JSONL is the durable journal; the graph remains the execution engine.

OpenAI-compatible streaming helpers are available as experimental subpaths:

import { composeEventHandlers } from '@librechat/agents';
import { createOpenAIHandlers } from '@librechat/agents/openai';
import { createResponsesEventHandlers } from '@librechat/agents/responses';

const customHandlers = composeEventHandlers(
  createOpenAIHandlers(openAIConfig),
  createResponsesEventHandlers(responsesConfig),
  hostHandlers
);

Accepted tool-call projection (opt-in)

createOpenAIToolCallStream from @librechat/agents/openai formats finalized calls accepted by the graph, not provider fragments. Existing handlers are unchanged.

  • Register projection.handlers in Run.create({ customHandlers }).
  • For streaming, share { tracker, emit } with the text/reasoning handlers and sendOpenAIFinalChunk. Do not also register legacy raw tool-call handlers. Map-only { toolCalls } supports JSON/custom finalization. Use fresh output state.
  • Call finish() only after natural completion: no error, aborted signal, getInterrupt() or getHaltReason(). Otherwise call abort() and discard it. A resolved processStream() alone does not mean success.
  • Calls execute in the graph by default. To hand a complete call to the OpenAI client instead, set clientDelegatedToolNames: ['my_tool'] in Run.create for a single-agent run and register its model-facing schema. The graph ends without executing that call. Batches mixing delegated and graph/provider tools fail closed; make separate model turns. ToolNode claims remain an additional guard, never proof that an unclaimed call belongs to the client.
  • emit is synchronous. Failed/partial writes cannot be retried; the host owns HTTP backpressure. This helper does not provide durable resume or undo tool effects.

Projected arguments must be JSON data: primitives, plain objects and dense arrays. Getters, custom objects, cycles and nesting beyond 64 levels are rejected before projection. Observers receive isolated snapshots; provider IDs are reserved before synthetic IDs. Accepted-event snapshots cap each response at 1,024 calls / 4 MiB. Projection uses those defaults for pending calls (maxToolCalls / maxBufferedBytes). These formatting limits do not apply to ordinary runs without accepted-event handlers; descriptor safety checks still apply before stream accounting and dispatch. These are output limits, not bounds on provider memory or tool execution.

See the design decision.

Development

npm ci
npm run build
npm test
npx tsc --noEmit
npx eslint src/

Documentation

License

MIT