meta-ads-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMeta Ads CLI Agent Skill
Meta Ads CLI Agent Skill
This skill teaches an AI agent to operate Meta ads through Meta's official Ads CLI instead of reimplementing the Marketing API.
The core command shape is:
bash
meta ads <resource> <action> [options]Examples from the official Ads CLI pattern include:
bash
meta ads campaign list
meta ads campaign create --name "Summer Sale" --objective OUTCOME_SALES --daily-budget 5000
meta ads adset create CAMPAIGN_ID --name "My Ad Set" --optimization-goal LINK_CLICKS --billing-event IMPRESSIONS --targeting-countries US
meta ads creative create --name "Hero Banner" --page-id 111222333 --image ./banner.jpg --body "50% off" --title "Shop Now" --link-url https://example.com/sale --call-to-action SHOP_NOW
meta ads ad create ADSET_ID --name "Hero Banner Ad" --creative-id CREATIVE_ID
meta ads insights get --campaign_id CAMPAIGN_ID --fields impressions,conversions,spend --date-preset last_7dUse the bundled guard script as the default execution path:
bash
python3 scripts/meta_ads_agent.py doctor
python3 scripts/meta_ads_agent.py classify -- meta ads campaign list
python3 scripts/meta_ads_agent.py run -- meta ads campaign list --limit 25The guard script does not replace Meta's CLI. It wraps it so agents behave safely and consistently.
本Skill用于指导AI Agent通过Meta官方Ads CLI操作Meta广告,而非重新实现Marketing API。
核心命令格式为:
bash
meta ads <resource> <action> [options]官方Ads CLI模式的示例包括:
bash
meta ads campaign list
meta ads campaign create --name "Summer Sale" --objective OUTCOME_SALES --daily-budget 5000
meta ads adset create CAMPAIGN_ID --name "My Ad Set" --optimization-goal LINK_CLICKS --billing-event IMPRESSIONS --targeting-countries US
meta ads creative create --name "Hero Banner" --page-id 111222333 --image ./banner.jpg --body "50% off" --title "Shop Now" --link-url https://example.com/sale --call-to-action SHOP_NOW
meta ads ad create ADSET_ID --name "Hero Banner Ad" --creative-id CREATIVE_ID
meta ads insights get --campaign_id CAMPAIGN_ID --fields impressions,conversions,spend --date-preset last_7d使用捆绑的防护脚本作为默认执行路径:
bash
python3 scripts/meta_ads_agent.py doctor
python3 scripts/meta_ads_agent.py classify -- meta ads campaign list
python3 scripts/meta_ads_agent.py run -- meta ads campaign list --limit 25防护脚本不会替代Meta的CLI,它只是对其进行封装,确保Agent的操作安全且一致。
Highest-priority rules
最高优先级规则
- Use Meta's official CLI first. Do not call Graph API directly unless the official CLI cannot do the task and the user explicitly accepts a lower-level workaround.
- Read before write. Inspect the relevant account/object/performance state before changing it.
- No spend-affecting change without explicit user approval. Writes, budget changes, activation, delete/remove, dataset/catalog connections, and creative uploads need approval.
- Never activate by accident. New objects should remain unless the user explicitly asks to activate.
PAUSED,ACTIVE,activate,delete, andremoveare high-risk.--force - Prefer machine-readable output. Use JSON whenever possible: . Use table output only for human presentation.
meta --output json ads ... - One write step at a time. Apply one mutation, verify it, then continue.
- Do not invent IDs. Resolve account, campaign, ad set, creative, page, pixel/dataset, catalog, product set, and targeting IDs from the CLI or user-provided values.
- Keep tokens out of chat and logs. Never print access tokens, app secrets, cookies, or contents.
.env - Ask for missing material only when blocking. For reads, proceed with defaults. For writes, collect exact account, IDs, budget, date range, page/dataset/catalog, destination URL, and approval.
- Treat regulated/special categories carefully. Housing, employment, credit, politics, social issues, health, financial services, minors, and sensitive audiences require extra review and conservative targeting.
- 优先使用Meta官方CLI。除非官方CLI无法完成任务且用户明确接受低级别替代方案,否则不要直接调用Graph API。
- 写前读。在进行更改前,先检查相关账户/对象/性能状态。
- 涉及支出的更改需明确用户批准。写入操作、预算变更、激活、删除/移除、数据集/目录关联以及创意上传都需要获得批准。
- 避免意外激活。新创建的对象应保持状态,除非用户明确要求激活。
PAUSED、ACTIVE、activate、delete和remove属于高风险操作。--force - 优先选择机器可读输出。尽可能使用JSON格式:。仅在面向人类展示时使用表格输出。
meta --output json ads ... - 一次执行一个写入步骤。执行一次变更,验证其有效性,再继续下一步。
- 不要自行生成ID。从CLI或用户提供的值中解析账户、广告系列、广告组、创意、主页、像素/数据集、目录、产品集和定向ID。
- 不要在聊天和日志中泄露令牌。绝不要打印访问令牌、应用密钥、Cookie或文件内容。
.env - 仅在阻塞时询问缺失信息。对于读取操作,使用默认值继续。对于写入操作,收集确切的账户、ID、预算、日期范围、主页/数据集/目录、目标URL以及用户批准。
- 谨慎处理受监管/特殊类别。住房、就业、信贷、政治、社会议题、健康、金融服务、未成年人和敏感受众相关的广告需要额外审核和保守的定向策略。
Recommended agent flow
推荐的Agent工作流
For almost every request, follow this order:
text
1. Classify request: read-only, ordinary write, budget/write, activation, destructive, regulated.
2. Run doctor/auth check if account access is uncertain.
3. Read current state with compact JSON output.
4. Produce a short plan with exact commands, risks, assumptions, and verification commands.
5. For read-only tasks: run commands and summarise.
6. For writes: wait for explicit approval, then run through scripts/meta_ads_agent.py.
7. Verify state after every write.
8. Report what changed, object IDs, before/after values, and any unresolved issues.几乎所有请求都应遵循以下顺序:
text
1. 分类请求:只读、普通写入、预算/写入、激活、破坏性操作、受监管操作。
2. 如果账户访问权限不确定,运行doctor/auth检查。
3. 使用紧凑的JSON输出读取当前状态。
4. 生成包含确切命令、风险、假设和验证命令的简短计划。
5. 对于只读任务:运行命令并总结结果。
6. 对于写入任务:等待明确批准,然后通过scripts/meta_ads_agent.py执行。
7. 每次写入后验证状态。
8. 报告变更内容、对象ID、变更前后的值以及任何未解决的问题。Install and auth checklist
安装与认证检查清单
bash
undefinedbash
undefinedMeta docs list meta-ads as the package name.
Meta文档中列出的包名为meta-ads。
python3.12 -m pip install meta-ads
python3.12 -m pip install meta-ads
Confirm the CLI is available.
确认CLI可用。
meta --help
meta ads --help
meta --help
meta ads --help
Auth status. Meta docs show ACCESS_TOKEN for token-based auth.
认证状态。Meta文档显示使用ACCESS_TOKEN进行基于令牌的认证。
export ACCESS_TOKEN=<ACCESS_TOKEN>
meta auth status
export ACCESS_TOKEN=<ACCESS_TOKEN>
meta auth status
Prefer an explicit ad account for every command until a default is proven.
在默认账户未确认前,为每个命令指定明确的广告账户。
meta ads --ad-account-id <AD_ACCOUNT_ID> campaign list
Do not guess config keys if auth fails. Run:
```bash
meta auth status
meta ads --help
meta ads <resource> --helpThen follow the official CLI setup/configuration docs for the installed version.
meta ads --ad-account-id <AD_ACCOUNT_ID> campaign list
如果认证失败,不要猜测配置密钥。运行以下命令:
```bash
meta auth status
meta ads --help
meta ads <resource> --help然后遵循已安装版本的官方CLI设置/配置文档。
Using the guard script
使用防护脚本
Check readiness
检查就绪状态
bash
python3 scripts/meta_ads_agent.py doctorbash
python3 scripts/meta_ads_agent.py doctorClassify command risk without executing
分类命令风险而不执行
bash
python3 scripts/meta_ads_agent.py classify -- meta ads campaign update 123 --status ACTIVEbash
python3 scripts/meta_ads_agent.py classify -- meta ads campaign update 123 --status ACTIVERun a read-only command
运行只读命令
bash
python3 scripts/meta_ads_agent.py run -- meta ads campaign list --limit 25bash
python3 scripts/meta_ads_agent.py run -- meta ads campaign list --limit 25Run a write after approval
获得批准后运行写入命令
bash
python3 scripts/meta_ads_agent.py run \
--approved "User approved creating the paused campaign named Summer Sale in account act_123" \
-- meta ads campaign create --name "Summer Sale" --objective OUTCOME_SALES --daily-budget 5000bash
python3 scripts/meta_ads_agent.py run \
--approved "User approved creating the paused campaign named Summer Sale in account act_123" \
-- meta ads campaign create --name "Summer Sale" --objective OUTCOME_SALES --daily-budget 5000Run an activation after stronger approval
获得更强批准后运行激活命令
bash
python3 scripts/meta_ads_agent.py run \
--approved "User approved activating campaign 123 after reviewing it" \
--allow-active \
-- meta ads campaign update 123 --status ACTIVEbash
python3 scripts/meta_ads_agent.py run \
--approved "User approved activating campaign 123 after reviewing it" \
--allow-active \
-- meta ads campaign update 123 --status ACTIVELint or run a multi-step plan
检查或运行多步骤计划
bash
python3 scripts/meta_ads_agent.py lint-plan templates/weekly-report-plan.json
python3 scripts/meta_ads_agent.py run-plan templates/weekly-report-plan.jsonWrite-heavy plans require ; activation/destructive plans require additional flags.
--approved ...bash
python3 scripts/meta_ads_agent.py lint-plan templates/weekly-report-plan.json
python3 scripts/meta_ads_agent.py run-plan templates/weekly-report-plan.json写入密集型计划需要参数;激活/破坏性计划需要额外的标志。
--approved ...Fast task routing
快速任务路由
| User intent | First action | Main workflow |
|---|---|---|
| “Show performance” | Read-only | |
| “What should I pause?” | Read insights, then propose | |
| “Pause this ad/campaign” | Read object + metrics | |
| “Increase budget” | Read currency, current budget, delivery | |
| “Launch campaign” | Build paused launch plan | |
| “Create catalogue/product set” | Check account/catalog context | |
| “Check pixel” | Dataset and insights audit | |
| “Use another endpoint” | Verify official CLI coverage first | |
| 用户意图 | 首要操作 | 主要工作流 |
|---|---|---|
| “展示广告效果” | 只读操作 | |
| “我应该暂停哪些广告?” | 读取洞察数据,然后提出建议 | |
| “暂停此广告/广告系列” | 读取对象+指标 | |
| “增加预算” | 读取货币类型、当前预算、投放情况 | |
| “启动广告系列” | 构建默认暂停的启动计划 | |
| “创建商品目录/产品集” | 检查账户/目录上下文 | |
| “检查像素” | 数据集和洞察审计 | |
| “使用其他端点” | 先验证官方CLI是否支持 | |
Output expectations
输出预期
For read-only analysis, return:
text
- what was queried
- date range and attribution assumptions
- top findings with numbers
- caveats about missing/zero/odd metrics
- recommended next actions separated from actual changesFor writes, return:
text
- object IDs touched
- before/after values
- command(s) run, redacted where needed
- verification result
- anything still paused/not live
- any follow-up the user must perform in Ads Manager对于只读分析,返回内容应包括:
text
- 查询内容
- 日期范围和归因假设
- 带数值的关键发现
- 关于缺失/零值/异常指标的说明
- 建议的后续操作(与实际变更分开)对于写入操作,返回内容应包括:
text
- 涉及的对象ID
- 变更前后的值
- 执行的命令(必要时脱敏)
- 验证结果
- 仍处于暂停/未上线状态的内容
- 用户必须在Ads Manager中执行的后续操作References in this skill
本Skill中的参考资料
- — what v1 got right/wrong and why v2 changed direction.
references/CRITICAL-ANALYSIS-v1.md - — concise Ads CLI reference for agents.
references/OFFICIAL-ADS-CLI.md - — how agents should reason, plan, execute, and recover.
references/AGENT-OPERATING-MODEL.md - — approval gates, budget/activation/destructive rules.
references/SAFETY.md - — account audits, reporting, launch, pause, budget, dataset/catalog workflows.
references/WORKFLOWS.md - — Insights fields, date ranges, breakdowns, and interpretation.
references/REPORTING.md - — command patterns and help-discovery strategy.
references/COMMANDS.md - — how to turn metrics into cautious recommendations.
references/OPTIMISATION-DECISIONING.md - and
resources/command-catalog.json— machine-readable aids for agents.resources/risk-rules.json - and
agent-prompts/— ready-made prompts/instructions for general shell agents.AGENTS.md - — auth, exit codes, output parsing, rate limits, API errors.
references/TROUBLESHOOTING.md - — using this skill in non-OpenClaw agents.
references/PORTABILITY.md - — JSON plan templates and schema.
templates/ - — optional safe command runner.
scripts/meta_ads_agent.py - — behavioural evals for agent skill quality.
evals/
- — v1版本的优缺点,以及v2版本调整方向的原因。
references/CRITICAL-ANALYSIS-v1.md - — 供Agent使用的简洁Ads CLI参考文档。
references/OFFICIAL-ADS-CLI.md - — Agent应如何推理、规划、执行和恢复。
references/AGENT-OPERATING-MODEL.md - — 批准机制、预算/激活/破坏性操作规则。
references/SAFETY.md - — 账户审计、报告、启动、暂停、预算、数据集/目录工作流。
references/WORKFLOWS.md - — 洞察字段、日期范围、细分维度及解读方式。
references/REPORTING.md - — 命令模式和帮助发现策略。
references/COMMANDS.md - — 如何将指标转化为谨慎的建议。
references/OPTIMISATION-DECISIONING.md - 和
resources/command-catalog.json— 供Agent使用的机器可读辅助工具。resources/risk-rules.json - 和
agent-prompts/— 为通用Shell Agent准备的提示词/说明文档。AGENTS.md - — 认证、退出码、输出解析、速率限制、API错误排查。
references/TROUBLESHOOTING.md - — 在非OpenClaw Agent中使用本Skill的方法。
references/PORTABILITY.md - — JSON计划模板和 schema。
templates/ - — 可选的安全命令运行器。
scripts/meta_ads_agent.py - — 用于评估Agent Skill质量的行为评估工具。
evals/