[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-pig-dot-dev--muscle-mem":3,"tool-pig-dot-dev--muscle-mem":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",149489,2,"2026-04-10T11:32:46",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":76,"owner_twitter":76,"owner_website":77,"owner_url":78,"languages":79,"stars":84,"forks":85,"last_commit_at":86,"license":87,"difficulty_score":88,"env_os":75,"env_gpu":89,"env_ram":89,"env_deps":90,"category_tags":93,"github_topics":76,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":94,"updated_at":95,"faqs":96,"releases":111},6209,"pig-dot-dev\u002Fmuscle-mem","muscle-mem","A cache for AI agents to learn and replay complex behaviors.","muscle-mem 是一款专为 AI 智能体设计的 Python SDK，旨在通过“行为缓存”机制让智能体学会并复现复杂的任务操作。它核心解决了大语言模型在处理重复性任务时响应慢、输出不稳定以及 Token 成本高昂的痛点。当智能体首次成功解决某个任务后，muscle-mem 会记录其工具调用的完整轨迹；再次遇到相同任务时，系统将直接回放已验证的操作序列，仅在检测到环境变化或边缘情况时才重新调用大模型进行推理。\n\n这款工具特别适合正在构建自动化工作流或 AI 智能体的开发者使用。其独特之处在于并非替代现有的智能体框架，而是作为一个轻量级引擎无缝嵌入现有架构中。开发者只需通过简单的装饰器（如 `@engine.function`）对工具函数进行标注，即可实现自动记录与回放。此外，muscle-mem 提供了灵活的标签系统和环境检查机制，确保缓存复用的安全性与准确性。通过将“本可以用脚本解决”的场景从大模型调用路径中剥离，muscle-mem 能显著提升系统执行速度，降低运行成本，同时保持处理复杂新任务时的灵活性。","# Muscle Memory\n\n`muscle-mem` is a behavior cache for AI agents.\n\nIt is a Python SDK that records your agent's tool-calling patterns as it solves tasks, and will deterministically replay those learned trajectories whenever the task is encountered again, falling back to agent mode if edge cases are detected.\n\nThe goal of `muscle-mem` is to get LLMs out of the hotpath for repetitive tasks, increasing speed, reducing variability, and eliminating token costs for the many cases that ***could have just been a script***.\n\nIt's unexplored territory, so all feedback is welcome!\n- Read [Muscle Mem - Removing LLM calls from Agents](https:\u002F\u002Ferikdunteman.com\u002Fblog\u002Fmuscle-mem\u002F) for more context\n- Join [Muscle Mem discord](https:\u002F\u002Fdiscord.gg\u002Fs84dXDff3K) for feedback\n\n### Dev Log\n- May 7, 2025 - [First working demo](https:\u002F\u002Fwww.loom.com\u002Fshare\u002F5936cd9779504aa5a7dce5d72370c35d)\n- May 8, 2025 - Open sourced\n- June 1, 2025 - Parameterization and Tags merged\n\u003Cbr>\n\u003Cbr>\n\n# How It Works\n\n`muscle-mem` is ***not*** another agent framework. \n\nYou implement your agent however you want, and then plug it into `muscle-mem`'s engine.\n\nWhen given a task, the engine will:\n1. determine if the environment has been seen before (cache-hit), or if it's new (cache-miss) using `Checks`\n2. perform the task, either\n   - using the retrieved trajectory on cache-hit,\n   - or passing the task to your agent on cache-miss.\n3. collect tool call events to add to cache as a new trajectory\n\n\n### It's all about Cache Validation\n\nTo add safe tool reuse to your agent, the critical question is cache validation. Ask yourself:\n> For each tool we give to our agent, what features in the environment can be used to indicate whether or not it's safe to perform that action?\n\nIf you can answer this, your agent can have Muscle Memory.\n\u003Cbr>\n\u003Cbr>\n\n\n# The API\n\n## Installation\n\n`pip install muscle-mem`\n\nMuscle Mem's API is v0 and will break on minor releases, so we strongly recommend pinning to a specific version for production use.\n\n## Engine\n\nThe engine wraps your agent and serves as the primary executor of tasks.\n\nIt manages its own cache of previous trajectories, and determines when to invoke your agent.\n\n```python\nfrom muscle_mem import Engine\n\nengine = Engine()\nengine.set_agent(your_agent).finalize()\n\n# your agent is independently callable\nyour_agent(\"do some task\")\n\n# the engine gives you the same interface, but with muscle memory\nengine(\"do some task\")\nengine(\"do some task\") # cache hit\n```\n\nIt is expected that your agent is callable, either as a function or with a `__call__` method. Any args and kwargs passed to `engine()` will be directly passed to your agent. Our examples use a string, but it could be a list of ChatCompletion messages or whatever your agent callable expects.\n\n\nBy default, trajectories are stored in a single cache. You may tag trajectories with a description of the task to create unique buckets.\n\n```python\nengine(\"do some task\", tags=[\"some task\"]) # cache miss\nengine(\"do some task\", tags=[\"some task\"]) # cache hit\n\nengine(\"do some task\", tags=[\"different task\"]) # cache miss\nengine(\"do some task\", tags=[\"different task\"]) # cache hit\n```\n\n## Tool Instrumentation\n\nDecorators are used to instrument action-taking tools, so that the engine can record actions as your agent takes them.\n\n### Functions\n\nUse the `@engine.function` decorator to instrument a simple function tool:\n\n```python\nfrom muscle_mem import Engine\n\nengine = Engine()\n\n@engine.function()\ndef hello(name: str):\n\tprint(f\"hello {name}!\")\n\t\nhello(\"world\") # invocation of hello is stored, with arg name=\"world\"\n```\n\n### Methods\n\nUse the `@engine.method` decorator to instrument a method attached to an object.\n\nThis allows for dependency injection of stateful API clients via the `self` argument, such as `self.db.get_user(id)` or `self.model.generate(prompt)`.\n\n\n```python\nfrom muscle_mem import Engine\n\nengine = Engine()\n\nclass SomeClient:\n   @engine.method()\n   def hello(self, name: str):\n       print(f\"hello {name}!\")\n\nclient = SomeClient()\n\nclient.hello(\"world\") # invocation of SomeClient.hello is stored, with arg name=\"world\"\n```\n\nNote that because runtime objects (`self`) cannot be serialized, `self` is omitted from the trajectory.\n\nFor the engine to replay a method-based tool, it must be explicitly passed an instance of the object to re-inject as `self`.\n\nUse `engine.set_context()` to provide the runtime object to the engine.\n\n```python \nengine = (\n    engine\n    .set_agent(your_agent)\n    .set_context(client) # your client object will be injected as self into SomeClient.hello\n    .finalize()\n)\nengine(\"say hello world!\")\n```\n\n`engine.finalize()` is an optional check to ensure you've provided all dependencies to the engine before using it.\n\n\n## Check\n\nThe Check is the fundamental building block for cache validation. They determine if it’s safe to execute a given action.\n\nEach Check encapsulates:\n\n- A `capture` callback to extract relevant features from the current environment\n- A `compare` callback to determine if current environment matches cached environment\n\n```python\nCheck(\n    capture: Callable[P, T],\n    compare: Callable[[T, T], Union[bool, float]],\n):\n```\n\nYou can attach Checks to each tool `@engine.function` (or `@engine.method`) to enforce cache validation. \n\nThis can be done before the tool call as a precheck (also used for query time validation), or after a tool call as a postcheck. \n\nBelow is a contrived example, which captures use of the `hello` tool, and uses timestamps and a one second expiration as the Check mechanic for cache validation.\n\n```python\n# our capture implementation, taking params and returning T\ndef capture(name: str) -> T:\n    now = time.time()\n    return T(name=name, time=now)\n\n# our compare implementation, taking current and candidate T\ndef compare(current: T, candidate: T) -> bool:\n    # cache is valid if happened within the last 1 second\n    diff = current.time - candidate.time\n    passed = diff \u003C= 1\n    return passed\n\n# decorate our tool with a precheck\n@engine.function(pre_check=Check(capture, compare))\ndef hello(name: str):\n    time.sleep(0.1)\n    print(f\"hello {name}\")\n```\n\n### Top Level Parameters\n\nMuscle Mem, by default, stores all arguments to a tool call as static values.\n\nThis may not always be desired, as some arguments may need to be dynamic per-run. For example, a form filling bot filling a `First Name` text field would invoke a `type(\"John\")` tool call, but on future runs we'd want a way to use a different name.\n\nMuscle Mem addresses this with a top level `params` system, which allows you to specify arguments that should be dynamic per-run.\n\nIf a value is known at runtime before calling your agent (you're likely already templating it into your prompt), it can be marked as a top level parameter with the optional `params` argument to `engine()`.\n\n```python\n@engine.function()\ndef type(text: str):\n    print(text)\n\n# first run stores invocation of type(\"John\"), with dynamic arg `text` mapped to top level param `name`\nengine(\"fill the form with name: John\", params={\"name\": \"John\"})\n\n# second run is a cache hit, using Jane instead of John\nengine(\"fill the form with name: Jane\", params={\"name\": \"Jane\"})\n```\n\nWhile recording a trajectory, if any underlying tool calls sees an argument that directly matches a top level parameter, the engine will mark it as dynamic and map it to the top level parameter by key.\n\nThe current implementation uses exact string matching on tool args to identify it as originating from a top level parameter. It is assumed that all tool args came from an LLM, therefore are string serializeable.\n\n### Putting it all together\n\nBelow is the combined script for all of the above code snippets. \n\n```python\nfrom dataclasses import dataclass\nfrom muscle_mem import Check, Engine\nimport time\n\nengine = Engine()\n\n# our \"environment\" features, stored in DB\n@dataclass\nclass T:\n    name: str\n    time: float\n\n# our capture implementation, taking params and returning T\ndef capture(name: str) -> T:\n    now = time.time()\n    return T(name=name, time=now)\n\n# our compare implementation, taking current and candidate T\ndef compare(current: T, candidate: T) -> bool:\n    # cache is valid if happened within the last 1 second\n    diff = current.time - candidate.time\n    passed = diff \u003C= 1\n    return passed\n\n# decorate our tool with a precheck\n@engine.function(pre_check=Check(capture, compare))\ndef hello(name: str):\n    time.sleep(0.1)\n    print(f\"hello {name}\")\n    \n# pretend this is your agent\ndef agent(name: str):\n   for i in range(9):\n        hello(name + \" + \" + str(i))\n\nengine.set_agent(agent).finalize()\n\n# Run once\ncache_hit = engine(\"erik\")\nassert not cache_hit\n\n# Run again \ncache_hit = engine(\"erik\")\nassert cache_hit\n\n# Break cache with a sleep, then run again\ntime.sleep(3)\ncache_hit = engine(\"erik\")\nassert not cache_hit\n```\n\nFor a more real example, see a computer-use agent implementation:\n\n[https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem\u002Fblob\u002Fmain\u002Fexamples\u002Fcua.py](https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem\u002Fblob\u002Fmain\u002Fexamples\u002Fcua.py)\n\n---\n\n# Call To Action\n\nI invite all feedback as this system develops!\n\nPlease consider:\n1. Joining the [Muscle Mem discord](https:\u002F\u002Fdiscord.gg\u002Fs84dXDff3K)\n2. Testing [the muscle-mem repo](https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem), and giving it a star\n\n","# 肌肉记忆\n\n`muscle-mem` 是一个用于 AI 代理的行为缓存。\n\n它是一个 Python SDK，能够在代理解决任务的过程中记录其工具调用模式，并在再次遇到相同任务时确定性地重放这些已学习的轨迹；如果检测到边缘情况，则会回退到代理模式。\n\n`muscle-mem` 的目标是让大型语言模型从重复性任务的热路径中脱离出来，从而提高速度、减少波动性，并为那些“本来只需一段脚本就能完成”的场景节省 token 成本。\n\n这仍是一个尚未被充分探索的领域，因此我们非常欢迎任何反馈！\n- 欲了解更多信息，请阅读 [Muscle Mem - 从代理中移除 LLM 调用](https:\u002F\u002Ferikdunteman.com\u002Fblog\u002Fmuscle-mem\u002F)。\n- 如需交流反馈，请加入 [Muscle Mem Discord 服务器](https:\u002F\u002Fdiscord.gg\u002Fs84dXDff3K)。\n\n### 开发日志\n- 2025年5月7日 - [首次可用演示](https:\u002F\u002Fwww.loom.com\u002Fshare\u002F5936cd9779504aa5a7dce5d72370c35d)\n- 2025年5月8日 - 开源发布\n- 2025年6月1日 - 参数化与标签功能合并\n\u003Cbr>\n\u003Cbr>\n\n# 工作原理\n\n`muscle-mem` 并非另一个代理框架。\n\n您可以按照自己习惯的方式实现代理，然后将其接入 `muscle-mem` 的引擎。\n\n当接收到一项任务时，引擎将执行以下步骤：\n1. 使用检查机制判断当前环境是否曾出现过（缓存命中），或是否为新环境（缓存未命中）；\n2. 执行任务，具体方式如下：\n   - 缓存命中时，使用检索到的轨迹；\n   - 缓存未命中时，将任务交由您的代理处理。\n3. 收集工具调用事件，作为新的轨迹添加到缓存中。\n\n\n### 关键在于缓存验证\n\n要为您的代理引入安全的工具复用功能，最关键的问题就是缓存验证。您需要自问：\n> 对于我们赋予代理的每一种工具，在当前环境中有哪些特征可以用来判断执行该操作是否安全？\n\n如果您能够回答这个问题，那么您的代理就可以具备肌肉记忆功能。\n\u003Cbr>\n\u003Cbr>\n\n\n# API 说明\n\n## 安装\n\n`pip install muscle-mem`\n\nMuscle Mem 的 API 当前处于 v0 版本，且会在小版本更新时发生破坏性变更，因此我们强烈建议在生产环境中固定使用某一特定版本。\n\n## 引擎\n\n引擎包装您的代理，充当任务的主要执行者。\n\n它管理着自己的历史轨迹缓存，并决定何时调用您的代理。\n\n```python\nfrom muscle_mem import Engine\n\nengine = Engine()\nengine.set_agent(your_agent).finalize()\n\n# 您的代理可以直接调用\nyour_agent(\"do some task\")\n\n# 引擎提供相同的接口，但具备肌肉记忆功能\nengine(\"do some task\")\nengine(\"do some task\") # 缓存命中\n```\n\n假设您的代理可以通过函数形式或 `__call__` 方法进行调用。传递给 `engine()` 的所有位置参数和关键字参数都会直接传递给您的代理。我们的示例中使用了字符串，但也可以是 ChatCompletion 消息列表，或者您的代理可调用方法所期望的任何内容。\n\n\n默认情况下，轨迹会被存储在一个统一的缓存中。您可以通过为轨迹添加描述性的标签来创建不同的存储桶。\n\n```python\nengine(\"do some task\", tags=[\"some task\"]) # 缓存未命中\nengine(\"do some task\", tags=[\"some task\"]) # 缓存命中\n\nengine(\"do some task\", tags=[\"different task\"]) # 缓存未命中\nengine(\"do some task\", tags=[\"different task\"]) # 缓存命中\n```\n\n## 工具插桩\n\n通过装饰器对执行动作的工具进行插桩，以便引擎能够在代理执行操作时记录这些动作。\n\n### 函数\n\n使用 `@engine.function` 装饰器为简单的函数工具进行插桩：\n\n```python\nfrom muscle_mem import Engine\n\nengine = Engine()\n\n@engine.function()\ndef hello(name: str):\n    print(f\"hello {name}!\")\n    \nhello(\"world\") # 调用 hello 被记录下来，参数 name=\"world\"\n```\n\n### 方法\n\n使用 `@engine.method` 装饰器为对象上的方法进行插桩。\n\n这允许通过 `self` 参数注入有状态的 API 客户端，例如 `self.db.get_user(id)` 或 `self.model.generate(prompt)`。\n\n\n```python\nfrom muscle_mem import Engine\n\nengine = Engine()\n\nclass SomeClient:\n   @engine.method()\n   def hello(self, name: str):\n       print(f\"hello {name}!\")\n\nclient = SomeClient()\n\nclient.hello(\"world\") # 调用 SomeClient.hello 被记录下来，参数 name=\"world\"\n```\n\n需要注意的是，由于运行时对象（`self`）无法序列化，因此 `self` 不会包含在轨迹中。\n\n为了使引擎能够重放基于方法的工具调用，必须显式地向引擎传递一个实例对象，以重新注入 `self`。\n\n使用 `engine.set_context()` 来为引擎提供运行时对象。\n\n```python \nengine = (\n    engine\n    .set_agent(your_agent)\n    .set_context(client) # 您的 client 对象会被注入为 self，用于调用 SomeClient.hello\n    .finalize()\n)\nengine(\"say hello world!\")\n```\n\n`engine.finalize()` 是一个可选检查，用于确保您在使用引擎之前已提供了所有依赖项。\n\n\n## 检查机制\n\n检查机制是缓存验证的基本构建模块。它们决定了执行某项操作是否安全。\n\n每个检查机制封装了：\n- 一个 `capture` 回调函数，用于从当前环境中提取相关特征；\n- 一个 `compare` 回调函数，用于判断当前环境是否与缓存中的环境匹配。\n\n```python\nCheck(\n    capture: Callable[P, T],\n    compare: Callable[[T, T], Union[bool, float]],\n):\n```\n\n您可以将检查机制附加到每个工具上（使用 `@engine.function` 或 `@engine.method`），以强制执行缓存验证。这些检查可以在工具调用之前作为预检（也可用于查询时验证），或在工具调用之后作为后检。\n\n下面是一个示例，它捕捉了 `hello` 工具的使用情况，并利用时间戳和一秒钟的过期机制作为缓存验证的检查逻辑。\n\n```python\n# 我们的捕获实现，接收参数并返回 T\ndef capture(name: str) -> T:\n    now = time.time()\n    return T(name=name, time=now)\n\n# 我们的比较实现，接收当前和候选的 T\ndef compare(current: T, candidate: T) -> bool:\n    # 如果发生在最近一秒钟内，则缓存有效\n    diff = current.time - candidate.time\n    passed = diff \u003C= 1\n    return passed\n\n# 为我们的工具添加预检\n@engine.function(pre_check=Check(capture, compare))\ndef hello(name: str):\n    time.sleep(0.1)\n    print(f\"hello {name}\")\n```\n\n### 顶层参数\n\n默认情况下，Muscle Mem 会将工具调用的所有参数存储为静态值。\n\n但这并不总是理想的，因为某些参数可能需要根据每次运行动态变化。例如，一个填写表单的机器人可能会调用 `type(\"John\")` 工具来填充“名字”字段，但在后续运行中，我们希望使用不同的名字。\n\n为此，Muscle Mem 提供了一个顶层 `params` 系统，允许您指定那些需要根据每次运行动态变化的参数。\n\n如果某个值在调用代理之前就已经在运行时确定（例如您已经将其模板化到提示词中），则可以通过 `engine()` 的可选 `params` 参数将其标记为顶层参数。\n\n```python\n@engine.function()\ndef type(text: str):\n    print(text)\n\n# 第一次运行会存储对 type(\"John\") 的调用，其中动态参数 `text` 被映射到顶级参数 `name`\nengine(\"用名字：John 填写表单\", params={\"name\": \"John\"})\n\n# 第二次运行命中缓存，使用 Jane 代替 John\nengine(\"用名字：Jane 填写表单\", params={\"name\": \"Jane\"})\n```\n\n在记录轨迹时，如果任何底层工具调用中的参数与顶级参数直接匹配，引擎会将其标记为动态，并按键名将其映射到顶级参数。\n\n当前的实现通过工具参数的精确字符串匹配来判断其是否源自顶级参数。假设所有工具参数都来自 LLM，因此都可以被序列化为字符串。\n\n### 整体整合\n\n以下是上述所有代码片段的合并脚本。\n\n```python\nfrom dataclasses import dataclass\nfrom muscle_mem import Check, Engine\nimport time\n\nengine = Engine()\n\n# 我们的“环境”特征，存储在数据库中\n@dataclass\nclass T:\n    name: str\n    time: float\n\n# 我们的捕获实现，接收参数并返回 T\ndef capture(name: str) -> T:\n    now = time.time()\n    return T(name=name, time=now)\n\n# 我们的比较实现，接收当前和候选的 T\ndef compare(current: T, candidate: T) -> bool:\n    # 如果发生时间在最近1秒内，则缓存有效\n    diff = current.time - candidate.time\n    passed = diff \u003C= 1\n    return passed\n\n# 使用预检查装饰我们的工具\n@engine.function(pre_check=Check(capture, compare))\ndef hello(name: str):\n    time.sleep(0.1)\n    print(f\"hello {name}\")\n    \n# 假设这是你的智能体\ndef agent(name: str):\n   for i in range(9):\n        hello(name + \" + \" + str(i))\n\nengine.set_agent(agent).finalize()\n\n# 第一次运行\ncache_hit = engine(\"erik\")\nassert not cache_hit\n\n# 再次运行\ncache_hit = engine(\"erik\")\nassert cache_hit\n\n# 通过睡眠打破缓存，然后再次运行\ntime.sleep(3)\ncache_hit = engine(\"erik\")\nassert not cache_hit\n```\n\n如需更真实的示例，请参阅计算机使用代理的实现：\n\n[https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem\u002Fblob\u002Fmain\u002Fexamples\u002Fcua.py](https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem\u002Fblob\u002Fmain\u002Fexamples\u002Fcua.py)\n\n---\n\n# 行动号召\n\n随着该系统的不断发展，诚邀大家提出反馈！\n\n请考虑：\n1. 加入 [Muscle Mem Discord 社区](https:\u002F\u002Fdiscord.gg\u002Fs84dXDff3K)\n2. 测试 [muscle-mem 仓库](https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem)，并给它点个赞","# Muscle Memory 快速上手指南\n\n`muscle-mem` 是一个专为 AI Agent 设计的“行为缓存”Python SDK。它能记录 Agent 解决任务时的工具调用模式，并在遇到相同任务时确定性重放这些轨迹，从而将 LLM 从重复性工作中解放出来，显著提升速度、降低波动并节省 Token 成本。\n\n## 环境准备\n\n- **系统要求**：支持 Python 3.8+ 的操作系统（Linux, macOS, Windows）\n- **前置依赖**：\n  - Python 3.8 或更高版本\n  - pip 包管理工具\n  - 一个已实现的 AI Agent（需为可调用对象，即函数或实现了 `__call__` 方法的类）\n\n> **注意**：Muscle Mem 目前处于 v0 阶段，API 可能在次版本更新中发生变化。生产环境使用时，强烈建议锁定具体版本号。\n\n## 安装步骤\n\n使用 pip 直接安装：\n\n```bash\npip install muscle-mem\n```\n\n*注：若国内下载速度较慢，可尝试配置清华或阿里镜像源：*\n```bash\npip install muscle-mem -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 基本使用\n\n### 1. 初始化引擎并接入 Agent\n\n`muscle-mem` 不是一个新的 Agent 框架，而是包裹在你现有 Agent 外层的执行引擎。\n\n```python\nfrom muscle_mem import Engine\n\n# 假设这是你现有的 Agent\ndef your_agent(task: str):\n    print(f\"Agent is working on: {task}\")\n    # ... 你的 Agent 逻辑 ...\n\n# 初始化引擎\nengine = Engine()\n\n# 将你的 Agent 注入引擎\nengine.set_agent(your_agent).finalize()\n\n# 现在可以通过 engine 调用，首次运行会记录轨迹\nengine(\"do some task\") \n\n# 再次运行相同任务，将直接命中缓存并重放，不再调用 LLM\nengine(\"do some task\") # cache hit\n```\n\n### 2. 工具插桩 (Tool Instrumentation)\n\n为了让引擎记录具体的工具调用行为，需要使用装饰器对工具函数进行标记。\n\n**标记普通函数：**\n\n```python\n@engine.function()\ndef hello(name: str):\n    print(f\"hello {name}!\")\n\n# 调用会被自动记录\nhello(\"world\") \n```\n\n**标记类方法（支持依赖注入）：**\n\n如果工具是类的方法（例如需要访问 `self.db`），引擎会在重放时重新注入实例对象。\n\n```python\nclass SomeClient:\n    @engine.method()\n    def hello(self, name: str):\n        print(f\"hello {name}!\")\n\nclient = SomeClient()\n\n# 设置上下文，以便重放时注入 self\nengine.set_context(client).finalize()\n\nclient.hello(\"world\") # 调用被记录\n```\n\n### 3. 缓存验证 (Cache Validation)\n\n为了安全地重用工具，必须定义何时缓存失效。通过 `Check` 机制，你可以指定如何捕获环境特征以及如何比较这些特征。\n\n以下示例展示了一个基于时间的预检查（Pre-check）：如果距离上次执行超过 1 秒，则视为缓存未命中，重新执行 Agent。\n\n```python\nfrom dataclasses import dataclass\nfrom muscle_mem import Check\nimport time\n\n@dataclass\nclass EnvState:\n    name: str\n    timestamp: float\n\n# 捕获当前环境状态\ndef capture(name: str) -> EnvState:\n    return EnvState(name=name, timestamp=time.time())\n\n# 比较当前状态与缓存状态\ndef compare(current: EnvState, cached: EnvState) -> bool:\n    # 如果在 1 秒内，认为缓存有效\n    return (current.timestamp - cached.timestamp) \u003C= 1\n\n# 将 Check 绑定到工具上\n@engine.function(pre_check=Check(capture, compare))\ndef hello(name: str):\n    time.sleep(0.1)\n    print(f\"hello {name}\")\n\n# 模拟 Agent 逻辑\ndef agent(name: str):\n    hello(name)\n\nengine.set_agent(agent).finalize()\n\n# 第一次运行：记录轨迹\nengine(\"erik\") # Cache Miss\n\n# 第二次运行：立即重放\nengine(\"erik\") # Cache Hit\n\n# 等待超过 1 秒后运行：缓存失效，重新执行\ntime.sleep(2)\nengine(\"erik\") # Cache Miss\n```\n\n### 4. 动态参数支持\n\n如果某些参数在每次运行时都需要变化（例如表单填写中的不同姓名），可以使用 `params` 参数将其标记为动态变量。\n\n```python\n@engine.function()\ndef type_text(text: str):\n    print(text)\n\n# 第一次运行：记录轨迹，将 \"John\" 映射为动态参数 `name`\nengine(\"fill form with John\", params={\"name\": \"John\"})\n\n# 第二次运行：命中缓存，但使用新的参数值 \"Jane\" 重放\nengine(\"fill form with Jane\", params={\"name\": \"Jane\"})\n```","某电商公司的自动化运维团队利用 AI Agent 每日处理数百起“用户订单状态异常”的客诉，需调用数据库查询、日志检索及退款接口进行标准化修复。\n\n### 没有 muscle-mem 时\n- **响应延迟高**：每个重复案例都需完整经过大模型推理链路，平均处理耗时从秒级拉长至分钟级，无法应对突发流量。\n- **运行成本昂贵**：大量本可脚本化解决的简单任务反复消耗昂贵的 Token 额度，造成不必要的算力浪费。\n- **执行结果不稳定**：大模型在面对相同报错时，偶尔会产生幻觉或生成非标准化的工具调用参数，导致修复失败率波动。\n- **调试困难**：由于每次执行路径由模型动态生成，难以复现特定的错误现场，排查问题如同“开盲盒”。\n\n### 使用 muscle-mem 后\n- **极速响应**：muscle-mem 首次学习成功后，后续相同场景直接回放缓存的执行轨迹，将处理时间压缩回毫秒级脚本速度。\n- **大幅降本**：对于命中缓存的常规任务，完全绕过 LLM 推理环节，消除了绝大部分重复性任务的 Token 开销。\n- **确定性执行**：通过严格回放已验证的工具调用序列，确保每次操作参数精准一致，彻底消除了模型行为变异带来的风险。\n- **智能降级机制**：遇到未见过的新颖边缘案例时，系统自动切换回 Agent 模式让大模型介入处理，并自动记录新轨迹入库，兼顾灵活性与稳定性。\n\nmuscle-mem 的核心价值在于将 AI 代理从重复劳动中解放出来，让大模型仅专注于真正的未知难题，而将成熟流程转化为确定性的低成本脚本。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fpig-dot-dev_muscle-mem_71550eef.png","pig-dot-dev","Pig","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fpig-dot-dev_706f3794.png","",null,"pig.dev","https:\u002F\u002Fgithub.com\u002Fpig-dot-dev",[80],{"name":81,"color":82,"percentage":83},"Python","#3572A5",100,756,41,"2026-04-09T10:37:46","Apache-2.0",1,"未说明",{"notes":91,"python":89,"dependencies":92},"该工具是一个纯 Python SDK，用于缓存 AI 代理的工具调用模式，不涉及大型模型推理，因此对 GPU 和内存无特殊高要求。安装方式为 pip install muscle-mem。API 处于 v0 阶段，建议在生产环境中锁定具体版本。工具通过装饰器（@engine.function, @engine.method）进行插桩，支持通过 Check 机制进行缓存验证以及通过 params 参数处理动态变量。",[64],[13,14],"2026-03-27T02:49:30.150509","2026-04-10T20:44:06.618164",[97,102,106],{"id":98,"question_zh":99,"answer_zh":100,"source_url":101},28120,"Muscle Mem 是否计划支持第三方存储后端（如 Redis）？","目前没有计划支持第三方存储后端。Muscle Mem 的核心价值在于轨迹的存储和高效检索，为了超越单纯的 Python SDK，项目需要完全掌控存储层。当前的持久化实现是临时的 Python 列表，正在探索 DuckDB 和 Chroma 等选项作为嵌入式本地数据库后端，以实现高速读写和用户自定义的比较函数。","https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem\u002Fissues\u002F2",{"id":103,"question_zh":104,"answer_zh":105,"source_url":101},28121,"Muscle Mem 的存储层设计目标和访问模式是什么？","存储层的核心目标是：1. 存储由 `capture` 函数生成的通用形状 T 的环境特征数据；2. 基于用户定义的 `compare` 函数高效检索候选轨迹。其访问模式为“一次写入，多次读取”，且读取操作通常在所有候选项中大规模并行进行。设计理念是“本地优先”和嵌入式以保证速度，仅通过同步远程服务器在不同代理间共享技能。",{"id":107,"question_zh":108,"answer_zh":109,"source_url":110},28122,"Muscle Mem 与关于缓存成功轨迹的 AI 论文（如 arXiv:2505.00234）有何区别？","主要区别在于执行方式。该论文提到的系统使用检索到的轨迹作为少样本示例（Few-shot examples），采用 RAG（检索增强生成）风格在运行时提高代理性能，仍需调用 LLM。而 Muscle Mem 的目标是完全消除对 LLM 的调用（不使用 RAG，直接执行轨迹），并更注重使用代码来验证每个步骤的安全性。","https:\u002F\u002Fgithub.com\u002Fpig-dot-dev\u002Fmuscle-mem\u002Fissues\u002F1",[]]