🤖 AI & Agent Patterns

A. Workflow patterns (deterministic control flow, LLM inside)

PatternStructureUse whenOrbit use case
Augmented LLMLLM + retrieval + tools + memoryBase blockEverywhere
Prompt chainingStep 1 → gate → step 2 …Decomposable tasksUC8 content pipeline, UC9
RoutingClassify → specialized path/modelDistinct categoriesUC1 triage, UC7
Parallelization: sectioningIndependent subtasks in parallelSpeed, specializationUC10 PR reviewers
Parallelization: votingSame task N times → aggregateConfidence, safetyUC12 guard
Orchestrator–workersLLM plans subtasks dynamically → workers → synthesizeUnpredictable subtasksUC4 research
Evaluator–optimizerGenerate → critique → refine (bounded loop)Clear quality criteriaUC4, UC8
Map-reduce over documentsSummarize chunks → combineLong inputsUC5, meeting notes

B. Agent patterns (the LLM controls the flow)

PatternNotesOrbit
ReActThink → act (tool) → observe → repeatGo from-scratch agent
Plan-and-executePlan once, execute steps, re-plan on failureUC6 analyst
Reflection / self-critiqueAgent reviews its own outputUC4
Supervisor (hierarchical multi-agent)A manager routes to specialist agentsUC11
Handoffs / swarmAgents transfer control with contextUC1 → UC3
Human-in-the-loop ⭐Approve / edit / reject tool calls; interrupt + resumeUC3, UC7, UC8
Durable agentCheckpoint every step; resume after a crashLangGraph checkpointer, Orbit engine
Tool-use loop with budgetsMax steps/tokens/$, loop detectionAll agents

C. Retrieval patterns

Naive RAG → advanced RAG (query rewrite, hybrid search, rerank, contextual chunks) → agentic RAG (the agent decides when/what to retrieve) → corrective RAG (grade retrieved docs, re-search if poor) → GraphRAG (entity graphs, awareness) · Parent-child chunks · Metadata/ACL filtering · Citations

D. Memory & context patterns

Conversation buffer · summary memory (compact old turns) · vector memory (recall past facts) · entity/profile memory · scratchpad · context compaction · tool-result truncation/summarization · stable prefix for prompt caching

E. Reliability, safety & cost patterns

PatternWhat
Structured output + validate + repairSchema → validate → re-ask with the error (≤ N)
Guardrail sandwichInput guard → LLM → output guard
Dual LLM / quarantine ⭐A privileged LLM never sees untrusted text; a quarantined LLM processes it and returns only symbolic references (Simon Willison)
Capability-scoped toolsLeast privilege per agent/tenant; no generic “run any SQL”
Confirmation for side effectsIrreversible tools require approval
LLM-as-judgeRubric-based grading, calibrated against humans
Model cascade / routerCheap model first; escalate on low confidence
Fallback chainProvider A → B → cached/degraded answer
Semantic cacheReuse answers for similar queries (measure false hits!)
Idempotent tool callsIdempotency keys so retries don’t double-act
Prompt versioning + A/BPrompts are code: version, test, roll back
Batch inferenceOffline jobs through batch APIs at lower cost

🔬 Katas

  • Implement all 6 workflow patterns as Orbit workflow definitions (JSON) with one eval each
  • The same task (UC4) as (a) prompt chain, (b) orchestrator–workers, (c) autonomous agent → compare quality, cost, and latency in a table
  • Dual-LLM pattern vs naive: run 20 indirect-injection docs through both
  • Model cascade: find the confidence threshold that minimizes cost at ≥ 95% of the strong model’s quality