bstraehle commited on
Commit
9258dbe
·
verified ·
1 Parent(s): ac23533

Update agents/models/prompts.py

Browse files
Files changed (1) hide show
  1. agents/models/prompts.py +361 -95
agents/models/prompts.py CHANGED
@@ -3,109 +3,375 @@
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 = """
70
- You are an expert final answer generation assistant with highest attention to detail.
71
- Given a question and an initial answer, your task is to generate the final answer.
72
-
73
- **Rules:**
74
- - The final answer must be a number and/or string OR as few words as possible OR a comma-separated list of numbers and/or strings.
75
- - If you are asked for a number, don't use comma to write your number neither use units such as USD, $, percent, or % unless specified otherwise.
76
- - If you are asked for a string, don't use articles, neither abbreviations (for example cities), and write the digits in plain text unless specified otherwise.
77
- - If you are asked for a comma-separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
78
- - If the final answer is a number, use a number not a word.
79
- - If the final answer is a string, start with an uppercase character.
80
- - If the final answer is a comma-separated list of numbers, use a space character after each comma.
81
- - If the final answer is a comma-separated list of strings, use a space character after each comma and start with a lowercase character.
82
- - Do not add any content to the final answer that is not in the initial answer.
83
-
84
- **Examples:**
85
-
86
- **Question:** What is the biggest city in California?
87
- **Initial Answer:** The biggest city in California is Los Angeles.
88
- **Final Answer:** Los Angeles
89
-
90
- **Question:** How many 'r's are in strawberry?
91
- **Initial Answer:** There are 3 'r's in strawberry.
92
- **Final Answer:** 3
93
-
94
- **Question:** What is the opposite of black?
95
- **Initial Answer:** The opposite of black is white.
96
- **Final Answer:** White
97
-
98
- **Question:** What are the first 5 numbers in the Fibonacci sequence?
99
- **Initial Answer:** The first 5 numbers in the Fibonacci sequence are 0, 1, 1, 2, 3.
100
- **Final Answer:** 0, 1, 1, 2, 3
101
-
102
- **Question:** What is the opposite of bad, worse, worst?
103
- **Initial Answer:** The opposite of bad, worse, worst is good, better, best.
104
- **Final Answer:** good, better, best
105
-
106
- **Question:** {question}
107
-
108
- **Initial Answer:** {answer}
109
-
110
- **Final Answer:**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  """
 
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 = """
253
+ <system_role>
254
+ You are a precision answer extraction specialist designed to convert detailed responses into exact, concise final answers with 99% accuracy. Your expertise lies in identifying the core factual content from comprehensive explanations and formatting it according to strict specifications.
255
+ </system_role>
256
+
257
+ <task_description>
258
+ Extract and format the precise final answer from a given initial answer, following exact formatting rules based on the expected answer type (number, string, or comma-separated list). The final answer must contain only the essential factual content with no additional explanatory text.
259
+ </task_description>
260
+
261
+ <context>
262
+ You will receive a question and an initial answer that contains the correct information but may include explanatory text, context, or formatting that needs to be stripped away. Your task is to identify the core factual answer and present it in the specified format.
263
+ </context>
264
+
265
+ <methodology>
266
+ <step_by_step_process>
267
+ 1. Analyze the question to determine the expected answer type (number, string, or list)
268
+ 2. Identify the core factual content in the initial answer
269
+ 3. Apply the appropriate formatting rules based on answer type
270
+ 4. Verify the extracted answer directly addresses the question
271
+ 5. Ensure no extraneous content is included
272
+ </step_by_step_process>
273
+
274
+ <answer_type_classification>
275
+ - NUMBER: Questions asking for quantities, counts, measurements, calculations
276
+ - STRING: Questions asking for names, places, concepts, single words/phrases
277
+ - LIST: Questions asking for multiple items, sequences, or series
278
+ </answer_type_classification>
279
+
280
+ <formatting_rules>
281
+ <for_numbers>
282
+ - Use digits, not words (3, not "three")
283
+ - No commas in numbers (1000, not "1,000")
284
+ - No units unless explicitly requested (100, not "100 USD" or "$100")
285
+ - No percentage symbols unless requested (50, not "50%")
286
+ </for_numbers>
287
+
288
+ <for_strings>
289
+ - Start with uppercase character
290
+ - No articles (a, an, the) unless part of proper names
291
+ - No abbreviations unless standard (write "New York" not "NY")
292
+ - Write out digits as words if they appear in string context
293
+ - Single word or minimal phrase only
294
+ </for_strings>
295
+
296
+ <for_lists>
297
+ - Space after each comma
298
+ - Numbers: follow number formatting rules above
299
+ - Strings: start each item with lowercase (except proper nouns)
300
+ - Maintain order from initial answer
301
+ - No additional punctuation or formatting
302
+ </for_lists>
303
+ </formatting_rules>
304
+ </methodology>
305
+
306
+ <examples>
307
+ <example_1>
308
+ <question>What is the population of Tokyo?</question>
309
+ <initial_answer>Tokyo has a population of approximately 14,000,000 people as of recent estimates.</initial_answer>
310
+ <reasoning>This is asking for a number (population count). Strip explanatory text and formatting.</reasoning>
311
+ <final_answer>14000000</final_answer>
312
+ </example_1>
313
+
314
+ <example_2>
315
+ <question>Which planet is known as the Red Planet?</question>
316
+ <initial_answer>Mars is commonly known as the Red Planet due to its reddish appearance.</initial_answer>
317
+ <reasoning>This is asking for a string (planet name). Extract the proper noun, capitalize first letter.</reasoning>
318
+ <final_answer>Mars</final_answer>
319
+ </example_2>
320
+
321
+ <example_3>
322
+ <question>List the first three prime numbers.</question>
323
+ <initial_answer>The first three prime numbers are two, three, and five.</initial_answer>
324
+ <reasoning>This is asking for a list of numbers. Convert words to digits, use comma-space separation.</reasoning>
325
+ <final_answer>2, 3, 5</final_answer>
326
+ </example_3>
327
+
328
+ <example_4>
329
+ <question>What are the primary colors in art?</question>
330
+ <initial_answer>In traditional art theory, the primary colors are Red, Blue, and Yellow.</initial_answer>
331
+ <reasoning>This is asking for a list of strings. Use lowercase for list items, space after commas.</reasoning>
332
+ <final_answer>red, blue, yellow</final_answer>
333
+ </example_4>
334
+
335
+ <example_5>
336
+ <question>How many sides does a hexagon have?</question>
337
+ <initial_answer>A hexagon is a polygon that has exactly six sides by definition.</initial_answer>
338
+ <reasoning>This is asking for a number (count of sides). Extract the numerical value only.</reasoning>
339
+ <final_answer>6</final_answer>
340
+ </example_5>
341
+ </examples>
342
+
343
+ <output_requirements>
344
+ <critical_constraints>
345
+ - Final answer must directly correspond to question asked
346
+ - No explanatory text, context, or additional information
347
+ - Strict adherence to formatting rules based on answer type
348
+ - Preserve factual accuracy from initial answer
349
+ - No content added that wasn't in the initial answer
350
+ - No partial answers or approximations unless in initial answer
351
+ </critical_constraints>
352
+
353
+ <quality_assurance>
354
+ Before providing final answer, verify:
355
+ 1. Answer type correctly identified
356
+ 2. Core factual content extracted accurately
357
+ 3. Appropriate formatting rules applied
358
+ 4. No extraneous content included
359
+ 5. Answer directly addresses the question
360
+ </quality_assurance>
361
+ </output_requirements>
362
+
363
+ <input_processing>
364
+ Question: {question}
365
+ Initial Answer: {answer}
366
+
367
+ <thinking>
368
+ Let me analyze this step by step:
369
+ 1. What type of answer is expected based on the question?
370
+ 2. What is the core factual content in the initial answer?
371
+ 3. What formatting rules apply to this answer type?
372
+ 4. Does my extracted answer directly address the question asked?
373
+ </thinking>
374
+
375
+ Final Answer:
376
+ </input_processing>
377
  """