Show HN: SafeAgent – AI智能体副作用的精确一次执行保护

3作者: Lions20266 个月前
我构建了一个名为 SafeAgent 的小型 Python 库,用于在 AI 智能体重试工具调用时保护现实世界的副作用。<p>在试验智能体工作流程时,我们遇到的一个问题是重试可能会多次触发不可逆转的操作:<p>智能体调用工具 ↓ 网络超时 ↓ 智能体重试 ↓ 副作用发生两次<p>示例:<p>• 重复付款 • 重复发送邮件 • 重复创建工单 • 重复交易<p>大多数系统通过使用散布在不同服务中的幂等键来临时解决这个问题。<p>SafeAgent 将其集中到一个小的执行保护程序中。<p>这个想法很简单:<p>1. 每次工具执行都会获得一个 request_id 2. SafeAgent 记录执行回执 3. 重试返回原始回执,而不是再次运行副作用<p>示例:<p>第一次调用 真实副作用:发送邮件<p>第二次调用,使用相同的 request_id SafeAgent 返回原始执行回执 (没有第二次副作用)<p>该项目还处于早期阶段,但包括以下示例:<p>• OpenAI 工具调用 • LangChain 风格的工具 • CrewAI 动作<p>PyPI: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;safeagent-exec-guard&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;safeagent-exec-guard&#x2F;</a><p>GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;azender1&#x2F;SafeAgent" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;azender1&#x2F;SafeAgent</a><p>很好奇其他人是如何处理智能体副作用的重试安全性的。
查看原文
I built a small Python library called SafeAgent that protects real-world side effects when AI agents retry tool calls.<p>One issue we ran into while experimenting with agent workflows is that retries can trigger irreversible actions multiple times:<p>agent calls tool ↓ network timeout ↓ agent retries ↓ side effect happens twice<p>Examples:<p>• duplicate payment • duplicate email • duplicate ticket • duplicate trade<p>Most systems solve this ad-hoc using idempotency keys scattered around different services.<p>SafeAgent centralizes this into a small execution guard.<p>The idea is simple:<p>1. every tool execution gets a request_id 2. SafeAgent records the execution receipt 3. retries return the original receipt instead of running the side effect again<p>Example:<p>FIRST CALL REAL SIDE EFFECT: sending email<p>SECOND CALL WITH SAME request_id SafeAgent returns the original execution receipt (no second side effect)<p>The project is early but includes examples for:<p>• OpenAI tool calls • LangChain style tools • CrewAI actions<p>PyPI: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;safeagent-exec-guard&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;safeagent-exec-guard&#x2F;</a><p>GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;azender1&#x2F;SafeAgent" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;azender1&#x2F;SafeAgent</a><p>Curious how other people are handling retry safety for agent side effects.