Skip to main content
Getting Started

Core Concepts

Understand the mental model behind Gem Team's engineering workflow.

The Mental Model

Gem Team treats AI coding like software engineering - not chat. Here are the core concepts that make it work.

These are just agent definitions and system instructions - nothing complex, nothing hidden, no magic.


1. Orchestrator + Specialists

┌─────────────────────────────────────┐
│         ORCHESTRATOR                │
│  (Plans, Routes, Tracks, Reports)   │
└──────────────┬──────────────────────┘
               │ delegates
     ┌─────────┼─────────┐
     ▼         ▼         ▼
┌────────┐ ┌────────┐ ┌────────┐
│Planner │ │Implement│ │Reviewer│
└────────┘ └────────┘ └────────┘
     ▲         ▲         ▲
     │         │         │
┌────────┐ ┌────────┐ ┌────────┐
│Debugger│ │Researcher│ │DevOps  │
└────────┘ └────────┘ └────────┘

The Orchestrator never writes code. It classifies, plans, delegates, and verifies. Specialists do the actual work.


2. Five-Phase Workflow

Every task follows this pipeline:

PhasePurposeKey Decision
0. Init & ClarifyClassify request, assess risk, assign complexityWhat kind of work is this?
1. RouteSend to right path (fast path vs full plan)Direct to specialist or plan first?
2. PlanBuild wave plan with handoffs (MEDIUM/HIGH only)How to break down and order the work?
3. ExecuteRun waves, delegate to specialists, verifyDo the work, wave by wave
4. OutputStructured status report + learningsWhat happened and what's reusable?

3. Complexity Tiers

Phase 0 assigns one of four tiers based on supplied evidence only (no repo inspection):

TierWhenPlanningReviewPersistence
TRIVIALOne bounded change, no riskNone (fast path)NoneCorrelation ID only
LOWSmall, reversible, single domainIn-memory wave planNoneCorrelation ID only
MEDIUMMultiple dependent tasks, no high-riskPersistent plan.yamlIf risky/explicitFull plan artifacts
HIGHArchitecture, contracts, security, migrationsPersistent plan.yamlRequiredFull plan artifacts

4. Scoped Handoffs (The Secret to Efficiency)

Instead of dumping full context, each agent receives exactly what it needs:

task_definition:
  objective: "Add user authentication"
  acceptance_criteria:
    - "Login endpoint returns JWT"
    - "Passwords hashed with bcrypt"
  handoff:
    constraints:
      - "Use existing user schema"
      - "Follow API conventions in api/conventions.md"
    relevant_context:
      - "auth-middleware: file=src/middleware/auth.ts"
      - "user-model: schema=User, fields=id,email,password_hash"
    plan_context:
      architectural_boundaries: ["auth module", "api layer"]
      risk_decisions: ["stateless JWT", "refresh token rotation"]

Benefits:

  • ~80% token reduction vs full history
  • High cache hit rates (stable prefix)
  • No context bloat across waves

5. Three-Tier Memory

TierScopePersistenceWhat Gets Stored
RepoWorkspaceWith repositoryConventions, decisions, patterns, failure modes
SessionConversationUntil session endsTask evidence, intermediate findings
GlobalUserAcross workspacesCross-project learnings, preferences

Promotion rule: Only findings with confidence ≥ 0.95 after final success become repo memory.


6. Wave-Based Execution

Planned work runs in ordered waves - each completes before the next starts:

Wave 1: [Researcher] Explore codebase
                 ↓
Wave 2: [Planner] Create plan (if MEDIUM/HIGH)
                 ↓
Wave 3: [Implementer] Write code + [Tester] Verify
                 ↓
Wave 4: [Reviewer] Security/a11y check (if triggered)
                 ↓
Done: [Orchestrator] Report + promote learnings

Parallel within wave: Independent tasks run simultaneously (up to max_concurrent_agents).

Cluster optimization: Tasks sharing context merge into one - saves invocation + context copy.


7. Failure Classification (No Blind Retries)

Every failure gets a specific classification and routes to the right handler:

ClassificationMeaningHandler
needs_retryTransient issue (network, flaky test)Retry same task (max 3x)
fixableCode bugDebugger → Implementer
regressionPreviously working, now brokenDebugger (bisect) → Implementer
needs_replanScope wrong, dependencies missedPlanner (bounded replan)
flakyIntermittent failureSpecialist re-runs once
platform_specificWorks on one platform, not anotherSpecialist verifies criteria
test_bugTest itself is wrongDebugger → Implementer
blocked / escalateExternal dependency / needs humanStop, escalate to user

8. Skills = Reusable Patterns

When a workflow pattern proves stable and reusable, it becomes a Skill:

Successful Pattern
        │
        ▼
┌───────────────┐
│ Skill Creator │  (packages as SKILL.md)
└───────┬───────┘
        │
        ▼
┌───────────────┐
│ .apm/skills/  │  (available for matching tasks)
│ my-skill/     │
│   SKILL.md    │
└───────────────┘

Skills keep agent definitions focused while providing task-specific guidance.


Mental Model Summary

ConceptKey Insight
OrchestratorCoordinator, not executor
PhasesStructured pipeline, not free-form chat
ComplexityDrives planning depth and review requirements
HandoffsScoped, cache-friendly, evidence-by-reference
MemoryTiered, confidence-gated, promotes after success
WavesOrdered barriers, parallel within
FailuresClassified → routed to correct specialist
SkillsExtracted from success, not designed upfront

Common Mistakes & Anti-Patterns

MistakeWhy It FailsCorrect Approach
Inspecting repo during Phase 0 to "be sure"Phase 0 is evidence-only; no repo inspection allowedUse only supplied context and request
Asking clarifying questions preemptivelyPhase 0 asks only for true decision blockersAsk once, only when blocked
Lowering complexity to skip planningEvidence may raise complexity; never lowerLet evidence drive the tier
Reusing one plan_id for unrelated workPlan identity ties state to one objectiveNew task = new plan_id
Sending full history to every agentBreaks cache, wastes tokensScoped handoffs with evidence by reference
Retrying without classificationBlind retries hide root causesClassify → route to correct handler
Implementing without a failing testTDD is mandatory for code tasksRed → Green → Refactor

Edge Cases

SituationHandling
discuss intentPhase 4 direct answer, no plan, no delegation
research standalonegem-researcher → Phase 4; no plan unless promoted
challenge intentgem-reviewer critic mode → Phase 4; read-only
continue_plan without valid plan_idBlock; request exact ID; no inference
Missing acceptance criteria on MEDIUM taskPlanner cannot emit plan; ask once for criteria
High-risk signal on TRIVIAL taskComplexity raised to MEDIUM; persistent plan required
Flaky testSpecialist re-runs once; second failure blocks

Decision Table: Choose Your Path

Your SituationPathExample
One-line bug fix, single fileFast path (TRIVIAL)"Fix typo in README.md"
Small refactor, one domainFast path (LOW)"Extract validation helper"
New API endpoint, multiple filesFull plan (MEDIUM)"Add /api/users/search"
Architecture change, breaking changeFull plan (HIGH)"Migrate auth to OAuth2"
Research question, no codeResearch path"How does caching work?"
Decision review, tradeoffsChallenge path"Should we use Redis or DB?"
Continue existing workContinue plan (exact plan_id)"Resume plan 20261121-user-search"

Next Steps