Update agents/tools/ai_tools.py
Browse files- agents/tools/ai_tools.py +31 -17
agents/tools/ai_tools.py
CHANGED
|
@@ -64,12 +64,14 @@ class AITools():
|
|
| 64 |
print(f"π€ AITools: {tool_name}: result={result}")
|
| 65 |
return result
|
| 66 |
except Exception as e:
|
|
|
|
| 67 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 68 |
|
| 69 |
def _extract_execution_result(response):
|
| 70 |
for part in response.candidates[0].content.parts:
|
| 71 |
if part.code_execution_result is not None:
|
| 72 |
return part.code_execution_result.output.strip()
|
|
|
|
| 73 |
return None
|
| 74 |
|
| 75 |
@tool("Web Search Tool")
|
|
@@ -105,6 +107,7 @@ class AITools():
|
|
| 105 |
print(f"π€ AITools: web_search_tool: result={result}")
|
| 106 |
return result
|
| 107 |
except Exception as e:
|
|
|
|
| 108 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 109 |
|
| 110 |
@tool("Web Browser Tool")
|
|
@@ -149,6 +152,7 @@ class AITools():
|
|
| 149 |
print(f"π€ AITools: web_browser_tool: result={result}")
|
| 150 |
return result
|
| 151 |
except Exception as e:
|
|
|
|
| 152 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 153 |
|
| 154 |
@tool("Image Analysis Tool")
|
|
@@ -234,6 +238,7 @@ class AITools():
|
|
| 234 |
print(f"π€ AITools: youtube_analysis_tool: result={result}")
|
| 235 |
return result
|
| 236 |
except Exception as e:
|
|
|
|
| 237 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 238 |
|
| 239 |
@tool("Document Analysis Tool")
|
|
@@ -283,6 +288,7 @@ class AITools():
|
|
| 283 |
print(f"π€ AITools: document_analysis_tool: result={result}")
|
| 284 |
return result
|
| 285 |
except Exception as e:
|
|
|
|
| 286 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 287 |
|
| 288 |
@tool("Code Generation Tool")
|
|
@@ -319,6 +325,7 @@ class AITools():
|
|
| 319 |
print(f"π€ AITools: code_generation_tool: result={result}")
|
| 320 |
return result
|
| 321 |
except Exception as e:
|
|
|
|
| 322 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 323 |
|
| 324 |
@tool("Code Execution Tool")
|
|
@@ -358,6 +365,7 @@ class AITools():
|
|
| 358 |
print(f"π€ AITools: code_execution_tool: result={result}")
|
| 359 |
return result
|
| 360 |
except Exception as e:
|
|
|
|
| 361 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 362 |
|
| 363 |
@tool("Image to FEN Tool")
|
|
@@ -421,6 +429,7 @@ class AITools():
|
|
| 421 |
print(f"π€ AITools: img_to_fen_tool: result={result}")
|
| 422 |
return result
|
| 423 |
except Exception as e:
|
|
|
|
| 424 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 425 |
|
| 426 |
@tool("Algebraic Notation Tool")
|
|
@@ -440,7 +449,7 @@ class AITools():
|
|
| 440 |
"""
|
| 441 |
print(f"π€ AITools: algebraic_notation_tool: question={question}, file_path={file_path}, best_move={best_move}")
|
| 442 |
|
| 443 |
-
try:
|
| 444 |
client = AITools._get_client()
|
| 445 |
|
| 446 |
with open(file_path, "rb") as f:
|
|
@@ -483,27 +492,32 @@ class AITools():
|
|
| 483 |
print(f"π€ AITools: algebraic_notation_tool: result={result}")
|
| 484 |
return result
|
| 485 |
except Exception as e:
|
|
|
|
| 486 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 487 |
|
| 488 |
def get_final_answer(question, answer):
|
| 489 |
print(f"π€ AITools: get_final_answer: question={question}, answer={answer}")
|
| 490 |
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
print(f"π€ AITools: get_final_answer: prompt={prompt}")
|
| 496 |
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
|
|
|
|
|
|
|
|
|
| 503 |
)
|
| 504 |
)
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
|
|
|
|
|
|
|
|
| 64 |
print(f"π€ AITools: {tool_name}: result={result}")
|
| 65 |
return result
|
| 66 |
except Exception as e:
|
| 67 |
+
print(f"π€ AITools: {tool_name}: result={str(e)}")
|
| 68 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 69 |
|
| 70 |
def _extract_execution_result(response):
|
| 71 |
for part in response.candidates[0].content.parts:
|
| 72 |
if part.code_execution_result is not None:
|
| 73 |
return part.code_execution_result.output.strip()
|
| 74 |
+
|
| 75 |
return None
|
| 76 |
|
| 77 |
@tool("Web Search Tool")
|
|
|
|
| 107 |
print(f"π€ AITools: web_search_tool: result={result}")
|
| 108 |
return result
|
| 109 |
except Exception as e:
|
| 110 |
+
print(f"π€ AITools: web_search_tool: result={str(e)}")
|
| 111 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 112 |
|
| 113 |
@tool("Web Browser Tool")
|
|
|
|
| 152 |
print(f"π€ AITools: web_browser_tool: result={result}")
|
| 153 |
return result
|
| 154 |
except Exception as e:
|
| 155 |
+
print(f"π€ AITools: web_browser_tool: result={str(e)}")
|
| 156 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 157 |
|
| 158 |
@tool("Image Analysis Tool")
|
|
|
|
| 238 |
print(f"π€ AITools: youtube_analysis_tool: result={result}")
|
| 239 |
return result
|
| 240 |
except Exception as e:
|
| 241 |
+
print(f"π€ AITools: youtube_analysis_tool: result={str(e)}")
|
| 242 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 243 |
|
| 244 |
@tool("Document Analysis Tool")
|
|
|
|
| 288 |
print(f"π€ AITools: document_analysis_tool: result={result}")
|
| 289 |
return result
|
| 290 |
except Exception as e:
|
| 291 |
+
print(f"π€ AITools: document_analysis_tool: result={str(e)}")
|
| 292 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 293 |
|
| 294 |
@tool("Code Generation Tool")
|
|
|
|
| 325 |
print(f"π€ AITools: code_generation_tool: result={result}")
|
| 326 |
return result
|
| 327 |
except Exception as e:
|
| 328 |
+
print(f"π€ AITools: code_generation_tool: result={str(e)}")
|
| 329 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 330 |
|
| 331 |
@tool("Code Execution Tool")
|
|
|
|
| 365 |
print(f"π€ AITools: code_execution_tool: result={result}")
|
| 366 |
return result
|
| 367 |
except Exception as e:
|
| 368 |
+
print(f"π€ AITools: code_execution_tool: result={str(e)}")
|
| 369 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 370 |
|
| 371 |
@tool("Image to FEN Tool")
|
|
|
|
| 429 |
print(f"π€ AITools: img_to_fen_tool: result={result}")
|
| 430 |
return result
|
| 431 |
except Exception as e:
|
| 432 |
+
print(f"π€ AITools: img_to_fen_tool: result={str(e)}")
|
| 433 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 434 |
|
| 435 |
@tool("Algebraic Notation Tool")
|
|
|
|
| 449 |
"""
|
| 450 |
print(f"π€ AITools: algebraic_notation_tool: question={question}, file_path={file_path}, best_move={best_move}")
|
| 451 |
|
| 452 |
+
try:
|
| 453 |
client = AITools._get_client()
|
| 454 |
|
| 455 |
with open(file_path, "rb") as f:
|
|
|
|
| 492 |
print(f"π€ AITools: algebraic_notation_tool: result={result}")
|
| 493 |
return result
|
| 494 |
except Exception as e:
|
| 495 |
+
print(f"π€ AITools: algebraic_notation_tool: result={str(e)}")
|
| 496 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 497 |
|
| 498 |
def get_final_answer(question, answer):
|
| 499 |
print(f"π€ AITools: get_final_answer: question={question}, answer={answer}")
|
| 500 |
|
| 501 |
+
try:
|
| 502 |
+
client = AITools._get_client()
|
| 503 |
+
|
| 504 |
+
prompt = PROMPT_FINAL_ANSWER.format(question=question, answer=answer)
|
|
|
|
| 505 |
|
| 506 |
+
print(f"π€ AITools: get_final_answer: prompt={prompt}")
|
| 507 |
+
|
| 508 |
+
response = client.models.generate_content(
|
| 509 |
+
model=LLM_FINAL_ANSWER,
|
| 510 |
+
contents=[prompt],
|
| 511 |
+
config=types.GenerateContentConfig(
|
| 512 |
+
thinking_config=types.ThinkingConfig(
|
| 513 |
+
thinking_level=THINKING_LEVEL_FINAL_ANSWER
|
| 514 |
+
)
|
| 515 |
)
|
| 516 |
)
|
| 517 |
+
|
| 518 |
+
result = response.text.strip()
|
| 519 |
+
print(f"π€ AITools: get_final_answer: result={result}")
|
| 520 |
+
return result
|
| 521 |
+
except Exception as e:
|
| 522 |
+
print(f"π€ AITools: get_final_answer: result={str(e)}")
|
| 523 |
+
raise RuntimeError(f"Processing failed: {str(e)}")
|