Architecture

Agent Patterns

Consumer agents initiate payments on behalf of users. Fulfillment agents receive payments for delivered services. Evaluator agents attest completion for deferred work. Three composable patterns covering the full agentic commerce surface.

Two Core Agent Types

REAPP defines two composable runtime patterns. Consumer agents hold a delegated mandate and autonomously execute payments to acquire services. Fulfillment agents expose services behind x402 paywalls and receive payments from consumer agents. Both patterns ship as reference implementations in the SDK.

Consumer vs Fulfillment Agent Patterns
Consumer agents wrap fetch(). Fulfillment agents wrap Express middleware. Both patterns are covered by @reapp/sdk with minimal boilerplate.

Consumer Agent

import { createReappAgent, loadIntentMandate } from '@reapp/sdk';
import { createKeypairSigner } from 'x402-stellar-fetch';

const mandate = await loadIntentMandate(mandateId);

const agent = createReappAgent({
  mandate,
  signer: createKeypairSigner(agentKeypair), // agent key, NOT user key
  mandateContract: MANDATE_CONTRACT_ADDRESS,
  network: 'stellar:pubnet',
});

// Transparently handles full 7-step x402 flow
const data = await agent.fetch('https://api.dataservice.com/premium/report');

Fulfillment Agent

import express from 'express';
import { reappMiddleware } from '@reapp/sdk/express';

const app = express();

app.use(reappMiddleware({
  payTo: merchantStellarAddress,
  facilitatorUrl: 'https://facilitator.x402stellar.xyz',
  routes: {
    'GET /api/data/*':    { price: '0.10', asset: 'USDC' },
    'POST /api/compute':  { price: '1.00', asset: 'USDC' },
  },
  requireMandate: { 'POST /api/compute': true },
  registry: MANDATE_CONTRACT_ADDRESS,
}));

The Evaluator Agent — When It's Needed

x402 works perfectly when delivery and payment are coupled — agent pays, server instantly returns data. But deferred or qualitative work breaks this model. Translate a document, write code, design a logo — payment happens now, delivery happens later. How do you know the work was actually done and done correctly?

API Payments vs Task Payments
The evaluator pattern is only required when delivery and payment are temporally decoupled. For standard API calls, x402 is self-evidencing — no evaluator needed.

Three Evaluator Tiers

REAPP ships three evaluator implementations ordered by trust level and value. The appropriate tier is selected at job creation based on the task value and whether correctness is objectively verifiable.

Evaluator Tier Selection
Tier selection is based on task value and verifiability. Low-value deterministic tasks use self-attestation. High-value qualitative tasks use the community registry with staked collateral.

Escrow + Evaluator Lifecycle

Money goes into Soroban escrow at payment time. The evaluator attests completion. Escrow releases to the provider on approval, refunds to the client on rejection or expiry. No funds move until the evaluator signs — and the evaluator's reputation score is updated on-chain based on dispute outcomes.

Escrow Job State Machine
Seven terminal states. The timeout path (Funded → Expired) ensures clients are never locked out if a provider disappears. Evaluator collateral is slashed on provably bad attestations.

Evaluator Interface

interface ReappEvaluator {
  // Called by fulfillment agent when work is submitted
  submitWork(jobId: string, deliverableHash: string): Promise<void>;

  // Called by evaluator to attest completion
  attestCompletion(
    jobId: string,
    approved: boolean,
    reason?: string
  ): Promise<TxHash>;

  // On-chain: escrow releases to provider on approval,
  //           refunds to client on rejection or expiry
}
Tier 1
Self-attestation
Low value · No third party

Deterministic outputs: API responses, file downloads. Consumer agent verifies delivery itself.

Tier 2
Reference evaluator
Medium value · REAPP-maintained

Qualitative tasks. REAPP-maintained ADK agent uses LLM judge to assess quality vs specification.

Tier 3
Community registry
High value · Staked + reputation

Any third party — DAO, multisig, specialized AI. Evaluators stake collateral, build reputation on-chain.