Skip to content

About

Autonomous AI Treasury Agent for Unicity Sphere

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

SphereFlow — Autonomous Procurement Treasury

SphereFlow is a policy-constrained agent that buys a recurring service on Unicity Testnet2 without a person approving each payment. An operator sets a standing goal and limits once. The agent service then discovers supplier quotes through the Sphere intent market, chooses an eligible counterparty, and settles a UCT payment with its own persisted wallet.

Submission declaration

Field Value
Track Autonomous agents / Payments and markets
Network Unicity Testnet2 (network ID 4)
Agentic Yes, when agent:run is deployed on a schedule. The worker makes and settles a purchase without a per-payment click.
AstridOS In progress — an Astrid capsule source is included, but do not claim the AstridOS XP boost until the capsule has been built and installed in an Astrid runtime.
Live dashboard https://sphereflow-psi.vercel.app

What is autonomous?

The dashboard is only the control plane. The economic action runs in agent/treasury-agent.mjs:

  1. Reads enabled procurement goals from Supabase.
  2. Searches Sphere's signed intent market for a matching service offer.
  3. Filters quotes by expiry, trusted-supplier setting, unit-price ceiling, rolling 24-hour budget, and interval budget.
  4. Claims one durable, idempotent job using a database lease.
  5. Sends UCT to the selected counterparty using the Testnet2 Node SDK wallet.
  6. Writes a hash-linked audit event and never re-sends an indeterminate settlement.

The agent wallet is separate from the browser wallet. Its key material lives only in SPHEREFLOW_AGENT_DATA_DIR, and the service-role database key never enters the dashboard bundle.

Architecture

Operator goal + limits → Supabase durable queue → SphereFlow worker
                                                ├─ Sphere intent market search
                                                ├─ deterministic policy selection
                                                ├─ Testnet2 UCT settlement
                                                └─ hash-linked audit trail

Run against Testnet2

Prerequisites: Node 22+, a Supabase project, and a funded Testnet2 Sphere wallet for the worker. Testnet UCT is self-minted through the official SDK; it is not mainnet value.

  1. Install app dependencies and copy .env.example to .env.local.
  2. Run supabase/migrations/20260727_autonomous_procurement.sql in the Supabase SQL editor.
  3. Set SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, and a non-shared SPHEREFLOW_AGENT_DATA_DIR. Never use a NEXT_PUBLIC_ name for the service key.
  4. On first boot, set SPHEREFLOW_AGENT_AUTOGENERATE=true, run npm run agent:run, save the generated wallet recovery phrase offline, then set it back to false.
  5. Fund the agent's Testnet2 wallet and register/publish its identity. Add at least one supplier service intent in the Sphere market. Its description must contain service=<tag>;recipient=<@nametag-or-DIRECT-address>; set its market price in UCT and its expiry normally.
  6. Insert an enabled procurement_goals row. Set service_tag to the offer tag and max_unit_price_uct to its maximum price. When require_trusted_supplier=true, set trusted_suppliers to the supplier's market agentPublicKey or recipient address—the supplier cannot self-attest into this allow-list.
  7. Run npm run agent:run from a persistent process, container, or scheduled job at least as often as the goal interval. The service needs a persistent volume for SPHEREFLOW_AGENT_DATA_DIR. For Astrid-controlled invocation, run node agent/treasury-agent.mjs --serve; it exposes an authenticated /tick endpoint only on loopback by default.

The app itself runs with npm run dev. Use npm run build before deployment (must pass for submission).

npm run agent:dry-run   # queue only
npm run agent:run       # one full autonomous tick
npm run agent:serve     # POST /tick on loopback for Astrid/cron

Follow-on operators: see docs/HANDOFF.md for remaining live-environment steps.

Reproducible acceptance demo

  1. Record the goal and the supplier's signed market offer.
  2. Run the worker with no dashboard interaction.
  3. Show the resulting procurement_jobs.transfer_id, the matching Testnet2 wallet history entry, and the agent_audit_events chain.
  4. Re-run the worker in the same interval: the unique idempotency key must prevent a second payment.
  5. Change the quote above the cap or let it expire: the job must be skipped, never paid.

Important safety properties

  • A database lease prevents concurrent workers from paying the same job.
  • A unique interval-derived idempotency key prevents duplicate scheduled work.
  • CERTIFICATION_UNCONFIRMED becomes sent_pending_confirmation; it is deliberately never retried as a new send.
  • The database tables have RLS enabled and are accessed by the worker using the Supabase service role only.
  • The worker’s intent-market parser intentionally rejects offers without the required machine-readable quote fields.

AstridOS path

astrid/sphereflow-procurement/ contains the capsule manifest and source for an Astrid capability-gated tick tool. Install Astrid, install the official JavaScript capsule SDK, build the capsule, and wire its HTTP tool to a privately authenticated worker endpoint before claiming the Astrid boost. The current browser “Astrid-aligned” controls are product UX only and are not the Astrid runtime.

About

Autonomous AI Treasury Agent for Unicity Sphere

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages