DEV Community

Cover image for Agentic Fork Squad: Multi-Agent Database Query Optimizer with Tiger Cloud Zero-Copy Forks
HCo-Innova
HCo-Innova

Posted on

Agentic Fork Squad: Multi-Agent Database Query Optimizer with Tiger Cloud Zero-Copy Forks

Agentic Postgres Challenge Submission

What I Built
AgenticForkSquad (AFS) is an AI-powered database query optimizer that uses multi-agent collaboration to automatically improve slow SQL queries.

The system leverages Tiger Cloud's zero-copy forks to create isolated testing environments for three specialized AI agents (powered by Google Vertex AI):

🧠 Cerebro Agent (gemini-2.5-pro): Strategic planner & quality assurance

⚑ Operativo Agent (gemini-2.5-flash): Code generator & execution specialist

πŸ”§ Bulk Agent (gemini-2.0-flash): High-volume operations optimizer

Each agent analyzes the query in its own Tiger Cloud fork, proposes optimizations, runs benchmarks, and competes in a consensus engine that evaluates:

Performance improvement (50%)
Storage efficiency (20%)
Code complexity (20%)
Implementation risk (10%)

The winning optimization is automatically applied to the main database, and all forks are cleaned up.

Demo
🌐 Live Application: https://agentic-fork-squad.vercel.app
πŸ™ GitHub Repository: https://github.com/HCo-Innova/AgenticForkSquad
πŸ“š Documentation: See docs folder for complete architecture

Quick Start

Login with test credentials

Submit a query: SELECT * FROM tasks WHERE status = 'pending' ORDER BY created_at DESC

Watch real-time WebSocket updates as 3 agents process in parallel

Review consensus decision with benchmarks
See optimized query applied

Tiger Cloud Features Showcase

βœ… Zero-Copy Forks (Core Feature)
Every task creates 3 isolated database forks instantly:

// Real fork creation via Tiger MCP
forkID, err := mcpClient.CreateFork(ctx, mainService, "fork-cerebro-task1")
// Returns pre-created fork: gwb579t287 (Agent 1) or mn4o89xewb (Agent 2)

MCP enables programmatic fork management, making multi-agent workflows possible.

βœ… Multi-Agent Collaboration
Three agents work in parallel forks:

Cerebro analyzes query patterns in fork-cerebro
Operativo generates optimizations in fork-operativo
Bulk tests scalability in fork-bulk
All running simultaneously on Tiger Cloud without blocking each other.

βœ… Real PostgreSQL Features
Full access to Tiger Cloud's PostgreSQL 16:

Information schema introspection
EXPLAIN ANALYZE for benchmarks
Index creation/deletion in forks
Transaction isolation testing
Journey & Tech Stack
Architecture
Backend: Go 1.21 with Fiber v2 (Clean Architecture pattern)
Frontend: React 18 + TypeScript + Vite + Tailwind CSS
Database: Tiger Cloud PostgreSQL 16
AI: Google Vertex AI (3 Gemini models)
MCP: Tiger Cloud MCP Server
Real-time: WebSocket Hub for live updates

Workflow

User submits slow query
↓
Router assigns 3 agents based on query complexity
↓
TaskProcessor creates 3 Tiger Cloud forks via MCP
↓
Orchestrator executes agents in parallel (10min timeout each)
↓
Each agent: Analyze β†’ Propose β†’ Benchmark in its fork
↓
ConsensusEngine scores proposals (multi-criteria)
↓
Winner applied to main DB
↓
Forks deleted (cleanup)
↓
WebSocket broadcasts completion to UI

Key Implementation Details
Fork Management:

type MCPClient struct {
fork1URL string // gwb579t287 (pre-created)
fork2URL string // mn4o89xewb (pre-created)
mainURL string // wuj5xa6zpz
}

We use persistent pre-created forks to ensure reliability. Each agent gets assigned a dedicated fork ID.

Consensus Scoring:
func (ce *ConsensusEngine) Decide(
proposals []*OptimizationProposal,
benchmarks []*BenchmarkResult,
criteria ScoringCriteria,
) (*ConsensusDecision, error)

Weighted scoring prevents agents from over-optimizing single metrics.

Real-time Updates:
// 11 WebSocket event types
EventTaskCreated
EventAgentsAssigned
EventForkCreated
EventAnalysisCompleted
EventProposalSubmitted
EventBenchmarkCompleted
EventConsensusReached
EventOptimizationApplied
EventTaskCompleted
EventTaskFailed
EventConnectionEstablished

Users see every step of the multi-agent workflow live.

Why Tiger Cloud Made This Possible
Before Tiger Cloud: Multi-agent database testing required:

Complex database replication setup
Manual fork management
Storage costs for duplicated data
Synchronization headaches
With Tiger Cloud:

One line of code creates a fork: CreateFork(ctx, parent, name)
Zero storage overhead (copy-on-write)
Instant creation (no wait time)
Perfect isolation (agents can't interfere)
MCP standard (works with any MCP client)
This project would be impractical without Tiger Cloud's zero-copy forks. Traditional database cloning would make parallel agent execution too slow and expensive.

What's Next
Hybrid search integration (pg_text) for query pattern matching
PITR (Point-in-Time Recovery) for rollback testing
Agent learning from previous optimizations
Fluid Storage for dynamic fork lifecycle
Production deployment (Vercel + Railway)
Technical Highlights

Clean Architecture Layers:

Domain (entities, interfaces, values)
↓
UseCases (orchestrator, consensus, agents)
↓
Infrastructure (MCP, Vertex AI, PostgreSQL)
↓
Presentation (HTTP handlers, WebSocket)

Database Schema:

tasks - User-submitted queries
agent_executions - Agent activity logs
optimization_proposals - AI-generated solutions
benchmark_results - Performance metrics
consensus_decisions - Winning selections

Testing:
All Tiger Cloud interactions are production-ready:

Direct PostgreSQL connections to forks
Error handling for fork unavailability
Graceful degradation if MCP unreachable
Transaction safety in main DB

Conclusion
AgenticForkSquad demonstrates how Tiger Cloud's Agentic Postgres enables a new class of AI applications:

βœ… Multi-agent systems that need isolated testing environments
βœ… Parallel experimentation without storage penalties
βœ… Safe production updates via fork-test-apply workflow
βœ… MCP integration for programmatic database management

Tiger Cloud's zero-copy forks transformed database testing from a bottleneck into an enabler for AI collaboration.

Top comments (0)