资讯详情

资讯详情

OpenClaw 里 my-first-skill 的 Agent,模型通道走 TaoToken 行不行?

OpenClaw 的 Agent 要想在长会话里连续调用 skills消耗最大的其实不是技能脚本而是每一次工具调用背后的模型请求。my-first-skill 在本地python scripts/hello.py能跑通clawhub publish也能发出去但只要 Agent 开始用 exec 反复调它模型通道就会变成瓶颈官方通道下 Key 分散、额度按通道切分会话一长就容易中途停住。本文把原文从建目录到 publish 的步骤原样保留只做一件事——把 OpenClaw 里 Agent 的模型通道切到 TaoToken先去 https://taotoken.net/?utm_sourcetaotoken_aicg_blog_end 注册并创建一把 KeyOpenClaw 侧 Base URL 填https://taotoken.net/api。1. my-first-skill 能在 Agent 里跑卡住的是模型通道先把原文那条路径完整走一遍确认技能本身没问题。创建技能目录和核心文件mkdir -p ~/.openclaw/skills/my-first-skill cd ~/.openclaw/skills/my-first-skill touch SKILL.md mkdir -p scriptsSKILL.md里写的是技能元信息name、version、description、author、homepage 这几项填全OpenClaw 才能在加载时正确识别这个技能是干什么的--- name: hello-world version: 1.0.0 description: 我的第一个 OpenClaw 技能say hello to the world author: your-name homepage: https://github.com/your-name/hello-world-skill --- # Hello World Skill 一个简单的示例技能展示 OpenClaw Skill 的基本结构。 ## 功能 - 向用户打招呼 - 返回当前时间 ## 使用 bash python scripts/hello.pyscripts/hello.py 先写命令行的最小版本 python #!/usr/bin/env python Hello World Skill - 我的第一个 OpenClaw 技能 import datetime def main(): now datetime.datetime.now() print(Hello from OpenClaw!) print(fCurrent time: {now.strftime(%Y-%m-%d %H:%M:%S)}) print(Your first skill is working!) if __name__ __main__: main()本地跑一次有输出就说明脚本这件事成了python scripts/hello.py真正让技能有价值的是让 Agent 能调用它所以脚本要再改成输出 JSON 的版本用sys.argv接收参数把问候语、时间、message 打包成结构化结果#!/usr/bin/env python Hello World Skill - Agent 可调用版本 import datetime import json import sys def get_greeting(nameWorld): hour datetime.datetime.now().hour if 5 hour 12: greeting 早上好 elif 12 hour 18: greeting 下午好 else: greeting 晚上好 return { greeting: greeting, name: name, time: datetime.datetime.now().isoformat(), message: f{greeting}{name}欢迎使用 OpenClaw Skills, } def main(): name sys.argv[1] if len(sys.argv) 1 else World result get_greeting(name) print(json.dumps(result, ensure_asciiFalse, indent2)) if __name__ __main__: main()Agent 通过 exec 工具调用的形式大致是这样result exec(python ~/.openclaw/skills/my-first-skill/scripts/hello.py 用户) print(result)发布环节照旧npm i -g clawhub装 CLIclawhub login后浏览器授权命令行出现Logged in as xxx即为登录成功。执行clawhub publish my-first-skill --slug my-first-skill-0311 --name my-first-skill-0311 --version 1.0.0 --changelog Initial release时大概率会撞上Publish payload: acceptLicenseTerms: invalid value这是 clawhub CLI 自身的问题官方给的临时方案是在本地安装目录的publish.js里往 payload 补一个字段// 临时添加 acceptLicenseTerms 参数 const acceptLicenseTerms true; form.set(payload, JSON.stringify({ slug, displayName, version, changelog, acceptLicenseTerms, tags, ...(forkOf ? { forkOf } : {}), }));改完再 publish会看到OK. Published ...1.0.0随后clawhub search my-first-skill-0311、clawhub install my-first-skill-0311都能验证发布结果。这一步不需要动本篇要动的是另一层。问题出在 Agent 侧每一次让 Agent 判断要不要调技能都要先发一次模型请求技能越多、会话越长请求次数增长得越快。如果每个技能各自绑一套官方通道Key 和额度就被切成了碎片任何一个通道先耗尽整段会话就断在中间。my-first-skill 和后面要做的 weather-skill 需要的是同一个通道。2. 接 TaoToken 前在官网建一把 Key顺手记下模型 ID接入只有两个前置动作都发生在 TaoToken 侧。打开官网 https://taotoken.net/?utm_sourcetaotoken_aicg_blog_endutm_mediumcsdnutm_campaignrewriteutm_contentopenclaw-my-first-skill 完成注册进入控制台创建一把 API Key。创建后 Key 只会完整显示一次直接复制到本地一处安全的地方后文统一用YOUR_API_KEY代替真实值。第二步是在模型广场里挑一个用于 OpenClaw Agent 的模型把模型 ID 复制下来。模型广场会列出当前可用的模型和对应 ID不同模型的上下文长度、响应速度、适合的任务类型都不一样长会话、多工具调用的 Agent 建议选上下文更长的那一档。这里不预设具体 ID按你在模型广场看到的实际值填文中统一写成MODEL_ID。需要记住的只有三条Key 从官网控制台建模型 ID 从模型广场复制Base URL 用https://taotoken.net/api。3. 改 OpenClaw 配置Base URL 填 https://taotoken.net/apiOpenClaw 的模型通道配置在~/.openclaw下的配置文件里常见形态是openclaw.json部分版本用的是 YAML字段名以你本机版本的配置项为准结构是一致的。要把 Agent 从官方通道切到 TaoToken改动集中在 provider 的 baseUrl、apiKey 和 model 三项。{ agent: { model: { provider: openai-compatible, baseUrl: https://taotoken.net/api, apiKey: YOUR_API_KEY, model: MODEL_ID, maxTokens: 8192, timeout: 120000 } } }这里有三个容易踩的细节。第一baseUrl只写到https://taotoken.net/api不要在后面补/v1。补上之后请求路径会变成/api/v1/...而 OpenClaw 自己还会再拼一次资源路径结果是路径重复返回 404 或一段 HTML。第二不要把官网地址https://taotoken.net/填进baseUrl。官网是给人看的页面不是接口入口填进去之后 Agent 拿到的是网页内容表现是解析失败或者反复重试。第三model必须和模型广场里的 ID 完全一致大小写、连字符都要对得上。写错的表现通常是请求能发出去但返回模型不存在的错误。如果你的 OpenClaw 版本支持环境变量覆盖也可以把敏感值放到 shell 配置里避免 Key 写进版本控制export OPENCLAW_BASE_URLhttps://taotoken.net/api export OPENCLAW_API_KEYYOUR_API_KEY export OPENCLAW_MODELMODEL_ID改完之后重启 OpenClaw 进程让新的 provider 配置生效。多技能的 Agent 只需要这一份配置my-first-skill 和后面新增的每个技能都共用它不必为每个技能单独准备通道。4. 验证一条 curl 一次 exec 连续调用 my-first-skill 与 weather-skill配置改完先别急着进会话用一条命令确认通道本身是通的curl -sS https://taotoken.net/api/chat/completions \ -H Authorization: Bearer YOUR_API_KEY \ -H Content-Type: application/json \ -d { model: MODEL_ID, messages: [ {role: user, content: 只回复两个字通了} ] }返回里能拿到正常的 message 内容说明 Base URL、Key、模型 ID 这三项是对的。如果返回的是 HTML 页面回头检查baseUrl是不是误填了官网地址如果返回 404检查是不是多写了/v1。通道确认后回到 OpenClaw 里验证 Agent 的连续调用能力。这一步的目标不是让 Agent 用一次技能而是让它在同一个会话里依次调用两个技能。先准备 weather-skill目录结构保持和 my-first-skill 一致weather-skill/ ├── SKILL.md ├── scripts/ │ └── weather.py └── README.mdSKILL.md里的 name 换成weather-querydescription 写清楚是查询城市天气、支持中文城市名。scripts/weather.py基于 wttr.in不需要额外的 API Key#!/usr/bin/env python Weather Query Skill - 天气查询基于 wttr.in import json import sys import urllib.request def get_weather(city): try: url fhttps://wttr.in/{city}?formatj1 req urllib.request.Request(url, headers{User-Agent: Mozilla/5.0}) with urllib.request.urlopen(req, timeout10) as response: data json.loads(response.read()) current data[current_condition][0] return { city: city, temp_c: current[temp_C], temp_f: current[temp_F], humidity: current[humidity], weather: current[weatherDesc][0][value], wind: f{current[windspeedKmph]} km/h, observed: current[observation_time], } except Exception as e: return {error: str(e)} def main(): if len(sys.argv) 2: print(json.dumps({error: 请提供城市名如python weather.py 北京}, ensure_asciiFalse)) return city sys.argv[1] print(json.dumps(get_weather(city), ensure_asciiFalse, indent2)) if __name__ __main__: main()单独跑一次确认输出结构没问题python scripts/weather.py 北京然后在 OpenClaw 会话里让 Agent 先调 hello 技能、再调 weather 技能观察两件事第一两次工具调用之间会话上下文是否保持第二第二次调用前是否还需要重新走一遍模型请求而没有因为额度或 Key 报错。两次调用都在同一段会话里完成说明 TaoToken 这条通道已经承担住了 Agent 的连续请求。weather-skill 的发布流程和 my-first-skill 完全一样把 slug、name 换成 weather-skill 相关值后走clawhub publish即可。5. 报错排查Base URL 写错、/v1 重复、acceptLicenseTerms 与长会话中断接入阶段常见的几类问题表现和原因基本可以一一对应。baseUrl填成https://taotoken.net/请求打到了官网页面返回内容是一段 HTMLOpenClaw 侧表现为 JSON 解析失败或 Agent 卡住不动。改成https://taotoken.net/api即可。baseUrl写成https://taotoken.net/api/v1请求路径多了一层接口返回 404。去掉/v1。Key 已经创建但请求仍然被拒绝先确认 shell 里是否真的加载了环境变量echo $OPENCLAW_API_KEY看一眼如果 Key 是写进 JSON 的注意有没有把末尾的换行或引号一起复制进去。model报不存在核对模型 ID 是否和模型广场里的写法完全一致。模型广场上架模型时 ID 会有增删以当前页面显示的为准不要沿用旧笔记里抄下来的值。Publish payload: acceptLicenseTerms: invalid value这是 clawhub CLI 的问题按前文往publish.js的 payload 里补acceptLicenseTerms: true的临时方案处理和模型通道无关不要在这一步去改 OpenClaw 的配置。长会话跑到一半停住优先看是不是多个技能各自绑了不同通道导致额度被分散。把 Agent 的 provider 统一到 TaoToken 这一份配置之后技能的增减不会再影响通道数量。如果确认只有一条通道还是中断再去看timeout设置——工具调用密集的会话把超时适当调大避免单次请求还在生成时就被判定失败。6. 技能发完只剩一件事把长会话的通道固定下来my-first-skill 从建目录到clawhub publish走完weather-skill 也照着同一套模板接进来了技能侧的事情基本结束。剩下的是通道侧的收尾Key 统一在 TaoToken 控制台管理OpenClaw 的baseUrl固定为https://taotoken.net/api模型 ID 跟着模型广场走多个技能勾在同一个 Agent 会话里连续调用。如果你准备继续往 ClawHub 上加第三个、第四个技能先把 Key 收拢到一处会更省事API Keys 控制台 里新建和管理 Key配合 Claude Code 接入文档 可以把下游工具的接入方式一并对照清楚。如果 OpenClaw 后面要承担的是长期跑的 Agent 任务多个技能链式调用、单次会话跨度很长看一下 Coding Plan 会更合适想先确认某个模型 ID 在你这台机器上的实际响应可以直接在 模型对话 里试一条请求再填进配置。
觉得有用,分享给同行:

为您的企业打造数字门面

稳重轻奢商务风格,端正雅致视觉,长效耐看不易过时。

立即咨询 →