Multi-Option - Let Agents Accept Multiple Payment Currencies - #342
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds unit coverage for multi-option execution_cost configurations and hardens the A2A message/send endpoint to safely attach (or omit) payment context from request state without causing 500s on missing/partial/unserializable state.
Changes:
- Added a new unit test suite covering multi-option
execution_costvalidation, extension construction behavior, and payment requirements generation. - Extended A2A endpoint tests to cover payment context forwarding and added targeted unit tests for state-object serialization.
- Introduced
_serialize_state_obj()and guarded payment-context attachment inagent_run_endpointto avoidAttributeError/serialization-related 500s.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/unit/test_execution_cost_multi_option.py | New unit tests for multi-option execution cost and multi-requirement generation. |
| tests/unit/test_a2a_endpoint.py | Adds tests ensuring payment context is attached only when complete and serializable. |
| bindu/server/endpoints/a2a_protocol.py | Adds safe serialization helper + more robust guards when attaching payment context. |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Earlier an agent could only specify one payment option - one amount, one token, on one network.
X402 already allows returning multiple
PaymentRequirementsin the402 Payment Requiredresponse, which lets the caller choose which currency/network to use. Agents just didn't have a way to expose multiple options.Now
execution_costcan accept a list of payment options.Example:
The existing single-dict format still works.
So nothing breaks for existing agents.
Problem
execution_costpreviously accepted only a single dictionary.That meant an agent could only request payment in one currency on one network.
The X402 spec allows multiple payment requirements in a
402response, but agents had no way to define more than one option.Changes
bindu/penguin/config_validator.pyValidation now allows either:
dictlist[dict]Invalid cases like empty lists, non-dict entries, or wrong types raise validation errors.
Examples that now pass validation:
bindu/penguin/bindufy.pyInput is normalized into a list internally.
That list is passed to
X402AgentExtension:bindu/extensions/x402/x402_agent_extension.pyX402AgentExtensionnow accepts:When provided:
the full list is stored in
self.payment_optionsthe first entry is used to populate the existing attributes (
amount,token,network,pay_to_address)This keeps existing code working without changes.
The old constructor with flat arguments still works.
bindu/server/applications.py_create_payment_requirementsnow builds payment requirements frompayment_optionsif it exists.Each entry becomes a
PaymentRequirementsobject.Different options can use different
pay_to_addressvalues.Tests
File:
Total: 22 tests
Config validator
single dict
list with one option
list with multiple options
Nonemissing field
empty list (invalid)
non-dict entries (invalid)
invalid types
X402AgentExtension
single payment option
multiple options (primary = index 0)
backward compatibility with flat args
empty list validation
non-dict validation
missing
pay_to_addressrequired=FalsebehaviorPayment requirement generation
no extension →
Nonesingle option → one requirement
multiple options → multiple requirements
fallback path without
payment_optionsdifferent
pay_to_addressvaluesresource URL handling
Backward Compatibility
Existing agent configurations do not need modification.
Checklist
multi-option execution cost supported
single-dict configuration still works
tests added and passing
no breaking API changes
optional integration test with X402 middleware