Antigravity's AgentKit 2.0 provides a powerful framework for building multi-agent systems where multiple agents collaborate to accomplish complex tasks. This guide walks you through designing, implementing, and operating agent orchestration systems that reliably run in production environments, complete with real-world code examples.
AgentKit 2.0 Architecture Overview
AgentKit 2.0 distributes large-scale task processing across multiple agents through three primary roles:
Manager Agent (Orchestration Lead)
Receives user requests and analyzes/decomposes tasks
Delegates work to Surface Agents with orchestration
Aggregates results from multiple Surfaces and generates final response
Implements error handling and fallback strategies
Surface Agent (Domain Specialist)
Executes processing specialized to specific domains (data analysis, text generation, image processing)
Manages Worker Agents based on clear Manager directives
Makes complex judgments within expertise area and optimizes workflows
Worker Agent (Execution Unit)
Executes concrete tool invocations, API integrations, and data processing
Takes instructions from Surface Agent and focuses on single responsibility
Reports back error logs and execution metrics
This hierarchy provides clear separation of concerns, allowing each layer to be tested and scaled independently.
Declarative Definition with agents.md
AgentKit 2.0 defines your entire agent system in a declarative agents.md file:
# Company Analytics System## Manager: AnalyticsOrchestratorrole: Coordinates data collection and reportinginstructions: | 1. Parse user queries for analytics scope 2. Delegate to DataCollector and ReportGenerator in parallel 3. Merge results with cross-validation 4. Return formatted dashboard JSON## Surface: DataCollectorrole: Gathers metrics from multiple sourcesdelegated_workers: - GoogleAnalyticsWorker - StripeWorker - CustomMetricsWorkerinstructions: | Normalize all metrics to common schema Validate completeness before returning## Worker: GoogleAnalyticsWorkerrole: Fetch GA4 data via APIinstructions: | 1. Authenticate with service account 2. Query date range from parent instruction 3. Transform response to standard format 4. Return with timestamp
This markdown approach makes your agent system architecture immediately clear to the entire team and enables straightforward version control.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦Understand AgentKit 2.0 Manager/Surface/Worker architecture to design scalable agent systems
✦Master implementation patterns for task decomposition, parallel execution, and result aggregation to automate complex workflows
✦Build production-grade operational infrastructure including error recovery, cost control, and security sandboxing
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
The Manager Agent must decompose complex requests appropriately and delegate to multiple Surfaces/Workers in parallel. Here's an e-commerce order processing example:
// Manager Agent: OrderProcessingOrchestratorconst managerInstructions = `You are the Order Processing Manager. Your role is to:1. Parse incoming orders and validate structure2. Delegate payment processing to PaymentSurface (parallel)3. Delegate inventory management to InventorySurface (parallel)4. Delegate notification to NotificationSurface (parallel)5. Aggregate results and detect conflicts6. If conflicts detected, trigger RollbackSurface7. Return final order status with timestampError handling:- If any Surface returns timeout, delegate to TimeoutRecoveryWorker- Log all delegations with parent_task_id for tracing`;// Implementation in AgentKit 2.0const manager = new Manager({ name: 'OrderProcessingOrchestrator', model: 'claude-opus', instructions: managerInstructions, surfaces: [ 'PaymentSurface', 'InventorySurface', 'NotificationSurface', 'RollbackSurface' ], parallel_workers: 3, // Max concurrent Surface invocations timeout: 30000, // 30 seconds total});
When the Manager delegates to Surfaces, context information (user ID, request metadata, timestamp) is automatically propagated. This ensures traceability across all layers.
Surface Agent Domain Specialization and Parallel Execution
Surface Agents receive high-level Manager directives and execute multiple Workers in parallel. Here's a data analysis Surface example:
// Surface Agent: DataAnalysisSurfaceconst surfaceInstructions = `You are the Data Analysis Surface. Your responsibilities:1. Receive analysis requests from Manager2. Decompose into atomic analysis tasks: - StatisticalAnalysisWorker (descriptive stats, correlations) - AnomalyDetectionWorker (outlier identification) - TrendAnalysisWorker (time-series forecasting)3. Execute Workers in parallel using delegation_ids4. Validate consistency across results5. Synthesize findings with confidence levelsFor each Worker result:- Check for data quality issues- Map outputs to common schema- Assign confidence scores- Return integrated analysis report`;// Parallel Worker executionconst surface = new Surface({ name: 'DataAnalysisSurface', model: 'claude-sonnet', instructions: surfaceInstructions, workers: { StatisticalAnalysisWorker: { role: 'Descriptive statistics and correlations', timeout: 15000 }, AnomalyDetectionWorker: { role: 'Outlier detection and validation', timeout: 15000 }, TrendAnalysisWorker: { role: 'Time-series forecasting', timeout: 15000 } }, max_parallel: 3,});
The critical point: Surface Agents don't just aggregate Worker results; they perform cross-validation, detecting inconsistencies and mismatches. This significantly improves reliability in production.
Worker Agents and Tool Chain Design
Worker Agents handle concrete tool invocations and external API integrations. The Tool Chain architecture lets workers compose multiple tools into complex workflows:
// Worker Agent: DatabaseQueryWorkerconst workerInstructions = `You are the Database Query Worker. Execute with precision:1. Receive query specification from parent Surface2. Build parameterized SQL (using prepared statements)3. Execute against READ_REPLICA for non-blocking reads4. Transform results to standard JSON schema5. Log execution metrics (rows returned, duration, memory)Available tools:- execute_read_query(sql, params, timeout=5000)- validate_schema(data, schema_id)- log_execution_metric(metric_name, value)Security constraints:- Maximum 10,000 rows per query- Queries must match pre-approved patterns- Log all parameters for audit trail`;// Tool Chain configurationconst toolChain = { tools: [ { name: 'execute_read_query', description: 'Execute SELECT query on replica', input_schema: { sql: { type: 'string', description: 'Parameterized SQL' }, params: { type: 'array', description: 'Query parameters' }, timeout: { type: 'number', default: 5000 } } }, { name: 'validate_schema', description: 'Validate result against schema', input_schema: { data: { type: 'object' }, schema_id: { type: 'string' } } }, { name: 'log_execution_metric', description: 'Log performance metrics', input_schema: { metric_name: { type: 'string' }, value: { type: 'number' } } } ]};const worker = new Worker({ name: 'DatabaseQueryWorker', model: 'claude-haiku', // Cost-optimized for simple tasks instructions: workerInstructions, tools: toolChain, execution_timeout: 30000,});
This approach leverages the LLM's generality while ensuring reliable system integration through tools.
Error Recovery and Distributed Transactions
Production environments inevitably encounter network latency, timeouts, and partial failures. AgentKit 2.0 supports sophisticated error recovery patterns:
Feedback Loop: Regularly collect user feedback, error logs, and performance metrics to refine your system.
A Note from an Indie Developer
Key Takeaways
Antigravity AgentKit 2.0 is a comprehensive framework for building scalable, reliable multi-agent systems. By combining Manager/Surface/Worker architecture, context sharing, error recovery, cost optimization, and security sandboxing, you can build production-grade AI-driven applications.
Through gradual rollout and continuous monitoring, establish a stable operational foundation that scales with your business needs.
Share
Thank You for Reading
Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.