Skip to content

feat(payments): add AgentCore Payments as first-class CLI resource#1261

Open
aidandaly24 wants to merge 3 commits into
mainfrom
feat/payments
Open

feat(payments): add AgentCore Payments as first-class CLI resource#1261
aidandaly24 wants to merge 3 commits into
mainfrom
feat/payments

Conversation

@aidandaly24
Copy link
Copy Markdown
Contributor

@aidandaly24 aidandaly24 commented May 14, 2026

Description

Adds AgentCore Payments as a first-class resource type in the CLI. Includes:

  • agentcore add payment-manager / payment-connector commands (CLI + TUI wizard)
  • agentcore remove payment-manager / payment-connector with cascading delete
  • CDK-backed deployment via AgentCorePaymentManager + AgentCorePaymentConnector L3 constructs
  • Payment credential provider setup (imperative, same /identities/ endpoint as API key/OAuth)
  • CFN output parsing for deployed-state persistence
  • Invoke flags: --payment-instrument-id, --payment-session-id, --auto-session
  • Python agent template with x402 payment interception via SDK plugin
  • Validate command checks for payment credential completeness
  • Dev mode env var injection (AUTH_MODE for CUSTOM_JWT support)

Related Issue

Closes #

Documentation PR

Type of Change

  • New feature

Testing

How have you tested the change?

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

120 new payment-specific unit tests added covering:

  • parsePaymentOutputs, PaymentManagerPrimitive, PaymentConnectorPrimitive
  • validate command payment paths, payment-env dev mode, pre-deploy credential setup
  • wirePaymentCapability template patching

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.


Update — runtime IAM + system prompt for x402 auto-pay (commit 1f6a2f2)

End-to-end testing surfaced a missing IAM grant and a stale system prompt. Both blockers are fixed in this commit; the rest of the PR is unchanged.

What broke without the fix

The agent runtime role only had sts:AssumeRole on the ProcessPaymentRole (which carries only ProcessPayment). But AgentCorePaymentsPlugin.generate_payment_header calls GetPaymentInstrument on the runtime's own credentials before any role assumption. The plugin failed with AccessDeniedException on the very first 402 it tried to settle:

Failed to get payment instrument: ... is not authorized to perform:
bedrock-agentcore:GetPaymentInstrument on resource: <pmgr-arn>
because no identity-based policy allows the bedrock-agentcore:GetPaymentInstrument action

Fix

Grant the runtime role the seven payment data-plane actions, scoped to the manager ARN, in the vended CDK stack template:

  • bedrock-agentcore:GetPaymentInstrument
  • bedrock-agentcore:ListPaymentInstruments
  • bedrock-agentcore:GetPaymentInstrumentBalance
  • bedrock-agentcore:GetPaymentSession
  • bedrock-agentcore:ListPaymentSessions
  • bedrock-agentcore:CreatePaymentSession (so --auto-session works without a separate ManagementRole call)
  • bedrock-agentcore:ProcessPayment

A code comment notes this deviates from the canonical 4-role split in the AgentCore Payments beta guide. The deviation is required by the current SDK plugin, which calls GetPaymentInstrument from inside generate_payment_header. If the SDK is later updated to accept a pre-fetched instrument and to split create-session into a backend-only flow, this grant can be tightened.

System-prompt update

PAYMENT_SYSTEM_PROMPT in capabilities/payments/payments.py now mentions the http_request tool that the SDK plugin auto-registers:

- Use http_request to call HTTP endpoints. 402 Payment Required responses
  are settled automatically by the plugin and the call is retried.

The other prompt lines (for get_payment_session, get_payment_instrument_balance, list_payment_instruments) are unchanged — those tools were already provided by the plugin.

SDK dependency

This commit's system-prompt change is forward-looking; the http_request tool ships in bedrock-agentcore SDK PR aws/bedrock-agentcore-sdk-python#493. Once that merges and a new SDK release ships, the template's pyproject.toml.hbs should pin bedrock-agentcore >= <released-version>. Pin bump intentionally NOT included in this commit — it should land alongside the published version number.

End-to-end verification (after IAM fix + SDK PR)

Tested against https://x402.bitcoinsapi.com/weather on Base Sepolia from a fresh project. Plugin path runs cleanly:

  1. Detected 402 Payment Required response from tool: http_request
  2. Successfully retrieved instrument (← fails without this commit's IAM grant)
  3. Successfully processed payment for user default-user (← fails without SDK PR feat: add agentcore traces command and trace link in invoke TUI #493)
  4. Added payment header to tool input headers: ['PAYMENT-SIGNATURE']
  5. ✅ Tool retried with the payment header

(Final on-chain settle currently fails inside the seller-side facilitator simulation due to two unrelated issues in CDP's signing service — validAfter set to current timestamp instead of now-N, and an ECRecover failure on the returned v byte. Those are tracked separately as service-side bugs and are out of scope for this PR.)

@aidandaly24 aidandaly24 requested a review from a team May 14, 2026 21:32
@github-actions github-actions Bot added the size/xl PR size: XL label May 14, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label May 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

Package Tarball

aws-agentcore-0.16.0.tgz

How to install

gh release download pr-1261-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.16.0.tgz

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 14, 2026
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 14, 2026
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 15, 2026
@github-actions github-actions Bot added the size/xl PR size: XL label May 15, 2026
Comment thread src/cli/commands/validate/command.tsx Dismissed
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 19, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 19, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 19, 2026
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 20, 2026
@github-actions github-actions Bot removed the size/xl PR size: XL label May 20, 2026
@github-actions github-actions Bot added the size/xl PR size: XL label May 20, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 20, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 20, 2026
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 21, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 21, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

Copy link
Copy Markdown
Contributor

@jesseturner21 jesseturner21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! just a few questions and maybe a quick change to update the schema to match the api.

Comment thread src/cli/commands/remove/command.tsx
Comment thread src/cli/commands/status/command.tsx Outdated
Comment thread src/cli/templates/render.ts Outdated
Comment thread src/cli/tui/components/ResourceGraph.tsx
Comment thread src/schema/schemas/primitives/payment.ts Outdated
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

Adds AgentCore Payments as a first-class resource type in the CLI:
- `agentcore add/remove payment-manager` and `payment-connector`
  (CoinbaseCDP + StripePrivy), CLI + TUI wizard
- Cascading delete of connectors + credentials + .env.local cleanup
- CDK-backed deploy via AgentCorePaymentManager / AgentCorePaymentConnector
  L3 constructs, including runtime-role payment data-plane IAM grants
- Payment credential provider setup (imperative, AgentCore Identity vault)
- CFN output parsing into deployed-state
- Invoke flags: --payment-instrument-id, --payment-session-id, --auto-session
- Strands template wires AgentCorePaymentsPlugin; PAYMENT_SYSTEM_PROMPT
  references the plugin-provided http_request tool

Schema:
- payments[] in agentcore.json, .optional() (non-breaking: absent configs
  are not rewritten with payments: [])
- payment manager name regex matches CreatePaymentManager API (no underscore);
  connector names allow underscores per CreatePaymentConnector
- getOrCreatePaymentSession unwraps the CreatePaymentSession `paymentSession`
  response so --auto-session forwards a real session id

Verified end-to-end on Base Sepolia: real on-chain USDC settle via the
SDK plugin (bedrock-agentcore >= 1.12.0 / PR #493).
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

The vended cdk/bin/cdk.ts compiles against the published @aws/agentcore-cdk
schema type, which lags the CLI's AgentCoreProjectSpec (no payments/harnesses
fields). Restore `const specAny = spec as any` and route payments/harnesses/
gateway field access through it, fixing TS2304 (specAny undefined) and TS2339
(payments missing) introduced while resolving the rebase conflict in this file.

Regenerates the asset snapshot to match.
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

# Conflicts:
#	src/lib/packaging/helpers.ts
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

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

Labels

size/xl PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants