Skip to content

Sidekick Routing Pipeline

How a user message becomes a response. Four tiers (trivial, simple, standard, complex) + trivial fast-path. Performance + correctness depend on it being right.

How a user message becomes a response. Every chat hits this pipeline. Performance + correctness depend on it being right.

TierModelToolsContext GatherTypical LatencyWhen
trivialFAST_MODELdisabledskipped< 2sGreetings, time/date, identity, chitchat, acks
simpleFAST_MODELenabledminimal3–5sShort factual lookups, single-entity queries
standardCAPABLE_MODELenabledmedium5–15sSynthesis, search, multi-step, external, actions
complexFLAGSHIP_MODELenableddeep15–30sReports, deep analysis, strategy

Constants live in server/services/router/model-constants.ts — never hardcode raw provider model strings.

The trivial fast-path (the key optimization)

Section titled “The trivial fast-path (the key optimization)”

Pure regex classification in IntentClassifier.TRIVIAL_PATTERNS that fires before pattern scoring and LLM classification. When matched:

  • Skips enrichWithTools
  • Skips preGatherContext
  • Skips Brain fetch
  • Skips live queries
  • Skips thinking mode
  • Goes straight to FAST_MODEL which answers from the system prompt (time, user name, timezone are always injected there)

Impact: “what time is it” went from ~30s → ~2s.

Queries are never trivially fast-pathed if:

  • They contain action verbs (create, add, schedule, etc.)
  • They’re longer than 80 chars
  • Search mode is not smart
  1. Add a regex to TRIVIAL_PATTERNS in intent-classifier.ts
  2. Add unit tests in tests/unit/router/trivial-fast-path.test.ts
  3. Run npm run test:unit -- trivial
  4. Update this page with the new pattern category

User-selected modes:

User picksWhat that means
Quick”I just want an answer.” Tools disabled by default.
Autopilot (default)“Do what you think is right.” Full tools, full context.
Deep Think”Take your time, reason harder.” Extended thinking, flagship model.
Code”I’m pairing on code.” Sandbox tools, 32k token budget.

Auto-elevation: if user picks Quick but their message needs a tool, the Sidekick transparently elevates to Autopilot for that turn. Implemented in buildModeElevation() in sidekick-chat-runtime-service.ts.

Users can scope Sidekick’s knowledge per chat:

ScopeBehavior
Smart (default)Full pipeline: Brain + web + memory
InternalBrain + memory only — skip web
ExternalWeb only — skip Brain/memory/live queries

Slash commands /quick, /auto, /think switch modes mid-conversation.

Every Sidekick turn assembles a context envelope before calling the model. Order of operations:

  1. Ambient context (always injected): explicit day name, full date, timezone, user, active integrations
  2. Context tags (explicit @ or + mentions): person, project, Brain doc, Brain folder
    • When explicit Brain tags are present, auto Brain semantic search is skipped — pinned context wins
    • Brain document tag: injects up to 8k chars of content (or summary + tool hint for file-backed)
    • Brain folder tag: injects up to 5 docs × 1500 chars from the folder
  3. Auto Brain semantic search (only if no explicit Brain tags): top results above similarity threshold
  4. Live queries: tasks due today, calendar events in next 4h, unread thread messages
  5. Memory: working memory snippets relevant to the message
  6. Conversation history: previous N turns in the same chat/thread

Resolved by context-envelope-loader.ts and the contextTagResolverRegistry.

The current routing uses an Anthropic proxy. The constants will swap to CMMD’s Apex models with a 3-file change:

FileChange
model-constants.tsFAST_MODEL = 'apex-flash', etc.
model-display-names.tsUpdate display strings (CMMD 1.0 Fast, etc.)
ai-model-registry-service.tsRegister Apex providers

No routing logic changes needed. Tier semantics stay identical. See ADR-0005 — Apex Model Family.

FailureSymptomFix
Trivial fast-path matches an action verb”Create a task” gets a 2s placeholder responseTighten regex, add safety guards
Tool call returns malformed JSONSidekick hangs or errorsTool-handler Zod validation; surface failure to user
Mode auto-elevation loopQuick → Autopilot → Quick endless flipElevation is one-shot per turn — guard at runtime layer
Brain semantic search times outSidekick blocks for 10+sTimeout budget + fallback to no-context
Context envelope > token limitProvider 4xxTruncate envelope by priority: keep ambient + tags, drop older history
ConcernFile
Tier classificationserver/services/router/intent-classifier.ts
Trivial patternsSame file, TRIVIAL_PATTERNS constant
Model constantsserver/services/router/model-constants.ts
Complexity evaluatorserver/services/router/complexity-evaluator.ts
Chat runtime orchestrationserver/services/sidekick/sidekick-chat-runtime-service.ts
Context envelopeserver/services/sidekick/context-envelope-loader.ts
Mode instructionsserver/services/sidekick/system-prompt-builder.ts
AI Gatewayserver/services/ai/ai-gateway.ts