LX Agent Optimizer
A unified skill for agents that want to learn, act proactively, run lean, and cost less — built from real production experience, not theory.
Born from weeks of real usage by Paolo + LX (OpenClaw). Every pattern here was tested, broke something, got fixed, and survived.
Notably: this skill was created by a non-coder author.
That is exactly why it is practical — it focuses on observable failures, reusable workflows, and user experience, instead of abstract agent philosophy.
Four Pillars
1. 🧠 Behavior Learning
Learn from real mistakes. Write them down. Review weekly. Change behavior.
→ See INLINECODE0
2. 🎯 Proactive Patterns
Know when to speak up, when to stay silent, and when to just do it.
→ See INLINECODE1
3. ⚙️ Cron Discipline
Script-first cron jobs that are silent on success, reliable, and cheap.
→ See INLINECODE2
4. 💰 Cost Control
Token spend is real. Route models wisely, cache aggressively, stay lean.
→ See references/cost-control.md
Quick Start
Step 1: Set up improvement log
CODEBLOCK0
Add this header:
CODEBLOCK1
Step 2: Add weekly analysis cron (main session)
CODEBLOCK2
Step 3: Run the optimizer audit
Say:
"audit my agent setup" — the skill will analyze your workspace and propose improvements.
Core Rules (Non-Negotiable)
These were learned the hard way:
| Rule | Why |
|---|
| File writes → main session only | work agents can't write files; main session can |
| Data fetch → validate with curl first |
SPAs return empty shells; APIs return 403; test before shipping |
|
Debugging → internal, not exposed | User sees results, not "trying A... trying B..." |
|
Infer before asking | Read filenames, context, history — ask only when truly ambiguous |
|
Script-first cron | Embed logic in
.py files, not in cron message prompts |
|
Silent on success | Only alert on anomalies, errors, or changes |
|
Channel health checks → real-time probe, not stale logs | Historical cron errors may be old; verify current channel state before alerting or auto-remediating |
|
Reminder source mapping → check both cron and HEARTBEAT.md | Some reminders live in cron jobs, others live in heartbeat rules; disabling one side is not enough |
|
Success once ≠ learned | A task is only truly learned after the verified path is written into external memory (
TOOLS.md, improvement log, or long-term memory) |
Tool Path Memory (Verified)
| Task | Use This | Not This |
|---|
| Token usage data | INLINECODE6 | codexbar, gateway.log |
| WeChat article body |
agent-browser eval "document.querySelector('#js_content')?.innerText" | Built-in browser tool |
| PDF image extraction |
pdfimages -j <file> /tmp/out | pymupdf (not installed) |
| Send image to user |
message tool (media/filePath) | Absolute/~ paths |
| Sports data (no API key) | ESPN public API | sofascore (403), official site (SPA) |
| Apple Calendar today events | Run
python3 /Users/paolo/.openclaw/workspace/skills/calendar-morning/scripts/today_events.py on Paolo's Mac mini; under the hood it uses
/usr/bin/osascript + Calendar.app | Re-guessing the tool, calendar names, or prompting from scratch |
| Telegram channel health check | Send a
silent real-time probe via
message tool and only remediate/alert on actual send failure | Scanning historical cron
lastError /
deliveryStatus and assuming the channel is currently down |
| Reminder disable audit | Check
both cron jobs and
HEARTBEAT.md before saying a reminder is removed | Looking only at cron list and missing heartbeat-driven reminders |
Weekly Improvement Cycle
CODEBLOCK3
Proactive Trigger Rules
Reach out when:
- - Important email or calendar event incoming (< 2h)
- Cron task failed with consecutive errors
- Something discovered user would want to know
- Haven't spoken in > 8h during waking hours
Stay silent when:
- - Late night (23:00–08:00) unless urgent
- User is clearly busy
- Nothing new since last check
- Just checked < 30 min ago
- Task succeeded (success = silent)
Do without asking:
- - Read files, search, organize
- Execute cron/heartbeat checks
- Update memory and logs
- Commit workspace changes
Always ask first:
- - Send emails, tweets, public posts
- Delete data
- Spend money
- Make commitments for the user
Heartbeat Design
Heartbeat = control plane only (cheap).
✅ Good heartbeat tasks:
- - Check cron consecutiveErrors
- Check if Telegram channel is down
- Quick calendar scan
❌ Move to isolated cron instead:
- - Heavy data fetching
- Report generation
- Multi-tool workflows
CODEBLOCK4
Cron Design Checklist
Before shipping any cron job:
- - [ ] Logic is in a
.py script, not embedded in the prompt - [ ] Script tested locally with INLINECODE17
- [ ] Silent on success (
exit(0) with no output = no message sent) - [ ] Output is minimal (< 200 chars for routine alerts)
- [ ] Model is cheapest tier that works (e.g.,
qwen-plus for simple tasks) - [ ] Timeout is realistic (not too short = retries, not too long = waste)
- [ ] File writes use main session, not work agent
- [ ] Validated data source with curl before embedding URL
Model Selection Guide
| Task Type | Recommended Tier | Example |
|---|
| Simple fetch + format | cheapest (qwen-plus / gemini-lite) | sports results, reminders, weather |
| 固定流程任务(文章总结、写文件、数据抓取) |
qwen-plus | 微信文章总结、Obsidian 写入、cron 推送 |
|
中文内容处理(总结/整理/改写) | qwen-plus | 中文语境更准,比 claude 省 token |
| 周复盘 / cron 状态检查 | gemini-2.5-flash | 够用,比 sonnet 便宜 |
| Reasoning + writing | mid-tier (sonnet) | self-improvement analysis, strategy |
| Complex multi-step | high-tier (opus) | only when mid-tier fails repeatedly |
分工原则:主 session(claude)只做判断+调度+对话;固定流程和中文任务一律 sessions_spawn → qwen-plus。
主模型注意事项(2026-03-28):
- - 不要把 Gemini 设为主 session 默认模型 →
compaction.mode: safeguard 与 Gemini preview 模型有 API 兼容性问题,导致 400 报错 - Gemini 适合做 fallback 或在 isolated cron 中指定使用
- 主 session 保持 INLINECODE21
Cost rule: Cache hit rate > 70% = healthy. If < 40%, you're creating too many new sessions.
Files
- -
references/behavior-learning.md — improvement log format and weekly cycle - INLINECODE23 — when to act, when to stay quiet
- INLINECODE24 — script-first cron patterns
- INLINECODE25 — token cost reduction playbook
- INLINECODE26 — weekly token usage report script
LX Agent Optimizer
一个面向智能体的统一技能,旨在实现 学习、主动行动、精简运行、降低成本 —— 基于真实生产经验,而非理论。
源自 Paolo + LX (OpenClaw) 数周的实际使用。这里的每一个模式都经过测试、出过问题、被修复并存活下来。
值得注意的是:这个技能由一位非编码作者创建。
这正是它实用的原因——它专注于可观察的失败、可复用的工作流和用户体验,而非抽象的智能体哲学。
四大支柱
1. 🧠 行为学习
从真实错误中学习。记录下来。每周回顾。改变行为。
→ 参见 references/behavior-learning.md
2. 🎯 主动模式
知道何时该发言、何时该沉默、何时直接行动。
→ 参见 references/proactive-patterns.md
3. ⚙️ Cron 纪律
脚本优先的 cron 任务,成功时静默、可靠且廉价。
→ 参见 references/cron-discipline.md
4. 💰 成本控制
Token 消耗是真实成本。明智地路由模型,积极缓存,保持精简。
→ 参见 references/cost-control.md
快速开始
步骤 1:建立改进日志
bash
touch ~/.openclaw/workspace/improvement_log.md
添加以下标题:
markdown
智能体改进日志
每周记录:遇到的问题、学到的教训、行为变更。
步骤 2:添加每周分析 cron(主会话)
json
{
name: 每周自我改进,
schedule: { kind: cron, expr: 0 9
1, tz: Asia/Shanghai },
sessionTarget: main,
payload: {
kind: systemEvent,
text: ⏰ 每周改进:读取 improvement_log.md,回顾上周问题,添加 2-3 个新教训,向用户发送简要报告。
}
}
步骤 3:运行优化器审计
说:
审计我的智能体设置 —— 该技能将分析你的工作空间并提出改进建议。
核心规则(不可协商)
以下规则是通过艰难方式学到的:
| 规则 | 原因 |
|---|
| 文件写入 → 仅限主会话 | 工作智能体无法写入文件;主会话可以 |
| 数据获取 → 先用 curl 验证 |
SPA 返回空壳;API 返回 403;上线前先测试 |
|
调试 → 内部进行,不对外暴露 | 用户看到的是结果,不是尝试 A... 尝试 B... |
|
先推断再询问 | 读取文件名、上下文、历史记录——仅在真正模棱两可时再询问 |
|
脚本优先的 cron | 将逻辑嵌入 .py 文件,而非 cron 消息提示中 |
|
成功时静默 | 仅在出现异常、错误或变更时发出警报 |
|
频道健康检查 → 实时探测,而非过时日志 | 历史 cron 错误可能已过时;在发出警报或自动修复前验证当前频道状态 |
|
提醒源映射 → 同时检查 cron 和 HEARTBEAT.md | 有些提醒存在于 cron 任务中,有些存在于心跳规则中;仅禁用一个方面是不够的 |
|
成功一次 ≠ 已学会 | 只有在验证过的路径写入外部记忆(TOOLS.md、改进日志或长期记忆)后,任务才算真正学会 |
工具路径记忆(已验证)
| 任务 | 使用此方法 | 不使用此方法 |
|---|
| Token 使用数据 | ~/.openclaw/agents//sessions/.jsonl | codexbar, gateway.log |
| 微信公众号文章正文 |
agent-browser eval document.querySelector(#js_content)?.innerText | 内置浏览器工具 |
| PDF 图片提取 | pdfimages -j
/tmp/out | pymupdf(未安装) |
| 向用户发送图片 | message 工具 (media/filePath) | 绝对路径/~ 路径 |
| 体育数据(无 API 密钥) | ESPN 公共 API | sofascore (403)、官方网站 (SPA) |
| Apple 日历今日事件 | 在 Paolo 的 Mac mini 上运行 python3 /Users/paolo/.openclaw/workspace/skills/calendar-morning/scripts/today_events.py;底层使用 /usr/bin/osascript + Calendar.app | 重新猜测工具、日历名称或从头开始提示 |
| Telegram 频道健康检查 | 通过 message 工具发送静默实时探测,仅在实际发送失败时进行修复/警报 | 扫描历史 cron lastError / deliveryStatus 并假设频道当前已宕机 |
| 提醒禁用审计 | 在说提醒已移除之前,同时检查 cron 任务和 HEARTBEAT.md | 仅查看 cron 列表而遗漏心跳驱动的提醒 |
每周改进周期
周一上午 9:00
↓
读取 improvement_log.md
↓
回顾上周对话中的:
- 需要重试的任务
- 用户等待时间过长的情况
- 错误的工具选择
- 重复出现的错误
↓
向 improvement_log.md 写入 2-3 个新教训
↓
发送简要报告:本周 N 个问题,关键教训:X,下周重点:Y
主动触发规则
主动联系时:
- - 重要邮件或日历事件即将到来(< 2 小时)
- Cron 任务连续失败
- 发现用户可能想知道的事情
- 在清醒时段超过 8 小时未发言
保持沉默时:
- - 深夜(23:00–08:00),除非紧急
- 用户明显很忙
- 自上次检查以来没有新内容
- 刚检查过不到 30 分钟
- 任务成功(成功 = 静默)
直接执行,无需询问:
- - 读取文件、搜索、整理
- 执行 cron/心跳检查
- 更新记忆和日志
- 提交工作空间变更
始终先询问:
- - 发送邮件、推文、公开帖子
- 删除数据
- 花钱
- 为用户做出承诺
心跳设计
心跳 = 仅控制平面(廉价)。
✅ 好的心跳任务:
- - 检查 cron 的 consecutiveErrors
- 检查 Telegram 频道是否宕机
- 快速扫描日历
❌ 移至隔离 cron 的任务:
HEARTBEAT_OK ← 99% 的时间
仅在以下情况发出警报:错误 > 0、频道宕机、有变化
Cron 设计清单
在部署任何 cron 任务之前:
- - [ ] 逻辑在 .py 脚本中,而非嵌入提示中
- [ ] 脚本已用 python3 script.py 在本地测试过
- [ ] 成功时静默(exit(0) 无输出 = 不发送消息)
- [ ] 输出最小化(常规警报 < 200 字符)
- [ ] 模型使用能完成任务的最廉价层级(例如简单任务用 qwen-plus)
- [ ] 超时设置合理(不要太短 = 重试,不要太长 = 浪费)
- [ ] 文件写入使用主会话,而非工作智能体
- [ ] 在嵌入 URL 前已用 curl 验证数据源
模型选择指南
| 任务类型 | 推荐层级 | 示例 |
|---|
| 简单获取 + 格式化 | 最廉价(qwen-plus / gemini-lite) | 体育结果、提醒、天气 |
| 固定流程任务(文章总结、写文件、数据抓取) |
qwen-plus | 微信公众号文章总结、Obsidian 写入、cron 推送 |
| 中文内容处理(总结/整理/改写) | qwen-plus | 中文语境更准,比 claude 省 token |
| 周复盘 / cron 状态检查 | gemini-2.5-flash | 够用,比 sonnet 便宜 |
| 推理 + 写作 | 中端(sonnet) | 自我改进分析、策略 |
| 复杂多步骤 | 高端(opus) | 仅当中端层级反复失败时使用 |
分工原则:主会话(claude)只做判断+调度+对话;固定流程和中文任务一律 sessions_spawn → qwen-plus。
主模型注意事项(2026-03-28):
- - 不要把 Gemini 设为主会话默认模型 → compaction.mode: safeguard 与 Gemini preview 模型有 API 兼容性问题,导致 400 报错
- Gemini 适合做 fallback 或在 isolated cron 中指定使用
- 主会话保持