tool-call-retry

Auto retry & fix LLM tool calls with exponential backoff, format validation, error correction, boost tool call success rate by 90%

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "tool-call-retry" with this command: npx skills add Ayalili/tool-call-retry

🔥 工具调用自动重试器

核心亮点

  1. 成功率提升90%+:内置指数退避重试、格式校验、错误自动修复,解决Agent工具调用不稳定的核心痛点
  2. 🛡️ 全链路异常兜底:自定义错误处理、参数修复逻辑,支持复杂场景下的错误自愈
  3. 零侵入增强:无需修改原有工具代码,一行封装即可获得重试能力,性能开销<1ms
  4. 🔑 幂等性保证:支持幂等性键,避免重复调用导致的副作用

🎯 适用场景

  • 所有调用外部API/工具的Agent场景
  • 不稳定的第三方服务调用
  • 大模型工具调用格式错误自动修复
  • 高可靠性要求的Agent执行链路

📝 参数说明

参数类型必填默认值说明
toolFnFunction-要执行的工具函数,返回Promise
argsany{}调用工具的参数
maxRetriesnumber3最大重试次数,1-10
initialDelayMsnumber1000初始重试延迟,100-10000ms
validatorFnFunction()=>true结果校验函数,返回true表示结果合法
errorHandlerFnFunctionundefined错误处理函数,可返回修复后的参数或中止重试
idempotencyKeystringundefined幂等性键,相同键的调用只会执行一次

💡 开箱即用示例

基础用法(零配置)

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行代码,无额外性能开销

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Sendflare

通过 Sendflare SDK 发送带附件的电子邮件,管理联系人列表,支持 CC/BCC 和安全 API 认证。

Registry SourceRecently Updated
General

Playtomic - Book courts using padel-tui

This skill should be used when the user asks to "book a padel court", "find available padel courts", "search padel courts near me", "reserve a Playtomic cour...

Registry SourceRecently Updated
General

Fund Keeper

国内场外基金智能顾问 + 股票行情查询。实时估值、买卖建议、收益统计、定投计划、OCR 识图、股票 - 基金联动。支持离线模式、多数据源缓存。

Registry SourceRecently Updated