{ "cells": [ { "cell_type": "code", "execution_count": 34, "id": "f2eb4141", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from agno.agent import Agent\n", "from agno.models.openai import OpenAIChat, OpenAILike\n", "from agno.tools.reasoning import ReasoningTools\n", "from agno.tools.yfinance import YFinanceTools\n", "import os\n", "from textwrap import dedent\n", "import dotenv\n", "\n", "dotenv.load_dotenv()" ] }, { "cell_type": "code", "execution_count": 35, "id": "9f73e3ae", "metadata": {}, "outputs": [], "source": [ "model = OpenAILike(\n", " id=\"qwen3-32b\",\n", " api_key=os.getenv(\"BAILIAN_API_KEY\"),\n", " base_url=os.getenv(\"BAILIAN_API_BASE_URL\"),\n", " request_params={\"extra_body\": {\"enable_thinking\": False}},\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "a0f662f7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
DEBUG ****** Agent ID: 005dffe2-dd4f-4efc-999e-bbf8012c7862 ******                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ****** Agent ID: \u001b[93m005dffe2-dd4f-4efc-999e-bbf8012c7862\u001b[0m ****** \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ***** Session ID: f5fb3d50-3e88-45d9-961e-c251429cdbff *****                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ***** Session ID: \u001b[93mf5fb3d50-3e88-45d9-961e-c251429cdbff\u001b[0m ***** \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Processing tools for model                                                                                   \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Processing tools for model \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Added tool get_news                                                                                          \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Added tool get_news \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ** Agent Run Start: 982007e4-557b-48d7-b368-e01617c617c3 ***                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ** Agent Run Start: \u001b[93m982007e4-557b-48d7-b368-e01617c617c3\u001b[0m *** \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG --------------- OpenAI Response Stream Start ---------------                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m --------------- OpenAI Response Stream Start --------------- \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG --------------------- Model: qwen3-32b ---------------------                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m --------------------- Model: qwen3-32b --------------------- \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG =========================== user ===========================                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m =========================== user =========================== \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG What's the latest news and financial performance of Apple (AAPL)?                                            \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m What's the latest news and financial performance of Apple \u001b[1m(\u001b[0mAAPL\u001b[1m)\u001b[0m? \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Calling OpenAI with request parameters: {'tools': [{'type': 'function', 'function': {'name': 'get_news',     \n",
       "      'description': '', 'parameters': {'type': 'object', 'properties': {'description': {'type': 'string'}},       \n",
       "      'required': ['description']}}}], 'tool_choice': 'auto', 'extra_body': {'enable_thinking': False}}            \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Calling OpenAI with request parameters: \u001b[1m{\u001b[0m\u001b[32m'tools'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'function'\u001b[0m, \u001b[32m'function'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'name'\u001b[0m: \u001b[32m'get_news'\u001b[0m, \n", " \u001b[32m'description'\u001b[0m: \u001b[32m''\u001b[0m, \u001b[32m'parameters'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'object'\u001b[0m, \u001b[32m'properties'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'description'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \n", " \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m'description'\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m'tool_choice'\u001b[0m: \u001b[32m'auto'\u001b[0m, \u001b[32m'extra_body'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'enable_thinking'\u001b[0m: \u001b[3;91mFalse\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9d2aae22bec94b57aab6c0c4584f9687", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ======================== assistant =========================                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ======================== assistant ========================= \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Tool Calls:                                                                                                  \n",
       "        - ID: 'call_60e1a1ea7d91423c9f34ba'                                                                        \n",
       "          Name: 'get_news'                                                                                         \n",
       "          Arguments: 'description: latest news and financial performance of Apple (AAPL)'                          \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Tool Calls: \n", " - ID: \u001b[32m'call_60e1a1ea7d91423c9f34ba'\u001b[0m \n", " Name: \u001b[32m'get_news'\u001b[0m \n", " Arguments: \u001b[32m'description: latest news and financial performance of Apple \u001b[0m\u001b[32m(\u001b[0m\u001b[32mAAPL\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ************************  METRICS  *************************                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ************************ METRICS ************************* \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Tokens:                      input=157, output=29, total=186                                               \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Tokens: \u001b[33minput\u001b[0m=\u001b[1;36m157\u001b[0m, \u001b[33moutput\u001b[0m=\u001b[1;36m29\u001b[0m, \u001b[33mtotal\u001b[0m=\u001b[1;36m186\u001b[0m \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Time:                        1.3610s                                                                       \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Time: \u001b[1;36m1.\u001b[0m3610s \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Tokens per second:           21.3081 tokens/s                                                              \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Tokens per second: \u001b[1;36m21.3081\u001b[0m tokens/s \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Time to first token:         1.3589s                                                                       \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Time to first token: \u001b[1;36m1.\u001b[0m3589s \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ************************  METRICS  *************************                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ************************ METRICS ************************* \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Running: get_news(description=...)                                                                           \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Running: \u001b[1;35mget_news\u001b[0m\u001b[1m(\u001b[0m\u001b[33mdescription\u001b[0m=\u001b[33m...\u001b[0m\u001b[1m)\u001b[0m \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
get_news: latest news and financial performance of Apple (AAPL)\n",
       "
\n" ], "text/plain": [ "get_news: latest news and financial performance of Apple (AAPL)\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG =========================== tool ===========================                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m =========================== tool =========================== \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Tool call Id: call_60e1a1ea7d91423c9f34ba                                                                    \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Tool call Id: call_60e1a1ea7d91423c9f34ba \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG No news                                                                                                      \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m No news \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG **********************  TOOL METRICS  **********************                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ********************** TOOL METRICS ********************** \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Time:                        0.0015s                                                                       \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Time: \u001b[1;36m0.\u001b[0m0015s \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG **********************  TOOL METRICS  **********************                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ********************** TOOL METRICS ********************** \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Calling OpenAI with request parameters: {'tools': [{'type': 'function', 'function': {'name': 'get_news',     \n",
       "      'description': '', 'parameters': {'type': 'object', 'properties': {'description': {'type': 'string'}},       \n",
       "      'required': ['description']}}}], 'tool_choice': 'auto', 'extra_body': {'enable_thinking': False}}            \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Calling OpenAI with request parameters: \u001b[1m{\u001b[0m\u001b[32m'tools'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'function'\u001b[0m, \u001b[32m'function'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'name'\u001b[0m: \u001b[32m'get_news'\u001b[0m, \n", " \u001b[32m'description'\u001b[0m: \u001b[32m''\u001b[0m, \u001b[32m'parameters'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'object'\u001b[0m, \u001b[32m'properties'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'description'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'type'\u001b[0m: \u001b[32m'string'\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \n", " \u001b[32m'required'\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m'description'\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m\u001b[1m]\u001b[0m, \u001b[32m'tool_choice'\u001b[0m: \u001b[32m'auto'\u001b[0m, \u001b[32m'extra_body'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'enable_thinking'\u001b[0m: \u001b[3;91mFalse\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ======================== assistant =========================                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ======================== assistant ========================= \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG It seems there is no recent news or financial performance update for Apple (AAPL) at this time. You might    \n",
       "      want to check a reliable financial news source or the company's official investor relations page for the     \n",
       "      latest updates. Let me know if you need assistance with anything else!                                       \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m It seems there is no recent news or financial performance update for Apple \u001b[1m(\u001b[0mAAPL\u001b[1m)\u001b[0m at this time. You might \n", " want to check a reliable financial news source or the company's official investor relations page for the \n", " latest updates. Let me know if you need assistance with anything else! \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ************************  METRICS  *************************                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ************************ METRICS ************************* \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Tokens:                      input=202, output=55, total=257                                               \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Tokens: \u001b[33minput\u001b[0m=\u001b[1;36m202\u001b[0m, \u001b[33moutput\u001b[0m=\u001b[1;36m55\u001b[0m, \u001b[33mtotal\u001b[0m=\u001b[1;36m257\u001b[0m \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Time:                        1.7711s                                                                       \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Time: \u001b[1;36m1.\u001b[0m7711s \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Tokens per second:           31.0548 tokens/s                                                              \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Tokens per second: \u001b[1;36m31.0548\u001b[0m tokens/s \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG * Time to first token:         1.4567s                                                                       \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m * Time to first token: \u001b[1;36m1.\u001b[0m4567s \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ************************  METRICS  *************************                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ************************ METRICS ************************* \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG ---------------- OpenAI Response Stream End ----------------                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m ---------------- OpenAI Response Stream End ---------------- \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG Added RunResponse to Memory                                                                                  \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m Added RunResponse to Memory \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
DEBUG *** Agent Run End: 982007e4-557b-48d7-b368-e01617c617c3 ****                                                 \n",
       "
\n" ], "text/plain": [ "\u001b[32mDEBUG\u001b[0m *** Agent Run End: \u001b[93m982007e4-557b-48d7-b368-e01617c617c3\u001b[0m **** \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from agno.utils.log import debug_level\n",
    "\n",
    "\n",
    "def get_news(description: str):\n",
    "   print(f\"get_news: {description}\", )\n",
    "   return \"No news\"\n",
    "\n",
    "agent = Agent(\n",
    "    model=model,\n",
    "    tool_choice=\"auto\",\n",
    "   #  tools=[YFinanceTools(stock_price=True)],\n",
    "   tools= [get_news],\n",
    "    # instructions=\"Use tables to display data. Don't include any other text.\",\n",
    "    instructions=dedent(\"\"\"\\\n",
    "        You are a seasoned Wall Street analyst with deep expertise in market analysis! 📊\n",
    "\n",
    "        Follow these steps for comprehensive financial analysis:\n",
    "        1. Market Overview\n",
    "           - Latest stock price\n",
    "           - 52-week high and low\n",
    "        2. Financial Deep Dive\n",
    "           - Key metrics (P/E, Market Cap, EPS)\n",
    "        3. Professional Insights\n",
    "           - Analyst recommendations breakdown\n",
    "           - Recent rating changes\n",
    "\n",
    "        4. Market Context\n",
    "           - Industry trends and positioning\n",
    "           - Competitive analysis\n",
    "           - Market sentiment indicators\n",
    "\n",
    "        Your reporting style:\n",
    "        - Begin with an executive summary\n",
    "        - Use tables for data presentation\n",
    "        - Include clear section headers\n",
    "        - Add emoji indicators for trends (📈 📉)\n",
    "        - Highlight key insights with bullet points\n",
    "        - Compare metrics to industry averages\n",
    "        - Include technical term explanations\n",
    "        - End with a forward-looking analysis\n",
    "\n",
    "        Risk Disclosure:\n",
    "        - Always highlight potential risk factors\n",
    "        - Note market uncertainties\n",
    "        - Mention relevant regulatory concerns\n",
    "    \"\"\"),\n",
    "    add_datetime_to_instructions=True,\n",
    "    show_tool_calls=True,\n",
    "   #  markdown=True,\n",
    "    # markdown=True,\n",
    "    # show_tool_calls=True,\n",
    "    debug_mode=True, debug_level=2\n",
    ")\n",
    "\n",
    "# agent.print_response(\"What is the stock price of Apple?\", stream=True)\n",
    "# agent.print_response(\"What is the stock price of Apple?\", stream=True)\n",
    "agent.print_response(\n",
    "    \"What's the latest news and financial performance of Apple (AAPL)?\", stream=True, show_message=True, show_reasoning=True,\n",
    "    \n",
    ")"
   ]
  }
 ],
 "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.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}