AI Skill Hub 强烈推荐:层次异步内存中间件 是一款优质的Agent工作流。AI 综合评分 8.0 分,在同类工具中表现稳健。如果你正在寻找可靠的Agent工作流解决方案,这是一个值得深入了解的选择。
层次异步内存中间件 是一套完整的 AI Agent 自动化工作流方案。通过可视化的节点编排,将复杂的多步骤任务拆解为清晰的自动化流程,实现全程无人值守的智能处理。支持与数百种外部服务和 API 无缝集成,适合构建数据处理管线、业务自动化和 AI 辅助决策系统。
层次异步内存中间件 是一套完整的 AI Agent 自动化工作流方案。通过可视化的节点编排,将复杂的多步骤任务拆解为清晰的自动化流程,实现全程无人值守的智能处理。支持与数百种外部服务和 API 无缝集成,适合构建数据处理管线、业务自动化和 AI 辅助决策系统。
# 方式一:pip 安装(推荐)
pip install sawtooth-memory
# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install sawtooth-memory
# 方式三:从源码安装(获取最新功能)
git clone https://github.com/jackmannx/sawtooth-memory
cd sawtooth-memory
pip install -e .
# 验证安装
python -c "import sawtooth_memory; print('安装成功')"
# 命令行使用
sawtooth-memory --help
# 基本用法
sawtooth-memory input_file -o output_file
# Python 代码中调用
import sawtooth_memory
# 示例
result = sawtooth_memory.process("input")
print(result)
# sawtooth-memory 配置文件示例(config.yml) app: name: "sawtooth-memory" debug: false log_level: "INFO" # 运行时指定配置文件 sawtooth-memory --config config.yml # 或通过环境变量配置 export SAWTOOTH_MEMORY_API_KEY="your-key" export SAWTOOTH_MEMORY_OUTPUT_DIR="./output"
A high-performance, asynchronous non-blocking hierarchical memory framework for LLM Agents.
tiktoken monitor checks thresholds without making API calls.OllamaCompressor or in the cloud using CloudCompressor (with modular adapters for OpenAI, Anthropic, and Gemini).max_unsummarized_turns to trigger compression safely by turn count, alongside token limits.hard_limit_tokens before the asynchronous background worker finishes a cycle, a fallback protocol forcefully truncates the oldest L1 messages on the main thread to prevent API crashes.---
pip install sawtooth-memory
Optional dependencies:
```bash
pip install langchain-openai langchain-anthropic langchain-google-genai
lc_messages = history.messages
```
The V2 configuration introduces dynamic validation, allowing you to set a single background_model parameter that automatically routes to the respective local or cloud backend. Cloud models (gpt-*, claude-*, gemini-*) read API keys from standard environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY).
import asyncio
from sawtooth_memory import ContextManager, ContextManagerConfig
async def main():
# V2 Simplified Configuration
config = ContextManagerConfig(
background_model="gpt-4o-mini", # Auto-routes to CloudCompressor (or "phi4" for local Ollama)
soft_limit_tokens=1000, # Token threshold to trigger background compression
hard_limit_tokens=2000, # Emergency truncation limit
max_unsummarized_turns=10, # Turn-based batching threshold
enable_deterministic_ner=True # Enable local regex extraction for the Entity Ledger
)
async with ContextManager(system_prompt="You are a helpful assistant.", config=config) as cm:
# Optional: Run a health check to verify backend routing and worker status
await cm.health_check()
# 1. Instantly ingest messages (Zero-latency on the main thread)
await cm.add_message("user", "My transaction ID is txn_998877_alpha")
await cm.add_message("assistant", "I have noted your transaction ID.")
# 2. Build the optimized prompt to send to your main LLM
prompt = await cm.build_prompt()
print(prompt)
if __name__ == "__main__":
asyncio.run(main())
For explicit cloud configuration without environment variables:
from sawtooth_memory.config import CloudConfig, Provider
config = ContextManagerConfig(
cloud=CloudConfig(
provider=Provider.OPENAI,
model="gpt-4o-mini",
api_key="sk-...",
),
)
---
If you are building in a traditional synchronous environment (like a standard Flask or Django view) where you cannot use asyncio or await, Sawtooth provides an enterprise-grade SawtoothSyncWrapper. It uses an AnyIO BlockingPortal to isolate the asynchronous background worker on a safe daemon thread, preventing event loop collisions while maintaining zero-latency writes.
from sawtooth_memory.sync_wrapper import SawtoothSyncWrapper
def my_flask_route():
# Use standard 'with' - no async required!
with SawtoothSyncWrapper("You are a helpful assistant.", config=config) as memory:
# 1. Instantly write to the background thread
memory.add_message("user", "Hello world!")
# 2. Safely read the compiled state machine
prompt = memory.build_prompt()
return prompt
pip install sawtooth-memory[langgraph]
Sawtooth provides a native SawtoothLangGraphAdapter to sync state seamlessly.
V2 Safety Feature: Strict cloud APIs (like Anthropic/OpenAI) will crash if a ToolMessage is sent without its parent AIMessage (the tool call request). The LangGraph adapter includes an advanced 3-pass sanitization logic that automatically detects and drops orphaned ToolMessages when their parent AIMessage has been compressed and evicted to L2 Archival Memory.
```python from langgraph.graph import StateGraph from sawtooth_memory.integrations.langgraph import SawtoothLangGraphAdapter
Sawtooth provides a native, pure-Python adapter that fully implements LangChain's modern BaseChatMessageHistory interface. This allows you to drop Sawtooth directly into any LCEL Runnable or Agent executor, bringing background compression and deterministic NER to standard LangChain pipelines without blocking the main thread.
```python from langchain_core.messages import HumanMessage from sawtooth_memory.integrations.langchain_adapter import SawtoothChatMessageHistory
history = SawtoothChatMessageHistory( system_prompt="You are a financial analyst.", config=config )
history.add_message(HumanMessage(content="Analyze these Q3 numbers."))
高质量的开源AI工作流项目,具有较强的实用价值
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
总体来看,层次异步内存中间件 是一款质量优秀的Agent工作流,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | sawtooth-memory |
| Topics | asyncagent-memorylanggraphpython |
| GitHub | https://github.com/jackmannx/sawtooth-memory |
| License | MIT |
| 语言 | Python |
收录时间:2026-07-07 · 更新时间:2026-07-07 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端