xonecas.io
5875
Os

ollama-space-molt-player / commit 8451d84

Add per-model context window recommendations

- Add recommendedMessages field to model configs (10-20 messages)
- Replace qwen2.5 with ministral-3 (262K context, 20 msgs)
- Fix qwen3 config (remove invalid thinking param)
- Update all model context windows to actual spec values
- Apply recommendedMessages as default in CLI and GameClient
- Add OLLAMA_CONTEXT_LENGTH setup instructions to README
- Add troubleshooting section for prompt truncation
- Update model comparison table with Messages column
- Add tests for recommendedMessages behavior (108 tests pass)

xonecas2026-02-03 8451d84c307d79db4e466177c0f1e0a4c11d733d parent 377e18e

9 files changed

README.md+44−1
@@ -25,7 +25,13 @@ See `docs/2026-02-03-client-refactor-design.md` for full details. Key principles
2525 # Install dependencies
2626 bun install
2727
28-# Install Ollama and default model
28+# Configure Ollama server (REQUIRED)
29+export OLLAMA_CONTEXT_LENGTH=16384
30+
31+# Start Ollama server
32+ollama serve
33+
34+# In another terminal, pull the default model
2935 ollama pull lfm2.5-thinking
3036
3137 # Run all checks (format, lint, test)
@@ -36,6 +42,8 @@ cd packages/client
3642 bun run start
3743 ```
3844
45+**Important:** Set `OLLAMA_CONTEXT_LENGTH=16384` before starting the Ollama server. The default limit (4096) truncates prompts and causes the bot to forget recent game history.
46+
3947 Model configurations are defined in `player-models.json` at the repo root.
4048
4149 ## Code Quality
@@ -76,6 +84,41 @@ This project automatically strips all code comments during the check process. Th
7684 - `bun run check:lint` - Type-check with TypeScript
7785 - `bun run check:test` - Run tests with Bun
7886
87+## Troubleshooting
88+
89+### Ollama truncation warnings
90+
91+If you see `truncating input prompt` warnings in Ollama server logs:
92+
93+**Symptom:** Bot forgets recent game events and repeats failed actions
94+
95+**Cause:** Ollama's default context limit (4096 tokens) is too small for game state history
96+
97+**Solution:**
98+
99+1. Stop Ollama server
100+2. Set environment variable: `export OLLAMA_CONTEXT_LENGTH=16384`
101+3. Restart: `ollama serve`
102+
103+**For systemd service:**
104+
105+```bash
106+sudo systemctl edit ollama
107+```
108+
109+Add to the override file:
110+
111+```ini
112+[Service]
113+Environment="OLLAMA_CONTEXT_LENGTH=16384"
114+```
115+
116+Then restart the service:
117+
118+```bash
119+sudo systemctl restart ollama
120+```
121+
79122 ## References
80123
81124 - Game Server API: https://www.spacemolt.com/api.md
packages/client/README.md+14−11
@@ -130,7 +130,7 @@ bun run start help
130130 | `--archetype <name>` | `-a` | Character archetype (see below) | None |
131131 | `--ollama-timeout <ms>` | | Ollama API timeout in milliseconds | `30000` |
132132 | `--server <url>` | `-s` | WebSocket server URL | `wss://game.spacemolt.com/ws` |
133-| `--context-window <n>` | `-cw` | Number of recent messages to include in LLM context | `20` |
133+| `--context-window <n>` | `-cw` | Number of recent messages to include in LLM context | Model's recommendedMessages |
134134
135135 ### Archetypes
136136
@@ -145,18 +145,21 @@ Character archetypes define gameplay personality:
145145 Models are configured in `player-models.json` at the repo root. Each configuration includes:
146146
147147 - **Ollama model name**: The actual model to load (e.g., `lfm2.5-thinking`)
148-- **Options**: Model-specific parameters (temperature, thinking mode, etc.)
148+- **Options**: Model-specific parameters (temperature, etc.)
149149 - **Context window**: Token limit for this model
150+- **Recommended messages**: Default history size for this model
150151 - **Metadata**: Display name, description, recommendation status
151152
152153 **Available Models:**
153154
154-| Config Name | Size | Context | Features | Recommended |
155-| ------------ | ----- | ------- | ----------------------------------- | ----------- |
156-| lfm-thinking | 731MB | 4K | Built-in thinking, fast | ✓ |
157-| qwen3 | 5.2GB | 32K | Strong reasoning, explicit thinking | |
158-| qwen2.5 | 4.7GB | 32K | Balanced performance | |
159-| deepseek-r1 | ~5GB | 128K | Advanced reasoning, large context | |
155+| Config Name | Size | Context | Messages | Thinking | Best For |
156+| ------------ | ----- | ------- | -------- | -------- | -------------------- |
157+| lfm-thinking | 731MB | 128K | 10 | ✅ | Fast, minimal VRAM |
158+| deepseek-r1 | 4.7GB | 131K | 12 | ✅ | Advanced reasoning |
159+| qwen3 | 5.2GB | 40K | 15 | ✅ | Tools + thinking |
160+| ministral-3 | 6.0GB | 262K | 20 | ❌ | Maximum game history |
161+
162+**Messages** column shows the recommended context window size (number of game state messages) for each model.
160163
161164 **Adding Custom Models:**
162165
@@ -171,11 +174,11 @@ Edit `player-models.json` and add your configuration:
171174 "ollama": {
172175 "model": "actual-ollama-name",
173176 "options": {
174- "temperature": 1.2,
175- "thinking": true
177+ "temperature": 1.2
176178 }
177179 },
178180 "contextWindow": 32768,
181+ "recommendedMessages": 12,
179182 "recommended": false
180183 }
181184 }
@@ -232,7 +235,7 @@ bun test tests/db.test.ts
232235 bun test --watch
233236 ```
234237
235-Test coverage: 81 tests across 6 test suites (db, ws-client, ollama, cli, json-extraction, model-config)
238+Test coverage: 108 tests across 8 test suites
236239
237240 ## Project Structure
238241
packages/client/src/cli.ts+2−1
@@ -58,6 +58,7 @@ export function parseArgs(args: string[]): ParsedArgs {
5858 }
5959
6060 if (command === "start" || command.startsWith("-")) {
61+ const contextWindowArg = getArg(cleanArgs, "--context-window", "-cw");
6162 const config: ClientConfig = {
6263 instanceId: getArg(cleanArgs, "--instance", "-i"),
6364 hint: getArg(cleanArgs, "--hint"),
@@ -67,7 +68,7 @@ export function parseArgs(args: string[]): ParsedArgs {
6768 tickRate: 20000,
6869 ollamaTimeout: Number.parseInt(getArg(cleanArgs, "--ollama-timeout") || "30000"),
6970 serverUrl: getArg(cleanArgs, "--server", "-s"),
70- contextWindowSize: Number.parseInt(getArg(cleanArgs, "--context-window", "-cw") || "20"),
71+ contextWindowSize: contextWindowArg ? Number.parseInt(contextWindowArg) : undefined,
7172 };
7273
7374 return {
packages/client/src/game-client.ts+5−1
@@ -41,6 +41,10 @@ export class GameClient {
4141
4242 const modelConfig = loadModelConfig(config.model);
4343
44+ if (this.config.contextWindowSize === undefined) {
45+ this.config.contextWindowSize = modelConfig.recommendedMessages ?? 12;
46+ }
47+
4448 this.ollama = new OllamaClient({
4549 baseUrl: "http://localhost:11434",
4650 model: modelConfig.ollama.model,
@@ -49,7 +53,7 @@ export class GameClient {
4953 });
5054
5155 console.log(
52- `[${config.instanceId}] Using model: ${config.model} (${modelConfig.ollama.model})`,
56+ `[${config.instanceId}] Using model: ${config.model} (${modelConfig.ollama.model}), context: ${config.contextWindowSize} messages`,
5357 );
5458
5559 this.ws = new GameWebSocketClient({
packages/client/src/index.ts+6−0
@@ -1,6 +1,7 @@
11 import { parseArgs, printHelp, printInstances } from "./cli.ts";
22 import { GameDatabase, generateInstanceId, instanceExists } from "./db.ts";
33 import { GameClient } from "./game-client.ts";
4+import { loadModelConfig } from "./model-config.ts";
45
56 async function main() {
67 try {
@@ -71,6 +72,11 @@ async function main() {
7172 console.log(`Creating new instance: ${parsed.config.instanceId}`);
7273 }
7374
75+ if (parsed.config.contextWindowSize === undefined) {
76+ const modelConfig = loadModelConfig(parsed.config.model);
77+ parsed.config.contextWindowSize = modelConfig.recommendedMessages ?? 12;
78+ }
79+
7480 const db = new GameDatabase(parsed.config.instanceId);
7581 const client = new GameClient(db, parsed.config);
7682
packages/client/src/model-config.ts+1−0
@@ -9,6 +9,7 @@ export interface ModelConfig {
99 options: Record<string, unknown>;
1010 };
1111 contextWindow: number;
12+ recommendedMessages?: number;
1213 recommended: boolean;
1314 }
1415
packages/client/tests/cli.test.ts+11−0
@@ -40,6 +40,7 @@ describe("CLI Argument Parser", () => {
4040 const result = parseArgs(["start"]);
4141 expect(result.command).toBe("start");
4242 expect(result.config?.model).toBe("lfm-thinking");
43+ expect(result.config?.contextWindowSize).toBeUndefined();
4344 });
4445
4546 test("should parse start with instance ID", () => {
@@ -97,6 +98,16 @@ describe("CLI Argument Parser", () => {
9798 expect(result.config?.hint).toBe("explore");
9899 });
99100
101+ test("should parse context window size when provided", () => {
102+ const result = parseArgs(["start", "--context-window", "15"]);
103+ expect(result.config?.contextWindowSize).toBe(15);
104+ });
105+
106+ test("should parse context window size with short flag", () => {
107+ const result = parseArgs(["start", "-cw", "25"]);
108+ expect(result.config?.contextWindowSize).toBe(25);
109+ });
110+
100111 test("should throw error for unknown command", () => {
101112 expect(() => {
102113 parseArgs(["unknown-command"]);
packages/client/tests/model-config.test.ts+17−12
@@ -17,36 +17,40 @@ describe("Model Configuration", () => {
1717 expect(config.displayName).toBe("LFM 2.5 Thinking (731MB)");
1818 expect(config.ollama.model).toBe("lfm2.5-thinking");
1919 expect(config.ollama.options).toEqual({ temperature: 1.2 });
20- expect(config.contextWindow).toBe(4096);
20+ expect(config.contextWindow).toBe(128000);
21+ expect(config.recommendedMessages).toBe(10);
2122 expect(config.recommended).toBe(true);
2223 });
2324
24- test("should load qwen3 config with thinking option", () => {
25+ test("should load qwen3 config without thinking option", () => {
2526 const config = loadModelConfig("qwen3");
2627
2728 expect(config.displayName).toBe("Qwen3 8B (5.2GB)");
2829 expect(config.ollama.model).toBe("qwen3:8b");
29- expect(config.ollama.options).toEqual({ temperature: 1.2, thinking: true });
30- expect(config.contextWindow).toBe(32768);
30+ expect(config.ollama.options).toEqual({ temperature: 1.2 });
31+ expect(config.contextWindow).toBe(40960);
32+ expect(config.recommendedMessages).toBe(15);
3133 expect(config.recommended).toBe(false);
3234 });
3335
34- test("should load qwen2.5 config", () => {
35- const config = loadModelConfig("qwen2.5");
36+ test("should load ministral-3 config", () => {
37+ const config = loadModelConfig("ministral-3");
3638
37- expect(config.displayName).toBe("Qwen2.5 7B (4.7GB)");
38- expect(config.ollama.model).toBe("qwen2.5:7b");
39+ expect(config.displayName).toBe("Ministral 3 8B (6.0GB)");
40+ expect(config.ollama.model).toBe("ministral-3:8b");
3941 expect(config.ollama.options).toEqual({ temperature: 1.2 });
40- expect(config.contextWindow).toBe(32768);
42+ expect(config.contextWindow).toBe(262144);
43+ expect(config.recommendedMessages).toBe(20);
4144 });
4245
4346 test("should load deepseek-r1 config", () => {
4447 const config = loadModelConfig("deepseek-r1");
4548
46- expect(config.displayName).toBe("DeepSeek R1 7B (~5GB)");
49+ expect(config.displayName).toBe("DeepSeek R1 7B (4.7GB)");
4750 expect(config.ollama.model).toBe("deepseek-r1:7b");
4851 expect(config.ollama.options).toEqual({ temperature: 1.2 });
4952 expect(config.contextWindow).toBe(131072);
53+ expect(config.recommendedMessages).toBe(12);
5054 });
5155
5256 test("should throw error for non-existent config", () => {
@@ -62,7 +66,7 @@ describe("Model Configuration", () => {
6266 if (error instanceof Error) {
6367 expect(error.message).toContain("lfm-thinking");
6468 expect(error.message).toContain("qwen3");
65- expect(error.message).toContain("qwen2.5");
69+ expect(error.message).toContain("ministral-3");
6670 expect(error.message).toContain("deepseek-r1");
6771 }
6872 }
@@ -73,8 +77,9 @@ describe("Model Configuration", () => {
7377
7478 expect(models).toContain("lfm-thinking");
7579 expect(models).toContain("qwen3");
76- expect(models).toContain("qwen2.5");
80+ expect(models).toContain("ministral-3");
7781 expect(models).toContain("deepseek-r1");
82+ expect(models).toHaveLength(4);
7883 });
7984
8085 test("should generate model list text", () => {
player-models.json+22−19
@@ -2,51 +2,54 @@
22 "models": {
33 "lfm-thinking": {
44 "displayName": "LFM 2.5 Thinking (731MB)",
5- "description": "Fast reasoning model with built-in thinking. Recommended for 12GB VRAM.",
5+ "description": "Fastest model with built-in thinking. 128K context.",
66 "ollama": {
77 "model": "lfm2.5-thinking",
88 "options": {
99 "temperature": 1.2
1010 }
1111 },
12- "contextWindow": 4096,
12+ "contextWindow": 128000,
13+ "recommendedMessages": 10,
1314 "recommended": true
1415 },
15- "qwen3": {
16- "displayName": "Qwen3 8B (5.2GB)",
17- "description": "General-purpose model with strong reasoning. Requires thinking flag.",
16+ "deepseek-r1": {
17+ "displayName": "DeepSeek R1 7B (4.7GB)",
18+ "description": "Advanced reasoning with thinking. 131K context.",
1819 "ollama": {
19- "model": "qwen3:8b",
20+ "model": "deepseek-r1:7b",
2021 "options": {
21- "temperature": 1.2,
22- "thinking": true
22+ "temperature": 1.2
2323 }
2424 },
25- "contextWindow": 32768,
25+ "contextWindow": 131072,
26+ "recommendedMessages": 12,
2627 "recommended": false
2728 },
28- "qwen2.5": {
29- "displayName": "Qwen2.5 7B (4.7GB)",
30- "description": "Balanced model with large context window.",
29+ "qwen3": {
30+ "displayName": "Qwen3 8B (5.2GB)",
31+ "description": "Strong reasoning + tools + thinking. 40K context.",
3132 "ollama": {
32- "model": "qwen2.5:7b",
33+ "model": "qwen3:8b",
3334 "options": {
3435 "temperature": 1.2
3536 }
3637 },
37- "contextWindow": 32768,
38+ "contextWindow": 40960,
39+ "recommendedMessages": 15,
3840 "recommended": false
3941 },
40- "deepseek-r1": {
41- "displayName": "DeepSeek R1 7B (~5GB)",
42- "description": "Advanced reasoning model with 128K context. Requires download.",
42+ "ministral-3": {
43+ "displayName": "Ministral 3 8B (6.0GB)",
44+ "description": "Largest context window (262K). No thinking mode.",
4345 "ollama": {
44- "model": "deepseek-r1:7b",
46+ "model": "ministral-3:8b",
4547 "options": {
4648 "temperature": 1.2
4749 }
4850 },
49- "contextWindow": 131072,
51+ "contextWindow": 262144,
52+ "recommendedMessages": 20,
5053 "recommended": false
5154 }
5255 },