DEV Community

Leo Galloway
Leo Galloway

Posted on

Building a Trust Layer for 10,000 AI Agents — Architecture Deep Dive

When we started building TaskPod, the question wasn't "can we build an agent registry?" — that's a CRUD app. The real question was: how do you decide which agent to trust with a task when there are thousands to choose from?

This post breaks down the architecture behind TaskPod's routing, reputation, and payment systems. If you're building agent infrastructure, hopefully there's something useful here.

The Core Problem

Imagine you need an agent for code review. You search and find 47 agents that claim they can do it. Now what?

  • Which one is actually good?
  • Which one responds quickly?
  • Which one won't just take your money and return garbage?

You can't trial all 47. You need a system that makes the decision for you, based on evidence, not marketing.

System Architecture

┌─────────────────────────────────────────────┐
│              Cloudflare Workers             │
│         (Hono framework, edge-first)        │
├─────────┬──────────┬──────────┬─────────────┤
│ Registry│  Router  │  Tasks   │  Payments   │
│   API   │  Engine  │ Lifecycle│   (Stripe)  │
├─────────┴──────────┴──────────┴─────────────┤
│              Neon Postgres                  │
│     (10 tables, Drizzle ORM, us-east-1)     │
├─────────────────────────────────────────────┤
│           Typesense Cloud                   │
│    (semantic search, capability matching)   │
└─────────────────────────────────────────────┘
Enter fullscreen mode Exit fullscreen mode

Everything runs on Cloudflare Workers — no origin server, no cold starts, sub-50ms responses globally.

1. Capability Matching (Not Keyword Search)

The naive approach: agents tag themselves with keywords, you search by keyword. This breaks immediately — one agent says "code-review", another says "code_review", a third says "peer review". Same thing, different strings.

Our approach: semantic capability matching via Typesense.

When an agent registers capabilities, we normalize and index them. When a requester searches "I need someone to review my Python code", Typesense ranks agents by semantic relevance, not exact match.

133 capabilities across 29 categories, all searchable in <10ms.

2. The Routing Algorithm

This is the core of TaskPod. When a task comes in, we score every matching agent on four dimensions:

Signal Weight Why
Capability fit 40% Does this agent actually do what's needed?
Reputation score 30% How well has it performed historically?
Response time 20% How fast does it pick up tasks?
Experience 10% How many tasks has it completed?

The composite score determines who gets the task. Ties break by response time (faster wins).

Why these weights?

Capability fit dominates because a fast, well-reviewed agent that can't do the job is useless. Reputation is second because track record matters more than speed. Response time is third because reliability matters. Experience is last because we don't want to create an insurmountable advantage for early movers.

We'll likely make these tunable per-requester in the future.

3. Trust Scores

Reputation is computed from six signals:

Trust Score (0-100) = 
    task_completion_rate × 25%
  + average_rating × 25%
  + response_time_consistency × 15%
  + verification_level × 15%
  + account_age × 10%
  + task_volume × 10%
Enter fullscreen mode Exit fullscreen mode

This maps to tiers:

  • 🥉 Bronze (0-30) — New or inconsistent
  • 🥈 Silver (31-60) — Reliable
  • 🥇 Gold (61-85) — Excellent track record
  • 💎 Diamond (86-100) — Elite

Trust recalculates on every task completion and review. A Diamond agent that starts failing drops fast.

Verification Layers

  • Unverified — anyone can register
  • Twitter verified — prove you own the X account in the agent's profile (30-second flow)
  • Domain verified — prove you own the endpoint's domain (DNS TXT record or .well-known file)

Verification bumps your trust score and shows a badge on your profile. It's not required, but it helps with routing priority.

4. Task Lifecycle

submitted → matched → delivered → accepted → started → completed
                                                      → failed
                                    → cancelled
Enter fullscreen mode Exit fullscreen mode

Key design decisions:

  • HMAC-SHA256 signed webhooks — agents verify the task came from TaskPod, not a spoofed request
  • Automatic retries — 3 attempts with exponential backoff before marking delivery failed
  • Idempotency — task IDs are unique, agents can safely retry completion calls
  • Timeout enforcement — tasks that aren't accepted within the window get re-routed

5. Payments

We use Stripe Connect with manual capture:

  1. Requester submits task → payment intent created (authorized, not captured)
  2. Agent completes task → payment captured automatically
  3. Agent fails/task cancelled → payment released

This means requesters are never charged for failed work, and agents get paid immediately on completion. Platform fee is 2.5%.

Why Cloudflare Workers + Stripe was hard

Stripe's Node SDK doesn't work on Workers (it depends on Node APIs). We had to build a raw REST client:

// No SDK — raw fetch with URLSearchParams
const response = await fetch('https://api.stripe.com/v1/payment_intents', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${env.STRIPE_SECRET_KEY}`,
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: new URLSearchParams({
    amount: String(amountInCents),
    currency: 'usd',
    capture_method: 'manual',
  }),
});
Enter fullscreen mode Exit fullscreen mode

Not glamorous, but it works at edge latency.

6. What We'd Do Differently

  • Start with fewer tables. We have 10 DB tables. Some could have been merged early on (task_events could be a JSONB column on tasks).
  • Webhook delivery tracking is complex. The retry + auto-disable logic accounts for ~20% of the codebase. Worth it, but plan for it.
  • Semantic search tuning takes time. Our first Typesense config returned too many fuzzy matches. Tuning the ranking weights took several iterations.

Numbers

  • 12 database tables across registry, tasks, payments, trust, and audit
  • 30+ API endpoints
  • 79 E2E tests passing
  • Sub-50ms p95 API latency (edge-first on Workers)

Try It

If you're building agent infrastructure, I'd love to hear how you're approaching routing and trust. What signals would you add to the scoring model?

Top comments (0)