◉ANTIGRAVITY LABJP
Articles/Agents & Manager
◈ Agents & Manager/2026-03-26Advanced

Multi-Agent Development with Antigravity — Building Autonomous AI Teams with AgentKit

Deep dive into AgentKit 2.0 multi-agent design patterns. 5 orchestration strategies, runaway prevention, cost control, and production-ready templates.

antigravity464multi-agent50agentkit13advanced20orchestration21agents-md8

Setup and context

The era of the single AI has passed. In 2026, orchestrating multiple specialized agents to build autonomous AI teams is a competitive advantage. Trends around "multi-agent," "swarm AI," and "runaway prevention" are accelerating because both the complexity and value of implementation are now visible.

This article introduces five production-grade multi-agent orchestration patterns using AgentKit 2.0's 16 specialist agents. You'll learn how to write AGENTS.md, leverage Manager Surface for oversight, and implement foolproof runaway prevention—all with real implementation examples.


1. AgentKit 2.0 Architecture

16 Specialist Agents

# AGENTS.md — Antigravity Agent Definitions
version: "2.0"
 
agents:
  # === Code Generation & Refactoring ===
  code-writer:
    description: "Generate new code, implement features"
    model: "gemini-3.1-pro"
    temperature: 0.7
    max_tokens: 4000
 
  code-reviewer:
    description: "Code quality audit, refactoring suggestions"
    model: "gemini-3.1-pro"
    temperature: 0.3
    max_tokens: 2000
 
  refactoring-expert:
    description: "Large-scale refactoring, architectural improvements"
    model: "gemini-3.1-pro"
    temperature: 0.5
    max_tokens: 3000
 
  # === Testing & Quality Assurance ===
  test-generator:
    description: "Auto-generate unit, integration, E2E tests"
    model: "gemini-3.1-flash"
    temperature: 0.3
    max_tokens: 2000
 
  test-reviewer:
    description: "Test case quality audit, coverage gaps"
    model: "gemini-3.1-pro"
    temperature: 0.4
    max_tokens: 1500
 
  # === Architecture & Design ===
  architect:
    description: "System design, scalability planning"
    model: "gemini-3.1-pro"
    temperature: 0.5
    max_tokens: 5000
 
  performance-analyzer:
    description: "Profiling, bottleneck identification, optimization"
    model: "gemini-3.1-pro"
    temperature: 0.4
    max_tokens: 3000
 
  # === Security & Compliance ===
  security-auditor:
    description: "Vulnerability scanning, penetration testing"
    model: "gemini-3.1-pro"
    temperature: 0.2
    max_tokens: 2500
 
  compliance-checker:
    description: "Regulatory compliance, license verification"
    model: "gemini-3.1-flash"
    temperature: 0.3
    max_tokens: 1500
 
  # === Documentation ===
  documentation-writer:
    description: "API docs, technical documentation auto-generation"
    model: "gemini-3.1-flash"
    temperature: 0.4
    max_tokens: 3000
 
  # === Data & DevOps ===
  data-analyzer:
    description: "Data transformation, schema optimization"
    model: "gemini-3.1-pro"
    temperature: 0.5
    max_tokens: 2500
 
  devops-engineer:
    description: "CI/CD optimization, deployment automation"
    model: "gemini-3.1-flash"
    temperature: 0.4
    max_tokens: 2000
 
  # === Communication & Learning ===
  technical-writer:
    description: "User guides, tutorials, learning materials"
    model: "gemini-3.1-flash"
    temperature: 0.6
    max_tokens: 3000
 
  code-explainer:
    description: "Code explanation, learning guides"
    model: "gemini-3.1-flash"
    temperature: 0.6
    max_tokens: 2000
 
  # === Specialists ===
  langsmith-optimizer:
    description: "LLM chain optimization, prompt engineering"
    model: "gemini-3.1-pro"
    temperature: 0.3
    max_tokens: 1500
 
  cost-analyzer:
    description: "Token usage, cost analysis, budget management"
    model: "gemini-3.1-flash"
    temperature: 0.2
    max_tokens: 1000

Critical Note: Each agent runs in isolation with separate context. Zero cross-contamination.


2. Five Orchestration Patterns

Pattern 1: Sequential

Use Case: Staged quality improvement (generate → review → test)

orchestration:
  pattern: "sequential"
  name: "Code Quality Pipeline"
 
  steps:
    - agent: "code-writer"
      input: "Build user authentication module"
      output_var: "generated_code"
 
    - agent: "code-reviewer"
      input: "{{ generated_code }}"
      output_var: "reviewed_code"
      condition: "quality_score > 7"
 
    - agent: "test-generator"
      input: "{{ reviewed_code }}"
      output_var: "test_suite"
 
    - agent: "security-auditor"
      input: "{{ reviewed_code }}"
      output_var: "security_report"
 
  # ===== Runaway Prevention =====
  max_iterations: 3
  loop_detection: true
  human_approval: true
  timeout_seconds: 300
  max_tokens_per_step: 4000
  total_token_budget: 20000

Benefits:

  • Clear stage visibility
  • Easy failure point identification
  • Explicit human approval timing

Pattern 2: Parallel

Use Case: Multi-perspective simultaneous evaluation (quality + security + performance)

orchestration:
  pattern: "parallel"
  name: "Multi-Perspective Audit"
 
  parallel_tasks:
    - agent: "code-reviewer"
      input: "{{ source_code }}"
      output_var: "quality_report"
 
    - agent: "security-auditor"
      input: "{{ source_code }}"
      output_var: "security_report"
 
    - agent: "performance-analyzer"
      input: "{{ source_code }}"
      output_var: "perf_report"
 
  wait_for_all: true
 
  # Cost Control
  parallel_token_limit: 3000  # per task
  max_concurrent_tasks: 3

Implementation:

const results = await orchestrator.parallel([
  { agent: 'code-reviewer', input: code },
  { agent: 'security-auditor', input: code },
  { agent: 'performance-analyzer', input: code },
]);
 
const synthesis = await orchestrator.synthesize(results);
// → { quality: 8.2, security: 9.1, performance: 7.5 }

Pattern 3: Router

Use Case: Dynamic agent selection based on input characteristics

orchestration:
  pattern: "router"
  name: "Smart Task Router"
 
  router_logic:
    - condition: "code_language == 'typescript'"
      agent: "code-writer"
      config:
        model: "gemini-3.1-pro"
        temperature: 0.7
 
    - condition: "task_type == 'security_audit'"
      agent: "security-auditor"
 
    - condition: "task_type == 'performance'"
      agent: "performance-analyzer"
 
    - default: "code-writer"
 
  # Safety Rails
  max_routing_depth: 2
  fallback_timeout: 60

Pattern 4: Orchestrator-Worker (Manager)

Use Case: Large projects with task decomposition and management

orchestration:
  pattern: "orchestrator-worker"
  name: "Project Manager Pattern"
 
  orchestrator:
    agent: "architect"  # Manager role
    instruction: |
      Decompose the task:
      1. Identify subtasks
      2. Assign to workers
      3. Aggregate results
      4. Enforce quality
 
  workers:
    - "code-writer"
    - "test-generator"
    - "documentation-writer"
    - "security-auditor"
 
  max_subtasks: 5
  worker_timeout_per_task: 180  # 3 minutes
  quality_threshold: 8.0
  max_iterations: 2

Pattern 5: Swarm

Use Case: Collaborative problem-solving (agents learn from each other)

orchestration:
  pattern: "swarm"
  name: "Collaborative AI Swarm"
 
  swarm_config:
    swarm_size: 4
    swarm_members:
      - "code-writer"
      - "code-reviewer"
      - "architect"
      - "test-generator"
 
    # === Communication ===
    consensus_required: true
    voting_strategy: "majority"
    max_consensus_rounds: 3
 
    # === Evolutionary Improvement ===
    iteration_count: 5
    fitness_function: "code_quality_and_test_coverage"
 
    # === Token Management ===
    swarm_token_budget: 50000
    token_per_agent: 10000
 
    # === Loop Prevention ===
    detect_stagnation: true
    stagnation_threshold: 3

3. Manager Surface for Team Oversight

Manager Surface provides a unified UI dashboard for all agents.

const managerSurface = {
  title: "Antigravity Development Team",
  layout: "grid",
 
  agents_panel: [
    {
      name: "code-writer",
      status: "idle",
      task: "Waiting for assignment",
      tokens_used: 0,
    },
    {
      name: "code-reviewer",
      status: "working",
      task: "Auditing UserAuthService.ts",
      tokens_used: 1852,
      efficiency: 92.3,
    },
  ],
 
  metrics: {
    budget: { total: 20000, used: 5234, remaining: 14766 },
    progress: 65,  // %
    quality: 8.4,
    cost_efficiency: 0.78,
  },
 
  timeline: [
    { stage: "Code Generation", duration: "12s", status: "✅" },
    { stage: "Code Review", duration: "8s", status: "⏳" },
    { stage: "Testing", duration: "pending", status: "⏱️" },
  ],
 
  controls: {
    pause_all: false,
    emergency_stop: false,
    adjust_budget: true,
  }
};

4. Runaway Prevention: Loop Detection & Cost Management

4.1 Loop Detection

safety_rails:
  loop_detection:
    enabled: true
 
    detect_patterns:
      - agent_output_matches_input:
          threshold: 0.95
          description: "Agent output mirrors input"
 
      - same_agent_called_twice:
          max_occurrences: 1
          description: "Agent can't improve further"
 
      - no_progress_after_iterations:
          iterations: 3
          quality_delta: 0.1
          description: "Stalled improvement"
 
    on_loop_detected:
      action: "pause"
      human_review: true
      message: |
        ⚠️ LOOP DETECTED: architect agent ran 4 times
        without meaningful improvement.

4.2 Token Budget & Iteration Limits

const safeguards = {
  max_iterations: 5,
  max_tokens_per_iteration: 4000,
  total_token_budget: 30000,
  timeout_minutes: 10,
 
  warn_at_80_percent_budget: true,
  require_approval_after_iteration_3: true,
 
  monitor: async (state) => {
    if (state.iterations >= 3) {
      const approval = await requestHumanApproval({
        quality: state.quality_score,
        tokens_used: state.tokens_used,
        budget_remaining: state.budget_remaining,
      });
 
      if (!approval) {
        return { action: 'HALT' };
      }
    }
 
    if (state.tokens_used > state.budget * 0.9) {
      console.warn(`⚠️ BUDGET WARNING`);
    }
  }
};

5. Production Template

# AGENTS.md — Production-Grade Template
version: "2.0"
name: "Enterprise SaaS Development Pipeline"
 
agents:
  code-writer:
    model: "gemini-3.1-pro"
    temperature: 0.7
    max_tokens: 4000
    expertise: "Full-stack implementation"
 
  code-reviewer:
    model: "gemini-3.1-pro"
    temperature: 0.3
    max_tokens: 2000
    expertise: "Code quality, design patterns"
 
  test-generator:
    model: "gemini-3.1-flash"
    temperature: 0.3
    max_tokens: 2000
    expertise: "Unit, integration, E2E tests"
 
  security-auditor:
    model: "gemini-3.1-pro"
    temperature: 0.2
    max_tokens: 3000
    expertise: "OWASP, CVE scanning"
 
  architect:
    model: "gemini-3.1-pro"
    temperature: 0.5
    max_tokens: 5000
    expertise: "System design, scalability"
 
orchestration:
  pattern: "orchestrator-worker"
 
  orchestrator:
    agent: "architect"
    role: "Project Manager"
    instruction: |
      Decompose feature into subtasks.
      Assign to workers. Monitor quality & budget.
      Escalate blockers.
 
  workflow:
    - name: "Feature Implementation"
      steps:
        - agent: "code-writer"
          timeout: 120
        - agent: "code-reviewer"
          quality_threshold: 7.5
        - agent: "test-generator"
          coverage_threshold: 80
        - agent: "security-auditor"
          risk_level: "low"
 
safety:
  max_iterations: 4
  loop_detection: true
  max_total_tokens: 50000
  timeout_minutes: 30
  human_approval_required_after_iteration: 2
 
monitoring:
  log_all_calls: true
  track_token_usage: true
  measure_quality: true

6. Real-World Example

Task: "Implement OAuth 2.0 with GitHub + Google providers"

Step 1: Architect → System Design
  ↓ (3,200 tokens)

Steps 2-4: Parallel (code-writer + security-auditor)
  ├─ code-writer: Implement OAuth endpoints
  │  ↓ (2,100 tokens)
  └─ security-auditor: Review OAuth implementation
     ↓ (1,800 tokens)

Step 5: test-generator
  ├─ Unit tests
  ├─ Integration tests
  ├─ E2E tests
  └─ Coverage: 92% (1,900 tokens)

RESULTS:
✅ Quality: 8.8/10
✅ Security: LOW risk
✅ Coverage: 92%
✅ Tokens: 8,800 / 20,000 (44% utilization)
⏱️ Time: 3m 42s

7. FAQs

Q: How do I prevent agent runaway?

A: Three layers:

  1. Loop Detection — Auto-detect repeated outputs
  2. Token Budget — Pre-set budget, operate within it
  3. Human Approval — Critical decisions (iteration 3+) need approval

This combo prevents runaway in ~90% of cases.

Q: AgentKit 2.0 vs Cursor Composer?

AspectAgentKit 2.0Cursor Composer
Automation⭐⭐⭐⭐⭐⭐⭐⭐
Control⭐⭐⭐⭐⭐⭐⭐⭐
Learning Curve⭐⭐⭐⭐⭐⭐⭐⭐⭐

Verdict: Large projects with multi-faceted oversight → AgentKit. Simple, hands-on control → Cursor Composer.

Q: AGENTS.md and Manager Surface—must I use both?

A: No. Use independently:

  • AGENTS.md only: CLI automation
  • Manager Surface only: Manual UI control
  • Both: Monitoring + automation (recommended for enterprise)

Conclusion

Multi-agent development isn't just "multiple AIs"—it's building professional team structures.

  • Five patterns for every use case
  • Runaway prevention is non-negotiable (loop detection + budget + human approval)
  • Manager Surface for visibility
  • Production-grade orchestration

In 2026, AI shifts from solo to team. Build your autonomous AI team with AgentKit 2.0.

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.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

◈ Agents & Manager2026-06-01
Capping Parallel Agents With a Token Budget — Designing a Guard That Stops Runaway Cost
Running many agents in parallel quietly inflates your token bill. This is not about shrinking prompts — it is about a governance layer that meters spend in real time and cuts it off at a budget. Full design and TypeScript implementation, drawn from my own overnight jobs.
◈ Agents & Manager2026-05-03
Multi-Agent CI/CD Quality Gate — Automating PR Review, Testing, and Security with Antigravity × GitHub Actions
A complete implementation guide for building a multi-agent CI/CD quality gate using AgentKit 2.0 and GitHub Actions. Covers parallel code review, test generation, and security scanning agents — with production cost management and pitfall solutions.
◈ Agents & Manager2026-04-28
Versioning and A/B Testing Prompts for Production AI Agents in Antigravity
Hard-coding prompts in production turns improvement into guesswork. This guide walks through registry design, A/B traffic routing, statistical promotion, and rollback — with code you can ship inside your Antigravity environment.