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 Code✓Codex CLI~Cursor
npx skills add totwo2/nm-agents

Installed? Explore more 写作与编辑 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

nm-agents 是做什么的?

A pure Python AI Agent runtime kernel: main loop + routing + model management + context + permissions + tool registration + self-evolution + persistent memory. Does not include any business tools—those are registered by the integrating party as needed.

When to Use

  • When you need to run an agent main loop (input → memory re-ingestion → route model → call LLM → execute tools → consolidate memory)
  • When you need persistent memory (cross-session decisions/facts/trajectories, surviving compression and model switches)
  • When you need task routing (local/cloud model selection based on signals), permission checking, and a self-evolution pipeline
  • It is a pure library: tools are registered by the integrating party

Installation

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

Minimal Setup (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)          # Must construct ModelManager first and register accounts/groups
reg = ToolRegistry().create_default()        # Only includes get_tool_detail; register your business tools yourself
perm = PermissionChecker(mode=PermissionMode.AUTO)

harness = AgentLoop(config, mem, router, reg, ctx, perm)
result = harness.run("Help me organize this data", user_id="user1")

run() returns {text, tool_calls, usage, model, turns}.

Memory API (MemoryAdapter)

  • ingest(role, content, scope) / distill(scope): Write conversation + distill into structured memory
  • recall(scopes): Full re-ingestion as a single text block
  • recall_anchors(scopes): Anchor layer (decisions + facts), typically kept in system prompt
  • recall_detail(scopes): Full detail (trajectory transcript), re-ingested on demand
  • capture({layer, ...}): Explicitly capture a structured memory entry
  • mark_used(ids) / stats(): Read receipts and statistics

Memory closure: ContextManager calls the on_compaction callback during compression to consolidate the compressed original text into anchors; AgentLoop supplements full details when switching models—both memory loss scenarios (compression and model switch) are covered.

Configuration

  • Memory defaults to .nm/ in the run directory (use config_dir or other explicit paths; writable directory required)
  • LLM endpoint (only needed for semantic extraction): Environment variables OPENAI_BASE_URL/OPENAI_API_KEY → llm_config.json → fallback to a local compatible gateway; default heuristic extraction requires no dependencies

Verification

python test_selfverify.py    # 22 assertions, covering 4 memory closure scenarios

Notes

  • Permissions default to ASK; without a callback, execution is denied—the integrating party must provide an ask_callback or change to AUTO
  • Tools must be explicitly registered; unregistered tools will be rejected
  • Does not include any network service entry point; it is a pure library

相关技能