summaryrefslogtreecommitdiffhomepage
path: root/.rules/plan/08-15-strip-ignored-params-and-temp.md
blob: 5d555ebe4d8aeb0cea1cd587988138457c95ddca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Phase 08 — Strip ignored params and validate temperature

**Estimated time:** ~15 minutes
**Touches:** `lib/dispatch/adapter/minimax/request_builder.rb`.

## Goal

Two related changes in `RequestBuilder.build`:

1. **Strip parameters MiniMax ignores** so the wire payload is clean.
   Per MiniMax's compatibility docs the following Anthropic parameters
   are *Ignored* by their endpoint: `top_k`, `stop_sequences`,
   `service_tier`, `mcp_servers`, `context_management`, `container`.
   Whatever shape they arrive in, they must not appear in the outgoing
   body.

2. **Validate `temperature`** to MiniMax's documented `(0.0, 1.0]` range.
   Outside that range MiniMax returns a 400. Rather than ship malformed
   requests, raise `ArgumentError` at build time when the value is `<= 0`
   or `> 1`. `nil` is allowed (means "don't send temperature, MiniMax
   uses its default").

## Steps

### 1. Open `lib/dispatch/adapter/minimax/request_builder.rb`

Locate the `RequestBuilder.build` method. It currently takes these
keywords:

```
model_id:, messages:, system:, tools:, is_oauth:, base_url:,
stream:, max_tokens:, thinking:, tool_choice:, cache_retention:,
metadata:, disable_strict_tools:
```

Phase 02 already removed the `is_oauth:` keyword from the callsite — make
sure it is removed from the parameter list here too. If it is not yet
removed, remove it now.

### 2. Add a `temperature:` keyword and a `top_p:` keyword

These are not currently exposed in `RequestBuilder.build`. Add them:

```ruby
def build(
  model_id:,
  messages:,
  system:,
  tools:,
  base_url:,
  stream: true,
  max_tokens: nil,
  temperature: nil,
  top_p: nil,
  thinking: nil,
  tool_choice: nil,
  cache_retention: nil,
  metadata: nil,
  disable_strict_tools: false
)
```

(`top_p` is fully supported per MiniMax docs.)

### 3. Validate temperature inside the method body

Right after `model_info = ModelCatalog.build(model_id)` (or wherever the
opening sanity checks live), add:

```ruby
unless temperature.nil?
  unless temperature.is_a?(Numeric)
    raise ArgumentError,
          "temperature must be Numeric or nil, got #{temperature.class}"
  end
  if temperature <= 0.0 || temperature > 1.0
    raise ArgumentError,
          "temperature must be in (0.0, 1.0], got #{temperature}"
  end
end
```

### 4. Plumb temperature and top_p into the body

After the base body assembly:

```ruby
body[:temperature] = temperature unless temperature.nil?
body[:top_p]       = top_p       unless top_p.nil?
```

### 5. Strip ignored parameters from the body

After all body assembly, before returning, strip the documented-ignored
keys (in case they were injected by `extra:` or merged in via metadata or
similar surprises):

```ruby
IGNORED_KEYS = %i[top_k stop_sequences service_tier mcp_servers
                  context_management container].freeze

def strip_ignored!(body)
  IGNORED_KEYS.each do |k|
    body.delete(k)
    body.delete(k.to_s)
  end
end
```

Call `strip_ignored!(body)` as the LAST step before `return body`.

`IGNORED_KEYS` is module-level (top of the `RequestBuilder` module).

### 6. Plumb the new kwargs from the adapter

In `lib/dispatch/adapter/minimax.rb`, the `chat` and `count_tokens`
methods accept caller kwargs. They almost certainly already accept
`temperature:` and `top_p:` if they followed the Anthropic interface. If
not, add them and forward to `RequestBuilder.build`. Defaults: `nil`.

DO NOT alter the temperature default behavior on the adapter — `nil`
means "don't send", which lets MiniMax pick its own server-side default.

## Acceptance criteria

- `grep -rn ':top_k\|:stop_sequences\|:service_tier\|:mcp_servers\|:context_management\|:container' lib/` should still match (the IGNORED_KEYS literal) but should NOT appear as keys in any built body.
- `RequestBuilder.build(temperature: 0.0, ...)` raises `ArgumentError`.
- `RequestBuilder.build(temperature: 1.01, ...)` raises `ArgumentError`.
- `RequestBuilder.build(temperature: -0.1, ...)` raises `ArgumentError`.
- `RequestBuilder.build(temperature: 0.5, ...)[:temperature]` is `0.5`.
- `RequestBuilder.build(temperature: 1.0, ...)[:temperature]` is `1.0`.
- `RequestBuilder.build(temperature: nil, ...).key?(:temperature)` is
  `false`.
- `bundle exec rubocop --autocorrect-all` exits 0.

## Verification

Run `run_tests` with `project_path=reference/dispatch-adapter-minimax`.
Rubocop must be clean. `request_builder_spec.rb` failures referencing
`is_oauth` or expecting different shapes are acceptable (retargeted in
phase 13). New examples covering the temperature validation and ignored-
key stripping are NOT required here; phase 13 will add them.