spendguard-strict-budget-runner

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SpendGuard Strict Budget Runner

SpendGuard 严格预算执行器

Overview

概述

Use this skill to operationalize strict-budget execution.
使用该Skill实现严格预算的落地执行。

Quick Start

快速开始

  1. Load
    references/strict-budget-quickstart.md
    .
  2. Start sidecar in strict remote-pricing mode.
  3. Create agent and set hard budget with CLI or
    scripts/bootstrap_strict_budget.py
    .
  4. Route model calls through SpendGuard and include required headers.
  5. Confirm budget decrement and handle failures using
    references/error-playbook.md
    .
  1. 加载
    references/strict-budget-quickstart.md
    文件。
  2. 以严格远程定价模式启动sidecar。
  3. 通过CLI或
    scripts/bootstrap_strict_budget.py
    创建Agent并设置硬预算。
  4. 将模型调用请求路由至SpendGuard,并包含必要的请求头。
  5. 确认预算扣减情况,并通过
    references/error-playbook.md
    处理失败场景。

Workflow

工作流程

1) Start SpendGuard in strict mode

1) 以严格模式启动SpendGuard

Use sidecar mode with remote signed pricing verification enabled. Do not bypass signature checks for normal usage.
See full env setup in
references/strict-budget-quickstart.md
.
使用sidecar模式并启用远程签名定价验证。正常使用时不要绕过签名校验。
详见
references/strict-budget-quickstart.md
中的完整环境配置。

2) Create budgeted agent identity

2) 创建带预算的Agent身份

Prefer CLI:
bash
spendguard agent create --name "my-agent"
spendguard budget set --agent <agent_id> --limit 5000 --topup 5000
spendguard budget get --agent <agent_id>
Use script when deterministic JSON output is needed:
bash
python scripts/bootstrap_strict_budget.py --name my-agent --limit 5000 --topup 5000
优先使用CLI:
bash
spendguard agent create --name "my-agent"
spendguard budget set --agent <agent_id> --limit 5000 --topup 5000
spendguard budget get --agent <agent_id>
当需要确定性JSON输出时,使用脚本:
bash
python scripts/bootstrap_strict_budget.py --name my-agent --limit 5000 --topup 5000

3) Route model calls through SpendGuard

3) 将模型调用路由至SpendGuard

Send requests to sidecar
.../v1/...
routes, not directly to provider APIs.
Required:
  • Header
    x-cynsta-agent-id: <agent_id>
  • Optional
    x-cynsta-run-id: <run_id>
    for explicit run tracking
Load
references/routing-patterns.md
for OpenAI SDK and direct HTTP patterns.
将请求发送至sidecar的
.../v1/...
路由,而非直接调用服务商API。
必填项:
  • 请求头
    x-cynsta-agent-id: <agent_id>
  • 可选请求头
    x-cynsta-run-id: <run_id>
    ,用于显式跟踪运行实例
如需了解OpenAI SDK和直接HTTP调用的模式,请加载
references/routing-patterns.md

4) Enforce strict budget behavior

4) 执行严格预算管控

Expect:
  • 402
    when budget is insufficient for reserve
  • 409
    when same agent budget is locked by another in-flight run
  • 400
    for malformed payload or missing required headers
Apply fixes from
references/error-playbook.md
.
预期出现以下情况:
  • 当预算不足以预留时,返回
    402
    状态码
  • 当同一Agent的预算被其他运行中的实例锁定时,返回
    409
    状态码
  • 当请求格式错误或缺少必填请求头时,返回
    400
    状态码
请根据
references/error-playbook.md
中的方案进行修复。

5) Validate before finishing

5) 完成前的验证

Run these checks after setup:
  1. Health endpoint returns
    {"status":"ok"}
    .
  2. budget get
    returns expected
    remaining_cents
    .
  3. One real or mocked model call succeeds through sidecar.
  4. Remaining budget decreases after settled usage.
设置完成后执行以下检查:
  1. 健康检查端点返回
    {"status":"ok"}
  2. budget get
    命令返回预期的
    remaining_cents
  3. 至少一次真实或模拟的模型调用通过sidecar执行成功
  4. 结算使用量后,剩余预算相应减少

Guardrails

防护规则

  • Use one agent per isolated budget domain; do not share agent IDs across unrelated workloads.
  • Keep budgets in cents and treat
    hard_limit_cents
    as the strict cap.
  • Keep
    CAP_PRICING_VERIFY_SIGNATURE=true
    in normal operation.
  • In hosted mode, pass API key via
    --api-key
    or
    CAP_API_KEY
    .
  • 每个独立预算域使用一个Agent;不要在不相关的工作负载间共享Agent ID
  • 预算以美分为单位,并将
    hard_limit_cents
    视为严格上限
  • 正常运行时保持
    CAP_PRICING_VERIFY_SIGNATURE=true
  • 在托管模式下,通过
    --api-key
    参数或
    CAP_API_KEY
    环境变量传递API密钥