-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestfeedbackUser feedback from events and hackathonsUser feedback from events and hackathonssdkSDK IssueSDK Issuex402
Description
Problem
When using decorator-based integrations (Strands @requires_payment, LangChain @requires_payment), each tool call triggers an independent blockchain settlement. In agentic flows where the LLM invokes multiple tools per request, this causes severe performance degradation.
Current behavior
Each decorated tool independently performs the full x402 cycle:
User Request
β tool_A β verify β execute β settle (blockchain write)
β tool_B β verify β execute β settle (blockchain write)
β tool_C β verify β execute β settle (blockchain write)
β Response to user
Performance impact
| Metric | 1 tool | 3 tools | 5 tools |
|---|---|---|---|
| Blockchain writes | 1 | 3 | 5 |
| Estimated added latency | ~2-5s | ~6-15s | ~10-25s |
Root cause
The @requires_payment decorator is stateless and isolated per tool. It has no awareness of the broader multi-tool execution, no shared context for credit accumulation, and calls settle_permissions() independently each time.
Desired behavior
User Request
β tool_A β verify β execute β accumulate 1 credit
β tool_B β verify β execute β accumulate 2 credits
β tool_C β verify β execute β accumulate 1 credit
β Single settlement: 4 credits (1 blockchain write)
β Response to user
Proposed Solutions
- Settlement session / accumulator β A
SettlementSessioncontext manager that decorators write to. Singlesettle_permissions()at the end. settle="deferred"parameter β Option on@requires_paymentto skip settlement and store credit count in tool context.- Agent-level decorator β
@agent_requires_paymentwrapping the entire agent, verify once + settle once. - Facilitator batch settlement API β New endpoint accepting an array of charges, single blockchain tx.
- Verify-only mode + explicit settle β Decorators only verify; caller settles with total after execution.
Additional Context
- Reported at the March 2026 hackathon event
- For agents routinely invoking 3-5+ tools, settlement latency dominates total response time
- Proposals build(deps): bump jinja2 from 3.1.3 to 3.1.4Β #2 and Create a Notebook that works as tutorial for
payments-pylibraryΒ #5 are lowest effort (decorator parameter change)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestfeedbackUser feedback from events and hackathonsUser feedback from events and hackathonssdkSDK IssueSDK Issuex402