{ "cells": [ { "cell_type": "markdown", "id": "cb28dbf0", "metadata": {}, "source": [ "#### Do the imports and prepare the agent code" ] }, { "cell_type": "code", "execution_count": 19, "id": "6cff8644", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Token was found\n" ] } ], "source": [ "import os\n", "token = os.getenv(\"HF_TOKEN\")\n", "\n", "if token is None:\n", " raise ValueError('You must set the HF_TOKEN environment variable')\n", "else:\n", " print('Token was found')\n", " #print('Token:', token)\n" ] }, { "cell_type": "code", "execution_count": 21, "id": "a414cce1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "BasicAgent initialized.\n" ] } ], "source": [ "import os\n", "import requests\n", "import inspect\n", "import pandas as pd\n", "import json\n", "import yaml\n", "\n", "from smolagents import ToolCallingAgent, Tool, InferenceClientModel, DuckDuckGoSearchTool, WikipediaSearchTool\n", "from smolagents import OpenAIServerModel\n", "from tools import fetch_file\n", "\n", "#model = InferenceClientModel(model_id=\"Qwen/Qwen3-32B\", provider=\"nscale\")\n", "model = InferenceClientModel(model_id=\"deepseek-ai/DeepSeek-R1\", provider=\"nebius\")\n", "\n", "# Set your Gemini API key in the environment variable GEMINI_API_KEY_1\n", "#model = OpenAIServerModel(\n", "# model_id=\"gemini-2.5-flash\", \n", "# api_base=\"https://generativelanguage.googleapis.com/v1beta\", \n", "# api_key=os.getenv(\"GEMINI_API_KEY_1\")\n", "# ) \n", "#print('API key was found:', os.getenv(\"GEMINI_API_KEY_1\") is not None)\n", "\n", "# --- Basic Agent Definition ---\n", "# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------\n", "class BasicAgent:\n", " def __init__(self):\n", " print(\"BasicAgent initialized.\")\n", " def __call__(self, taskid: str, question: str) -> str:\n", " print(f\"Agent received question (first 50 chars): {question[:50]}...\")\n", " #fixed_answer = \"This is a default answer.\"\n", " #print(f\"Agent returning fixed answer: {fixed_answer}\")\n", "\n", " prompt = f\"\"\"\n", " \n", " You are a general AI assistant. \n", " I will ask you a question and you can use 9 steps to answer the question.\n", " You can use the tools I provide you to answer my question. Every tool call reduces the number \n", " of remaining steps available to answer the question. \n", " Report your thoughts, and finish your answer with the following template: \n", " FINAL ANSWER: [YOUR FINAL ANSWER]. \n", " \n", " YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.\n", " If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent sign unless specified otherwise.\n", " If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.\n", " 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. \n", "\n", " The taskid is {taskid}. If you need to download a file that comes with the question then use the taskid to fetch the file\n", " The question is '{question}'.\n", "\n", " You have 9 steps to answer the question.\n", "\n", " \"\"\"\n", "\n", " agent = ToolCallingAgent(\n", " tools=[\n", " fetch_file, \n", " DuckDuckGoSearchTool(), \n", " WikipediaSearchTool()\n", " ], \n", " model=model, \n", " max_steps=9,\n", " )\n", "\n", " # Run the agent with the prompt\n", " fixed_answer = agent.run(prompt)\n", "\n", " return fixed_answer\n", "\n", "agent = BasicAgent()\n" ] }, { "cell_type": "markdown", "id": "9190ad36", "metadata": {}, "source": [ "Run first question against agent" ] }, { "cell_type": "code", "execution_count": 22, "id": "09b50aa1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Agent received question (first 50 chars): How many studio albums were published by Mercedes ...\n" ] }, { "data": { "text/html": [ "
╭──────────────────────────────────────────────────── New run ────────────────────────────────────────────────────╮\n",
       "                                                                                                                 \n",
       " You are a general AI assistant.                                                                                 \n",
       "         I will ask you a question and you can use 9 steps to answer the question.                               \n",
       "         You can use the tools I provide you to answer my question. Every tool call reduces the number           \n",
       "         of remaining steps available to answer the question.                                                    \n",
       "         Report your thoughts, and finish your answer with the following template:                               \n",
       "         FINAL ANSWER: [YOUR FINAL ANSWER\\].                                                                     \n",
       "                                                                                                                 \n",
       "         YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers   \n",
       " and/or strings.                                                                                                 \n",
       "         If you are asked for a number, don’t use comma to write your number neither use units such as $ or      \n",
       " percent sign unless specified otherwise.                                                                        \n",
       "         If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write   \n",
       " the digits in plain text unless specified otherwise.                                                            \n",
       "         If you are asked for a comma separated list, apply the above rules depending of whether the element to  \n",
       " be put in the list is a number or a string.                                                                     \n",
       "                                                                                                                 \n",
       "         The taskid is 8e867cd7-cff9-4e6c-867a-ff5ddc2550be. If you need to download a file that comes with the  \n",
       " question then use the taskid to fetch the file                                                                  \n",
       "         The question is 'How many studio albums were published by Mercedes Sosa between 2000 and 2009           \n",
       " (included)? You can use the latest 2022 version of english wikipedia.'.                                         \n",
       "                                                                                                                 \n",
       "         You have 9 steps to answer the question.                                                                \n",
       "                                                                                                                 \n",
       "╰─ InferenceClientModel - deepseek-ai/DeepSeek-R1 ────────────────────────────────────────────────────────────────╯\n",
       "
\n" ], "text/plain": [ "\u001b[38;2;212;183;2m╭─\u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[1;38;2;212;183;2mNew run\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╮\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mYou are a general AI assistant. \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m I will ask you a question and you can use 9 steps to answer the question.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m You can use the tools I provide you to answer my question. Every tool call reduces the number \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m of remaining steps available to answer the question. \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m Report your thoughts, and finish your answer with the following template: \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m FINAL ANSWER: [YOUR FINAL ANSWER\\]. \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mand/or strings.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m If you are asked for a number, don’t use comma to write your number neither use units such as $ or \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mpercent sign unless specified otherwise.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mthe digits in plain text unless specified otherwise.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m If you are asked for a comma separated list, apply the above rules depending of whether the element to \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mbe put in the list is a number or a string. \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m The taskid is 8e867cd7-cff9-4e6c-867a-ff5ddc2550be. If you need to download a file that comes with the \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mquestion then use the taskid to fetch the file\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m The question is 'How many studio albums were published by Mercedes Sosa between 2000 and 2009 \u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m(included)? You can use the latest 2022 version of english wikipedia.'.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m You have 9 steps to answer the question.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m╰─\u001b[0m\u001b[38;2;212;183;2m InferenceClientModel - deepseek-ai/DeepSeek-R1 \u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╯\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n",
       "
\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m1\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Error while generating output:\n",
       "(Request ID: Root=1-686d606c-1f8bffb50e7ac4b077a26fe0;2128d2d1-4e56-4788-a9eb-3015f54f1e44)\n",
       "\n",
       "Bad request:\n",
       "
\n" ], "text/plain": [ "\u001b[1;31mError while generating output:\u001b[0m\n", "\u001b[1;31m(\u001b[0m\u001b[1;31mRequest ID: \u001b[0m\u001b[1;33mRoot\u001b[0m\u001b[1;31m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;31m-686d606c-1f8bffb50e7ac4b077a26fe0;\u001b[0m\u001b[93m2128d2d1-4e56-4788-a9eb-3015f54f1e44\u001b[0m\u001b[1;31m)\u001b[0m\n", "\n", "\u001b[1;31mBad request:\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
[Step 1: Duration 0.80 seconds]\n",
       "
\n" ], "text/plain": [ "\u001b[2m[Step 1: Duration 0.80 seconds]\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "ename": "AgentGenerationError", "evalue": "Error while generating output:\n(Request ID: Root=1-686d606c-1f8bffb50e7ac4b077a26fe0;2128d2d1-4e56-4788-a9eb-3015f54f1e44)\n\nBad request:", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mHTTPError\u001b[0m Traceback (most recent call last)", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\huggingface_hub\\utils\\_http.py:409\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[1;34m(response, endpoint_name)\u001b[0m\n\u001b[0;32m 408\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 409\u001b[0m \u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 410\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\requests\\models.py:1024\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1023\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[1;32m-> 1024\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m)\n", "\u001b[1;31mHTTPError\u001b[0m: 400 Client Error: Bad Request for url: https://router.huggingface.co/nebius/v1/chat/completions", "\nThe above exception was the direct cause of the following exception:\n", "\u001b[1;31mBadRequestError\u001b[0m Traceback (most recent call last)", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\smolagents\\agents.py:1272\u001b[0m, in \u001b[0;36mToolCallingAgent._step_stream\u001b[1;34m(self, memory_step)\u001b[0m\n\u001b[0;32m 1271\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m-> 1272\u001b[0m chat_message: ChatMessage \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1273\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_messages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1274\u001b[0m \u001b[43m \u001b[49m\u001b[43mstop_sequences\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mObservation:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mCalling tools:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1275\u001b[0m \u001b[43m \u001b[49m\u001b[43mtools_to_call_from\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtools_and_managed_agents\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1276\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1278\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger\u001b[38;5;241m.\u001b[39mlog_markdown(\n\u001b[0;32m 1279\u001b[0m content\u001b[38;5;241m=\u001b[39mchat_message\u001b[38;5;241m.\u001b[39mcontent \u001b[38;5;28;01mif\u001b[39;00m chat_message\u001b[38;5;241m.\u001b[39mcontent \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mstr\u001b[39m(chat_message\u001b[38;5;241m.\u001b[39mraw),\n\u001b[0;32m 1280\u001b[0m title\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOutput message of the LLM:\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 1281\u001b[0m level\u001b[38;5;241m=\u001b[39mLogLevel\u001b[38;5;241m.\u001b[39mDEBUG,\n\u001b[0;32m 1282\u001b[0m )\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\smolagents\\models.py:1408\u001b[0m, in \u001b[0;36mInferenceClientModel.generate\u001b[1;34m(self, messages, stop_sequences, response_format, tools_to_call_from, **kwargs)\u001b[0m\n\u001b[0;32m 1399\u001b[0m completion_kwargs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_prepare_completion_kwargs(\n\u001b[0;32m 1400\u001b[0m messages\u001b[38;5;241m=\u001b[39mmessages,\n\u001b[0;32m 1401\u001b[0m stop_sequences\u001b[38;5;241m=\u001b[39mstop_sequences,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1406\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[0;32m 1407\u001b[0m )\n\u001b[1;32m-> 1408\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mchat_completion\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mcompletion_kwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1410\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_last_input_token_count \u001b[38;5;241m=\u001b[39m response\u001b[38;5;241m.\u001b[39musage\u001b[38;5;241m.\u001b[39mprompt_tokens\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\huggingface_hub\\inference\\_client.py:924\u001b[0m, in \u001b[0;36mInferenceClient.chat_completion\u001b[1;34m(self, messages, model, stream, frequency_penalty, logit_bias, logprobs, max_tokens, n, presence_penalty, response_format, seed, stop, stream_options, temperature, tool_choice, tool_prompt, tools, top_logprobs, top_p, extra_body)\u001b[0m\n\u001b[0;32m 917\u001b[0m request_parameters \u001b[38;5;241m=\u001b[39m provider_helper\u001b[38;5;241m.\u001b[39mprepare_request(\n\u001b[0;32m 918\u001b[0m inputs\u001b[38;5;241m=\u001b[39mmessages,\n\u001b[0;32m 919\u001b[0m parameters\u001b[38;5;241m=\u001b[39mparameters,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 922\u001b[0m api_key\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtoken,\n\u001b[0;32m 923\u001b[0m )\n\u001b[1;32m--> 924\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_inner_post\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest_parameters\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 926\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m stream:\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\huggingface_hub\\inference\\_client.py:280\u001b[0m, in \u001b[0;36mInferenceClient._inner_post\u001b[1;34m(self, request_parameters, stream)\u001b[0m\n\u001b[0;32m 279\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 280\u001b[0m \u001b[43mhf_raise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 281\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m response\u001b[38;5;241m.\u001b[39miter_lines() \u001b[38;5;28;01mif\u001b[39;00m stream \u001b[38;5;28;01melse\u001b[39;00m response\u001b[38;5;241m.\u001b[39mcontent\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\huggingface_hub\\utils\\_http.py:465\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[1;34m(response, endpoint_name)\u001b[0m\n\u001b[0;32m 462\u001b[0m message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 463\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mendpoint_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m endpoint:\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m endpoint_name \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request:\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 464\u001b[0m )\n\u001b[1;32m--> 465\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m _format(BadRequestError, message, response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m 467\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m403\u001b[39m:\n", "\u001b[1;31mBadRequestError\u001b[0m: (Request ID: Root=1-686d606c-1f8bffb50e7ac4b077a26fe0;2128d2d1-4e56-4788-a9eb-3015f54f1e44)\n\nBad request:", "\nThe above exception was the direct cause of the following exception:\n", "\u001b[1;31mAgentGenerationError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[22], line 11\u001b[0m\n\u001b[0;32m 8\u001b[0m question_text \u001b[38;5;241m=\u001b[39m item[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mquestion\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m 9\u001b[0m task_id \u001b[38;5;241m=\u001b[39m item[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtask_id\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m---> 11\u001b[0m submitted_answer \u001b[38;5;241m=\u001b[39m \u001b[43magent\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtask_id\u001b[49m\u001b[43m,\u001b[49m\u001b[43mquestion_text\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 13\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSubmitted answer:\u001b[39m\u001b[38;5;124m\"\u001b[39m, submitted_answer)\n", "Cell \u001b[1;32mIn[21], line 65\u001b[0m, in \u001b[0;36mBasicAgent.__call__\u001b[1;34m(self, taskid, question)\u001b[0m\n\u001b[0;32m 54\u001b[0m agent \u001b[38;5;241m=\u001b[39m ToolCallingAgent(\n\u001b[0;32m 55\u001b[0m tools\u001b[38;5;241m=\u001b[39m[\n\u001b[0;32m 56\u001b[0m fetch_file, \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 61\u001b[0m max_steps\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m9\u001b[39m,\n\u001b[0;32m 62\u001b[0m )\n\u001b[0;32m 64\u001b[0m \u001b[38;5;66;03m# Run the agent with the prompt\u001b[39;00m\n\u001b[1;32m---> 65\u001b[0m fixed_answer \u001b[38;5;241m=\u001b[39m \u001b[43magent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 67\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fixed_answer\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\smolagents\\agents.py:442\u001b[0m, in \u001b[0;36mMultiStepAgent.run\u001b[1;34m(self, task, stream, reset, images, additional_args, max_steps)\u001b[0m\n\u001b[0;32m 439\u001b[0m run_start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n\u001b[0;32m 440\u001b[0m \u001b[38;5;66;03m# Outputs are returned only at the end. We only look at the last step.\u001b[39;00m\n\u001b[1;32m--> 442\u001b[0m steps \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_run_stream\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtask\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_steps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmax_steps\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mimages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mimages\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 443\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(steps[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m], FinalAnswerStep)\n\u001b[0;32m 444\u001b[0m output \u001b[38;5;241m=\u001b[39m steps[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\u001b[38;5;241m.\u001b[39moutput\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\smolagents\\agents.py:530\u001b[0m, in \u001b[0;36mMultiStepAgent._run_stream\u001b[1;34m(self, task, max_steps, images)\u001b[0m\n\u001b[0;32m 527\u001b[0m final_answer \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39moutput\n\u001b[0;32m 528\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m AgentGenerationError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 529\u001b[0m \u001b[38;5;66;03m# Agent generation errors are not caused by a Model error but an implementation error: so we should raise them and exit.\u001b[39;00m\n\u001b[1;32m--> 530\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[0;32m 531\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m AgentError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 532\u001b[0m \u001b[38;5;66;03m# Other AgentError types are caused by the Model, so we should log them and iterate.\u001b[39;00m\n\u001b[0;32m 533\u001b[0m action_step\u001b[38;5;241m.\u001b[39merror \u001b[38;5;241m=\u001b[39m e\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\smolagents\\agents.py:517\u001b[0m, in \u001b[0;36mMultiStepAgent._run_stream\u001b[1;34m(self, task, max_steps, images)\u001b[0m\n\u001b[0;32m 515\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger\u001b[38;5;241m.\u001b[39mlog_rule(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mStep \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstep_number\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, level\u001b[38;5;241m=\u001b[39mLogLevel\u001b[38;5;241m.\u001b[39mINFO)\n\u001b[0;32m 516\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 517\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43moutput\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_step_stream\u001b[49m\u001b[43m(\u001b[49m\u001b[43maction_step\u001b[49m\u001b[43m)\u001b[49m\u001b[43m:\u001b[49m\n\u001b[0;32m 518\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Yield streaming deltas\u001b[39;49;00m\n\u001b[0;32m 519\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43misinstance\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43moutput\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[43mActionOutput\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mToolOutput\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m:\u001b[49m\n\u001b[0;32m 520\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43;01myield\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43moutput\u001b[49m\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\smolagents\\agents.py:1289\u001b[0m, in \u001b[0;36mToolCallingAgent._step_stream\u001b[1;34m(self, memory_step)\u001b[0m\n\u001b[0;32m 1287\u001b[0m memory_step\u001b[38;5;241m.\u001b[39mtoken_usage \u001b[38;5;241m=\u001b[39m chat_message\u001b[38;5;241m.\u001b[39mtoken_usage\n\u001b[0;32m 1288\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m-> 1289\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m AgentGenerationError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mError while generating output:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00me\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m 1291\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m chat_message\u001b[38;5;241m.\u001b[39mtool_calls \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(chat_message\u001b[38;5;241m.\u001b[39mtool_calls) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m 1292\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", "\u001b[1;31mAgentGenerationError\u001b[0m: Error while generating output:\n(Request ID: Root=1-686d606c-1f8bffb50e7ac4b077a26fe0;2128d2d1-4e56-4788-a9eb-3015f54f1e44)\n\nBad request:" ] } ], "source": [ "item = {\n", " \"task_id\": \"8e867cd7-cff9-4e6c-867a-ff5ddc2550be\",\n", " \"question\": \"How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.\",\n", " \"Level\": \"1\",\n", " \"file_name\": \"\"\n", " }\n", "\n", "question_text = item[\"question\"]\n", "task_id = item[\"task_id\"]\n", "\n", "submitted_answer = agent(task_id,question_text)\n", "\n", "print(\"Submitted answer:\", submitted_answer)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.13.5" } }, "nbformat": 4, "nbformat_minor": 5 }