解决 OpenClaw 飞书插件 API 过度调用问题

当前 OpenClaw 版本:v2026.2.21-2

问题背景

在使用 OpenClaw 的飞书插件时,发现 bot/v3/info 接口调用非常频繁,月调用量轻松超过飞书 API 的免费配额限制(5 万次)。

经过排查,发现问题出在 OpenClaw 的 Channel Health Check 机制上。

根因分析

OpenClaw Gateway 会定期执行通道健康检查,每分钟一次 。每次检查会调用各通道插件的 probeAccount 方法来验证连接状态。

对于飞书插件,调用链如下:

scss 复制代码
Gateway Health Check (每分钟)
  → plugin.status.probeAccount()
  → probeFeishu()
  → HTTP GET /open-apis/bot/v3/info

计算一下调用量:1 × 60 × 24 × 30 = 43,200 次/月。如果没有缓存机制,单这一个接口就会耗尽免费配额。

解决方案

既然机器人信息是静态数据,天然适合缓存。修改飞书插件的 probe 模块,增加缓存机制。

代码修改

修改文件:extensions/feishu/src/probe.ts

typescript 复制代码
import { createFeishuClient, type FeishuClientCredentials } from "./client.js";
import type { FeishuProbeResult } from "./types.js";

// 缓存配置:10 分钟有效期
const botInfoCache = new Map<
  string,
  { data: FeishuProbeResult; expiresAt: number }
>();
const CACHE_TTL_MS = 10 * 60 * 1000;

export async function probeFeishu(
  creds?: FeishuClientCredentials,
): Promise<FeishuProbeResult> {
  if (!creds?.appId || !creds?.appSecret) {
    return { ok: false, error: "missing credentials" };
  }

  // 优先读取缓存
  const cacheKey = creds.appId;
  const cached = botInfoCache.get(cacheKey);
  if (cached && cached.expiresAt > Date.now()) {
    return cached.data;
  }

  // 发起 API 请求
  const client = createFeishuClient(creds);
  const response = await (client as any).request({
    method: "GET",
    url: "/open-apis/bot/v3/info",
    data: {},
  });

  let result: FeishuProbeResult;
  if (response.code !== 0) {
    result = { ok: false, appId: creds.appId, error: response.msg };
  } else {
    const bot = response.bot || response.data?.bot;
    result = { ok: true, appId: creds.appId, botName: bot?.bot_name, botOpenId: bot?.open_id };
  }

  // 存入缓存
  botInfoCache.set(cacheKey, { data: result, expiresAt: Date.now() + CACHE_TTL_MS });

  return result;
}

// 手动清空缓存(可选)
export function clearFeishuProbeCache(appId?: string): void {
  appId ? botInfoCache.delete(appId) : botInfoCache.clear();
}

效果对比

指标 修改前 修改后
API 调用频率 每分钟 1 次 每小时约 1 次
月调用量 ~43,200 次 ~1,440 次

从超出免费额度到完全在安全范围内。

注意事项

  1. 缓存时间是 10 分钟,可根据实际需求调整
  2. 这是临时修复方案,OpenClaw 官方可能会在后续版本中自带优化,建议关注官方更新
  3. 修改源码后,重启 Gateway 生效
  4. 此修改在 OpenClaw 更新版本时可能会被覆盖,需要重新应用

总结

健康检查机制本身是好的,但对于变化频率低的元数据,引入缓存可以显著减少不必要的 API 调用。这个思路同样适用于其他通道插件(如 Telegram、WhatsApp 等)。

相关推荐
hoaxxcj16 小时前
AI编程2026:Copilot桌面应用发布,我们正在经历一场不可逆的范式转移
copilot·agent·ai编程·github copilot·编程工具
摸鱼同学18 小时前
17-Codex 高级工作流:Subagent、Worktree、多模型路由
ai·agent·codex
XLYcmy18 小时前
一个基于 Python 的轻量级 LLM(大语言模型)API 客户端程序:从API交互到LLM应用架构
服务器·python·ai·llm·prompt·agent·token
云烟成雨TD18 小时前
Agent Scope Java 2.x 系列【1】核心架构
java·人工智能·agent
AustinXu19 小时前
谁在驾驭 AI-Native 的组织?一份实战报告
人工智能·agent·敏捷开发
阿泽·黑核19 小时前
使用 C 语言结构体设计模块化按键检测
嵌入式·agent·模块化设计
菜鸟小九19 小时前
hello agent(智能体经典范式、框架开发实践)
python·langchain·agent
guyoung19 小时前
BoxAgnts 工具系统(5)——WASM 工具开发:从 Hello World 到生产部署
rust·agent·ai编程
人工智能培训19 小时前
医疗行业的数字孪生革命
大数据·人工智能·重构·知识图谱·agent
zyk_computer19 小时前
AI Agent ,让循环收敛的那套闭环控制系统
人工智能·后端·python·ai·架构·agent·ai agent