File size: 4,824 Bytes
e36cfa2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# 🧠 Thinking Mode Setup Guide

## Overview

Gemini 2.0 Flash introduces **thinking mode** - the model explicitly "thinks" through problems before responding. This generates higher quality responses for complex tasks like game strategy.

---

## πŸš€ Quick Start

### 1. Switch to Thinking Model

**Option A: Edit config.yaml** (Recommended)
```yaml
llm:
  model_name: "gemini-2.0-flash-thinking-exp"
  enable_thinking: true
  thinking_budget: 16000  # Max tokens for thinking (8k-32k)
```

**Option B: Edit config.py** (For default settings)
```python
@dataclass
class LLMConfig:
    model_name: str = "gemini-2.0-flash-thinking-exp"
    enable_thinking: bool = True
    thinking_budget: int = 16000
```

### 2. Run Your Game

```bash
python play_catan.py
```

The AI will now use thinking mode automatically!

---

## πŸ“Š How to Monitor Thinking

### In Console Logs

Look for thinking token counts:
```
βœ… Response received: 450 tokens (+1200 thinking), 3.5s
```

### In Log Files

**JSON logs** (`examples/ai_testing/my_games/AI_Agent_1/prompt_1.json`):
```json
{
  "tokens": {
    "prompt": 1523,
    "completion": 450,
    "thinking": 1200,
    "total": 3173
  }
}
```

**TXT logs** (`examples/ai_testing/my_games/AI_Agent_1/prompt_1.txt`):
```
Tokens: prompt=1523, completion=450, thinking=1200, total=3173
```

### In Web Viewer

Visit: http://localhost:5001

The viewer will show:
- πŸ“Š Token breakdown including thinking tokens
- πŸ’° Cost calculation (thinking tokens = input cost)
- πŸ“ˆ Thinking usage trends

---

## βš™οΈ Configuration Options

### Model Selection

| Model | Thinking | Speed | Quality |
|-------|----------|-------|---------|
| `gemini-2.0-flash-exp` | ❌ | ⚑ Fast | Good |
| `gemini-2.0-flash-thinking-exp` | βœ… | 🐒 Slower | Better |

### Thinking Budget

Controls max tokens the model can use for thinking:

```yaml
thinking_budget: 16000  # Recommended: 8000-32000
```

- **Lower (8k)**: Faster, less thorough
- **Medium (16k)**: Balanced (default)
- **Higher (32k)**: Slower, more thorough

### Enable/Disable

```yaml
enable_thinking: true   # Turn on thinking mode
enable_thinking: false  # Turn off (faster, cheaper)
```

---

## πŸ’° Cost Impact

**Thinking tokens are charged as input tokens:**

Example (16k thinking budget):
- Standard mode: ~450 output tokens = $0.000034
- Thinking mode: ~1200 thinking + 450 output = $0.000056

**~1.6x cost increase for better decisions** 🎯

---

## πŸ” Viewing the Schema

The **response schema** is logged in TXT files for debugging:

```
=== Prompt #1 (Active Turn) ===

--- Response Schema ---
{
  "type": "object",
  "properties": {
    "internal_thinking": {
      "type": "string",
      "description": "Your reasoning process...",
      "minLength": 200
    },
    ...
  }
}

--- Prompt Content ---
{
  "meta_data": { ... }
}
```

Location: `examples/ai_testing/my_games/AI_Agent_1/prompt_N.txt`

---

## βœ… Testing Thinking Mode

### Quick Test

1. Edit `pycatan/ai/config.py`:
   ```python
   model_name: str = "gemini-2.0-flash-thinking-exp"
   enable_thinking: bool = True
   ```

2. Run a game:
   ```bash
   python play_catan.py
   ```

3. Check console output for thinking tokens:
   ```
   βœ… Response received: 450 tokens (+1200 thinking), 3.5s
   ```

4. View logs:
   ```bash
   # Check TXT file
   cat examples/ai_testing/my_games/AI_Agent_1/prompt_1.txt
   
   # Or JSON
   cat examples/ai_testing/my_games/AI_Agent_1/prompt_1.json
   ```

### Web Viewer

```bash
cd examples/ai_testing
python web_viewer.py
```

Visit http://localhost:5001 to see:
- Token breakdowns with thinking
- Cost calculations
- Response quality metrics

---

## πŸ› Troubleshooting

### Not Seeing Thinking Tokens?

1. **Check model name**: Must be `gemini-2.0-flash-thinking-exp`
2. **Check enable_thinking**: Must be `true` in config
3. **Check logs**: Look for "enable_thinking" in debug output

### Error: "thinking_config not supported"

- Your model doesn't support thinking mode
- Switch to: `gemini-2.0-flash-thinking-exp`

### High Costs?

- Reduce `thinking_budget` (e.g., 8000)
- Or disable thinking: `enable_thinking: false`

---

## πŸ“š Configuration Files

### Location

- **Active config**: `pycatan/ai/config_dev.yaml`
- **Example**: `pycatan/ai/config_example.yaml`
- **Defaults**: `pycatan/ai/config.py`

### Priority

1. Config YAML file (if exists)
2. Default values in `config.py`

---

## 🎯 Summary

**To enable thinking mode:**

1. Set `model_name: "gemini-2.0-flash-thinking-exp"`
2. Set `enable_thinking: true`
3. Set `thinking_budget: 16000` (optional)
4. Run your game
5. Check logs for thinking token counts

**Benefits:**
- βœ… Better strategic decisions
- βœ… More thorough reasoning
- βœ… Higher quality play

**Trade-offs:**
- ⏱️ Slower responses (~2-5s)
- πŸ’° Higher costs (~1.5-2x)