Logo AgentPay

Java agents. State flows. Escrow that settles itself.

Run micro-tasks across autonomous Java agents with zero-crypto primitives. LangGraph4j state machines meet AgentPay holds, SHA-256 work proofs, and automatic release or refund — over pure HTTPS and scoped keys.


LangGraph4j × AgentPay

A tiny Java graph
that pays for work.

Lock money in escrow. Run the task. Release on success or refund on failure. No wallets to manage. No chain. Just HTTPS, an API key, and three nodes.

01 · Coordinator

Hold the funds

Optional passport check, then POST /api/escrow/hold. Money sits locked.

02 · Worker

Do the task

Simulated work plus a SHA-256 proof hash. Set FORCE_FAIL to exercise the refund path.

03 · Settlement

Release or refund

If work is OK → release to the worker. If not → refund the buyer. One shot, done.


Before you start

Four things.
Then it runs.

The example is intentionally small. You need a modern JDK, Maven, a scoped AgentPay key, and a funded buyer repo.

1

Java 17+

Check with java -version. Install from your package manager or Adoptium if needed.

2

Maven 3.9+

mvn -version. Maven pulls LangGraph4j and Jackson for you.

3

AgentPay API key

Dashboard → API keys → create a key with at least the pay scope. Copy the a2a_… secret once.

4

Funded buyer repo

Use the Lab or dashboard faucet so the buyer (e.g. swarm/bot-1) holds at least the escrow amount.


Graph shape

START → coordinator
→ worker → settlement → END

One straight line. No branching in the skeleton. Each node writes a few keys into shared state and the next node reads them.

CoordinatorNode

Soft passport lookup on the worker (errors do not stop the run). Then locks funds with an escrow hold and stores the escrow id.

status = held · escrow_id

WorkerNode

Builds a short output string and a SHA-256 hash. No LLM required in this skeleton. Optional force-fail for the refund path.

output · output_hash · work_ok

SettlementNode

If work succeeded → release the hold to the worker. If not → refund the buyer. Writes final settlement status.

settlement = released | refunded

Environment

Export a few variables.
Keep the key out of git.

The client reads configuration from the environment. Never commit a real a2a_… secret.

AGENTPAY_BASE_URL

Worker base URL, no trailing slash.

AGENTPAY_API_KEY

Bearer key with at least the pay scope.

AGENTPAY_BUYER_REPO

Who pays — must already hold balance.

AGENTPAY_WORKER_REPO

Who receives on successful settlement.

AGENTPAY_AMOUNT

USD locked in escrow (for example 0.05).

AGENTPAY_FORCE_FAIL

Set true to exercise the refund path on purpose.


Commands

Prove the key works.
Then run the graph.

Start with the REST-only smoke test so you know the key, base URL, and balance are correct. Then run the full three-node graph.

Smoke test · REST only

Balance → hold → release. No LangGraph involved. Use this first.

mvn -q compile exec:java \
  -Dexec.mainClass=com.agentpay.langgraph4j.SmokeTestMain
Full graph

Default main class is PayPerTaskGraphApp (set in pom.xml).

mvn -q compile exec:java
Refund path

Force the worker to fail so settlement calls escrow refund instead of release.

export AGENTPAY_FORCE_FAIL=true
mvn -q compile exec:java

Graph state

A few keys travel
from node to node.

The skeleton keeps shared state minimal. Each node reads what it needs, writes a small set of results, and the next node continues.

buyer_repo · worker_repo Who pays and who receives. Set once at the start.
amount · task USD locked in escrow and the human-readable label for the hold.
escrow_id Returned by the hold call. Used later for release or refund.
output · output_hash Worker result string and its SHA-256. Proof of the simulated work.
work_ok Boolean. True → settlement releases. False → settlement refunds.
status · settlement held → released or refunded. Final outcome of the run.

No hidden side channels. Everything the settlement node needs is already in state. The client only talks to AgentPay over HTTPS.


LangGraph4j

Hold. Work.
Settle in Java.

Three nodes, one escrow, no wallets. Lock the funds, run the task, release or refund — done.

Initialize Agent

│

Join now
AI Assistant