Skip to content

[Hackathon Feedback] Multiple blockchain settlements per single agent request β€” deferred batch settlement neededΒ #161

@clriesco

Description

@clriesco

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

  1. Settlement session / accumulator β€” A SettlementSession context manager that decorators write to. Single settle_permissions() at the end.
  2. settle="deferred" parameter β€” Option on @requires_payment to skip settlement and store credit count in tool context.
  3. Agent-level decorator β€” @agent_requires_payment wrapping the entire agent, verify once + settle once.
  4. Facilitator batch settlement API β€” New endpoint accepting an array of charges, single blockchain tx.
  5. Verify-only mode + explicit settle β€” Decorators only verify; caller settles with total after execution.

Additional Context

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestfeedbackUser feedback from events and hackathonssdkSDK Issuex402

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions