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

@sisu-ai/mw-invariants

v12.0.0

Published

Detect protocol-level mistakes early with runtime checks for message and tool-call invariants.

Readme

@sisu-ai/mw-invariants

Detect protocol-level mistakes early with runtime checks for message and tool-call invariants.

Tests CodeQL License Downloads PRs Welcome

Setup

npm i @sisu-ai/mw-invariants

Exports

  • toolCallInvariant({ strict?: boolean })
    • strict: false (default) logs a warning and continues.
    • strict: true throws an error to fail fast.

What It Does

  • Validates the tool-calling protocol in your transcript after a step completes.
  • Specifically: for each assistant message that includes tool_calls, ensures a matching tool message exists later for every call.
  • Reports violations via warning logs or by throwing (strict mode).

How It Works

toolCallInvariant({ strict }) runs after await next() and inspects ctx.messages:

  • Scans assistant messages with tool_calls.
  • For each call, looks forward for a tool message that matches by tool_call_id (preferred) or name (fallback for providers without IDs).
  • If any are missing, either logs a warning with details or throws when strict: true.

This is a development-time safety net to catch mis-ordered or missing tool replies in your loop.

Example

import 'dotenv/config';
import { Agent, createConsoleLogger, InMemoryKV, NullStream, SimpleTools, type Ctx } from '@sisu-ai/core';
import { openAIAdapter } from '@sisu-ai/adapter-openai';
import { inputToMessage } from '@sisu-ai/mw-conversation-buffer';
import { registerTools } from '@sisu-ai/mw-register-tools';
import { toolCalling } from '@sisu-ai/mw-tool-calling';
import { toolCallInvariant } from '@sisu-ai/mw-invariants';

const model = openAIAdapter({ model: 'gpt-5.4' });

// Example tool
const echo = {
  name: 'echo',
  description: 'Echo back a message',
  schema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
  handler: async ({ text }: { text: string }) => ({ text })
};

const ctx: Ctx = {
  input: 'Call the echo tool with text "hello" then answer briefly.',
  messages: [{ role: 'system', content: 'Be concise.' }],
  model,
  tools: new SimpleTools(),
  memory: new InMemoryKV(),
  stream: new NullStream(),
  state: {},
  signal: new AbortController().signal,
  log: createConsoleLogger({ level: 'info' })
};

const app = new Agent()
  .use(inputToMessage)
  .use(registerTools([echo as any]))
  .use(toolCalling) // or iterativeToolCalling
  // After tool loop completes, assert that every tool_call got a tool reply
  .use(toolCallInvariant({ strict: true }));

await app.handler()(ctx);

Placement & Ordering

  • Place after your tool-calling middleware so it can verify the result of a turn.
  • Use strict: true in development and CI to catch regressions early; relax to warnings in production if you prefer resilience over hard failures.

When To Use

  • During development/CI to ensure your tool loop respects the provider protocol.
  • In staging/production as a warning-only monitor to surface unexpected provider behavior.

When Not To Use

  • If your app never uses tools.
  • If you handle protocol validation elsewhere (e.g., custom loop with its own assertions).

Notes & Gotchas

  • Matching strategy: prefers tool_call_id. Falls back to name when the provider omits ids.
  • Parallel calls: works with multiple tool calls; each must have a corresponding tool message.
  • Cross-turn behavior: invariant checks within a single turn. If you intentionally defer tool responses to a later request, adjust placement or disable strict mode.
  • Streaming: this runs post-next(). For streaming loops that push an assistant_message event, ensure that the final message is added to ctx.messages before this check or defer the check to the end of the run.

Community & Support

Discover what you can do through examples or documentation. Check it out at https://github.com/finger-gun/sisu. Example projects live under examples/ in the repo.


Documentation

CorePackage docs · Error types

AdaptersOpenAI · Anthropic · Ollama

Anthropichello · control-flow · stream · weather

Ollamahello · stream · vision · weather · web-search

OpenAIhello · weather · stream · vision · reasoning · react · control-flow · branch · parallel · graph · orchestration · orchestration-adaptive · guardrails · error-handling · rag-chroma · web-search · web-fetch · wikipedia · terminal · github-projects · server · aws-s3 · azure-blob


Contributing

We build Sisu in the open. Contributions welcome.

Contributing Guide · Report a Bug · Request a Feature · Code of Conduct


Star on GitHub if Sisu helps you build better agents.

Quiet, determined, relentlessly useful.

Apache 2.0 License