Skip to content

Commit 72c2380

Browse files
Merge pull request Aider-AI#4228 from maliayas/reset-thinking-tokens
2 parents 2df4beb + e91efda commit 72c2380

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

aider/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def get_parser(default_config_files, git_root):
143143
group.add_argument(
144144
"--thinking-tokens",
145145
type=str,
146-
help="Set the thinking token budget for models that support it (default: not set)",
146+
help="Set the thinking token budget for models that support it. Use 0 to disable. (default: not set)",
147147
)
148148
group.add_argument(
149149
"--verify-ssl",

aider/commands.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ def cmd_edit(self, args=""):
15411541
return self.cmd_editor(args)
15421542

15431543
def cmd_think_tokens(self, args):
1544-
"Set the thinking token budget (supports formats like 8096, 8k, 10.5k, 0.5M)"
1544+
"Set the thinking token budget (supports formats like 8096, 8k, 10.5k, 0.5M, or 0 to disable)"
15451545
model = self.coder.main_model
15461546

15471547
if not args.strip():
@@ -1559,10 +1559,14 @@ def cmd_think_tokens(self, args):
15591559
value = args.strip()
15601560
model.set_thinking_tokens(value)
15611561

1562-
formatted_budget = model.get_thinking_tokens()
1563-
budget = model.get_raw_thinking_tokens()
1562+
# Handle the special case of 0 to disable thinking tokens
1563+
if value == "0":
1564+
self.io.tool_output("Thinking tokens disabled.")
1565+
else:
1566+
formatted_budget = model.get_thinking_tokens()
1567+
budget = model.get_raw_thinking_tokens()
1568+
self.io.tool_output(f"Set thinking token budget to {budget:,} tokens ({formatted_budget}).")
15641569

1565-
self.io.tool_output(f"Set thinking token budget to {budget:,} tokens ({formatted_budget}).")
15661570
self.io.tool_output()
15671571

15681572
# Output announcements

aider/models.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ def set_thinking_tokens(self, value):
794794
"""
795795
Set the thinking token budget for models that support it.
796796
Accepts formats: 8096, "8k", "10.5k", "0.5M", "10K", etc.
797+
Pass "0" to disable thinking tokens.
797798
"""
798799
if value is not None:
799800
num_tokens = self.parse_token_value(value)
@@ -805,9 +806,17 @@ def set_thinking_tokens(self, value):
805806
if self.name.startswith("openrouter/"):
806807
if "extra_body" not in self.extra_params:
807808
self.extra_params["extra_body"] = {}
808-
self.extra_params["extra_body"]["reasoning"] = {"max_tokens": num_tokens}
809+
if num_tokens > 0:
810+
self.extra_params["extra_body"]["reasoning"] = {"max_tokens": num_tokens}
811+
else:
812+
if "reasoning" in self.extra_params["extra_body"]:
813+
del self.extra_params["extra_body"]["reasoning"]
809814
else:
810-
self.extra_params["thinking"] = {"type": "enabled", "budget_tokens": num_tokens}
815+
if num_tokens > 0:
816+
self.extra_params["thinking"] = {"type": "enabled", "budget_tokens": num_tokens}
817+
else:
818+
if "thinking" in self.extra_params:
819+
del self.extra_params["thinking"]
811820

812821
def get_raw_thinking_tokens(self):
813822
"""Get formatted thinking token budget if available"""

aider/website/assets/sample.aider.conf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
## Set the reasoning_effort API parameter (default: not set)
8484
#reasoning-effort: xxx
8585

86-
## Set the thinking token budget for models that support it (default: not set)
86+
## Set the thinking token budget for models that support it. Use 0 to disable. (default: not set)
8787
#thinking-tokens: xxx
8888

8989
## Verify the SSL cert when connecting to models (default: True)

aider/website/docs/config/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Set the reasoning_effort API parameter (default: not set)
173173
Environment variable: `AIDER_REASONING_EFFORT`
174174

175175
### `--thinking-tokens VALUE`
176-
Set the thinking token budget for models that support it (default: not set)
176+
Set the thinking token budget for models that support it. Use 0 to disable. (default: not set)
177177
Environment variable: `AIDER_THINKING_TOKENS`
178178

179179
### `--verify-ssl`

aider/website/docs/config/reasoning.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ aider --model r1
2525
```
2626

2727
Inside the aider chat, you can use `/thinking-tokens 4k` or `/reasoning-effort low` to change
28-
the amount of reasoning.
28+
the amount of reasoning. Use `/thinking-tokens 0` to disable thinking tokens.
2929

3030
The rest of this document describes more advanced details which are mainly needed
3131
if you're configuring aider to work with a lesser known reasoning model or one served
@@ -47,6 +47,7 @@ You can use the `--thinking-tokens` switch to request
4747
the model use a certain number of thinking tokens.
4848
This switch is useful for Sonnet 3.7.
4949
You can specify the token budget like "1024", "1k", "8k" or "0.01M".
50+
Use "0" to disable thinking tokens.
5051

5152
### Model compatibility and settings
5253

aider/website/docs/usage/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cog.out(get_help_md())
5757
| **/save** | Save commands to a file that can reconstruct the current chat session's files |
5858
| **/settings** | Print out the current settings |
5959
| **/test** | Run a shell command and add the output to the chat on non-zero exit code |
60-
| **/think-tokens** | Set the thinking token budget (supports formats like 8096, 8k, 10.5k, 0.5M) |
60+
| **/think-tokens** | Set the thinking token budget (supports formats like 8096, 8k, 10.5k, 0.5M, or 0 to disable) |
6161
| **/tokens** | Report on the number of tokens used by the current chat context |
6262
| **/undo** | Undo the last git commit if it was done by aider |
6363
| **/voice** | Record and transcribe voice input |

0 commit comments

Comments
 (0)