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

@coderyi/multi-agent

v0.1.0

Published

Tools for building multi-agent apps.

Readme

multi-agent

一个 TypeScript 多智能体编排工具。

multi-agent 关注的是 Agent 应用里的基础编排问题:任务如何拆分、如何按依赖顺序执行、多个 Agent 如何共享状态、流程如何暂停等待人工确认,以及如何接入事件驱动场景。

它不绑定任何 LLM 厂商,也不内置模型调用。你可以把它作为一个小而清晰的编排内核,嵌入到自己的应用里。

特性

  • 基于 Operation 的异步任务单元
  • 基于 AgentQueue 的依赖调度、并发控制和优先级执行
  • 支持取消、超时、失败传播和生命周期事件
  • 支持 human-in-the-loop:任务可暂停,等待外部确认后恢复
  • 提供轻量 Store,适合做多 Agent 共享状态
  • 提供模型无关的消息、工具调用和 LLM provider 类型
  • 支持 RunLoop,可处理定时器或外部输入驱动的长期运行流程
  • TypeScript 编写,ESM,运行时零依赖

要求 Node.js >=18

安装

npm install @coderyi/multi-agent

快速开始

import { AgentQueue, createOperation } from "multi-agent";

const queue = new AgentQueue({
  id: "main",
  maxConcurrent: 2,
});

const fetchUser = createOperation("fetchUser", async () => {
  return { id: 1, name: "Alice" };
});

const fetchStats = createOperation("fetchStats", async () => {
  return { posts: 17 };
});

const summarize = createOperation("summarize", async () => {
  const user = await fetchUser.result;
  const stats = await fetchStats.result;
  return `${user.name} has ${stats.posts} posts`;
})
  .addDependency(fetchUser)
  .addDependency(fetchStats);

queue.submitAll([fetchUser, fetchStats, summarize]);

await queue.waitFor([summarize]);
console.log(await summarize.result);

await queue.close();

fetchUserfetchStats 可以并发执行;summarize 会等两个依赖都成功后再运行。

核心概念

Operation

Operation 是最小工作单元。它有自己的状态、结果、依赖、取消信号和生命周期回调。

常见状态包括:

  • pending
  • running
  • interrupted
  • finished
  • cancelled
  • failed

AgentQueue

AgentQueue 负责调度 Operation。它会根据依赖关系决定执行顺序,并处理并发、失败传播、暂停恢复和队列关闭。

const queue = new AgentQueue({
  id: "workflow",
  maxConcurrent: 4,
  onEvent: (event) => {
    console.log(event.type);
  },
});

Store

Store 是一个简单的共享状态容器,适合做多 Agent 的状态黑板。

import { createStore, messagesReducer, textMessage } from "multi-agent";
import type { Message } from "multi-agent";

const store = createStore<{ messages: Message[] }>(
  { messages: [] },
  { reducers: { messages: messagesReducer } },
);

store.merge({
  messages: [textMessage("user", "Hello")],
});

LLM

multi-agent 不直接调用模型。

具体的模型服务、推理接口或内部系统,可以在应用层按需接入。

Interrupt

Operation 可以通过 ctx.interrupt() 暂停执行,并等待外部调用 queue.resolveInterrupt() 恢复。

这适合审批、确认、权限申请、人工输入等流程。

RunLoop

RunLoop 用于事件驱动场景。内置:

  • TimerSource
  • InputSource

也可以把事件源注册到 AgentQueue,让每次事件触发一轮新的任务执行。

示例

仓库提供了几个示例:

npm run example -- examples/01-queue.ts
npm run example -- examples/02-workflow.ts
npm run example -- examples/03-interrupt.ts
npm run example -- examples/04-runloop.ts

模块入口

import { AgentQueue, createOperation } from "multi-agent";
import { createStore } from "multi-agent/state";
import { textMessage, messagesReducer } from "multi-agent/llm";

也可以从主入口直接导入常用能力:

import {
  AgentQueue,
  createOperation,
  createStore,
  textMessage,
  messagesReducer,
} from "multi-agent";

License

MIT