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

@lite-agent/core

v0.12.0

Published

Pluggable, event-driven agent core: kernel, strategy interfaces, middleware pipeline, and normalized types.

Readme

@lite-agent/core

English | 简体中文

可插拔、事件驱动的 Agent 内核。一个精简、与具体模型无关的核心,由可替换的**策略(strategy)接口、洋葱式中间件(middleware)管道,以及类型化的事件(event)**流构成。它对任何具体模型、权限 UI、存储方式一无所知 —— 这些都是插进来的。

其公开 API 参照 @anthropic-ai/claude-agent-sdk 设计,但内核为自研,因此也能通过可插拔的 tool-call 编解码器(codec)驱动本地小模型。

若需要开箱即用的组合(真实工具、技能、子 Agent、会话、权限门),请用 @lite-agent/sdk —— 它就是在本内核之上组装出来的。当你想用这些原语自己搭建 Agent 时,才直接使用 @lite-agent/core

安装

pnpm add @lite-agent/core zod

快速开始

import { createAgent, nativeCodec, fakeProvider, textBlock } from "@lite-agent/core";

const agent = createAgent({
  model: fakeProvider([
    { text: "hi", message: { role: "assistant", content: [textBlock("hi")] } },
  ]),
  codec: nativeCodec(),
});

// 流式消费类型化事件……
for await (const ev of agent.run("hello")) {
  if (ev.type === "text_delta") process.stdout.write(ev.text);
}

// ……或等待最终结果。
const result = await agent.send("hello");
console.log(result.text);

fakeProvider 是内置的测试替身。要接真实模型,请传入来自 @lite-agent/providerModelProvideranthropic() / openai())。

内核

runKernel(cfg, input, signal, sessionId) 是一个产出 AgentEventasync function*。每一轮:codec.encode 编码请求 → provider.stream(被 wrapModelCall 中间件包裹)→ 累积文本 / 用量 → codec.decode 解码出 tool 调用 → 每个调用穿过 wrapToolCall 链、包裹 tool.execute 执行 → 把结果回灌 → 循环,直到模型不再调用工具或达到 maxTurns。中断(abort)在轮次边界被观测。

九个可替换策略

每个角色一个实现,可热插拔:

ModelProvider · ToolCallCodec · Tool · Compactor · PermissionPolicy · ApprovalHandler · InputHandler · Store · Sandbox

设计口诀

  • 策略(Strategy)——替换某个部件ModelProviderToolCallCodecToolCompactorPermissionPolicyApprovalHandlerInputHandlerStoreSandbox
  • 中间件(Middleware)——叠加一层wrapModelCallwrapToolCall,以及生命周期钩子(beforeAgent / afterAgent / beforeModel)。用 composeModelCall / composeToolCall 折叠。
  • 事件(Event)——只观察:一个类型化的 AgentEvent 流(turn_starttext_deltamessagetool_usetool_resultapproval_request|resolvedinput_request|resolvedcompactionturn_enderrordone)。

导出内容

  • 组装 —— createAgentdefineTool / toToolSpecnativeCodecjsonCodecreactCodec
  • 中间件 —— permission + policyretrycompaction 及压缩工具箱(defaultCompactorreactiveCompactionllmCompactor、spill store 等)、composeModelCall / composeToolCall
  • 持久化 —— 事件溯源的 Checkpointer 原语:memoryCheckpointerfoldEventsstoreEventslegacyStoreAdapter,以及 memoryStore。(持久化后端见 @lite-agent/checkpoint-sqlite 或 SDK 的文件 checkpointer。)
  • 沙箱 —— noopSandbox(默认的无边界沙箱;操作系统级边界在 @lite-agent/sandbox-anthropic)。
  • 引导(Steering) —— SteerController,用于在运行中注入输入。
  • 错误 —— AgentError + ProviderError / ToolError / CodecError / MaxTurnsError / AbortError / CheckpointConflictError
  • 测试 —— fakeProvidercheckpointerConformance
  • 类型 —— 归一化的 Message / ContentBlock / ToolCall / ToolResult / UserQuestion / UserAnswer,全部策略接口,以及 AgentEvent 联合类型。

完整架构说明见 monorepo 根目录