Skip to main content

autogen-ucash

Microsoft AutoGen tools to charge per agent task via U.CASH (HTTP-402). Non-custodial.

autogen-ucash lets an AutoGen agent quote a price for a task and mint a U.CASH checkout link before the task runs. Funds settle directly to the merchant's own receive addresses: U.CASH is non-custodial, and the store Cloud Token used here is publishable (safe to ship in a browser, a tool, or an agent runtime). It can mint incoming checkouts; it cannot spend funds, read balances, or rotate keys.

Two checkout surfaces are supported:

  • Client-side hosted pay link (publishable, no server secret): builds a https://pay.u.cash/embed.php URL from the store Cloud Token.
  • Server-side tracked checkout (idempotent per external_reference): POST https://pay.u.cash/payment/ajax.php returns a recorded transaction plus its payment URL.

Install

pip install autogen-ucash            # core client + tool
pip install "autogen-ucash[autogen]" # also pulls autogen-agentchat

Requires Python 3.9+. The only hard runtime dependency is httpx. AutoGen itself is optional (install via the autogen extra).

Quick start: a standalone billing wrapper

from autogen_ucash import TaskBilling, TaskQuote

with TaskBilling(cloud_token="st_YOUR_STORE_CLOUD_TOKEN") as billing:
    result = billing.charge(TaskQuote(
        amount=0.50,
        currency="USD",
        title="Summarize support thread #4821",
        task_id="thread-4821",        # idempotency key
    ))
    print("Pay here:", result.payment_url)
    print("Transaction:", result.transaction_id)

task_id becomes the external_reference, so retrying the same task returns the same checkout instead of minting a duplicate. Settlement (the actual on-chain or card payment) is confirmed out of band by U.CASH via webhook / on-chain; charge() returns the checkout URL and does not block on payment.

AutoGen usage

Option A: AutoGen 0.2 (ConversableAgent)

from autogen import ConversableAgent, UserProxyAgent
from autogen_ucash import UcashPayTool, register_ucash

tool = UcashPayTool(
    cloud_token="st_YOUR_STORE_CLOUD_TOKEN",
    tracked=True,                 # server-side, idempotent checkout
    default_currency="USD",
)

assistant = ConversableAgent(
    name="billing_assistant",
    system_message=(
        "You bill the operator 0.50 USD per task by calling "
        "create_checkout BEFORE you start the work, then wait for them "
        "to confirm payment."
    ),
    llm_config={"config_list": [{"model": "gpt-4o-mini"}]},
)

user = UserProxyAgent(name="operator", human_input_mode="ALWAYS")

# Wire the tool: the executor runs it, the assistant knows it exists.
register_ucash(assistant, tool, executor=user, name="create_checkout")

user.initiate_chat(
    assistant,
    message="Summarize support thread #4821.",
)

Option B: any function-tool framework

UcashPayTool.create_checkout is a plain callable, so you can wrap it in any function-tool layer (AutoGen 0.4 tools, LangChain tools, OpenAI function calling, etc.):

from autogen_ucash import UcashPayTool

tool = UcashPayTool(cloud_token="st_YOUR_STORE_CLOUD_TOKEN", tracked=True)

checkout = tool.create_checkout(
    amount=0.50,
    currency="USD",
    title="Summarize support thread #4821",
    task_id="thread-4821",
)
# checkout -> {"payment_url": "...", "transaction_id": "...",
#              "external_reference": "thread-4821", "amount": 0.5, "currency": "USD"}

Function-tool schema for the create_checkout tool:

parameter type required description
amount number yes Amount to charge, in the given currency (> 0).
currency string no ISO 4217 code (default USD).
title string no Description shown on the checkout.
task_id string no Stable per-task id used as the idempotency key.

Low-level client

If you only need the pay.u.cash endpoints (no AutoGen), use UcashPayClient directly:

from autogen_ucash import UcashPayClient

client = UcashPayClient("st_YOUR_STORE_CLOUD_TOKEN")

# 1) Publishable, no network call (safe in the browser/app):
url = client.create_embed_link(
    amount=1.0,
    currency="USD",
    title="Agent task",
    external_reference="task-123",
    redirect="https://your.app/done",
)

# 2) Server-side, idempotent tracked checkout (call from a server route):
result = client.create_transaction(
    amount=1.0,
    currency="USD",
    title="Agent task",
    external_reference="task-123",   # required; idempotency key
    redirect="https://your.app/done",
)
# result.payment_url, result.transaction_id

Set up your pay.u.cash account

  1. Sign up at pay.u.cash, then click the verification link in the email.
  2. Set receive addresses under Settings -> Addresses (raw address, ENS, Unstoppable Domains, or FIO).
  3. Create a store under Account -> Stores and copy its Store Cloud Token (use the store-level token, not the account-wide one).
  4. For fiat cards, connect your own Stripe under Settings -> Payment processors.

How settlement works (and what this package does not do)

This package is non-custodial and opt-in optimistic: it mints the checkout and returns the URL. It does not:

  • hold funds (U.CASH settles directly to your receive addresses),
  • block the agent until the chain or card confirms, or
  • automatically reconcile payment status.

Confirm payment out of band (a U.CASH webhook on your server, on-chain polling, or an explicit operator "I paid" confirmation in chat) before treating a task as paid. The server-side create_transaction mode makes that reconciliation trivial: the same external_reference always maps to one transaction.

Limitations

  • No automatic crypto recurring billing. U.CASH does not support subscription debits on-chain; each task is a one-time checkout. For metered/subscription billing, mint a fresh checkout per period or per task.
  • Card acceptance requires your own Stripe. Connect it under pay.u.cash Settings -> Payment processors; the store Cloud Token only mints the checkout.
  • Idempotency is per external_reference. Reuse the same value to avoid double-minting; change it to force a new checkout.

Publish (for maintainers)

python -m pip install --upgrade build
python -m build
python -m twine upload dist/*

This package is distributed without publishing in this repo; the command above is the documented release path.

License

MIT. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autogen_ucash-0.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autogen_ucash-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file autogen_ucash-0.1.0.tar.gz.

File metadata

  • Download URL: autogen_ucash-0.1.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for autogen_ucash-0.1.0.tar.gz
Algorithm Hash digest
SHA256 535145085d4d559db845c13e92adb8c68f1061261bc29405c5b7ef9577380b38
MD5 2bca34e72a5dca0cf8d92a71c6b50d5c
BLAKE2b-256 af01e145330881a86b1c0f370cd7b3767651efda6ff228170bade73a39cf683d

See more details on using hashes here.

File details

Details for the file autogen_ucash-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autogen_ucash-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for autogen_ucash-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3c38d3047ea36d3bb388b80f4f8fb289d722aaa5be2514d2f6c9c38c7b0ccec
MD5 16c0fa7a0bb9d921bf029559cfd2a37c
BLAKE2b-256 4c2897179b8e8ae90a5ffae2285bfb0e8d126921b780a5d7f032db38fe458c44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page