Community寫作與編輯github.com

totwo2/nm-agents

AI Agent 运行时内核,把记忆做成第一公民。压缩/切模型都不失忆的分层持久记忆 + 强制回灌 + 智能路由 + 类型感知压缩 + 自进化。零默认 LLM 依赖。Agent harness with first-class memory that survives compaction and model switches.

nm-agents 是什麼?

nm-agents is a Codex agent skill that aI Agent 运行时内核,把记忆做成第一公民。压缩/切模型都不失忆的分层持久记忆 + 强制回灌 + 智能路由 + 类型感知压缩 + 自进化。零默认 LLM 依赖。Agent harness with first-class memory that survives compaction and model switches.

相容平台~Claude CodeCodex CLI~Cursor
npx skills add totwo2/nm-agents

Installed? Explore more 寫作與編輯 skills: steipete/notion, affaan-m/seo, affaan-m/brand-voice · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

nm-agents 是做什麼的?

纯 Python 的 AI Agent 运行时内核:主循环 + 路由 + 模型管理 + 上下文 + 权限 + 工具注册 + 自进化 + 持久记忆。不附带任何业务工具,由接入方按需注册。

何时使用

  • 要跑一个 agent 主循环(输入 → 记忆回灌 → 路由模型 → 调 LLM → 执行工具 → 沉淀记忆)
  • 要持久记忆(跨会话决策/事实/轨迹,压缩与切模型不失忆)
  • 要任务路由(本地/云端模型按信号选择)、权限校验、自进化流水线
  • 纯库:工具由接入方注册

安装

pip install -e .
# 依赖: openai>=2.0, pydantic>=2.0, requests>=2.30(Python >= 3.10)

最小装配(AgentLoop)

from nm.config import HarnessConfig, DEFAULT_SYSTEM_PROMPT
from nm.agent_loop import AgentLoop
from nm.memory.memory_adapter import MemoryAdapter
from nm.context_manager import ContextManager
from nm.permission_checker import PermissionChecker
from nm.tool_registry import ToolRegistry

config = HarnessConfig(stream_output=False)
mem = MemoryAdapter("memory_store.json", "transcript.jsonl")
ctx = ContextManager(DEFAULT_SYSTEM_PROMPT, workspace_dir=".")
router = TaskRouter(model_manager)          # 需先构造 ModelManager 并注册账号/分组
reg = ToolRegistry().create_default()        # 只含 get_tool_detail;业务工具自行 register
perm = PermissionChecker(mode=PermissionMode.AUTO)

harness = AgentLoop(config, mem, router, reg, ctx, perm)
result = harness.run("帮我整理这些数据", user_id="user1")

run() 返回 {text, tool_calls, usage, model, turns}

记忆 API(MemoryAdapter)

  • ingest(role, content, scope) / distill(scope):对话写入 + 提炼为结构化记忆
  • recall(scopes):全量回灌(单块文本)
  • recall_anchors(scopes):锚点层(决策+事实,日常常驻 system)
  • recall_detail(scopes):全量细节(轨迹流水,按需回灌)
  • capture({layer, ...}):显式捕获一条结构化记忆
  • mark_used(ids) / stats():读回执与统计

记忆闭环:ContextManager 压缩时通过 on_compaction 回调把被压原文沉淀为锚点;AgentLoop 切模型时补注全量细节——压缩、切模型两种失忆场景都有兜底。

配置

  • 记忆默认落运行目录 .nm/(可用 config_dir 等显式指定,需目录可写)
  • LLM 端点(仅语义提取需要):环境变量 OPENAI_BASE_URL/OPENAI_API_KEYllm_config.json → 本机兼容网关兜底;默认启发式提取零依赖

验证

python test_selfverify.py    # 22 项断言,覆盖记忆闭环 4 场景

注意

  • 权限默认 ASK,无回调时拒绝执行——接入方需提供 ask_callback 或改 AUTO
  • 工具必须显式 register,未注册的工具会被拒绝
  • 不包含任何网络服务入口,纯库

相關技能

steipete/notion

Notion CLI/API for pages, Markdown content, data sources, files, comments, search, Workers, and raw API calls.

community

affaan-m/seo

Audit, plan, and implement SEO improvements across technical SEO, on-page optimization, structured data, Core Web Vitals, and content strategy. Use when the user wants better search visibility, SEO remediation, schema markup, sitemap/robots work, or keyword mapping.

community

affaan-m/brand-voice

Build a source-derived writing style profile from real posts, essays, launch notes, docs, or site copy, then reuse that profile across content, outreach, and social workflows. Use when the user wants voice consistency without generic AI writing tropes.

community

affaan-m/crosspost

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

community

affaan-m/x-api

X/Twitter API integration for posting tweets, threads, reading timelines, search, and analytics. Covers OAuth auth patterns, rate limits, and platform-native content posting. Use when the user wants to interact with X programmatically.

community

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

community