The problem
Traditional AI agents dump all available tools into the system prompt. With 15+ tools (built-in + MCP), this means:- Slower — more tokens in context = longer inference
- Expensive — every tool description costs tokens
- Less accurate — the model gets confused by irrelevant tools
Architecture overview
Components
Domain Router (router.ts)
The entry point. Uses the fast model to classify a user message into one of the registered domains. The classification prompt is deterministic — same message always routes to the same domain.
Domains are defined by Skill Packs (see below). The router scores each domain and selects the highest-confidence match.
Skill Packs (packs/)
Each domain has a Skill Pack — a directory containing a pack.json that defines:
- Domain name — e.g.,
code,research,creative - Description — what this domain handles
- Keywords — routing hints for the fast model
- Tool set — which built-in tools to include
- System prompt additions — domain-specific instructions
code, research, creative, business, personal, general.
Skill Graph (graph.ts)
Tracks tool co-occurrence — which tools tend to succeed together. Stored at ~/.niom/skill-graph.json.
The graph is a weighted adjacency matrix where:
- Nodes = tools
- Edges = co-occurrence frequency
- Weights = success-weighted count
webSearch → fetchUrl → writeFile co-occur in a successful run, edges between these three tools are strengthened. Over time, selecting one tool boosts the weight of tools that commonly co-occur with it.
Traversal Engine (traversal.ts)
The core resolver. Takes a user message and produces a SkillPath:
- Domain classification — ask the fast model which domain matches
- Pack lookup — get the base tool set from the matched Skill Pack
- Graph boosting — overlay co-occurrence weights to adjust tool selection
- MCP merge — add relevant MCP tools if connected
- Schedule detection — check for temporal intent (2-tier)
- Cache — store the result for similar future queries
SkillPath: { domain, tools, executionMode, confidence }.
Schedule Detection (intent-validator.ts)
A 2-tier system that detects scheduling intent:
Tier 1 — Pattern matching (zero latency):
- Regex-based: detects “every day”, “weekly”, “in 2 hours”, “daily”, etc.
- Only fires on high-confidence patterns
- Fires when: ambiguous domain scores, weak temporal language, action+temporal combos
- Does NOT fire when: high-confidence single domain, simple queries, greetings
- Uses the fast model with structured output (Zod schema)
- Only applies override if confidence > 0.7
Embeddings (embeddings.ts)
Pre-computed embeddings for tool descriptions and domain keywords. Used for semantic similarity matching when routing ambiguous queries.
Data flow
Learning loop
After each run, the Skill Graph is updated:Performance
| Metric | Value |
|---|---|
| Domain classification | ~200ms (fast model) |
| Full resolution | ~300ms (with Tier 2) |
| Cache hit | ~1ms |
| Tools selected | 4-8 (vs 15+ without Skill Tree) |
| Accuracy improvement | Measurable after ~30 interactions |