Agentic Orchestration + x402 Tool Chaining on MongoDB Atlas
Paigent Studio is a workflow IDE that enables you to design and execute multi-agent workflows with automatic micropayments. Describe what you want to accomplish using voice or text, and our AI planner creates an optimal execution graph that pays for premium tools on-demand using USDC.
- π€ Voice-First Design - Describe workflows using natural language or voice input
- π€ Multi-Agent System - Specialized agents for planning, retrieval, negotiation, execution, and QA
- π° x402 Micropayments - Pay only for tools you use with USDC via Coinbase CDP
- π Real-Time Execution - Watch workflows execute with live SSE updates
- π Enterprise Security - SSRF protection, tool allowlisting, complete audit trails
- π Smart Tool Discovery - VoyageAI embeddings + MongoDB Atlas Vector Search
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PAIGENT STUDIO β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ β
β β Voice Input β β Text Input β β Graph Editor β β
β β (Whisper ASR) β β (Natural Lang) β β (React Flow) β β
β ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ β
β β β β β
β βββββββββββββββββββββββββΌββββββββββββββββββββββββ β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β PLANNER AGENT β β
β β (GLM-4.7 Thinking Model) β β
β β Intent β Workflow Graph (Nodes + Edges + Dependencies) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββΌββββββββββββββββββββββββ β
β βΌ βΌ βΌ β
β ββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββββββ β
β β RETRIEVER β β NEGOTIATOR β β EXECUTOR β β
β β (Tool Search) β β (Payment Logic) β β (Step Runner) β β
β β β β β β β β
β β VoyageAI + β β Budget checks, β β tool_call, β β
β β Atlas Vector β β approval gates, β β llm_reason, β β
β β Search β β pay decisions β β approval, branch, β β
β ββββββββββββββββββ βββββββββββββββββββ β wait, merge, β β
β β finalize β β
β βββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β AUDITOR AGENT β β
β β QA Review, Policy Compliance, Cost Analysis β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β DATA LAYER β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MongoDB Atlas β β
β β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β β
β β βworkspacesβ β runs β βrun_steps β βrun_eventsβ β receipts β β β
β β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β β
β β ββββββββββββ ββββββββββββ ββββββββββββββββββββββββββββββββββββ β β
β β β tools β βartifacts β β Vector Search Index β β β
β β ββββββββββββ ββββββββββββ ββββββββββββββββββββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β PAYMENT LAYER β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Coinbase CDP Server Wallet v2 β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββββ β β
β β β Agent Wallet β β x402 Protocolβ β Base Sepolia (USDC) β β β
β β β (Backend) β β (Payments) β β Testnet β β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Agent | Role | Model |
|---|---|---|
| Planner | Converts user intent into workflow graphs | GLM-4.7 Thinking |
| Retriever | Discovers relevant tools via vector search | VoyageAI + Atlas |
| Negotiator | Makes payment decisions based on budget/reputation | GLM-4.7 |
| Executor | Runs workflow steps with retry logic | - |
| Auditor | QA review and policy compliance checking | GLM-4.7 |
tool_call- External API calls (may require x402 payment)llm_reason- LLM analysis, summarization, decisionsapproval- Human approval gatebranch- Conditional branchingwait- Async pollingmerge- Join parallel branchesfinalize- Produce final output
- Node.js 18+
- MongoDB Atlas account
- Clerk account (authentication)
- Coinbase CDP account (payments)
- Fireworks AI account (LLM)
# Clone the repository
git clone https://github.com/yourusername/paigent.git
cd paigent
# Install dependencies
npm install
# Copy environment template
cp env.example .env.local
# Start development server
npm run devCreate a .env.local file with the following variables:
# Clerk Authentication
# Get from: https://dashboard.clerk.com/
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxx
CLERK_SECRET_KEY=sk_test_xxx
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard
# MongoDB Atlas
# Get from: https://cloud.mongodb.com/
MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/?retryWrites=true&w=majority
MONGODB_DB_NAME=paigent_studio
# Coinbase CDP Server Wallet
# Get from: https://portal.cdp.coinbase.com/
CDP_API_KEY_ID=your_api_key_id
CDP_API_KEY_SECRET=your_api_key_secret
CDP_WALLET_SECRET=your_wallet_secret
# Fireworks AI
# Get from: https://app.fireworks.ai/
FIREWORKS_API_KEY=fw_xxx
# VoyageAI (Optional - for vector search)
# Get from: https://dash.voyageai.com/
VOYAGE_API_KEY=
# Galileo (Optional - for observability)
# Get from: https://app.galileo.ai/
# See: https://v2docs.galileo.ai/sdk-api/typescript/sdk-reference
GALILEO_API_KEY=
GALILEO_PROJECT=paigent-studio
GALILEO_LOG_STREAM=production
# Cron Secret (generate a random string)
CRON_SECRET=your_random_secret_here- Create a MongoDB Atlas cluster (M0 free tier works)
- Create a database named
paigent_studio - The collections and indexes are created automatically on first run
- For vector search, create an Atlas Vector Search index named
tool_vector_indexon thetoolscollection
src/
βββ app/
β βββ (auth)/ # Sign-in/sign-up pages
β βββ (dashboard)/ # Authenticated dashboard pages
β β βββ dashboard/ # Main dashboard
β β βββ runs/ # Workflow runs
β β βββ tools/ # Tool registry
β β βββ wallet/ # Wallet management
β β βββ analytics/ # Usage analytics
β β βββ settings/ # Workspace settings
β βββ api/ # API routes
β βββ runs/ # Run CRUD + events SSE
β βββ wallet/ # Balance + faucet
β βββ asr/ # Voice transcription
β βββ cron/ # Background execution
βββ components/
β βββ dashboard/ # Sidebar, header
β βββ runs/ # Graph visualization, step nodes
β βββ ui/ # shadcn/ui components
βββ hooks/
β βββ use-voice-input.ts # Voice recording hook
β βββ use-run-events.ts # SSE subscription hook
βββ lib/
β βββ agents/ # Multi-agent system
β β βββ planner.ts # Intent β Graph
β β βββ executor.ts # Step execution
β β βββ retriever.ts # Tool discovery
β β βββ negotiator.ts # Payment decisions
β β βββ auditor.ts # QA review
β βββ cdp/ # Coinbase CDP integration
β β βββ client.ts # CDP SDK client
β β βββ wallet.ts # Wallet operations
β β βββ x402-fetch.ts # Payment-aware fetch
β βββ db/ # MongoDB
β β βββ client.ts # Connection
β β βββ collections.ts # Schema definitions
β β βββ queries/ # Query helpers
β βββ fireworks/ # LLM + ASR
β β βββ client.ts # OpenAI-compatible client
β β βββ asr.ts # Speech-to-text
β β βββ prompts/ # Agent prompts
β βββ voyage/ # Embeddings
β β βββ embeddings.ts # VoyageAI client
β βββ galileo/ # Observability
β β βββ client.ts # Trace logging
β βββ ssrf/ # Security
β βββ validator.ts # URL validation
βββ types/
βββ database.ts # Document schemas
βββ graph.ts # Workflow graph types
βββ api.ts # API payloads
// Create a new run
POST /api/runs
{
"workspaceId": "string",
"intent": "Summarize top 5 AI news articles",
"budgetMaxAtomic": "5000000", // 5 USDC
"autoPayEnabled": true
}
// List runs
GET /api/runs?workspaceId=xxx&status=running&page=1
// Get run details
GET /api/runs/[runId]
// Update run status
PATCH /api/runs/[runId]
{ "status": "canceled" }
// Subscribe to events (SSE)
GET /api/runs/[runId]/events// Get wallet balance
GET /api/wallet/balance
// Request faucet funds (testnet)
POST /api/wallet/fund// Process queued steps (Vercel Cron)
// Vercel Cron Jobs trigger this endpoint using GET requests.
// The CRON_SECRET is automatically sent via Authorization header.
GET /api/cron/tick
Authorization: Bearer {CRON_SECRET}
// Alternative POST endpoint for manual triggering/testing
POST /api/cron/tick
Authorization: Bearer {CRON_SECRET}1. Agent calls tool endpoint
2. Tool returns 402 Payment Required + PAYMENT-REQUIRED header
3. Negotiator checks budget limits
4. CDP wallet signs EIP-3009 authorization
5. Retry request with PAYMENT-SIGNATURE header
6. Tool verifies and processes payment
7. Tool returns response + PAYMENT-RESPONSE header
8. Receipt recorded in MongoDB
- SSRF Protection: All tool URLs validated against private IP ranges and cloud metadata endpoints
- Tool Allowlisting: Workspace-level domain allowlist
- Budget Controls: Per-step and per-run spending limits
- Approval Gates: Human approval for high-cost or sensitive operations
- Audit Trail: Every action logged in
run_eventscollection
| Category | Technology |
|---|---|
| Framework | Next.js 15 (App Router) |
| Language | TypeScript 5 |
| Styling | Tailwind CSS + shadcn/ui |
| Auth | Clerk |
| Database | MongoDB Atlas |
| Vector Search | Atlas Vector Search + VoyageAI |
| LLM | Fireworks AI (GLM-4.7) |
| ASR | Fireworks Whisper |
| Payments | Coinbase CDP Server Wallet v2 |
| Real-time | Server-Sent Events |
| Deployment | Vercel |
# Run development server
npm run dev
# Type checking
npm run type-check
# Linting
npm run lint
# Build for production
npm run build- Push to GitHub
- Import in Vercel
- Add environment variables
- Deploy
The vercel.json configures the cron job to run once daily at midnight UTC (Vercel Hobby tier limitation).
Set all variables from .env.local in your Vercel project settings.
MIT License - see LICENSE for details.
Built for the MongoDB AI Hackathon with:
β‘ Automate with intelligence. Pay only for what you use. β‘