Skip to main content
Guide

Smart & Efficient

Model routing, scoped handoffs, cache optimization, and proportional architecture.

Cost & Performance by Design

Every architectural decision optimizes for token efficiency and execution speed.


Model Routing (Configurable)

Two tiers match model strength to task complexity:

TierAgentsPurposeRecommended Models
PremiumPlanner, Debugger, ReviewerReasoning-heavy: planning, diagnosis, challenge, verificationgpt-5.6-sol, claude-4, gemini-2.5-pro
ExploreResearcher, Implementer, Browser Tester, Mobile Tester, DevOps, Documentation, Skill Creator, Code SimplifierFast exploration & bounded executiongpt-5.6-luna, claude-3.5-haiku, gemini-2.5-flash
# .gem-team.yaml
model_routing:
  enabled: true
  tiers:
    premium: "gpt-5.6-sol (openai)"
    explore: "gpt-5.6-luna (openai)"

Orchestrator not routed - Uses session default model. Enable in config to activate. This is the single biggest cost optimization for multi-agent workflows.


Scoped Handoffs (The 80% Token Reduction)

Each agent receives only what it needs - not full history.

flowchart LR
    subgraph Traditional [Traditional AI Chat]
        A1[Full History] --> B1[Agent]
        B1 --> C1[Full History + Response] --> D1[Next Agent]
    end

    subgraph GemTeam [Gem Team Scoped Handoff]
        A2[Plan Constant] --> B2[Task Handoff]
        A3[Cluster Shared] --> B2
        A4[Per-Task] --> B2
        A5[Per-Attempt] --> B2
        B2 --> C2[Agent]
        C2 --> D2[Minimal Output + Artifact Paths]
    end

    style GemTeam fill:#e8f5e9

Handoff Structure (Cache-Lifetime Order)

# Plan-constant (same for ALL tasks in plan)
plan_id: "20261121-user-search-api"
config_snapshot: { ... }

# Cluster-shared (same for tasks in same context_cluster)
context_cluster: "api-search"
shared_context: "REST patterns...; Pagination: src/utils/pagination.ts"

# Per-task (differs per task)
task_id: "implement-search"
task_definition:
  objective: "Implement GET /api/users/search"
  acceptance_criteria: [...]
  handoff:
    constraints: [...]
    relevant_context:
      - "research-api-patterns: patterns=REST, pagination=src/utils/pagination.ts"

# Per-attempt (only on retry)
retries_used: 1

Result: ~80% token reduction vs full history re-send.


Cache Optimization

LLM providers cache exact prompt prefixes. Gem Team maximizes hits:

TechniqueHow It Works
Stable system promptsAgent definitions don't change between tasks
Consistent handoff shapetask_definition structure identical across waves
Cache-lifetime field orderRetries diverge only in payload tail
Cluster-contiguous schedulingShared-context tasks run back-to-back
Minimal churnOnly new evidence appends; previous waves referenced

Observed Cache Performance (DeepSeek V4.1 Flash)

MetricValue
Tokens processed82.8M+ across 666 runs
Avg context/run~124K tokens
Typical API callSub-$0.001 (100K+ input, mostly cached)
Typical latency2-5s for 100K-190K input

Cost at Scale

Cache StateCost per 150K Call
100% miss$0.0225
95% cached~$0.00153
99% cached~$0.00067
100% hit$0.00045

30x cost difference between miss and hit - that's what makes sub-penny runs possible.


Evidence by Reference

Logs, traces, screenshots, reports stay in task artifacts - handoffs return paths.

# Agent output (minimal)
status: "completed"
handoff:
  implemented_files:
    - "src/api/users/search.ts"
  test_results_path: "wave-3/implement-search/artifacts/test-results.xml"
  api_contract_path: "wave-3/implement-search/artifacts/api-contract.json"

Exception: shared_context findings (consumed by ≥2 tasks) inlined once per cluster.


Proportional Architecture (YAGNI/KISS)

DecisionPrinciple
Agent setSmallest that satisfies criteria
Wave sequenceMinimum ordered barriers
Validation pathLeast review that covers risk
ContextBounded to objective

Fewer agents = less context multiplied = lower cost, faster execution.


Conditional Learning

Only stable, reusable, high-confidence findings promoted:

Promotion CriteriaThreshold
Final successAll waves complete
Confidence≥ 0.95
Stabilitystable: true (not task-specific)
ReusabilityApplies beyond this task
Non-duplicationNot already in memory

30-day TTL prevents stale accumulation.


Quick Wins Checklist

  • Enable model_routing.enabled: true in .gem-team.yaml
  • Use project-scoped installs (commit apm.lock.yaml)
  • Pin versions for reproducible cache (gem-team-v<version>)
  • Write specific acceptance criteria (enables fast path)
  • Avoid discuss intent for executable work (triggers full plan)
  • Reuse plan IDs for continued work (preserves cache)

Concrete Cost Scenarios

Scenario: MEDIUM feature with 5 tasks

ApproachTokens SentApprox Cost
Direct chat (5 tasks, full history each)~750K~$0.11
Gem Team (scoped handoffs, 95% cached)~240K~$0.003

Scenario: HIGH feature with 8 tasks

ApproachTokens SentApprox Cost
Direct chat (8 tasks, full history each)~1.2M~$0.18
Gem Team (scoped handoffs, 99% cached)~320K~$0.001

Rule of thumb: Gem Team cost scales with new work, not total conversation history.


Checklist: Verify Your Cache Hits

  • Plan-constant fields come first in every delegation payload
  • Cluster-contiguous scheduling used for shared-context tasks
  • No per-task fields before stable fields (prefix corruption)
  • Resumed plans load from plan.yaml, not reconstructed from conversation
  • shared_context inlined once per cluster, not per task