Skip to content

Python: feat(middleware): add agentpay-mcp payment governance middleware example#5048

Open
up2itnow0822 wants to merge 2 commits intomicrosoft:mainfrom
up2itnow0822:feat/payment-governance-middleware
Open

Python: feat(middleware): add agentpay-mcp payment governance middleware example#5048
up2itnow0822 wants to merge 2 commits intomicrosoft:mainfrom
up2itnow0822:feat/payment-governance-middleware

Conversation

@up2itnow0822
Copy link
Copy Markdown

Summary

Adds a new middleware sample (payment_governance_middleware.py) demonstrating how to enforce spend governance on AI agent tool calls using agentpay-mcp.

Problem

Agent Framework ships a rich middleware system with examples for logging, security, usage tracking, and shared state — but no example for payment governance. As agents gain the ability to make paid API calls (via x402 or other payment protocols), operators need middleware that enforces budget limits before money leaves the wallet.

AI gateways (LiteLLM, Portkey) govern inference costs. Nothing in the current samples governs outbound agent spending.

Solution

A function-based middleware that enforces three gates before every paid tool call:

  1. Per-call limit — no single payment exceeds a threshold
  2. Session cap — total session spend stays within budget
  3. Category cap — independent limits per spending category (data, compute, services)

The sample follows the existing middleware patterns (same imports, same structure as usage_tracking_middleware.py) and runs standalone with uv run.

Why agentpay-mcp

Changes

  • python/samples/02-agents/middleware/payment_governance_middleware.py — new sample
  • python/samples/02-agents/middleware/README.md — added table entry

…tpay-mcp

Adds a new middleware sample demonstrating spend governance for AI agents
making paid tool calls via x402 protocol.

Features:
- Per-session budget caps
- Per-call spend limits
- Category-based spending policies (data, compute, services)
- Integration pattern with agentpay-mcp for production use

This fills the payment governance gap in the middleware examples.
AI gateways handle inference costs — this middleware handles everything
else the agent spends.

Reference: NVIDIA/NeMo-Agent-Toolkit-Examples PR microsoft#17 (merged)
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Apr 2, 2026
@github-actions github-actions bot changed the title feat(middleware): add agentpay-mcp payment governance middleware example Python: feat(middleware): add agentpay-mcp payment governance middleware example Apr 2, 2026
@up2itnow0822
Copy link
Copy Markdown
Author

@up2itnow0822 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants