{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "d:\\ankelodon_multiagent_system\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "from agent import build_workflow\n", "from config import config\n", "from tools.code_interpreter import safe_code_run" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "graph = build_workflow()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "💡 ════════════════════\n", "💡 USER QUERY \n", "💡 ════════════════════\n", "Processing 1 files:\n", "\n", "📁 ════════════════════\n", "📁 FILE PREPARATION \n", "📁 ════════════════════\n", "📁 Processing 1 file(s)\n", " - D:/ankelodon_multiagent_system/data/Screenshot_1.png: image (979539 bytes) -> vision_qa_gemma\n", " • path: D:/ankelodon_multiagent_system/data/Screenshot_1.png\n", " • type: image\n", " • size: 979539 bytes\n", " • suggested_tool: vision_qa_gemma\n", "=== COMPLEXITY ASSESSMENT ===\n", "Complexity: simple\n", "Needs planning: False\n", "Reasoning: A mate-in-one is a single-step chess puzzle: it requires identifying one legal white move that delivers checkmate. That is one distinct step, no multi-stage data processing, and no specialized tools are required (unless you want to verify moves with a chess engine). Note: the user did not supply a board position (FEN/diagram/image); if the position is provided the task remains SIMPLE.\n", "=== SIMPLE EXECUTION ===\n", "Response generated for simple query.\n", "=== GENERATING EXECUTION REPORT ===\n", "Report generated - Confidence: high\n", "Key findings: 3\n", "Data sources: 2\n", "query_summary='User requested the mate-in-one move for White from a provided chess diagram and asked to return only the algebraic notation of the move.' approach_used='Used an image-based QA tool (vision_qa_gemma) to identify the chess position from the supplied screenshot, determine that it is White to move, compute the mate-in-one, and return the move in algebraic notation.' tools_executed=[ToolExecution(tool_name='vision_qa_gemma', arguments='{\\'question\\': \"Identify the chess position and find mate in one for White. Provide the algebraic notation of the move only. It\\'s White to move.\", \\'image_path\\': \\'D:/ankelodon_multiagent_system/data/Screenshot_1.png\\', \\'temperature\\': 0.2}', call_id='call_RxKLwrV2KP1sJ7ShaImQqbUl')] key_findings=['The position in the provided image was analyzed and confirmed to be White to move.', 'A forced mate in one was identified for White.', 'The mate-in-one move in algebraic notation is: Qf7#.'] data_sources=['Screenshot image: D:/ankelodon_multiagent_system/data/Screenshot_1.png', 'vision_qa_gemma tool output (see Tools Executed)'] assumptions_made=[\"Standard algebraic notation is used (including '#' for mate).\", 'Board orientation is conventional with White pieces at the bottom (as interpreted from the image).', 'The image is an accurate and complete representation of the game state (no hidden or obscured pieces).'] confidence_level='high' limitations=['Result depends on the accuracy of the vision tool interpreting the image; any misread piece or orientation could change the correct move.', 'Only one tool/analysis pass was used; no independent engine verification was run here.', 'If there are multiple legal mate-in-one moves in the position, this report records the move returned by the tool without enumerating alternatives.'] final_answer='Qf7#'\n", "=== ENHANCED ANSWER CRITIQUE ===\n", "Quality Score: 7/10\n", "Complete: True\n", "Accurate: True\n", "=== REPLAN DECISION ===\n", "Iteration: 1/10\n", "Quality score: 7\n", "Needs replanning: False\n", "Quality acceptable, ending execution\n" ] } ], "source": [ "query = \"Find the chekmate in one move and provide only algebraic notation of the move, its a white turn.\"\n", "result = graph.invoke({\"query\" : query, \"current_step\": 0, \"reasoning_done\": False, \"files\" : [\"D:/ankelodon_multiagent_system/data/Screenshot_1.png\"], \"files_contents\" : {}, \"iteration_count\" : 0, \"max_iterations\" : 10, \"plan\" : None} , config = config)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FINAL ANSWER: Qf7#\n" ] } ], "source": [ "print(result[\"final_answer\"])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'messages': [SystemMessage(content='You are a COMPLEXITY ASSESSOR for a multi-tool agent system.\\nYour job is to analyze user queries and determine their complexity level and processing requirements.\\n\\nCOMPLEXITY LEVELS:\\n1. SIMPLE: Direct questions that can be answered immediately without tools or with single tool use\\n - Examples: \"What is photosynthesis?\", \"Define machine learning\", \"What\\'s the capital of France?\"\\n - NOTE: Simple math like \"2+2\" still requires calculator tool but counts as SIMPLE\\n\\n !ALSO: It can be a logical reasoning or explanation task that does not require tools.\\n \\n2. MODERATE: Questions requiring 2-4 tool calls or basic multi-step analysis\\n - Examples: \"Search for recent news about AI\", \"Analyze this CSV file for trends\", \"Calculate ROI from this data\"\\n - \"Compare two datasets\", \"Summarize multiple documents\"\\n \\n3. COMPLEX: Multi-step problems requiring planning, multiple tools, and sophisticated reasoning\\n - Examples: \"Research market trends and create investment strategy\", \"Analyze multiple data sources and predict outcomes\"\\n - \"Build comprehensive report from various inputs\", \"Multi-stage data processing with validation\"\\n\\nMOST OF THE LOGICAL TASKS ARE SIMPLE, UNLESS THEY REQUIRE TOOLS.\\n\\nASSESSMENT CRITERIA:\\n- Number of distinct steps likely needed (1 = Simple, 2-4 = Moderate, 5+ = Complex)\\n- Tool complexity and dependencies between steps\\n- Data processing requirements and validation needs\\n- Need for intermediate reasoning and synthesis\\n- Risk of failure without proper step-by-step planning\\n- Presence of calculations (automatically requires tool usage)\\n\\nSPECIAL CONSIDERATIONS:\\n- Any calculation/counting task requires tools (affects complexity assessment)\\n- File analysis tasks usually need multiple steps (load + analyze + calculate)\\n- Research tasks typically need search + fetch/extract + synthesis steps\\n- Comparison tasks need separate analysis steps for each item being compared\\n\\nRULES:\\n- SIMPLE queries may bypass planning for non-calculation tasks\\n- MODERATE queries benefit from lightweight planning\\n- COMPLEX queries require full planning with fallbacks\\n- When in doubt, err toward higher complexity\\n- Calculation tasks are never truly \"simple\" due to mandatory tool usage\\n\\nAnalyze the query and respond with your assessment.', additional_kwargs={}, response_metadata={}, id='a857824a-40fa-4453-8cdd-5dd9c73cd1dc'),\n", " HumanMessage(content='Query: Find the chekmate in one move and provide only algebraic notation of the move, its a white turn.', additional_kwargs={}, response_metadata={}, id='5a765bb0-2ced-4919-aa4c-3cb6852b6a6d'),\n", " AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_RxKLwrV2KP1sJ7ShaImQqbUl', 'function': {'arguments': '{\"question\":\"Identify the chess position and find mate in one for White. Provide the algebraic notation of the move only. It\\'s White to move.\",\"image_path\":\"D:/ankelodon_multiagent_system/data/Screenshot_1.png\",\"temperature\":0.2}', 'name': 'vision_qa_gemma'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 140, 'prompt_tokens': 1771, 'total_tokens': 1911, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 64, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-5-mini-2025-08-07', 'system_fingerprint': None, 'id': 'chatcmpl-CIjeuIxLBZoq7rEjlZRWcfUO3KQWZ', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--d9288bb8-21be-4a2e-a8b9-7e4fa97936e9-0', tool_calls=[{'name': 'vision_qa_gemma', 'args': {'question': \"Identify the chess position and find mate in one for White. Provide the algebraic notation of the move only. It's White to move.\", 'image_path': 'D:/ankelodon_multiagent_system/data/Screenshot_1.png', 'temperature': 0.2}, 'id': 'call_RxKLwrV2KP1sJ7ShaImQqbUl', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1771, 'output_tokens': 140, 'total_tokens': 1911, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 64}}),\n", " ToolMessage(content='{\"answer\": \"Qf7#\"}', name='vision_qa_gemma', id='559a320c-cb49-4f46-8e18-8b50d13fcbde', tool_call_id='call_RxKLwrV2KP1sJ7ShaImQqbUl')],\n", " 'query': 'Find the chekmate in one move and provide only algebraic notation of the move, its a white turn.',\n", " 'final_answer': 'FINAL ANSWER: Qf7#',\n", " 'plan': None,\n", " 'complexity_assessment': ComplexityLevel(level='simple', reasoning='A mate-in-one is a single-step chess puzzle: it requires identifying one legal white move that delivers checkmate. That is one distinct step, no multi-stage data processing, and no specialized tools are required (unless you want to verify moves with a chess engine). Note: the user did not supply a board position (FEN/diagram/image); if the position is provided the task remains SIMPLE.', needs_planning=False, suggested_approach='Ask the user to provide the chess position (FEN string, diagram, or image). Once the position is available, generate all legal white moves, test which move results in immediate checkmate, and return only the move in algebraic notation (e.g., Qh7#).'),\n", " 'current_step': 0,\n", " 'reasoning_done': False,\n", " 'files': ['D:/ankelodon_multiagent_system/data/Screenshot_1.png'],\n", " 'file_contents': {'D:/ankelodon_multiagent_system/data/Screenshot_1.png': {'path': 'D:/ankelodon_multiagent_system/data/Screenshot_1.png',\n", " 'extension': '.png',\n", " 'size': 979539,\n", " 'type': 'image',\n", " 'suggested_tool': 'vision_qa_gemma',\n", " 'preview': None}},\n", " 'critique_feedback': CritiqueFeedback(quality_score=7, is_complete=True, is_accurate=True, missing_elements=[], errors_found=[], suggested_improvements=['Consider using an additional chess engine for verification of the mate-in-one move to ensure accuracy.', 'Provide a brief explanation of the reasoning behind the identified move to enhance clarity for the user.'], needs_replanning=False, replan_instructions=None),\n", " 'iteration_count': 1,\n", " 'max_iterations': 10,\n", " 'execution_report': ExecutionReport(query_summary='User requested the mate-in-one move for White from a provided chess diagram and asked to return only the algebraic notation of the move.', approach_used='Used an image-based QA tool (vision_qa_gemma) to identify the chess position from the supplied screenshot, determine that it is White to move, compute the mate-in-one, and return the move in algebraic notation.', tools_executed=[ToolExecution(tool_name='vision_qa_gemma', arguments='{\\'question\\': \"Identify the chess position and find mate in one for White. Provide the algebraic notation of the move only. It\\'s White to move.\", \\'image_path\\': \\'D:/ankelodon_multiagent_system/data/Screenshot_1.png\\', \\'temperature\\': 0.2}', call_id='call_RxKLwrV2KP1sJ7ShaImQqbUl')], key_findings=['The position in the provided image was analyzed and confirmed to be White to move.', 'A forced mate in one was identified for White.', 'The mate-in-one move in algebraic notation is: Qf7#.'], data_sources=['Screenshot image: D:/ankelodon_multiagent_system/data/Screenshot_1.png', 'vision_qa_gemma tool output (see Tools Executed)'], assumptions_made=[\"Standard algebraic notation is used (including '#' for mate).\", 'Board orientation is conventional with White pieces at the bottom (as interpreted from the image).', 'The image is an accurate and complete representation of the game state (no hidden or obscured pieces).'], confidence_level='high', limitations=['Result depends on the accuracy of the vision tool interpreting the image; any misread piece or orientation could change the correct move.', 'Only one tool/analysis pass was used; no independent engine verification was run here.', 'If there are multiple legal mate-in-one moves in the position, this report records the move returned by the tool without enumerating alternatives.'], final_answer='Qf7#')}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#TO-DO\n", "#1. Check routing with REPLANNER -> может придумывать несуществующие инструменты -> PARTIALLY COMPLETED\n", "#2. Add crawling tool \n", "#3. Enhance description of coder tool and прописать более четко в промпте важность вывода через print() или return или result/_ -> COMPLETED?\n", "#4. Смягчить критика COMPLETED" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 2 }