Skip to content

feat(a2a): formalize agent-to-agent payment protocol spec + fix tests#25

Open
kite-builds wants to merge 1 commit intokcolbchain:mainfrom
kite-builds:feat/a2a-payment-spec
Open

feat(a2a): formalize agent-to-agent payment protocol spec + fix tests#25
kite-builds wants to merge 1 commit intokcolbchain:mainfrom
kite-builds:feat/a2a-payment-spec

Conversation

@kite-builds
Copy link
Copy Markdown

Summary

Closes #2.

Three concrete things, all grounded in the actual code:

1. New RFC-style spec at docs/agent-payment-protocol.md

Formalizes what was implicit in src/payment_protocol.py:

  • Every PaymentRequest field with type, required-ness, and meaning
  • Canonical wire encoding (sort_keys=True + tight separators) so the JSON is byte-deterministic
  • content_hash semantics — excludes created_at and status so two requests for the same payment intent hash identically
  • State-machine + lifecycle diagrams (happy path + refund path)
  • Multi-chain section (current: EIP-155 chain_id; future: CAIP-2 for non-EVM)
  • Backwards-compat notes for the two behavior changes below

2. Fix content_hash determinism in src/payment_protocol.py

Previously the hash included created_at (Unix epoch from time.time()), so two PaymentRequest objects with identical payment data but different instantiation times produced different hashes. That contradicted the docstring's "content-based hash for integrity check" promise.

New behavior: content_hash excludes created_at and status. For replay protection, agents should use request_id (UUID) — that's what it's there for.

3. Fix parse_wei("N wei") in src/payment_protocol.py

multiplier = {
    "ETH": 10**18,
    "wei": 1,        # ← lowercase, .upper() returns "WEI", falls through to default
    "KETH": 10**21,
}.get(currency.upper(), 10**18)

parse_wei("1000000000000000000 wei") was returning 10^36, not 10^18. Fix: uppercase the dictionary keys.

4. Make tests/test_payment_protocol.py collectible

The file had def/events(self): (literal / in a method name) on line 56, which made the whole file a SyntaxError and prevented pytest from collecting any of the 10 tests in it. Fixed and added the missing MockEvents stub the file referenced.

Test results

$ python -m pytest tests/ --ignore=tests/test_nonce_manager.py
50 passed in 0.25s

test_nonce_manager.py has a pre-existing missing-dep issue (sortedcontainers not in any requirements file) that's outside this PR's scope.

What this PR does NOT cover

Issue #2 mentions "multi-chain support" as a goal. v1.0 of the spec explicitly captures EIP-155 chain_id and flags CAIP-2 chain identifiers as future work in §7 / §9. Implementing actual non-EVM settlement (Solana, Stellar) is a separate larger PR — happy to follow up if you want a v1.1 design proposal.

Closes kcolbchain#2 ("Add agent-to-agent payment protocol").

Changes:

1. docs/agent-payment-protocol.md — RFC-style v1.0 spec covering:
   - Message format (every PaymentRequest field with type + required-ness)
   - Canonical wire encoding (sort_keys + tight separators)
   - Content-hash semantics (excludes created_at, status)
   - State machine + lifecycle diagrams (happy path + refund path)
   - Multi-chain considerations (EIP-155 chain_id, CAIP-2 future work)

2. src/payment_protocol.py: PaymentRequest.content_hash() now excludes
   created_at and status so two requests representing the same
   payment intent hash identically. Previously the hash drifted with
   wall-clock time, which contradicted the dataclass docstring's
   "content-based hash for integrity check" promise.

3. src/payment_protocol.py: parse_wei("N wei") now returns N. The unit
   dict had a lowercase "wei" key while .upper() was applied to the
   incoming unit, so "wei" silently fell through to the ETH default
   and returned N * 10**18. Both tested.

4. tests/test_payment_protocol.py: fix syntax error (`def/events`)
   that prevented the entire file from being collected, and add the
   missing MockEvents stub the test infrastructure expected.

Test status: 50/50 passing in tests/ excluding test_nonce_manager.py
(which has a pre-existing missing-dep issue unrelated to this PR).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add agent-to-agent payment protocol

1 participant