You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`--thinking <level>`| string |profile default | Reasoning depth — see [Thinking Levels](#thinking-levels). Leave empty for profile/provider default.|
89
89
|`--sandbox`| bool | false | Run all shell commands inside an isolated Docker container |
90
90
|`--system <prompt>`| string | built-in | Override the system prompt |
91
91
@@ -151,9 +151,101 @@ Any endpoint that accepts `POST /chat/completions` with an OpenAI-compatible JSO
151
151
152
152
---
153
153
154
+
## Model Profiles
155
+
156
+
kode ships with built-in **model profiles** that automatically apply sensible defaults (thinking mode, request timeout) based on the model name. Profiles are matched by longest prefix — adding a new model is one entry.
157
+
158
+
| Model | Family | Default Thinking | Timeout | Max Context | Best For |
kode run --model deepseek-v4-flash "List the files"
195
+
196
+
# Override profile default explicitly
197
+
kode run --model deepseek-v4-pro --thinking disabled "Quick status check"
198
+
```
199
+
200
+
---
201
+
202
+
## Context Window Management
203
+
204
+
kode automatically manages the conversation history to stay within each model's context window. When a model profile defines a `MaxContext` value, the loop engine estimates token usage and trims old messages before they fill the window.
205
+
206
+
### How it works
207
+
208
+
1.**Token estimation**: kode uses a conservative heuristic (~4 chars/token + structural overhead) — no tokenizer needed.
209
+
2.**Safety margin**: 75% of `MaxContext` is reserved for input; the remaining 25% is left for the model's output.
210
+
3.**Trim strategy**: Before each LLM call, if estimated tokens exceed the budget, the oldest non-essential messages (tool call → tool result pairs) are dropped, preserving:
211
+
- The **system prompt** (always first)
212
+
- The **original task message** (first user message)
213
+
4.**No limit = no trimming**: Models with `MaxContext: 0` (or no profile) have no context enforcement — the full history is sent every time.
214
+
215
+
### Example
216
+
217
+
```
218
+
Messages before trim (6 messages, ~250K estimated tokens, budget=200K):
219
+
[system] You are kode...
220
+
[user] Refactor this module...
221
+
[assistant]" ← DROPPED
222
+
[tool] ← DROPPED
223
+
[assistant] Let me check... ← KEPT
224
+
[tool] File: main.go... ← KEPT
225
+
226
+
Messages after trim (4 messages, ~180K estimated tokens):
227
+
[system] You are kode...
228
+
[user] Refactor this module...
229
+
[assistant] Let me check...
230
+
[tool] File: main.go...
231
+
```
232
+
233
+
### Token estimation accuracy
234
+
235
+
| Content | Estimated | Actual (approx) | Notes |
236
+
|---------|-----------|-----------------|-------|
237
+
| "hello" | 2 tokens |~1 token | Overestimates short text |
238
+
| 1000 chars of text | 250 tokens |~200-300 tokens | Accurate range |
| Message JSON overhead | 50 per msg |~30-50 | Margin for nested fields |
241
+
242
+
The estimator is intentionally conservative — it overestimates to prevent context limit errors. In practice, the model never sees a `context_length_exceeded` error because trimming happens proactively at 75% of the limit.
243
+
244
+
---
245
+
154
246
## Thinking Levels
155
247
156
-
The `--thinking` flag controls how deeply the model reasons before responding. kode automatically maps your value to the provider's native format.
248
+
The `--thinking` flag controls how deeply the model reasons before responding. kode automatically maps your value to the provider's native format. When the flag is not set, the [model profile](#model-profiles) default is applied (if any).
0 commit comments