Agent Integration · Python · x402

Connect your agent
to Tally.

Drop the integration folder into your agent's project. The app generates the full .env block for you. Open the Agents tab, create a new connection, tap Copy .env block, paste. Everything pre-filled.

In practice: point your agent at the folder and tell it to read the contents. It figures out the rest on its own. We tested funding and x402 end-to-end by asking the agent to run both, no manual steps, no guidance needed. It just worked.

How it works
01
Agent requests budget
Calls request_funding()
02
Telegram notification
Amount + task description sent to your phone
03
Card tap authorizes
Funds a session for a set time window
04
Funds sweep back
Remaining USDC returns to vault automatically

tally_integration.zip

warm_vault_auth.py · tg_bot.py · .env.example · SETUP.md · demo scripts

Download ↓ View on GitHub ↗
Setup: 4 steps
1

Install dependencies

Python 3.10+ required. Install the three packages the skill uses.

pip install solana solders requests
2

Connect in the Tally app

Open the Tally app → Agents tab → New Connection. The wizard walks you through Telegram bot setup and generates a session keypair. At the end, tap Copy .env block.

That block has everything pre-filled: Telegram token, chat ID, session private key, vault address, and deep-link secret. Paste it directly into tally_integration/.env.

No Telegram bot yet? The wizard has step-by-step instructions inside the app under each field.
3

Fund your vault

Your vault needs SOL for gas and USDC for agent sessions. On devnet, both are free.

# SOL airdrop (replace with your vault address from Tally home screen)
solana airdrop 1 <YOUR_VAULT_ADDRESS> --url devnet

# USDC, use the Circle faucet (also creates the required USDC token account)
# https://faucet.circle.com
The Circle faucet creates the USDC Associated Token Account on your vault address. This is required for fund sweeps to work. Do it once before your first session.
4

Run the demo

Test the full x402 flow end-to-end. The agent hits the live paywalled endpoint, your phone gets a Telegram notification, you tap your card, real USDC moves on-chain, signal returned.

cd tally_integration
python3 run_x402_demo.py

Expected output:

→ GET tally.lll.mk/api/signal
← 402 Payment Required
→ Telegram notification sent
← Card tap received · Session funded
→ 0.1 USDC sent on-chain (tx: 3xKp...)
→ Waiting for propagation...
→ GET /api/signal + X-Tally-Session + X-Tally-Tx
← 200 OK
   signal: BULLISH | SOL/USDC | entry · target · stop loss · R:R returned
→ Funds swept back to vault
Quick usage

Request funding and execute a task. One card tap authorizes a budget for a time window, set with ttl in seconds. Every call inside that window reuses the same session, no re-tap.

from warm_vault_auth import request_funding, is_session_active, return_funds

# Sends Telegram notification, waits for one card tap.
# ttl=3600 means the tap authorizes spending for the next hour.
session = request_funding(
    amount_usdc=5.0,
    task_description="Research flight prices to Tokyo",
    ttl=3600,
)

# Reuse the session for every call inside the window. Only re-tap once it expires.
while work_remaining():
    if not is_session_active(session):
        session = request_funding(amount_usdc=5.0, task_description="more work", ttl=3600)
    do_one_call(session)

# Sweep residual back to vault when done
return_funds(session)

Hit a paywalled x402 API automatically:

from warm_vault_auth import request_with_payment

# Full x402 flow: 402 → card tap → USDC on-chain → signal → sweep back
result = request_with_payment(
    url="https://tally.lll.mk/api/signal",
    amount_usdc=1.0,
    task_description="Fetch SOL/USDC market signal",
    return_funds_after=True,
)

if result["ok"]:
    signal = result["data"]["signal"]
    print(signal["signal"])   # BULLISH / BEARISH
    print(signal["entry"])    # entry price
Standing budget · pay direct

The flow above funds a fresh session per task and sweeps the residual back. The second model skips the per-task tap entirely: with one card tap the user pre-authorizes a capped, time-boxed budget on Solana's allowances program (a FixedDelegation). The agent then pays merchants straight from the vault within that budget, no further taps. The cap and expiry are enforced on-chain and the cap decrements per payment, so the unspent remainder never leaves the cold vault — nothing to sweep back. Revoke one agent, or all of them, instantly.

No budget yet? The agent proposes one. The user gets a Telegram deep link that opens the app's Authorize Budget screen pre-filled, and approves with a single card tap.

from warm_vault_auth import request_budget, wait_for_budget

# Propose a budget. ttl_seconds accepts seconds or "7d" / "24h".
# Sends the user a Telegram deep link → Authorize Budget screen → one card tap.
req = request_budget(amount_usdc=15, ttl_seconds="7d", reason="60 signal API calls")

# Optionally block until approved (or poll budget_status() later).
budget = wait_for_budget(timeout_seconds=600)   # dict if approved, None on timeout

With a budget active, the agent pays directly — no tap, no sweep:

from warm_vault_auth import budget_status, pay_from_budget, request_with_payment

# Inspect the active budget (reads the on-chain FixedDelegation).
b = budget_status()
# → {"remaining_usdc": 14.0, "expiry_ts": 1769900000, "active": True}

# Pay a payee straight from the vault, within the cap. No card tap.
# Signed by the session key; the program checks cap + expiry and decrements on-chain.
sig = pay_from_budget(destination_pubkey="<PAYEE>", amount_usdc=1.0)

# x402 in budget mode: pay the endpoint directly, no tap, no sweep.
result = request_with_payment(
    url="https://tally.lll.mk/api/signal",
    amount_usdc=1.0,
    source="budget",
)

What's in the zip

warm_vault_auth.py
Core skill: request_funding (with ttl), is_session_active, check_balance, return_funds, request_with_payment — plus standing budgets: request_budget, budget_status, pay_from_budget
tg_bot.py
Telegram notifications: funding requests, payment confirmations, sweep alerts
.env.example
Config template with all TALLY_* variables documented
SETUP.md
Full setup guide including manual config, mainnet checklist, and troubleshooting table
SKILL.md
Quick reference for AI agents: function signatures and usage patterns
AGENT_PROMPT.md
System prompt and user message to trigger the x402 demo in any AI agent
run_x402_demo.py
Full x402 demo: hits the live paywalled endpoint, card tap, real USDC, signal returned
run_test.py
Smoke test: request funding and verify on-chain balance
test_session_policy.py
Unit tests for the time-bounded policy taps: ttl validation and is_session_active
run_return_funds.py
Sweep residual USDC back to vault from an existing session
run_send_only.py
Send-only: transfer USDC from a session that run_test.py already funded, no new card tap
run_spend_3to2.py
Demo variant: request 3 USDC via card tap, send 2 to a destination address
run_spend_test.py
End-to-end variant: request 2 USDC via card tap, send 1 USDC on-chain