OpenClaw 自动化与技能开发:扩展你的 AI 能力
OpenClaw 支持定时任务、自动化工作流和自定义技能。本文讲解如何使用 cron 系统设置提醒、自动化任务,以及如何开发和安装自定义技能,让你的 AI 助手更加强大。
一、Cron 定时任务系统
1.1 Cron 基础
OpenClaw 内置 cron 系统,支持:
- 一次性提醒
- 周期性任务
- 自动降级确保送达
1.2 创建定时任务
一次性提醒:
openclaw cron add '{
"name": "会议提醒",
"schedule": { "kind": "at", "at": "2026-03-24T10:00:00+08:00" },
"payload": { "kind": "systemEvent", "text": "提醒:10 点有会议" },
"sessionTarget": "main"
}'
周期性任务:
openclaw cron add '{
"name": "每日站会",
"schedule": { "kind": "every", "everyMs": 86400000 },
"payload": { "kind": "systemEvent", "text": "每日站会时间到了" },
"sessionTarget": "main"
}'
Cron 表达式:
openclaw cron add '{
"name": "周报提醒",
"schedule": { "kind": "cron", "expr": "0 9 <em 1", "tz": "Asia/Shanghai" },
"payload": { "kind": "systemEvent", "text": "提醒:提交周报" },
"sessionTarget": "main"
}'
1.3 管理任务
列出所有任务
openclaw cron list
运行任务
openclaw cron run
删除任务
openclaw cron remove
查看运行历史
openclaw cron runs
二、技能系统
2.1 什么是技能
技能是预定义的工作流,让 AI 能够:
- 执行特定任务
- 访问外部服务
- 使用专用工具
2.2 内置技能
| 技能 | 功能 | 触发词 |
|---|---|---|
| weather |
| web_search | 网络搜索 | “搜索” |
| cron | 定时任务 | “提醒” |
2.3 安装技能
从 ClawHub 安装:
openclaw skills install
从本地安装:
openclaw skills install /path/to/skill
三、自定义技能开发
3.1 技能结构
my-skill/
├── SKILL.md # 技能描述
├── scripts/
│ └── main.py # 主脚本
└── assets/ # 资源文件
3.2 SKILL.md 模板
---
name: my-skill
description: 我的自定义技能
author: Your Name
version: 1.0.0
triggers:
- "触发词 1"
- "触发词 2"
技能说明
使用方法
bash
uv run scripts/main.py
配置
需要设置以下环境变量:- API_KEY: xxx
3.3 技能脚本示例
#!/usr/bin/env python3
import sys
def main():
query = sys.argv[1] if len(sys.argv) 1 else ""
# 执行任务
result = do_something(query)
print(result)
if __name__ == "__main__":
main()
四、自动化工作流
4.1 邮件检查
{
cron: {
jobs: [
{
name: "检查邮件",
schedule: { kind: "every", everyMs: 1800000 },
payload: {
kind: "agentTurn",
message: "检查是否有紧急邮件"
},
sessionTarget: "isolated"
}
]
}
}
4.2 日历提醒
{
cron: {
jobs: [
{
name: "日历检查",
schedule: { kind: "every", everyMs: 3600000 },
payload: {
kind: "agentTurn",
message: "检查未来 2 小时的日历事件"
},
sessionTarget: "isolated"
}
]
}
}
4.3 天气提醒
{
cron: {
jobs: [
{
name: "天气检查",
schedule: { kind: "cron", expr: "0 7 <em *" },
payload: {
kind: "agentTurn",
message: "查询今天天气,如果有雨提醒带伞"
},
sessionTarget: "isolated"
}
]
}
}
五、Heartbeat 系统
5.1 配置 Heartbeat
编辑 HEARTBEAT.md:
Heartbeat 任务
- [ ] 检查邮件
- [ ] 查看日历
- [ ] 检查天气
5.2 Heartbeat 响应
HEARTBEAT_OK # 无需要处理的事项
或
📧 有 3 封未读邮件
📅 1 小时后有会议
🌧️ 今天有雨,记得带伞
六、最佳实践
6.1 任务设计
1. 明确目标:每个任务有清晰目的
2. 合理频率:避免过于频繁
3. 错误处理:考虑失败情况
4. 日志记录:记录执行情况
6.2 技能开发
1. 单一职责:每个技能做一件事
2. 文档完整:清晰的使用说明
3. 错误处理:优雅的失败处理
4. 测试充分:确保可靠性
七、总结
自动化配置清单:
- [ ] 设置必要的提醒
- [ ] 配置定期检查任务
- [ ] 安装常用技能
- [ ] 开发自定义技能
关键要点:
- Cron 系统支持多种调度方式
- 技能扩展 AI 能力
- Heartbeat 实现主动检查
- 自动化提升效率
下一篇预告:《OpenClaw 远程部署指南:VPS/云服务器完整教程》
/* 基础样式 */
.article-container {
max-width: 100%;
margin: 0 auto;
padding: 15px;
font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, sans-serif;
line-height: 1.8;
color: #333;
background: #fff;
}
/* 文章头部 */
.article-header {
border-bottom: 3px solid #4a90e2;
padding-bottom: 20px;
margin-bottom: 25px;
}
.main-title {
font-size: 1.8em;
color: #1a1a1a;
margin-bottom: 12px;
font-weight: 700;
line-height: 1.3;
}
.article-meta {
display: flex;
gap: 12px;
flex-wrap: wrap;
align-items: center;
}
.category-badge {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
padding: 4px 12px;
border-radius: 16px;
font-size: 0.85em;
font-weight: 500;
}
.read-time {
color: #666;
font-size: 0.85em;
}
/* 导读框 */
.intro-box {
background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 100%);
border-left: 4px solid #4a90e2;
padding: 18px;
margin: 20px 0;
border-radius: 0 8px 8px 0;
display: flex;
gap: 12px;
align-items: flex-start;
}
.intro-icon {
font-size: 1.8em;
flex-shrink: 0;
}
.intro-text {
margin: 0;
color: #444;
font-size: 1em;
line-height: 1.6;
}
/* 目录 */
.toc-container {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 8px;
padding: 15px;
margin: 25px 0;
}
.toc-title {
font-size: 1.2em;
color: #333;
margin-bottom: 12px;
font-weight: 600;
}
.toc-list {
list-style: none;
padding: 0;
margin: 0;
}
.toc-list li {
margin: 6px 0;
}
.toc-list a {
color: #4a90e2;
text-decoration: none;
display: block;
padding: 6px 10px;
border-radius: 4px;
font-size: 0.95em;
transition: all 0.2s;
}
.toc-list a:hover {
background: #4a90e2;
color: #fff;
}
/* 文章内容 */
.article-content {
font-size: 1em;
}
.article-title {
font-size: 1.6em;
color: #1a1a1a;
margin: 35px 0 18px;
padding-bottom: 8px;
border-bottom: 2px solid #4a90e2;
}
.section-title {
font-size: 1.4em;
color: #2c3e50;
margin: 30px 0 12px;
padding-left: 12px;
border-left: 4px solid #4a90e2;
}
.subsection-title {
font-size: 1.2em;
color: #34495e;
margin: 22px 0 10px;
}
.subsubsection-title {
font-size: 1.05em;
color: #666;
margin: 18px 0 8px;
}
/* 代码块 – 支持横向滚动 */
.code-wrapper {
margin: 18px 0;
border-radius: 6px;
overflow: hidden;
}
.code-block {
background: #1e1e1e;
padding: 15px;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
margin: 0;
border-radius: 6px;
}
.code-block code {
color: #d4d4d4;
font-family: “Fira Code”, “Consolas”, “Monaco”, monospace;
font-size: 0.85em;
line-height: 1.6;
white-space: pre;
}
.inline-code {
background: #f5f5f5;
color: #e83e8c;
padding: 2px 6px;
border-radius: 3px;
font-family: “Fira Code”, “Consolas”, monospace;
font-size: 0.9em;
}
/* 表格 – 响应式滚动 */
.table-wrapper {
margin: 20px 0;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.styled-table {
width: 100%;
border-collapse: collapse;
min-width: 600px;
font-size: 0.9em;
}
.styled-table thead {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
}
.styled-table th {
padding: 12px 15px;
text-align: left;
font-weight: 600;
white-space: nowrap;
}
.styled-table td {
padding: 12px 15px;
border-bottom: 1px solid #e1e4e8;
vertical-align: top;
}
.styled-table tbody tr {
transition: background 0.2s;
}
.styled-table tbody tr:hover {
background: #f8f9fa;
}
.styled-table tbody tr:nth-child(even) {
background: #fafbfc;
}
.styled-table tbody tr:nth-child(odd) {
background: #fff;
}
/* 列表 */
.styled-list {
list-style: none;
padding: 0;
margin: 15px 0;
}
.list-item {
padding: 6px 0 6px 22px;
position: relative;
color: #333;
}
.list-item::before {
content: “•”;
position: absolute;
left: 0;
color: #4a90e2;
font-weight: bold;
font-size: 1.2em;
}
.checkbox-item {
padding: 6px 0 6px 32px;
position: relative;
color: #333;
}
.checkbox-item.checked {
color: #28a745;
}
/* 信息框 */
.info-box {
background: #e8f4fd;
border-left: 4px solid #4a90e2;
padding: 15px;
margin: 18px 0;
border-radius: 0 6px 6px 0;
color: #2c3e50;
}
/* 分隔线 */
.section-divider {
border: none;
height: 2px;
background: linear-gradient(to right, transparent, #4a90e2, transparent);
margin: 35px 0;
}
/* 文章尾部 */
.article-footer {
margin-top: 40px;
padding-top: 25px;
border-top: 2px solid #e9ecef;
}
.tags-section {
margin-bottom: 20px;
}
.tag-label {
font-weight: 600;
color: #666;
margin-right: 8px;
}
.tag {
display: inline-block;
background: #f0f4ff;
color: #4a90e2;
padding: 4px 10px;
border-radius: 12px;
margin: 3px;
font-size: 0.85em;
text-decoration: none;
transition: all 0.2s;
}
.tag:hover {
background: #4a90e2;
color: #fff;
}
.back-to-top {
text-align: center;
padding: 15px;
background: #f8f9fa;
border-radius: 6px;
}
.back-to-top a {
color: #4a90e2;
text-decoration: none;
font-weight: 500;
}
/* 移动端优化 */
@media (max-width: 768px) {
.article-container {
padding: 12px;
}
.main-title {
font-size: 1.4em;
}
.article-title {
font-size: 1.3em;
}
.section-title {
font-size: 1.2em;
}
.code-block {
padding: 12px;
font-size: 0.8em;
}
.styled-table {
font-size: 0.85em;
min-width: 500px;
}
.styled-table th,
.styled-table td {
padding: 10px 12px;
}
.intro-box {
padding: 15px;
}
.intro-icon {
font-size: 1.5em;
}
}
@media (max-width: 480px) {
.main-title {
font-size: 1.3em;
}
.article-meta {
flex-direction: column;
gap: 8px;
}
.category-badge,
.read-time {
font-size: 0.8em;
}
.code-block {
font-size: 0.75em;
padding: 10px;
}
.styled-table {
min-width: 450px;
font-size: 0.8em;
}
.styled-table th,
.styled-table td {
padding: 8px 10px;
}
}
// 移动端表格提示
document.addEventListener(‘DOMContentLoaded’, function() {
var tables = document.querySelectorAll(‘.table-wrapper’);
tables.forEach(function(table) {
if (!table.querySelector(‘.scroll-hint’)) {
var hint = document.createElement(‘div’);
hint.className = ‘scroll-hint’;
hint.innerHTML = ‘👈 左右滑动查看更多’;
hint.style.cssText = ‘text-align:center;padding:8px;background:#f8f9fa;color:#666;font-size:12px;border-radius:0 0 8px 8px;’;
table.parentNode.insertBefore(hint, table.nextSibling);
}
});
});