Agent
Policies
用策略引擎约束 Agent 与后台动作。
Agent 策略 决定 MCP 服务器 能以你工作区的名义做哪些事。 策略作用域是 组织 + 环境,同一工作区下所有 agent session 共享一套规则,新 session 不必重复授权。
如果没有显式策略,默认是保守值:只允许只读工具、任何写入动作都要人工审批、不设金额上限。
字段
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
allowed_tools | AgentToolName[] | 只读集合 | 工具白名单。 |
per_action_limit | 十进制字符串 | null | null | 单次 create_payment_order 的金额上限。 |
daily_limit | 十进制字符串 | null | null | 24 小时滚动累计上限。 |
require_approval | boolean | true | 为 true 时所有非只读工具都返回 pending_approval。 |
per_action_limit / daily_limit 单位是结算资产("100.00" 表示 100 USDC)。
只对带 amount 入参的工具生效,目前只有 create_payment_order。
allowed_tools 的判断早于金额校验。不在白名单内的工具直接返回
403 tool … not allowed by policy。
查询当前策略
curl -X GET $STABLEOPS_API_URL/v1/agent/policy \
-H "authorization: Bearer $STABLEOPS_API_KEY" \
-H 'x-stableops-env: sandbox'{
"id": "agp_01",
"allowed_tools": ["get_order", "list_events", "list_webhook_deliveries"],
"per_action_limit": null,
"daily_limit": null,
"require_approval": true
}更新策略
POST /v1/agent/policy 是 upsert。只传你想改的字段,其余保持不变。
curl -X POST $STABLEOPS_API_URL/v1/agent/policy \
-H "authorization: Bearer $STABLEOPS_API_KEY" \
-H 'x-stableops-env: sandbox' \
-H 'content-type: application/json' \
-d '{
"allowed_tools": [
"get_order",
"list_events",
"create_payment_order",
"request_action_approval"
],
"per_action_limit": "100.00",
"daily_limit": "500.00",
"require_approval": false
}'需要清空某个上限时传 null:
{ "per_action_limit": null }决策流程
tool call ─▶ /v1/agent/actions
│
├─ 工具是否在 allowed_tools? 否 ─▶ 403 not allowed
│
├─ amount ≤ per_action_limit? 否 ─▶ 403 exceeds per_action_limit
│
├─ amount + 近 24h ≤ daily_limit? 否 ─▶ 403 exceeds daily_limit
│
├─ require_approval == true? 是 ─▶ pending_approval(进人工队列)
│ 否 ─▶ auto_allowed(Agent 继续)
└─ 只读工具? ─▶ auto_allowedDashboard 会把每条 pending_approval 动作、入参、发起 session 都展示出来。
批准后下一次重试即可放行;拒绝则把审批人填写的原因写进审计日志。
推荐档位
严格 —— 全部人工复核,首次接入生产时建议使用:
{
"allowed_tools": ["get_order", "list_events", "list_webhook_deliveries"],
"require_approval": true
}限额放行 —— 允许 Agent 自主开小额订单,超出再升级:
{
"allowed_tools": [
"get_order",
"list_events",
"create_payment_order",
"request_action_approval"
],
"per_action_limit": "50.00",
"daily_limit": "500.00",
"require_approval": false
}只读审计 —— 保留人工审批,把只读工具放开:
{
"allowed_tools": ["get_order", "list_events", "list_webhook_deliveries"],
"require_approval": true
}小贴士
- 即使在 sandbox 也建议把
per_action_limit/daily_limit都设上 —— Agent 不能超过, 也能在切到 live 前及早发现策略漂移。 - 吊销 session 与更新策略是两件事:前者只影响一段对话,后者影响所有 session。
- 审批会记录操作人 id(dashboard 登录用户或调用
/v1/agent/actions/:id/approve时显式传入的approver_id)。可按 session 检索审计轨迹。
这篇文档怎么样?
最后更新