• You will be disconnected and reconnected again.

Whitepaper: Discord bot using analytical game data

MoistNut

Administrator
Staff member
Frosties Admin
Alliance Leader (R4)
Whiteout Survival
MoistBanananana [NUT]

Nutter: How the Bot Works​

Overview​

Nutter is a Discord bot that answers questions about Whiteout Survival and in-game happenings. A language model looks up captured game data through tools, and the bot checks the answer against those results before posting it.
It also posts live game alerts, never loses a request across restarts, and remembers each conversation.

System architecture​

Questions go through one agent; alerts skip the model entirely.
---
title: "Answers go through one bounded agent; alerts skip the model"
config:
  look: classic
  themeVariables:
    fontSize: "13px"
    lineColor: "#8a8a8a"
---
flowchart TB
  discord("<b style='white-space:nowrap'>Discord</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Commands, mentions, thread<br/>replies and reactions</span>")
  console("<b style='white-space:nowrap'>Operator console</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Terminal UI: ask, answer<br/>in a channel, post</span>")
  jobs("<b style='white-space:nowrap'>Durable jobs</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Saved before work and leased,<br/>so a restart loses nothing</span>")
  memory("<b style='white-space:nowrap'>Memory</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Sessions, lookups,<br/>summaries, history</span>")
  agent("<b style='white-space:nowrap'>Agent</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Tool loop with hard budgets,<br/>grounding check, sub-agents</span>")
  model("<b style='white-space:nowrap'>Model endpoint</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>OpenAI-compatible,<br/>streamed, one per role</span>")
  mcp("<b style='white-space:nowrap'>MCP tool registry</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Tools discovered live; compact<br/>definitions, results, cache</span>")
  extras("<b style='white-space:nowrap'>Optional extras</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Web, shared memory,<br/>planning, Discord search</span>")
  capture("<b style='white-space:nowrap'>Capture server</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Captured game traffic: players,<br/>alliances, map, chat, events</span>")
  alerts("<b style='white-space:nowrap'>Alert service</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Posts live changes,<br/>no model involved</span>")
  discord --> jobs --> agent
  console -->|asks directly| agent
  memory <--> agent
  agent <--> model
  agent -->|tool calls| mcp
  mcp --> capture
  mcp --> extras
  capture -->|change notifications| alerts
  alerts --> discord
  classDef default fill:transparent,stroke:#8a8a8a,stroke-width:1.25px
  classDef main fill:#3b82f61f,stroke:#3b82f6,stroke-width:2px
  class agent main
  linkStyle default stroke:#8a8a8a,stroke-width:1.25px

Request lifecycle​

Every question is saved, answered by a budgeted tool loop, then fact-checked.
---
title: "Every answer is checked against tool results before it is sent"
config:
  look: classic
  themeVariables:
    fontSize: "13px"
    lineColor: "#8a8a8a"
---
flowchart TB
  arrive("<b style='white-space:nowrap'>Message arrives</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Slash command, mention or thread reply</span>")
  triage{"Follow-up meant<br/>for the bot?"}
  silent("<b style='white-space:nowrap'>Stay silent</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Chatter or others' talk</span>")
  job("<b style='white-space:nowrap'>Save job, post progress</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Durable job; status message edited live</span>")
  context("<b style='white-space:nowrap'>Build context</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Resume last transcript, or rebuild from<br/>history, summary and carried lookups</span>")
  model("<b style='white-space:nowrap'>Model</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Streamed replies</span>")
  loop("<b style='white-space:nowrap'>Tool loop</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Model picks tools each round; stops when<br/>done or at its round, call or time budget</span>")
  tools("<b style='white-space:nowrap'>MCP tools</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Compacted, cached</span>")
  final("<b style='white-space:nowrap'>Final answer turn</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Tools removed; partial answer if time is up</span>")
  ground{"Unsourced ids<br/>or figures?"}
  fix("<b style='white-space:nowrap'>Fix turn</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Correct, drop or keep</span>")
  deliver("<b style='white-space:nowrap'>Deliver answer</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Text plus optional embed; progress collapses</span>")
  remember("<b style='white-space:nowrap'>Remember for next turn</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Save transcript and lookups; summarize later</span>")
  arrive --> triage
  triage -->|no| silent
  triage -->|yes, or not a thread| job
  job --> context --> loop
  model <--> loop
  loop <--> tools
  loop --> final --> ground
  ground -->|yes| fix
  ground -->|no| deliver
  fix --> deliver
  deliver --> remember
  classDef default fill:transparent,stroke:#8a8a8a,stroke-width:1.25px
  classDef main fill:#3b82f61f,stroke:#3b82f6,stroke-width:2px
  class loop main
  linkStyle default stroke:#8a8a8a,stroke-width:1.25px
Triage is optional and applies only to follow-ups in threads.

The agent​

The model picks its own tools; the bot sets the limits.
MechanismWhat it does
System promptGame primer plus a map of which tools answer which questions
Per-question hintLight steering, such as expanding player shorthand
Budgets8 rounds, 6 tool calls, 120 s per run (defaults)
Grounding checkFlags ids and large numbers no tool returned; one turn to fix them
Timeout salvageOut of time: a partial answer from data already gathered
Sub-agentsOptional: split a question into parallel research tasks
Thread triageOptional: reply in a thread only when addressed

Model layer​

Any OpenAI-compatible endpoint works, hosted or local. Replies always stream.
  • One model per role. Answers, triage, sub-agents, summaries and eval judging can each use a different model.
  • Tuned for slow local hardware. Tool definitions are trimmed, rarely used tools load on demand, and follow-ups reuse a cached prompt prefix.
  • Only the bot's own timeouts apply: per run, per model call and per tool call.

Data access​

All tools come through MCP and are discovered at startup, so new server tools work without code changes.
  • Sources: the capture server (players, alliances, chat, map, events, SQL), plus optional web search, shared memory, planning and Discord search.
  • Smaller prompts: tool descriptions are capped, and JSON results are reshaped into columns and rows, cutting 16–36% of tokens.
  • Cache: repeat calls reuse results for 30 s (game data) or 15 min (web).

Memory and sessions​

Follow-ups rarely repeat a lookup, because each conversation keeps four layers of memory.
LayerHoldsKept
TranscriptThe last run, tool results included24 h
LookupsRecent tool results, trimmed24 h
SummaryOlder turns, condensed7 days
HistoryThe last 20 messages30 min
A message sent during a run joins it instead of waiting. /reset clears everything.

Alerts and background jobs​

Live alerts​

Alerts post game changes as they happen, without the model.
---
title: "Alerts post only what changed since the last event seen"
config:
  look: classic
  themeVariables:
    fontSize: "13px"
    lineColor: "#8a8a8a"
---
flowchart TB
  notify("<b style='white-space:nowrap'>Capture server</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Pushes topic changed<br/>over a WebSocket</span>")
  debounce("<b style='white-space:nowrap'>Debounce 3 s</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>A burst of changes<br/>becomes one update</span>")
  read("<b style='white-space:nowrap'>Read new events</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Own MCP session, only<br/>past the last seq seen</span>")
  render("<b style='white-space:nowrap'>Render feed</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Colour by gain, loss<br/>or neutral</span>")
  post("<b style='white-space:nowrap'>Post to Discord</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Summary edited in place;<br/>details in its thread</span>")
  save("<b style='white-space:nowrap'>Save progress</b><br/><span style='font-size:11.5px;opacity:0.72;white-space:nowrap'>Seq, message and thread,<br/>so restarts resume</span>")
  notify --> debounce --> read --> render --> post --> save
  classDef default fill:transparent,stroke:#8a8a8a,stroke-width:1.25px
  classDef main fill:#3b82f61f,stroke:#3b82f6,stroke-width:2px
  class read main
  linkStyle default stroke:#8a8a8a,stroke-width:1.25px
FeedPosts
StructuresWho holds each key building, and every change
RalliesEnemy attacks on our buildings, with countdowns
EventsThe schedule, starts and reminders
BattlesLive score, then the result
LeaderboardsDamage rankings and who moved
Each battle gets one summary message, updated in place, with details in a thread. Red means a threat or loss, green a gain.

Durable jobs​

Every request is saved before work starts, so a crash or deploy never loses one.
  • Leases make sure exactly one instance answers.
  • Retry limits (3 tries, 24 h) stop a bad request from looping.
  • Catch-up answers mentions sent while the bot was offline.

Other features​

FeatureWhat it does
Operator consoleTerminal UI to ask questions, post as the bot and watch logs
Progress messagesLive status while the agent works, then a short summary
Identity linkingA one-time code ties a Discord account to a game player
Linked rolesDiscord roles based on in-game rank
Gift codesRedeem a code for every alliance member
FeedbackA 👎 on an answer triggers a fresh attempt

Quality: evals and testing​

Each eval case runs through the real agent and must pass two checks: required text and tool use, and a judge model score of 4 out of 5 or higher.
Members' 👍 and 👎 votes become new eval cases. Unit tests, smoke scripts and tracing cover the rest.

Deployment and configuration​

One container on Kubernetes, always a single replica, since Discord allows one connection per bot.
  • Valkey stores jobs, memory and alert state.
  • A tunnel exposes the sign-in pages for linked roles.
  • Configuration is environment variables; every optional feature is off by default.

Conclusion​

The model chooses the lookups; the bot decides what counts as an answer. Budgets bound each run, the grounding check catches invented numbers, and member votes keep the evals honest.
 
Back
Top