goal-agent
Overview
The goal-agent skill creates a workspace that turns an OpenClaw agent into a focused, autonomous optimizer. You give it a goal and a shell command that measures progress — the agent does the rest, iterating heartbeat by heartbeat, learning what works and what doesn't.
Usage
Step 1: Collect inputs
| Input | Flag | Required | Default |
|---|
| Goal description | INLINECODE0 | ✅ | — |
| Metric command (returns a number) |
--metric | ✅ | — |
| Target value |
--target | ✅ | — |
| Direction (up/down) |
--direction | ❌ |
up |
| Safety constraints |
--constraints | ❌ |
None |
| Max iterations |
--max-iterations | ❌ |
50 |
| Output directory |
--output-dir | ❌ |
./ |
Step 2: Run scaffold.sh
CODEBLOCK0
This generates the following files in --output-dir:
- -
GOAL.md — goal definition, iteration counter, history table - INLINECODE13 — current approach, hypotheses, next action
- INLINECODE14 — rules extracted from experience
- INLINECODE15 — the feedback loop instructions (replaces main HEARTBEAT.md)
- INLINECODE16 — runnable metric evaluator
Step 3: Activate the feedback loop
The generated HEARTBEAT.md is the goal-agent loop. Each heartbeat, the agent:
- 1. Measures the metric
- Compares against target and history
- Reflects on what worked/didn't
- Decides the next action
- Acts
- Records results
- Adapts strategy
To activate: Copy HEARTBEAT.md to ~/clawd/HEARTBEAT.md (or symlink it):
CODEBLOCK1
Step 4: Deploy options
Option A — Current agent (fastest)
Copy all generated files into your workspace and activate HEARTBEAT.md as above.
Option B — Dedicated VM (cleanest)
Use the spawn-agent skill to create a fresh agent VM, then copy the goal workspace there:
# On the new agent
scp -r ~/clawd/goals/dau-growth/ ubuntu@new-agent:~/clawd/goals/
ssh ubuntu@new-agent "cp ~/clawd/goals/dau-growth/HEARTBEAT.md ~/clawd/HEARTBEAT.md"
Examples
Example 1: Optimize test coverage
CODEBLOCK3
Example 2: Reduce build time
CODEBLOCK4
Example 3: Grow social followers
bash ~/clawd/skills/goal-agent/scripts/scaffold.sh \
--goal "Reach 500 Twitter followers" \
--metric "~/.openclaw/scripts/twitter-follower-count.sh" \
--target 500 \
--direction up \
--constraints "Only post authentic content. No follow-for-follow schemes." \
--output-dir ~/clawd/goals/twitter-growth
Safety & Sandboxing
Before activating a goal-agent loop, review these guidelines:
- - Review generated files before activating. Always read the generated
HEARTBEAT.md and evaluate.sh before copying them into your workspace. Confirm the metric command and constraints are what you intended. - Use
--constraints to limit scope. The agent will only take actions within the constraints you define. Be explicit: "Only modify files in ~/myproject/src", "Do not make network requests", "Do not delete files". - Set a low
--max-iterations for first runs. Start with 5-10 to observe behavior before allowing longer runs. - Prefer dedicated VMs for autonomous goals. Use
spawn-agent to isolate goal-agents from your main workspace. This limits blast radius if the agent takes unexpected actions. - Metric commands should be read-only. The
--metric command should only measure — never modify state. Use simple commands like cat, wc, jq, grep. - The "Act" step is constrained by text, not code. The agent follows the constraints you set in
--constraints, but there is no programmatic sandbox. For high-stakes goals, combine with filesystem permissions, network egress controls, or a restricted user account. - Monitor early iterations. Check
GOAL.md history after the first few heartbeats to verify the agent is behaving as expected.
How it works
The HEARTBEAT.md implements a tight cognitive loop:
CODEBLOCK6
Each iteration, the agent reads its own history (GOAL.md), its current understanding (STRATEGY.md), and accumulated wisdom (LEARNINGS.md) before taking action. Over time it builds a library of what works for your specific goal.
Files reference
| File | Purpose | Agent modifies? |
|---|
| INLINECODE37 | Source of truth: goal, metric, target, history | Status + History only |
| INLINECODE38 |
Current plan, hypotheses, next action | Yes (every iteration) |
|
LEARNINGS.md | Extracted rules and patterns | Yes (as it learns) |
|
HEARTBEAT.md | Loop instructions | No |
|
evaluate.sh | Runnable metric command | No |
Skill location
INLINECODE42
goal-agent
概述
goal-agent技能创建了一个工作空间,将OpenClaw智能体转变为专注、自主的优化器。你只需设定目标和一个衡量进度的shell命令——智能体会完成其余工作,通过一次次心跳迭代,学习哪些方法有效、哪些无效。
使用方法
步骤1:收集输入参数
| 输入项 | 标志位 | 必填 | 默认值 |
|---|
| 目标描述 | --goal | ✅ | — |
| 指标命令(返回数值) |
--metric | ✅ | — |
| 目标值 | --target | ✅ | — |
| 方向(上升/下降) | --direction | ❌ | up |
| 安全约束 | --constraints | ❌ | None |
| 最大迭代次数 | --max-iterations | ❌ | 50 |
| 输出目录 | --output-dir | ❌ | ./ |
步骤2:运行scaffold.sh
bash
bash ~/clawd/skills/goal-agent/scripts/scaffold.sh \
--goal 将日活跃用户提升至100 \
--metric cat /tmp/my-metric.json | jq .dau \
--target 100 \
--direction up \
--constraints 不得修改数据库架构。每日预算控制在50美元以内。 \
--max-iterations 30 \
--output-dir ~/clawd/goals/dau-growth
该命令会在--output-dir目录下生成以下文件:
- - GOAL.md — 目标定义、迭代计数器、历史记录表
- STRATEGY.md — 当前方案、假设、下一步行动
- LEARNINGS.md — 从经验中提取的规则
- HEARTBEAT.md — 反馈循环指令(替换主HEARTBEAT.md)
- evaluate.sh — 可执行的指标评估器
步骤3:激活反馈循环
生成的HEARTBEAT.md就是goal-agent循环。每次心跳,智能体会:
- 1. 测量指标
- 与目标值和历史数据对比
- 反思哪些方法有效/无效
- 决定下一步行动
- 执行行动
- 记录结果
- 调整策略
激活方法: 将HEARTBEAT.md复制到~/clawd/HEARTBEAT.md(或创建符号链接):
bash
cp ~/clawd/goals/dau-growth/HEARTBEAT.md ~/clawd/HEARTBEAT.md
步骤4:部署选项
选项A — 当前智能体(最快)
将所有生成的文件复制到工作空间,并按照上述方法激活HEARTBEAT.md。
选项B — 专用虚拟机(最干净)
使用spawn-agent技能创建一个全新的智能体虚拟机,然后将目标工作空间复制到该虚拟机:
bash
在新智能体上执行
scp -r ~/clawd/goals/dau-growth/ ubuntu@new-agent:~/clawd/goals/
ssh ubuntu@new-agent cp ~/clawd/goals/dau-growth/HEARTBEAT.md ~/clawd/HEARTBEAT.md
示例
示例1:优化测试覆盖率
bash
bash ~/clawd/skills/goal-agent/scripts/scaffold.sh \
--goal 将测试覆盖率提升至80% \
--metric cd ~/myproject && npx jest --coverage --coverageReporters=text-summary 2>/dev/null | grep Statements | grep -oP \d+\.\d+(?=%) \
--target 80 \
--direction up \
--max-iterations 20 \
--output-dir ~/clawd/goals/test-coverage
示例2:减少构建时间
bash
bash ~/clawd/skills/goal-agent/scripts/scaffold.sh \
--goal 将构建时间缩短至30秒以内 \
--metric cd ~/myproject && time npm run build 2>&1 | grep real | grep -oP \d+\.\d+ \
--target 30 \
--direction down \
--constraints 不得移除任何构建步骤。不得破坏生产构建。 \
--output-dir ~/clawd/goals/build-speed
示例3:增加社交媒体粉丝
bash
bash ~/clawd/skills/goal-agent/scripts/scaffold.sh \
--goal 达到500个Twitter粉丝 \
--metric ~/.openclaw/scripts/twitter-follower-count.sh \
--target 500 \
--direction up \
--constraints 仅发布真实内容。不得使用互粉策略。 \
--output-dir ~/clawd/goals/twitter-growth
安全与沙箱机制
在激活goal-agent循环之前,请审阅以下指南:
- - 激活前审查生成的文件。 在将生成的HEARTBEAT.md和evaluate.sh复制到工作空间之前,务必仔细阅读。确认指标命令和约束条件符合你的预期。
- 使用--constraints限制范围。 智能体只会在你定义的约束范围内采取行动。要明确说明:仅修改~/myproject/src目录下的文件、不得发起网络请求、不得删除文件。
- 首次运行时设置较低的--max-iterations值。 从5-10次迭代开始,观察行为后再允许更长时间的运行。
- 自主目标优先使用专用虚拟机。 使用spawn-agent将目标智能体与主工作空间隔离。这样可以在智能体采取意外行动时限制影响范围。
- 指标命令应为只读操作。 --metric命令应仅用于测量——不得修改状态。使用cat、wc、jq、grep等简单命令。
- 执行步骤受文本约束,而非代码约束。 智能体会遵循你在--constraints中设定的约束,但没有程序化的沙箱机制。对于高风险目标,应结合文件系统权限、网络出口控制或受限用户账户使用。
- 监控早期迭代。 在前几次心跳后检查GOAL.md的历史记录,确认智能体行为符合预期。
工作原理
HEARTBEAT.md实现了一个紧凑的认知循环:
测量 → 对比 → 反思 → 决策 → 执行 → 记录 → 调整
↑_|
每次迭代,智能体在执行行动前会读取自己的历史记录(GOAL.md)、当前理解(STRATEGY.md)和积累的经验(LEARNINGS.md)。随着时间的推移,它会为你的特定目标建立一个有效方法的库。
文件参考
| 文件 | 用途 | 智能体是否修改? |
|---|
| GOAL.md | 事实来源:目标、指标、目标值、历史记录 | 仅更新状态和历史记录 |
| STRATEGY.md |
当前计划、假设、下一步行动 | 是(每次迭代) |
| LEARNINGS.md | 提取的规则和模式 | 是(随学习过程更新) |
| HEARTBEAT.md | 循环指令 | 否 |
| evaluate.sh | 可执行的指标命令 | 否 |
技能位置
~/clawd/skills/goal-agent/