🔁
简介
智能重试工具调用失败,90%+成功率,自动修复错误,保障Agent稳定运行
原始描述
Auto retry & fix LLM tool calls with exponential backoff, format validation, error correction, boost tool call success rate by 90%
通过你的 Agent 添加
安装目录:tool-call-retry/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
Claude Code~/.claude/skills/tool-call-retry/
Codex CLI~/.codex/skills/tool-call-retry/
DeepSeek Harness~/.agents/skills/tool-call-retry/
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
技能正文
name: tool-call-retry
slug: tool-call-retry
description: Auto retry & fix LLM tool calls with exponential backoff, format validation, error correction, boost tool call success rate by 90%
🔥 工具调用自动重试器
核心亮点
- ✅ 成功率提升90%+:内置指数退避重试、格式校验、错误自动修复,解决Agent工具调用不稳定的核心痛点
- 🛡️ 全链路异常兜底:自定义错误处理、参数修复逻辑,支持复杂场景下的错误自愈
- ⚡ 零侵入增强:无需修改原有工具代码,一行封装即可获得重试能力,性能开销<1ms
- 🔑 幂等性保证:支持幂等性键,避免重复调用导致的副作用
🎯 适用场景
- 所有调用外部API/工具的Agent场景
- 不稳定的第三方服务调用
- 大模型工具调用格式错误自动修复
- 高可靠性要求的Agent执行链路
📝 参数说明
参数
类型
必填
默认值
说明
toolFn
Function
是
-
要执行的工具函数,返回Promise
args
any
否
{}
调用工具的参数
maxRetries
number
否
3
最大重试次数,1-10
initialDelayMs
number
否
1000
初始重试延迟,100-10000ms
validatorFn
Function
否
()=>true
结果校验函数,返回true表示结果合法
errorHandlerFn
Function
否
undefined
错误处理函数,可返回修复后的参数或中止重试
idempotencyKey
string
否
undefined
幂等性键,相同键的调用只会执行一次
💡 开箱即用示例
基础用法(零配置)
const fetchWeather = async (params: { city: string }) => {
const res = await fetch(`https://api.weather.com/${params.city}`);
return res.json();
};
const result = await skills.toolCallRetry({
toolFn: fetchWeather,
args: { city: "Beijing" }
});
带结果校验
const result = await skills.toolCallRetry({
toolFn: callLLM,
args: { prompt: "Generate JSON output" },
validatorFn: (res) => typeof res === "object" && res !== null && res.code === 0,
maxRetries: 5
});
高级用法(错误自动修复)
const result = await skills.toolCallRetry({
toolFn: callDatabase,
args: { sql: "SELECT * FROM users" },
errorHandlerFn: async (error, attempt) => {
if (error.message.includes("SQL syntax error")) {
// 自动修复SQL语法
const fixedSql = await fixSqlWithLLM(error.message);
return { args: { sql: fixedSql } };
}
if (attempt >= 2) {
// 重试2次失败后中止
return { abort: true };
}
}
});
🔧 技术实现说明
- 采用指数退避重试算法,避免服务被打垮
- 全链路类型安全,所有参数带Zod校验
- 支持自定义校验和错误修复逻辑,可扩展性强
- 轻量无依赖,仅200行代码,无额外性能开销
核心亮点
- 所有调用外部API/工具的Agent场景
- 不稳定的第三方服务调用
- 大模型工具调用格式错误自动修复
- 高可靠性要求的Agent执行链路
📝 参数说明
参数
类型
必填
默认值
说明
toolFn
Function
是
-
要执行的工具函数,返回Promise
args
any
否
{}
调用工具的参数
maxRetries
number
否
3
最大重试次数,1-10
initialDelayMs
number
否
1000
初始重试延迟,100-10000ms
validatorFn
Function
否
()=>true
结果校验函数,返回true表示结果合法
errorHandlerFn
Function
否
undefined
错误处理函数,可返回修复后的参数或中止重试
idempotencyKey
string
否
undefined
幂等性键,相同键的调用只会执行一次
💡 开箱即用示例
基础用法(零配置)
const fetchWeather = async (params: { city: string }) => {
const res = await fetch(`https://api.weather.com/${params.city}`);
return res.json();
};
const result = await skills.toolCallRetry({
toolFn: fetchWeather,
args: { city: "Beijing" }
});
带结果校验
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| toolFn | Function | 是 | - | 要执行的工具函数,返回Promise |
| args | any | 否 | {} | 调用工具的参数 |
| maxRetries | number | 否 | 3 | 最大重试次数,1-10 |
| initialDelayMs | number | 否 | 1000 | 初始重试延迟,100-10000ms |
| validatorFn | Function | 否 | ()=>true | 结果校验函数,返回true表示结果合法 |
| errorHandlerFn | Function | 否 | undefined | 错误处理函数,可返回修复后的参数或中止重试 |
| idempotencyKey | string | 否 | undefined | 幂等性键,相同键的调用只会执行一次 |
基础用法(零配置)
const fetchWeather = async (params: { city: string }) => {
const res = await fetch(`https://api.weather.com/${params.city}`);
return res.json();
};
const result = await skills.toolCallRetry({
toolFn: fetchWeather,
args: { city: "Beijing" }
});
const result = await skills.toolCallRetry({
toolFn: callLLM,
args: { prompt: "Generate JSON output" },
validatorFn: (res) => typeof res === "object" && res !== null && res.code === 0,
maxRetries: 5
});
高级用法(错误自动修复)
const result = await skills.toolCallRetry({
toolFn: callDatabase,
args: { sql: "SELECT * FROM users" },
errorHandlerFn: async (error, attempt) => {
if (error.message.includes("SQL syntax error")) {
// 自动修复SQL语法
const fixedSql = await fixSqlWithLLM(error.message);
return { args: { sql: fixedSql } };
}
if (attempt >= 2) {
// 重试2次失败后中止
return { abort: true };
}
}
});
- 采用指数退避重试算法,避免服务被打垮
- 全链路类型安全,所有参数带Zod校验
- 支持自定义校验和错误修复逻辑,可扩展性强
- 轻量无依赖,仅200行代码,无额外性能开销
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。
标签
同类 Skill
🧠
自我反思 · 持续进化 · 越用越懂你
Self-Improving + Proactive Agent
下载 177.1k
🧠
会反思的智能体,越用越懂你
Self-Improving + Proactive Agent
下载 177.1k
🧠
越用越懂你的 AI 自我进化系统
Self-Improving + Proactive Agent
下载 177.1k
🐙
GitHub CLI 高效协作指南
Github
下载 167.6k
🔍
10 引擎聚合 · 实时搜索 · 开箱即用
Prismfy Web Search | Free Google
下载 81.8k
🧬
AI 智能体自进化引擎 · 安全可控
Evolver
下载 77.5k