feat(examples): add budget governance example with agentpay-mcp#324
feat(examples): add budget governance example with agentpay-mcp#324up2itnow0822 wants to merge 1 commit intoAgentlyHQ:mainfrom
Conversation
Adds a new example showing how to add spend governance on top of aixyz's native x402 payments using agentpay-mcp. aixyz ships x402 pricing (per-tool and per-agent) but has no mechanism for session-level budget caps, velocity limits, or category policies. This example demonstrates the governance layer: - Per-session budget caps (e.g., $5.00 max per session) - Per-call spend limits (e.g., $1.00 max per payment) - Category-based policies (data, compute, services) - Budget checking tool for transparency agentpay-mcp complements aixyz's `accepts` system by adding the operator-side controls that production deployments need. Reference: NVIDIA/NeMo-Agent-Toolkit-Examples PR AgentlyHQ#17 (merged)
|
The latest updates on your projects. Learn more about Vercel for GitHub. 4 Skipped Deployments
|
|
@up2itnow0822 is attempting to deploy a commit to the Agently Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46b271bf97
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| reason: z.string().describe("Why this payment is needed"), | ||
| }), | ||
| execute: async ({ amount, category, recipient, reason }) => { | ||
| const cost = parseFloat(amount); |
There was a problem hiding this comment.
Validate payment amount before governance checks
Parsing amount with parseFloat without validating finiteness/positivity lets invalid inputs bypass the gates: e.g., "abc" becomes NaN (all > checks are false) and then recordSpend turns totals into NaN, while negative values reduce spend and effectively increase remaining budget. This breaks the governance guarantees and can approve payments that should be blocked.
Useful? React with 👍 / 👎.
| categorySpent: Record<string, number>; | ||
| } | ||
|
|
||
| const state: BudgetState = { |
There was a problem hiding this comment.
Scope budget state to a session key
The example advertises session-level caps, but this singleton state is shared process-wide, so spending/blocks from one conversation affect all others. In a multi-user server process this causes cross-session interference and incorrect enforcement of the documented “per session” limits.
Useful? React with 👍 / 👎.
| { | ||
| "name": "budget-governance", | ||
| "version": "0.1.0", | ||
| "private": true, |
There was a problem hiding this comment.
Add runnable scripts to the new example package
This package is missing scripts.dev/scripts.build, so the documented example workflow does not work here (bun run dev in this directory exits with Script not found "dev"). Without these scripts, users cannot run or build this example consistently with the other examples/* packages.
Useful? React with 👍 / 👎.
Summary
Adds a
budget-governanceexample showing how to layer spend governance on top of aixyz's native x402 payments using agentpay-mcp.Problem
aixyz ships x402 pricing beautifully —
accepts: { scheme: "exact", price: "$0.005" }per tool, per agent. But there's no mechanism for the operator (the person deploying the agent) to enforce:Without these, an autonomous agent with a funded wallet can drain it.
Solution
A new example (
examples/budget-governance/) that demonstrates the governance layer:budget-state.ts— in-memory budget tracker (replace with agentpay-mcp MCP calls in production)tools/check-budget.ts— tool for the agent to inspect its own remaining budgettools/request-payment.ts— payment tool with three governance gates (per-call, session, category)agent.ts— governance-aware agent with instructions explaining the budget rulesaixyz.config.ts— standard aixyz config with budget governance skillsHow it complements aixyz
acceptsThese are complementary —
acceptssays "this costs $0.005", governance says "but you can only spend $5 total."Credential
agentpay-mcp is merged into NVIDIA NeMo Agent Toolkit Examples (PR #17) as an official catalog entry. 475 weekly npm downloads. MIT licensed.
Changes
examples/budget-governance/— complete new example (7 files)