TowerAI

The assistant core behind The Tower Run Tracker's in-app assistant, published as its own MIT package. It answers from a knowledge base you curate rather than from whatever a general model absorbed.

npm install towerai

How The Knowledge Base Works

A knowledge base is an array of chunks. Each chunk carries a topic, tags, a disambiguation line saying what it is not about, and its content. Retrieval scores a question against those chunks and answers from the best match.

The split that matters: curated prose supplies meaning, and the SDK catalogs supply numbers. A chunk that says "Attack Speed has 99 levels" in prose goes stale the next time the game rebalances; one that reads the count from LAB_CATALOG does not.

Building One

import {
  buildTrackerAiCanonicalKbChunks,
  validateCanonicalKbArray,
  buildCanonicalKbVersion,
} from 'towerai/kb'
import { LAB_CATALOG } from 'thetowersdk/data'

// The shipped chunks, then your own on top.
const base = buildTrackerAiCanonicalKbChunks()

const mine = LAB_CATALOG.map((lab) => ({
  chunk_id: `lab_cost_${lab.slug}`,
  source: 'My Notes',
  section: 'Labs',
  topic: `${lab.name} cost`,
  title: `${lab.name} cost`,
  disambiguation: 'Cost to max this lab, not research order.',
  mechanics: [lab.name],
  tags: ['labs', lab.name.toLowerCase()],
  // Numbers come from the catalog, so prose cannot go stale.
  content: `${lab.name} has ${lab.levels.length} levels.`,
}))

const knowledgeBase = [...base, ...mine]

// It tells you what is malformed instead of failing at query time.
validateCanonicalKbArray(knowledgeBase)
console.log(buildCanonicalKbVersion(knowledgeBase), knowledgeBase.length, 'chunks')

Exports

  • buildTrackerAiCanonicalKbChunks — the shipped chunk set, to extend or replace
  • validateCanonicalKbArray — reports malformed chunks up front, not at query time
  • formatKbValidationError — turns a validation failure into a readable message
  • buildCanonicalKbVersion — a content-derived version string for cache keys
  • loadCanonicalKbFromJson / loadCanonicalKbFromFile — load a prebuilt base
  • toCanonicalRuntimeKnowledgeRecord — chunk to the runtime record shape

Artifacts Are Fetched, Not Bundled

Embedding indexes are served from a manifest URL rather than shipped in the tarball, which keeps the package small. Point it at your own manifest to serve a knowledge base you host.

A Note On Accuracy

AI assistants are known to make mistakes. A curated base narrows what an assistant can say, and declining to answer is a valid outcome worth designing for — but it is not a guarantee of correctness. Say so wherever you surface answers to players.

MCP & Oracles → · AI & ACS Guide →