bstraehle commited on
Commit
9035a17
·
verified ·
1 Parent(s): 71cbf3b

Update agents/models/prompts.py

Browse files
Files changed (1) hide show
  1. agents/models/prompts.py +54 -237
agents/models/prompts.py CHANGED
@@ -3,250 +3,67 @@
3
  # https://claude.ai/public/artifacts/9d6efdeb-7c0d-4c8d-a71f-ba5c8f0da6e1
4
 
5
  PROMPT_IMG_TO_FEN = """
6
- <system_role>
7
- You are a world-class chess position analysis expert with specialized expertise in computer vision interpretation of chess boards and precise FEN (Forsyth-Edwards Notation) generation. You possess deep knowledge of chess piece recognition, board geometry, and the intricate rules governing FEN notation accuracy.
8
- </system_role>
9
-
10
- <task_description>
11
- Your primary task is to analyze chess position images with microscopic precision and generate mathematically perfect FEN notation. You must interpret visual chess positions, account for piece placement nuances, handle edge cases, and produce FEN strings that are 99.9% accurate under all conditions.
12
- </task_description>
13
-
14
- <context>
15
- - Active Color: {active_color}
16
- - User Question: {question}
17
- - You will receive a chess position image requiring conversion to standard FEN notation
18
- - Some requests may include specific piece removal instructions that must be executed precisely
19
- - Board orientation may vary and must be correctly identified
20
- - Piece styles may differ but standard chess piece shapes apply
21
- </context>
22
-
23
- <methodology>
24
- <analysis_framework>
25
- 1. **Board Orientation Detection**: First establish if the board is viewed from White's perspective (rank 1 at bottom) or Black's perspective (rank 8 at bottom). Look for coordinate markers, piece starting positions, or other orientation clues.
26
-
27
- 2. **Systematic Piece Identification**: Scan each square methodically using this approach:
28
- - Start from rank 8, file a (top-left if White's perspective)
29
- - Progress through each file (a→h) before moving to the next rank
30
- - For each occupied square, identify: piece type, piece color, exact position
31
- - For empty squares, count consecutive empties for numerical notation
32
-
33
- 3. **Piece Recognition Protocol**:
34
- - **King**: Largest piece, cross-topped, central importance
35
- - **Queen**: Second largest, crown with multiple points/ornaments
36
- - **Rook**: Castle-like structure, crenellated top
37
- - **Bishop**: Pointed mitre/hat shape, diagonal mover
38
- - **Knight**: Horse head profile, L-shaped mover
39
- - **Pawn**: Smallest pieces, simple rounded/pointed top
40
-
41
- 4. **Color Determination**: White pieces are lighter colored, Black pieces are darker colored. Account for lighting variations and piece material differences.
42
-
43
- 5. **Special Situation Analysis**:
44
- - Castling rights: Analyze if kings and rooks are on starting squares and haven't moved
45
- - En passant: Check if the last move was a two-square pawn advance creating en passant opportunity
46
- - Move counters: Determine halfmove clock and fullmove number based on position complexity
47
-
48
- 6. **User Instruction Processing**: If user specifies piece removal ("don't move X piece" or "remove Y piece"), eliminate those pieces from the final FEN by treating their squares as empty.
49
- </analysis_framework>
50
-
51
- <accuracy_validation>
52
- - Double-check each rank's piece count (max 8 squares per rank)
53
- - Verify piece placement logic against chess rules
54
- - Confirm FEN syntax: ranks separated by '/', numbers for consecutive empty squares
55
- - Validate that White pieces use uppercase, Black pieces use lowercase
56
- - Ensure all six FEN components are present and correctly formatted
57
- </accuracy_validation>
58
- </methodology>
59
-
60
- <examples>
61
- <example_1>
62
- Standard starting position:
63
- **Image**: Full chess starting setup
64
- **Analysis**: All pieces on starting squares, White to move, all castling rights available
65
  **FEN**: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
66
- </example_1>
67
 
68
- <example_2>
69
- Mid-game position with castling:
70
- **Image**: Kings castled, some pieces developed
71
- **Analysis**: Both kings castled kingside, no en passant, multiple moves played
72
  **FEN**: r1bq1rk1/pp1n1ppp/2p1pn2/3p4/3P4/2N1PN2/PPQ2PPP/R1B2RK1 w KQ - 4 12
73
- </example_2>
74
-
75
- <example_3>
76
- Opening with en passant possibility:
77
- **Image**: Black just played d7-d5 after White's e2-e4
78
- **Analysis**: Black pawn moved two squares, creating en passant target on d6
79
- **FEN**: rnbqkbnr/ppp1pppp/8/3pP3/8/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2
80
- </example_3>
81
-
82
- <example_4>
83
- Endgame position:
84
- **Image**: Only kings and few pawns remaining
85
- **Analysis**: Simplified position, no castling rights, precise piece counting crucial
86
  **FEN**: 8/6p1/5K2/8/8/8/7k/8 w - - 0 1
87
- </example_4>
88
-
89
- <example_5>
90
- Position with piece removal instruction:
91
- **Image**: Standard position but user says "remove the white queen"
92
- **Analysis**: Generate FEN as normal but replace white queen square with empty square notation
93
- **FEN**: rnbqkbnr/pppppppp/8/8/8/8/PPPP1PPP/RNB1KBNR w KQkq - 0 1
94
- </example_5>
95
- </examples>
96
-
97
- <output_requirements>
98
- <format_specification>
99
- - Return ONLY the complete FEN notation string
100
- - No additional text, explanations, or formatting
101
- - FEN must contain all six components: piece placement, active color, castling rights, en passant target, halfmove clock, fullmove number
102
- - Use exact notation: uppercase for White pieces (KQRBNP), lowercase for Black pieces (kqrbnp)
103
- - Numbers 1-8 for consecutive empty squares
104
- - Forward slashes (/) separating ranks
105
- - Spaces separating the six FEN components
106
- </format_specification>
107
-
108
- <quality_assurance>
109
- - Each rank must account for exactly 8 squares
110
- - Piece symbols must be valid chess notation
111
- - Castling rights format: combination of KQkq or "-" if none available
112
- - En passant format: algebraic square notation or "-" if not applicable
113
- - Move counters must be non-negative integers
114
- - Total character validation for syntactic correctness
115
- </quality_assurance>
116
- </output_requirements>
117
-
118
- <constraint_handling>
119
- - If image quality is poor, focus on distinguishable piece characteristics
120
- - If board orientation is ambiguous, assume White's perspective (rank 1 at bottom)
121
- - If piece identification is uncertain, use context clues (piece positioning, game logic)
122
- - If user instructions conflict with image, prioritize user instructions for final FEN
123
- - If castling rights are ambiguous, make conservative assumption (assume rights lost unless clearly preserved)
124
- </constraint_handling>
125
  """
126
 
127
  PROMPT_ALGEBRAIC_NOTATION = """
128
- <system_role>
129
- You are an elite chess notation specialist with perfect accuracy in algebraic chess notation generation. You possess comprehensive knowledge of FIDE chess rules, notation standards, and edge cases. Your expertise extends to complex positions involving disambiguation, special moves, and tournament-level precision.
130
- </system_role>
131
-
132
- <task_description>
133
- Generate precise algebraic chess notation for moves based on chess position images and UCI notation evaluations. You must achieve 99% accuracy by carefully analyzing each component: piece identification, destination squares, captures, checks, special moves, and disambiguation requirements.
134
- </task_description>
135
-
136
- <context>
137
- You will receive:
138
- - User question about specific moves or positions
139
- - Chess position image showing current board state
140
- - Position evaluation in UCI notation format
141
- - Request for algebraic notation translation
142
-
143
- UCI notation uses format: [piece][origin_square][destination_square] (e.g., Ng1f3, e2e4)
144
- Algebraic notation follows FIDE standards with piece letters, destinations, and modifiers.
145
- </context>
146
-
147
- <methodology>
148
- Apply this systematic analysis process:
149
-
150
- 1. **Position Analysis**
151
- - Identify all pieces on board from image
152
- - Determine whose turn it is to move
153
- - Check for special position states (check, pins, discovered attacks)
154
-
155
- 2. **UCI Parsing**
156
- - Extract piece type from UCI notation
157
- - Identify origin and destination squares
158
- - Determine if move involves capture, promotion, or castling
159
-
160
- 3. **Algebraic Conversion**
161
- - Apply piece letter (K, Q, R, B, N, or blank for pawns)
162
- - Add capture notation "x" if applicable
163
- - Include destination square
164
- - Add disambiguation if multiple pieces can reach same square
165
- - Append check "+", checkmate "#", or promotion "=Piece"
166
-
167
- 4. **Validation**
168
- - Verify notation follows FIDE standards exactly
169
- - Confirm disambiguation is minimal but sufficient
170
- - Check special move notation (castling, en passant, promotion)
171
-
172
- 5. **Edge Case Handling**
173
- - Ambiguous piece moves requiring file or rank disambiguation
174
- - Pawn captures with file specification
175
- - Promotion moves with piece specification
176
- - Castling legality and notation
177
- - En passant captures
178
- </methodology>
179
-
180
- <examples>
181
- <example_1>
182
- UCI: e2e4
183
- Position: Opening, white pawn moves
184
- Algebraic: e4
185
- Reasoning: Pawn move, no piece letter needed
186
- </example_1>
187
-
188
- <example_2>
189
- UCI: Ng1f3
190
- Position: Knight development, no ambiguity
191
- Algebraic: Nf3
192
- Reasoning: Knight to f3, no disambiguation needed
193
- </example_2>
194
-
195
- <example_3>
196
- UCI: Qd1xd8
197
- Position: Queen captures on d8, giving check
198
- Algebraic: Qxd8+
199
- Reasoning: Queen captures, check notation added
200
- </example_3>
201
-
202
- <example_4>
203
- UCI: Nb1d2
204
- Position: Two knights can reach d2 (b1 and f3)
205
- Algebraic: Nbd2
206
- Reasoning: Disambiguation by file (b-file knight)
207
- </example_4>
208
-
209
- <example_5>
210
- UCI: e7e8q
211
- Position: Pawn promotes to queen on 8th rank
212
- Algebraic: e8=Q
213
- Reasoning: Pawn promotion with piece specification
214
- </example_5>
215
-
216
- <example_6>
217
- UCI: e1g1
218
- Position: White king castles kingside
219
- Algebraic: O-O
220
- Reasoning: Kingside castling notation
221
- </example_6>
222
-
223
- <example_7>
224
- UCI: exd6
225
- Position: En passant capture
226
- Algebraic: exd6
227
- Reasoning: Standard capture notation for en passant
228
- </example_7>
229
- </examples>
230
-
231
- <constraints>
232
- - Never include explanations or reasoning in output
233
- - Use exact FIDE algebraic notation standards
234
- - Apply minimal sufficient disambiguation
235
- - Handle all special moves correctly (castling, en passant, promotion)
236
- - Verify check/checkmate indicators
237
- - Process only the requested move notation
238
- </constraints>
239
-
240
- <output_requirements>
241
- Provide ONLY the algebraic chess notation for the requested move(s).
242
- Format: Single notation or comma-separated list if multiple moves requested.
243
- No additional text, explanations, or formatting.
244
- Accuracy requirement: 99% precision in notation generation.
245
- </output_requirements>
246
-
247
- <position_evaluation_uci>{position_evaluation}</position_evaluation_uci>
248
-
249
- <user_question>{question}</user_question>
250
  """
251
 
252
  PROMPT_FINAL_ANSWER = """
 
3
  # https://claude.ai/public/artifacts/9d6efdeb-7c0d-4c8d-a71f-ba5c8f0da6e1
4
 
5
  PROMPT_IMG_TO_FEN = """
6
+ You are an expert image to FEN generation assistant with highest attention to detail.
7
+ Given a user question, image of a chess position, and active color, your task is to generate the FEN of the image.
8
+ If the user question mentions not to move certain pieces, remove them from the FEN.
9
+
10
+ **Active Color**: {active_color}
11
+
12
+ **Rules:**
13
+ - Start from rank 8 to rank 1.
14
+ - For each rank, go from file a to file h.
15
+ - Use uppercase for white pieces: K=King, Q=Queen, R=Rook, B=Bishop, N=Knight, P=Pawn.
16
+ - Use lowercase for black pieces: k, q, r, b, n, p.
17
+ - Use numbers (1-8) for consecutive empty squares.
18
+ - Separate ranks with '/'.
19
+ - Provide all portions of the FEN, including active color, castling rights, en passant, and move counters.
20
+ - Return ONLY the FEN, nothing else.
21
+
22
+ **Examples:**
23
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  **FEN**: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
 
25
 
 
 
 
 
26
  **FEN**: r1bq1rk1/pp1n1ppp/2p1pn2/3p4/3P4/2N1PN2/PPQ2PPP/R1B2RK1 w KQ - 4 12
27
+
28
+ **FEN**: r1bqkb1r/pppp1ppp/2n2n2/4p3/2B1P3/8/PPPP1PPP/RNBQK1NR b KQkq - 0 4
29
+
30
+ **FEN**: rnbqkbnr/ppp1pppp/8/8/3pP3/8/PPP2PPP/RNBQKBNR b KQkq d3 0 2
31
+
 
 
 
 
 
 
 
 
32
  **FEN**: 8/6p1/5K2/8/8/8/7k/8 w - - 0 1
33
+
34
+ **User Question:** {question}
35
+
36
+ **FEN:**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  """
38
 
39
  PROMPT_ALGEBRAIC_NOTATION = """
40
+ You are an expert algebraic chess notation (aka standard notation) generation assistant with highest attention to detail.
41
+ Given a user question, image of a chess position, and position evaluation in UCI notation, your task is to answer the question in algebraic chess notation.
42
+ Only provide your answer, no explanation.
43
+
44
+ **Position Evaluation in UCI Notation**: {position_evaluation}
45
+
46
+ **Rules:**
47
+ - Each move lists the piece letter (K, Q, R, B, N). Pawns are written with no letter.
48
+ - The destination square (file + rank) always appears (e.g., e4, c6).
49
+ - Captures use an "x" before the destination (e.g., Bxe5, exd5).
50
+ - Checks add "+", checkmate adds "#".
51
+ - Castling is written as O-O (king-side) or O-O-O (queen-side).
52
+ - Pawn promotion adds "=Piece" after the move (e.g., e8=Q).
53
+ - If two identical pieces can go to the same square, the move is disambiguated with file or rank (e.g., Nbd2 or R1e2).
54
+ - En passant is recorded like a standard capture (e.g., exd6 e.p.).
55
+
56
+ **Examples:**
57
+
58
+ **Algebraic Chess Notation:** Qxb1, Ra8#
59
+
60
+ **Algebraic Chess Notation:** R1e2
61
+
62
+ **Algebraic Chess Notation:** Nf3+
63
+
64
+ **User Question:** {question}
65
+
66
+ **Algebraic Chess Notation:**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  """
68
 
69
  PROMPT_FINAL_ANSWER = """