linzhaoxin319319 1 month ago
parent
commit
c6c103e7de

+ 52 - 0
林兆新/2/1.testDemo.ipynb

@@ -0,0 +1,52 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "961a0e18",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from agno.agent import Agent\n",
+    "from agno.models.anthropic import Claude\n",
+    "from agno.tools.reasoning import ReasoningTools\n",
+    "from agno.tools.yfinance import YFinanceTools\n",
+    "from agno.models.ollama import Ollama\n",
+    "#步骤1 获取对应文件全部信息\n",
+    "from openai import OpenAI\n",
+    "from dotenv import load_dotenv \n",
+    "import os\n",
+    "import glob\n",
+    "import json\n",
+    "import pandas as pd\n",
+    "client = OpenAI(base_url=os.getenv(\"BAILIAN_API_BASE_URL\"),\n",
+    "       api_key=os.getenv(\"BAILIAN_API_KEY\"))\n",
+    "\n",
+    "selected_model = Ollama(id=\"qwen2.5:32b\")  # 🎯 通义千问 3-32B 模型 (本地运行)\n",
+    "\n",
+    "reasoning_agent = Agent(\n",
+    "    model=Ollama(id=\"qwen3-30b-a3b\"),\n",
+    "    tools=[\n",
+    "        ReasoningTools(add_instructions=True),\n",
+    "        YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True),\n",
+    "    ],\n",
+    "    instructions=\"Use tables to display data.\",\n",
+    "    markdown=True,\n",
+    ")"
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": ".venv",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "name": "python",
+   "version": "3.11.13"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}

+ 531 - 0
林兆新/2/Running your Agent.ipynb

@@ -0,0 +1,531 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "id": "606a0000",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "True"
+      ]
+     },
+     "execution_count": 14,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# from typing import Iterator\n",
+    "from agno.agent import Agent, RunResponse,RunResponseEvent\n",
+    "from typing import Iterator\n",
+    "# from agno.models.openai import OpenAIChat\n",
+    "from agno.utils.pprint import pprint_run_response\n",
+    "\n",
+    "# agent = Agent(model=OpenAIChat(id=\"gpt-4o-mini\"))\n",
+    "\n",
+    "# # Run agent and return the response as a variable\n",
+    "# response: RunResponse = agent.run(\"Tell me a 5 second short story about a robot\")\n",
+    "\n",
+    "# # Print the response in markdown format\n",
+    "# pprint_run_response(response, markdown=True)\n",
+    "\n",
+    "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": 9,
+   "id": "d026bfb6",
+   "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": 18,
+   "id": "885e3313",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "c026f81db6784970a50844f45cda0493",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\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",
+    "\n",
+    "pprint_run_response(agent.run(\n",
+    "    \"Tell me a 5 second short story about a lion\",\n",
+    "    stream=True, show_message=True\n",
+    "    ))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "60497530",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "\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",
+    "# Run agent and return the response as a variable\n",
+    "response: RunResponse = agent.run(\"Tell me a 5 second short story about a robot\")\n",
+    "\n",
+    "# Print the response in markdown format\n",
+    "pprint_run_response(response, markdown=True)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "id": "f77d6ce0",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ****** Agent ID: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">381fc96f-9733-4c24-a9d3-2ffeb63fea9d</span> ******                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ****** Agent ID: \u001b[93m381fc96f-9733-4c24-a9d3-2ffeb63fea9d\u001b[0m ******                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ***** Session ID: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">e179c625-5edd-45e5-9ec3-46054fb5f0f8</span> *****                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ***** Session ID: \u001b[93me179c625-5edd-45e5-9ec3-46054fb5f0f8\u001b[0m *****                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ** Agent Run Start: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">bd026372-0439-4bce-8de0-30b76c4980d6</span> ***                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ** Agent Run Start: \u001b[93mbd026372-0439-4bce-8de0-30b76c4980d6\u001b[0m ***                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> --------------- OpenAI Response Stream Start ---------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m --------------- OpenAI Response Stream Start ---------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> --------------------- Model: qwen3-32b ---------------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m --------------------- Model: qwen3-32b ---------------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ========================== system ==========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ========================== system ==========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> <span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">additional_information</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;</span>                                                                                     \n",
+       "      <span style=\"color: #000000; text-decoration-color: #000000\">- The current time is </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2025</span><span style=\"color: #000000; text-decoration-color: #000000\">-</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">07</span><span style=\"color: #000000; text-decoration-color: #000000\">-</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">08</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #00ff00; text-decoration-color: #00ff00; font-weight: bold\">16:17:58</span><span style=\"color: #000000; text-decoration-color: #000000\">.</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">971363</span><span style=\"color: #000000; text-decoration-color: #000000\">.</span>                                                            \n",
+       "      <span style=\"color: #000000; text-decoration-color: #000000\">&lt;</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">additional_information</span><span style=\"font-weight: bold\">&gt;</span>                                                                                    \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m \u001b[1m<\u001b[0m\u001b[1;95madditional_information\u001b[0m\u001b[39m>\u001b[0m                                                                                     \n",
+       "      \u001b[39m- The current time is \u001b[0m\u001b[1;36m2025\u001b[0m\u001b[39m-\u001b[0m\u001b[1;36m07\u001b[0m\u001b[39m-\u001b[0m\u001b[1;36m08\u001b[0m\u001b[39m \u001b[0m\u001b[1;92m16:17:58\u001b[0m\u001b[39m.\u001b[0m\u001b[1;36m971363\u001b[0m\u001b[39m.\u001b[0m                                                            \n",
+       "      \u001b[39m<\u001b[0m\u001b[35m/\u001b[0m\u001b[95madditional_information\u001b[0m\u001b[1m>\u001b[0m                                                                                    \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> =========================== user ===========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m =========================== user ===========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Tell me a <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> second short story about a lion                                                                  \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Tell me a \u001b[1;36m5\u001b[0m second short story about a lion                                                                  \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Calling OpenAI with request parameters: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'tools'</span>: <span style=\"font-weight: bold\">[{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'get_news'</span>,     \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">''</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'parameters'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span><span style=\"font-weight: bold\">}}</span>,       \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span><span style=\"font-weight: bold\">]}}}]</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'tool_choice'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'auto'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'extra_body'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'enable_thinking'</span>: <span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span><span style=\"font-weight: bold\">}}</span>            \n",
+       "</pre>\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": "792427e6e9de4ef5ad0ff33767031701",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ======================== assistant =========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ======================== assistant =========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Once upon a time, in the heart of the savannah, there lived a proud lion named Leo. Every day, he roamed the \n",
+       "      golden grasslands, his mighty roar echoing through the trees. One sunny afternoon, while chasing shadows, he \n",
+       "      met a curious gazelle who challenged him to a race. With a chuckle, Leo agreed, and together they sprinted   \n",
+       "      across the plains. Though he was swift, the gazelle outpaced him with grace and agility. Instead of feeling  \n",
+       "      defeated, Leo laughed, realizing that joy lies not just in winning, but in the journey itself. From then on, \n",
+       "      they became friends, sharing adventures and stories under the vast African sky.                              \n",
+       "                                                                                                                   \n",
+       "      Would you like me to fetch some news about lions or wildlife?                                                \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Once upon a time, in the heart of the savannah, there lived a proud lion named Leo. Every day, he roamed the \n",
+       "      golden grasslands, his mighty roar echoing through the trees. One sunny afternoon, while chasing shadows, he \n",
+       "      met a curious gazelle who challenged him to a race. With a chuckle, Leo agreed, and together they sprinted   \n",
+       "      across the plains. Though he was swift, the gazelle outpaced him with grace and agility. Instead of feeling  \n",
+       "      defeated, Leo laughed, realizing that joy lies not just in winning, but in the journey itself. From then on, \n",
+       "      they became friends, sharing adventures and stories under the vast African sky.                              \n",
+       "                                                                                                                   \n",
+       "      Would you like me to fetch some news about lions or wildlife?                                                \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens:                      <span style=\"color: #808000; text-decoration-color: #808000\">input</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">195</span>, <span style=\"color: #808000; text-decoration-color: #808000\">output</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">148</span>, <span style=\"color: #808000; text-decoration-color: #808000\">total</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">343</span>                                              \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Tokens:                      \u001b[33minput\u001b[0m=\u001b[1;36m195\u001b[0m, \u001b[33moutput\u001b[0m=\u001b[1;36m148\u001b[0m, \u001b[33mtotal\u001b[0m=\u001b[1;36m343\u001b[0m                                              \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time:                        <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5.</span>2285s                                                                       \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Time:                        \u001b[1;36m5.\u001b[0m2285s                                                                       \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens per second:           <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">28.3066</span> tokens/s                                                              \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Tokens per second:           \u001b[1;36m28.3066\u001b[0m tokens/s                                                              \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time to first token:         <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.</span>6973s                                                                       \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Time to first token:         \u001b[1;36m1.\u001b[0m6973s                                                                       \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ---------------- OpenAI Response Stream End ----------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ---------------- OpenAI Response Stream End ----------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Added RunResponse to Memory                                                                                  \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Added RunResponse to Memory                                                                                  \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> *** Agent Run End: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">bd026372-0439-4bce-8de0-30b76c4980d6</span> ****                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m *** Agent Run End: \u001b[93mbd026372-0439-4bce-8de0-30b76c4980d6\u001b[0m ****                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "# Run agent and return the response as a stream\n",
+    "response_stream: Iterator[RunResponseEvent] = agent.run(\n",
+    "    \"Tell me a 5 second short story about a lion\",\n",
+    "    stream=True\n",
+    ")\n",
+    "\n",
+    "# Print the response stream in markdown format\n",
+    "pprint_run_response(response_stream, markdown=True)"
+   ]
+  }
+ ],
+ "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
+}

+ 675 - 0
林兆新/2/agnoDemo.ipynb

@@ -0,0 +1,675 @@
+{
+ "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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ****** Agent ID: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">005dffe2-dd4f-4efc-999e-bbf8012c7862</span> ******                                                 \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ***** Session ID: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">f5fb3d50-3e88-45d9-961e-c251429cdbff</span> *****                                                 \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Processing tools for model                                                                                   \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Processing tools for model                                                                                   \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Added tool get_news                                                                                          \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Added tool get_news                                                                                          \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ** Agent Run Start: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">982007e4-557b-48d7-b368-e01617c617c3</span> ***                                                 \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> --------------- OpenAI Response Stream Start ---------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m --------------- OpenAI Response Stream Start ---------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> --------------------- Model: qwen3-32b ---------------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m --------------------- Model: qwen3-32b ---------------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> =========================== user ===========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m =========================== user ===========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> What's the latest news and financial performance of Apple <span style=\"font-weight: bold\">(</span>AAPL<span style=\"font-weight: bold\">)</span>?                                            \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Calling OpenAI with request parameters: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'tools'</span>: <span style=\"font-weight: bold\">[{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'get_news'</span>,     \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">''</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'parameters'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span><span style=\"font-weight: bold\">}}</span>,       \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span><span style=\"font-weight: bold\">]}}}]</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'tool_choice'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'auto'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'extra_body'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'enable_thinking'</span>: <span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span><span style=\"font-weight: bold\">}}</span>            \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ======================== assistant =========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ======================== assistant =========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Tool Calls:                                                                                                  \n",
+       "        - ID: <span style=\"color: #008000; text-decoration-color: #008000\">'call_60e1a1ea7d91423c9f34ba'</span>                                                                        \n",
+       "          Name: <span style=\"color: #008000; text-decoration-color: #008000\">'get_news'</span>                                                                                         \n",
+       "          Arguments: <span style=\"color: #008000; text-decoration-color: #008000\">'description: latest news and financial performance of Apple (AAPL)'</span>                          \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens:                      <span style=\"color: #808000; text-decoration-color: #808000\">input</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">157</span>, <span style=\"color: #808000; text-decoration-color: #808000\">output</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">29</span>, <span style=\"color: #808000; text-decoration-color: #808000\">total</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">186</span>                                               \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time:                        <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.</span>3610s                                                                       \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Time:                        \u001b[1;36m1.\u001b[0m3610s                                                                       \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens per second:           <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">21.3081</span> tokens/s                                                              \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time to first token:         <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.</span>3589s                                                                       \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Running: <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">get_news</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">description</span>=<span style=\"color: #808000; text-decoration-color: #808000\">...</span><span style=\"font-weight: bold\">)</span>                                                                           \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">get_news: latest news and financial performance of Apple (AAPL)\n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "get_news: latest news and financial performance of Apple (AAPL)\n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> =========================== tool ===========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m =========================== tool ===========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Tool call Id: call_60e1a1ea7d91423c9f34ba                                                                    \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Tool call Id: call_60e1a1ea7d91423c9f34ba                                                                    \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> No news                                                                                                      \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m No news                                                                                                      \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> **********************  TOOL METRICS  **********************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m **********************  TOOL METRICS  **********************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time:                        <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.</span>0015s                                                                       \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Time:                        \u001b[1;36m0.\u001b[0m0015s                                                                       \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> **********************  TOOL METRICS  **********************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m **********************  TOOL METRICS  **********************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Calling OpenAI with request parameters: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'tools'</span>: <span style=\"font-weight: bold\">[{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'get_news'</span>,     \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">''</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'parameters'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span><span style=\"font-weight: bold\">}}</span>,       \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span><span style=\"font-weight: bold\">]}}}]</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'tool_choice'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'auto'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'extra_body'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'enable_thinking'</span>: <span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span><span style=\"font-weight: bold\">}}</span>            \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ======================== assistant =========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ======================== assistant =========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> It seems there is no recent news or financial performance update for Apple <span style=\"font-weight: bold\">(</span>AAPL<span style=\"font-weight: bold\">)</span> 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",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens:                      <span style=\"color: #808000; text-decoration-color: #808000\">input</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">202</span>, <span style=\"color: #808000; text-decoration-color: #808000\">output</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">55</span>, <span style=\"color: #808000; text-decoration-color: #808000\">total</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">257</span>                                               \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time:                        <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.</span>7711s                                                                       \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Time:                        \u001b[1;36m1.\u001b[0m7711s                                                                       \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens per second:           <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">31.0548</span> tokens/s                                                              \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time to first token:         <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.</span>4567s                                                                       \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ---------------- OpenAI Response Stream End ----------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ---------------- OpenAI Response Stream End ----------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Added RunResponse to Memory                                                                                  \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Added RunResponse to Memory                                                                                  \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> *** Agent Run End: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">982007e4-557b-48d7-b368-e01617c617c3</span> ****                                                 \n",
+       "</pre>\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": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\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
+}

+ 455 - 0
林兆新/2/agnoMetricsDemo.ipynb

@@ -0,0 +1,455 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "id": "07721677",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "True"
+      ]
+     },
+     "execution_count": 6,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# from typing import Iterator\n",
+    "from agno.agent import Agent, RunResponse,RunResponseEvent\n",
+    "from typing import Iterator\n",
+    "# from agno.models.openai import OpenAIChat\n",
+    "from agno.utils.pprint import pprint_run_response\n",
+    "from rich.pretty import pprint\n",
+    "\n",
+    "# agent = Agent(model=OpenAIChat(id=\"gpt-4o-mini\"))\n",
+    "\n",
+    "# # Run agent and return the response as a variable\n",
+    "# response: RunResponse = agent.run(\"Tell me a 5 second short story about a robot\")\n",
+    "\n",
+    "# # Print the response in markdown format\n",
+    "# pprint_run_response(response, markdown=True)\n",
+    "\n",
+    "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": 2,
+   "id": "473a716e",
+   "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": 9,
+   "id": "bb65de5a",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "3cd0c24e001148909c3c86e13037084d",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\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",
+    "\n",
+    "pprint_run_response(agent.run(\n",
+    "    \"Tell me a 5 second short story about a lion\",\n",
+    "    stream=True, show_message=True\n",
+    "    ))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "id": "927a70d0",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "c4e88c67d8de4c19a6790f3f1835cede",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
+      ],
+      "text/plain": []
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Tool calls: [{'id': 'call_4c2c8551b4d249f8a3f58a', 'type': 'function', 'function': {'name': 'get_current_stock_price', 'arguments': '{\"symbol\": \"NVDA\"}'}}]\n",
+      "Tool calls: [{'id': 'call_4c2c8551b4d249f8a3f58a', 'type': 'function', 'function': {'name': 'get_current_stock_price', 'arguments': '{\"symbol\": \"NVDA\"}'}}]\n",
+      "--------------- Metrics ---------------\n"
+     ]
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">MessageMetrics</span><span style=\"font-weight: bold\">(</span>\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">218</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">output_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">22</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">total_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">240</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">output_audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">cached_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">cache_write_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">reasoning_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">218</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">completion_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">22</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt_tokens_details</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">completion_tokens_details</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_metrics</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">time</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.3018417499988573</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">time_to_first_token</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.3011846250010421</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">timer</span>=<span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">agno.utils.timer.Timer</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x15c4545d0</span><span style=\"font-weight: bold\">&gt;</span>\n",
+       "<span style=\"font-weight: bold\">)</span>\n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[1;35mMessageMetrics\u001b[0m\u001b[1m(\u001b[0m\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33minput_tokens\u001b[0m=\u001b[1;36m218\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_tokens\u001b[0m=\u001b[1;36m22\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtotal_tokens\u001b[0m=\u001b[1;36m240\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33maudio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33minput_audio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_audio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcached_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcache_write_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mreasoning_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mprompt_tokens\u001b[0m=\u001b[1;36m218\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens\u001b[0m=\u001b[1;36m22\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mprompt_tokens_details\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens_details\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33madditional_metrics\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime\u001b[0m=\u001b[1;36m1\u001b[0m\u001b[1;36m.3018417499988573\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime_to_first_token\u001b[0m=\u001b[1;36m1\u001b[0m\u001b[1;36m.3011846250010421\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtimer\u001b[0m=\u001b[1m<\u001b[0m\u001b[1;95magno.utils.timer.Timer\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x15c4545d0\u001b[0m\u001b[1m>\u001b[0m\n",
+       "\u001b[1m)\u001b[0m\n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "------------------------------------------------------------\n",
+      "Message: It seems I'm currently rate-limited and unable to fetch the stock price for NVDA. Please try again later or check a financial platform for real-time stock information.\n",
+      "--------------- Metrics ---------------\n"
+     ]
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">MessageMetrics</span><span style=\"font-weight: bold\">(</span>\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">273</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">output_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">34</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">total_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">307</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">output_audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">cached_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">cache_write_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">reasoning_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">273</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">completion_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">34</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt_tokens_details</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">completion_tokens_details</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_metrics</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">time</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.7436456249997718</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">time_to_first_token</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.7402209589999984</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">timer</span>=<span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">agno.utils.timer.Timer</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x15b177910</span><span style=\"font-weight: bold\">&gt;</span>\n",
+       "<span style=\"font-weight: bold\">)</span>\n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[1;35mMessageMetrics\u001b[0m\u001b[1m(\u001b[0m\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33minput_tokens\u001b[0m=\u001b[1;36m273\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_tokens\u001b[0m=\u001b[1;36m34\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtotal_tokens\u001b[0m=\u001b[1;36m307\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33maudio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33minput_audio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_audio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcached_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcache_write_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mreasoning_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mprompt_tokens\u001b[0m=\u001b[1;36m273\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens\u001b[0m=\u001b[1;36m34\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mprompt_tokens_details\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens_details\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33madditional_metrics\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime\u001b[0m=\u001b[1;36m1\u001b[0m\u001b[1;36m.7436456249997718\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime_to_first_token\u001b[0m=\u001b[1;36m1\u001b[0m\u001b[1;36m.7402209589999984\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtimer\u001b[0m=\u001b[1m<\u001b[0m\u001b[1;95magno.utils.timer.Timer\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x15b177910\u001b[0m\u001b[1m>\u001b[0m\n",
+       "\u001b[1m)\u001b[0m\n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "------------------------------------------------------------\n",
+      "--------------- Collected Metrics ---------------\n"
+     ]
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'input_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">218</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">273</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'output_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">22</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">34</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'total_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">240</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">307</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'audio_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'input_audio_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'output_audio_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'cached_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'cache_write_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'reasoning_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'prompt_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">218</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">273</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'completion_tokens'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">22</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">34</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'time'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.3018417499988573</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.7436456249997718</span><span style=\"font-weight: bold\">]</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #008000; text-decoration-color: #008000\">'time_to_first_token'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.3011846250010421</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.7402209589999984</span><span style=\"font-weight: bold\">]</span>\n",
+       "<span style=\"font-weight: bold\">}</span>\n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[1m{\u001b[0m\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'input_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m218\u001b[0m, \u001b[1;36m273\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'output_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m22\u001b[0m, \u001b[1;36m34\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'total_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m240\u001b[0m, \u001b[1;36m307\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'audio_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m, \u001b[1;36m0\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'input_audio_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m, \u001b[1;36m0\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'output_audio_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m, \u001b[1;36m0\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'cached_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m, \u001b[1;36m0\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'cache_write_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m, \u001b[1;36m0\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'reasoning_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m, \u001b[1;36m0\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'prompt_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m218\u001b[0m, \u001b[1;36m273\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'completion_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m22\u001b[0m, \u001b[1;36m34\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'time'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m1.3018417499988573\u001b[0m, \u001b[1;36m1.7436456249997718\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'time_to_first_token'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m1.3011846250010421\u001b[0m, \u001b[1;36m1.7402209589999984\u001b[0m\u001b[1m]\u001b[0m\n",
+       "\u001b[1m}\u001b[0m\n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "--------------- Session Metrics ---------------\n"
+     ]
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">SessionMetrics</span><span style=\"font-weight: bold\">(</span>\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">712</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">output_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">109</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">total_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">821</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">output_audio_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">cached_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">cache_write_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">reasoning_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">712</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">completion_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">109</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt_tokens_details</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">completion_tokens_details</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">additional_metrics</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">time</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4.989817458998004</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">time_to_first_token</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.5254021249966172</span>,\n",
+       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">timer</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
+       "<span style=\"font-weight: bold\">)</span>\n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[1;35mSessionMetrics\u001b[0m\u001b[1m(\u001b[0m\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33minput_tokens\u001b[0m=\u001b[1;36m712\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_tokens\u001b[0m=\u001b[1;36m109\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtotal_tokens\u001b[0m=\u001b[1;36m821\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33maudio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33minput_audio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_audio_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcached_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcache_write_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mreasoning_tokens\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mprompt_tokens\u001b[0m=\u001b[1;36m712\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens\u001b[0m=\u001b[1;36m109\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mprompt_tokens_details\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens_details\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33madditional_metrics\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime\u001b[0m=\u001b[1;36m4\u001b[0m\u001b[1;36m.989817458998004\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime_to_first_token\u001b[0m=\u001b[1;36m1\u001b[0m\u001b[1;36m.5254021249966172\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtimer\u001b[0m=\u001b[3;35mNone\u001b[0m\n",
+       "\u001b[1m)\u001b[0m\n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "agent.print_response(\n",
+    "    \"What is the stock price of NVDA\", stream=True\n",
+    ")\n",
+    "\n",
+    "# Print metrics per message\n",
+    "if getattr(agent.run_response, \"messages\", None) is not None:\n",
+    "    for message in agent.run_response.messages or []:\n",
+    "        if getattr(message, \"role\", None) == \"assistant\":\n",
+    "            if getattr(message, \"content\", None):\n",
+    "                print(f\"Message: {message.content}\")\n",
+    "            elif getattr(message, \"tool_calls\", None):\n",
+    "                print(f\"Tool calls: {message.tool_calls}\")\n",
+    "                print(f\"Tool calls: {message.tool_calls}\")\n",
+    "            print(\"---\" * 5, \"Metrics\", \"---\" * 5)\n",
+    "            pprint(message.metrics)\n",
+    "            print(\"---\" * 20)\n",
+    "\n",
+    "# Print the aggregated metrics for the whole run\n",
+    "print(\"---\" * 5, \"Collected Metrics\", \"---\" * 5)\n",
+    "pprint(agent.run_response.metrics)\n",
+    "# Print the aggregated metrics for the whole session\n",
+    "print(\"---\" * 5, \"Session Metrics\", \"---\" * 5)\n",
+    "pprint(agent.session_metrics)"
+   ]
+  }
+ ],
+ "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
+}

+ 529 - 0
林兆新/2/agnoToosDemo.ipynb

@@ -0,0 +1,529 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "fb666050",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "True"
+      ]
+     },
+     "execution_count": 1,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# from typing import Iterator\n",
+    "from agno.agent import Agent, RunResponse,RunResponseEvent\n",
+    "from typing import Iterator\n",
+    "# from agno.models.openai import OpenAIChat\n",
+    "from agno.utils.pprint import pprint_run_response\n",
+    "\n",
+    "# agent = Agent(model=OpenAIChat(id=\"gpt-4o-mini\"))\n",
+    "\n",
+    "# # Run agent and return the response as a variable\n",
+    "# response: RunResponse = agent.run(\"Tell me a 5 second short story about a robot\")\n",
+    "\n",
+    "# # Print the response in markdown format\n",
+    "# pprint_run_response(response, markdown=True)\n",
+    "\n",
+    "from agno.agent import Agent\n",
+    "from agno.models.openai import OpenAIChat, OpenAILike\n",
+    "from agno.tools.duckduckgo import DuckDuckGoTools\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",
+    "import json\n",
+    "import httpx\n",
+    "dotenv.load_dotenv()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "id": "1b9e8791",
+   "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": 5,
+   "id": "b97c0629",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def get_top_hackernews_stories(num_stories: int = 10) -> str:\n",
+    "    \"\"\"Use this function to get top stories from Hacker News.\n",
+    "\n",
+    "    Args:\n",
+    "        num_stories (int): Number of stories to return. Defaults to 10.\n",
+    "\n",
+    "    Returns:\n",
+    "        str: JSON string of top stories.\n",
+    "    \"\"\"\n",
+    "\n",
+    "    # Fetch top story IDs\n",
+    "    response = httpx.get('https://hacker-news.firebaseio.com/v0/topstories.json')\n",
+    "    story_ids = response.json()\n",
+    "\n",
+    "    # Fetch story details\n",
+    "    stories = []\n",
+    "    for story_id in story_ids[:num_stories]:\n",
+    "        story_response = httpx.get(f'https://hacker-news.firebaseio.com/v0/item/{story_id}.json')\n",
+    "        story = story_response.json()\n",
+    "        if \"text\" in story:\n",
+    "            story.pop(\"text\", None)\n",
+    "        stories.append(story)\n",
+    "    return json.dumps(stories)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "a4862c47",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "90104001",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ****** Agent ID: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">468e8297-e5d0-49cf-bed3-6d42d27ff3b9</span> ******                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ****** Agent ID: \u001b[93m468e8297-e5d0-49cf-bed3-6d42d27ff3b9\u001b[0m ******                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ***** Session ID: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">263e0b0a-c944-4ac2-898d-26b55d366714</span> *****                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ***** Session ID: \u001b[93m263e0b0a-c944-4ac2-898d-26b55d366714\u001b[0m *****                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Processing tools for model                                                                                   \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Processing tools for model                                                                                   \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Added tool get_news                                                                                          \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Added tool get_news                                                                                          \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ** Agent Run Start: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">eb0147d4-ab3d-4cb9-bb6e-df48dabba64d</span> ***                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ** Agent Run Start: \u001b[93meb0147d4-ab3d-4cb9-bb6e-df48dabba64d\u001b[0m ***                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> --------------- OpenAI Response Stream Start ---------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m --------------- OpenAI Response Stream Start ---------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> --------------------- Model: qwen3-32b ---------------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m --------------------- Model: qwen3-32b ---------------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ========================== system ==========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ========================== system ==========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> <span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">additional_information</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;</span>                                                                                     \n",
+       "      <span style=\"color: #000000; text-decoration-color: #000000\">- The current time is </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2025</span><span style=\"color: #000000; text-decoration-color: #000000\">-</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">07</span><span style=\"color: #000000; text-decoration-color: #000000\">-</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">09</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #00ff00; text-decoration-color: #00ff00; font-weight: bold\">10:44:38</span><span style=\"color: #000000; text-decoration-color: #000000\">.</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">514495</span><span style=\"color: #000000; text-decoration-color: #000000\">.</span>                                                            \n",
+       "      <span style=\"color: #000000; text-decoration-color: #000000\">&lt;</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">additional_information</span><span style=\"font-weight: bold\">&gt;</span>                                                                                    \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m \u001b[1m<\u001b[0m\u001b[1;95madditional_information\u001b[0m\u001b[39m>\u001b[0m                                                                                     \n",
+       "      \u001b[39m- The current time is \u001b[0m\u001b[1;36m2025\u001b[0m\u001b[39m-\u001b[0m\u001b[1;36m07\u001b[0m\u001b[39m-\u001b[0m\u001b[1;36m09\u001b[0m\u001b[39m \u001b[0m\u001b[1;92m10:44:38\u001b[0m\u001b[39m.\u001b[0m\u001b[1;36m514495\u001b[0m\u001b[39m.\u001b[0m                                                            \n",
+       "      \u001b[39m<\u001b[0m\u001b[35m/\u001b[0m\u001b[95madditional_information\u001b[0m\u001b[1m>\u001b[0m                                                                                    \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> =========================== user ===========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m =========================== user ===========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Tell me a <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> second short story about a lion                                                                  \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Tell me a \u001b[1;36m5\u001b[0m second short story about a lion                                                                  \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Calling OpenAI with request parameters: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'tools'</span>: <span style=\"font-weight: bold\">[{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'function'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'name'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'get_news'</span>,     \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">''</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'parameters'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'object'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'string'</span><span style=\"font-weight: bold\">}}</span>,       \n",
+       "      <span style=\"color: #008000; text-decoration-color: #008000\">'required'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span><span style=\"font-weight: bold\">]}}}]</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'tool_choice'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'auto'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'extra_body'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'enable_thinking'</span>: <span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span><span style=\"font-weight: bold\">}}</span>            \n",
+       "</pre>\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": "99ed8e58fb0c4649be558f325b0417ce",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ======================== assistant =========================                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ======================== assistant =========================                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> A lion, majestic and proud, roamed the savanna. With a mighty roar, he called his pride, and together they   \n",
+       "      vanished into the golden sunset.                                                                             \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m A lion, majestic and proud, roamed the savanna. With a mighty roar, he called his pride, and together they   \n",
+       "      vanished into the golden sunset.                                                                             \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens:                      <span style=\"color: #808000; text-decoration-color: #808000\">input</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">195</span>, <span style=\"color: #808000; text-decoration-color: #808000\">output</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">32</span>, <span style=\"color: #808000; text-decoration-color: #808000\">total</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">227</span>                                               \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Tokens:                      \u001b[33minput\u001b[0m=\u001b[1;36m195\u001b[0m, \u001b[33moutput\u001b[0m=\u001b[1;36m32\u001b[0m, \u001b[33mtotal\u001b[0m=\u001b[1;36m227\u001b[0m                                               \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time:                        <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.</span>5037s                                                                       \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Time:                        \u001b[1;36m1.\u001b[0m5037s                                                                       \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Tokens per second:           <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">21.2808</span> tokens/s                                                              \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Tokens per second:           \u001b[1;36m21.2808\u001b[0m tokens/s                                                              \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> * Time to first token:         <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1.</span>5024s                                                                       \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m * Time to first token:         \u001b[1;36m1.\u001b[0m5024s                                                                       \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ************************  METRICS  *************************                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ************************  METRICS  *************************                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> ---------------- OpenAI Response Stream End ----------------                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m ---------------- OpenAI Response Stream End ----------------                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> Added RunResponse to Memory                                                                                  \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m Added RunResponse to Memory                                                                                  \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">DEBUG</span> *** Agent Run End: <span style=\"color: #ffff00; text-decoration-color: #ffff00\">eb0147d4-ab3d-4cb9-bb6e-df48dabba64d</span> ****                                                 \n",
+       "</pre>\n"
+      ],
+      "text/plain": [
+       "\u001b[32mDEBUG\u001b[0m *** Agent Run End: \u001b[93meb0147d4-ab3d-4cb9-bb6e-df48dabba64d\u001b[0m ****                                                 \n"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/html": [
+       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\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",
+    "    tools=[get_top_hackernews_stories],\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",
+    "\n",
+    "pprint_run_response(agent.run(\n",
+    "    # \"Tell me a 5 second short story about a lion\",\n",
+    "    \"Summarize the top 5 stories on hackernews?\",\n",
+    "    stream=True, show_message=True\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
+}

+ 434 - 0
林兆新/2/chat_with_agent_transfer.py

@@ -0,0 +1,434 @@
+#!/usr/bin/env python3
+"""
+交互式Agent对话脚本
+基于agno框架创建的终端对话界面
+"""
+
+from agno.agent import Agent, RunResponse, RunResponseEvent
+from agno.models.openai import OpenAILike
+from agno.utils.pprint import pprint_run_response
+import os
+import sys
+import json
+import re
+from typing import Iterator
+import dotenv
+
+# 加载环境变量
+dotenv.load_dotenv()
+
+# 全局联系人数组
+CONTACTS = [
+    {"name": "张三", "phone": "138-0000-1001"},
+    {"name": "李四", "phone": "139-0000-1002"},
+    {"name": "王五", "phone": "136-0000-1003"},
+    {"name": "赵六", "phone": "137-0000-1004"},
+    {"name": "孙七", "phone": "135-0000-1005"},
+    {"name": "周八", "phone": "133-0000-1006"},
+    {"name": "吴九", "phone": "188-0000-1007"},
+    {"name": "郑十", "phone": "180-0000-1008"}
+]
+
+from typing import Optional
+def find_contact_by_name(name: str) -> Optional[str]:
+    """根据姓名查找联系人电话号码"""
+    for contact in CONTACTS:
+        if contact["name"] == name:
+            return contact["phone"]
+    return None
+
+
+def create_agent():
+    """创建并配置Agent实例"""
+    model = OpenAILike(
+        id="qwen3-32b",
+        api_key=os.getenv("BAILIAN_API_KEY"),
+        base_url=os.getenv("BAILIAN_API_BASE_URL"),
+        request_params={"extra_body": {"enable_thinking": False}},
+    )
+    
+    def get_news(description: str):
+        """示例工具函数 - 获取新闻"""
+        print(f"[工具调用] get_news: {description}")
+        return "暂无相关新闻"
+    
+    def extract_transfer_info(user_message: str) -> str:
+        """从用户消息中提取转账信息
+        
+        Args:
+            user_message: 用户的自然语言输入
+            
+        Returns:
+            JSON字符串,包含提取的信息:
+            {
+                "is_transfer": true/false,
+                "recipient_name": "姓名" (如果找到),
+                "amount": "金额" (如果找到),
+                "confidence": 0.0-1.0 (置信度)
+            }
+        """
+        return f"请分析以下用户消息,判断是否包含转账意图,并提取相关信息:'{user_message}'"
+    
+    agent = Agent(
+        model=model,
+        tool_choice="auto",
+        tools=[get_news, extract_transfer_info],
+        add_datetime_to_instructions=True,
+        show_tool_calls=True,
+        markdown=True,
+        instructions="""
+你是一个智能助手,能够理解用户的各种需求。当用户表达转账意图时,你需要:
+
+1. 识别转账关键词(如:转账、转钱、给...钱、汇款等)
+2. 提取收款人姓名
+3. 提取转账金额(如果有的话)
+4. 返回JSON格式的结果
+
+对于转账相关的消息,请使用extract_transfer_info工具来分析。
+
+JSON格式示例:
+{
+    "is_transfer": true,
+    "recipient_name": "张三", 
+    "amount": "100",
+    "confidence": 0.9
+}
+
+如果不是转账相关的消息,正常回答用户问题。
+        """,
+    )
+    
+    return agent
+
+def check_transfer_intent(user_input: str, agent: Agent) -> tuple[bool, Optional[str], Optional[str]]:
+    """使用Agent检查用户输入是否包含转账意图
+    
+    Returns:
+        tuple: (是否转账, 收款人姓名, 金额)
+    """
+    try:
+        # 让Agent分析用户输入
+        response = agent.run(f"请分析这句话是否包含转账意图,并提取相关信息:'{user_input}'")
+        
+        # 从Agent响应中提取信息
+        response_text = ""
+        if hasattr(response, 'content') and response.content:
+            response_text = str(response.content)
+        elif hasattr(response, 'messages') and response.messages:
+            for msg in response.messages:
+                if hasattr(msg, 'content') and msg.content:
+                    response_text += str(msg.content)
+        
+        # 尝试从响应中解析JSON
+        import json
+        # 查找JSON格式的数据
+        json_match = re.search(r'\{[^}]*"is_transfer"[^}]*\}', response_text)
+        if json_match:
+            transfer_info = json.loads(json_match.group())
+            
+            is_transfer = transfer_info.get("is_transfer", False)
+            recipient_name = transfer_info.get("recipient_name")
+            amount = transfer_info.get("amount")
+            confidence = transfer_info.get("confidence", 0.0)
+            
+            print(f"🔍 AI分析结果: 转账意图={is_transfer}, 置信度={confidence}")
+            if recipient_name:
+                print(f"📝 提取信息: 收款人={recipient_name}, 金额={amount or '未指定'}")
+            
+            # 只有在高置信度且确实是转账意图时才返回True
+            if is_transfer and confidence > 0.7:
+                return True, recipient_name, amount
+        
+        return False, None, None
+        
+    except Exception as e:
+        print(f"⚠️  AI分析过程中出错: {e}")
+        # 如果AI分析失败,回退到关键词检测
+        transfer_keywords = ["转账", "转钱", "汇款", "给钱", "付款", "支付"]
+        if any(keyword in user_input for keyword in transfer_keywords):
+            print("🔍 使用关键词检测到转账意图")
+            return True, None, None
+        return False, None, None
+
+def get_missing_info_via_agent(agent: Agent, prompt: str) -> Optional[str]:
+    """使用Agent获取缺失的信息
+    
+    Args:
+        agent: Agent实例
+        prompt: 询问提示
+        
+    Returns:
+        用户提供的信息,如果无法获取则返回None
+    """
+    try:
+        print(f"\n🤖 Agent: {prompt}")
+        user_response = input("🙋 您: ").strip()
+        
+        if not user_response:
+            return None
+            
+        # 使用Agent分析用户响应
+        analysis_prompt = f"用户说:'{user_response}',请提取出用户想要表达的具体信息(如姓名、金额、电话号码等),只返回提取到的关键信息,不要额外解释。"
+        
+        response = agent.run(analysis_prompt)
+        
+        # 从Agent响应中提取信息
+        response_text = ""
+        if hasattr(response, 'content') and response.content:
+            response_text = str(response.content)
+        elif hasattr(response, 'messages') and response.messages:
+            for msg in response.messages:
+                if hasattr(msg, 'content') and msg.content:
+                    response_text += str(msg.content)
+        
+        # 简单清理响应文本,提取关键信息
+        cleaned_response = response_text.strip()
+        # 移除常见的解释性词语
+        for phrase in ["用户想要表达的是", "提取到的信息是", "关键信息是", "具体信息是"]:
+            cleaned_response = cleaned_response.replace(phrase, "").strip()
+        
+        return cleaned_response if cleaned_response else user_response
+        
+    except Exception as e:
+        print(f"⚠️  AI分析用户输入时出错: {e}")
+        return user_response if 'user_response' in locals() else None
+
+def handle_transfer_with_extracted_info(agent: Agent, name: Optional[str] = None, amount: Optional[str] = None):
+    """处理转账功能(使用已提取的信息和Agent补全缺失信息)"""
+    
+    # 如果没有提取到姓名,使用Agent询问
+    if not name:
+        print("📝 需要获取收款人信息...")
+        name = get_missing_info_via_agent(agent, "请告诉我您要转账给谁?(请提供收款人的姓名)")
+        if not name:
+            print("⚠️  无法获取收款人姓名,转账操作取消")
+            return
+    
+    print(f"\n💰 准备转账给: {name}")
+    
+    # 查找联系人电话号码
+    phone = find_contact_by_name(name)
+    
+    if phone:
+        print(f"📞 找到联系人电话: {phone}")
+    else:
+        print(f"❌ 联系人列表中未找到 {name} 的电话号码")
+        phone = get_missing_info_via_agent(agent, f"请提供 {name} 的电话号码:")
+        
+        if not phone:
+            print("⚠️  无法获取电话号码,转账操作取消")
+            return
+            
+        # 验证电话号码格式
+        # 先去除所有非数字字符,只保留数字
+        def normalize_phone(phone_str):
+            return re.sub(r'\D', '', phone_str or "")
+
+        while phone:
+            normalized_phone = normalize_phone(phone)
+            if re.match(r"^1\d{10}$", normalized_phone):
+                phone = normalized_phone  # 用标准化后的号码
+                break
+            print("⚠️  电话号码格式不正确,您之前输入的电话号码是:", phone)
+            phone = get_missing_info_via_agent(agent, "请提供正确格式的电话号码(如:138-0000-1001 或 13800001001):")
+            if not phone:
+                print("⚠️  无法获取有效电话号码,转账操作取消")
+                return
+    
+    # 处理转账金额
+    validated_amount = None
+    if amount:
+        # 验证AI提取的金额
+        try:
+            amount_float = float(amount)
+            if amount_float > 0:
+                validated_amount = amount
+                print(f"💵 转账金额: ¥{amount}")
+            else:
+                print(f"⚠️  提取的金额 {amount} 无效")
+                amount = None  # 重置amount,触发重新获取
+        except ValueError:
+            print(f"⚠️  提取的金额 {amount} 格式错误")
+            amount = None  # 重置amount,触发重新获取
+    
+    # 如果没有有效金额,使用Agent询问
+    if not validated_amount:
+        print("💵 需要获取转账金额...")
+        while True:
+            amount_str = get_missing_info_via_agent(agent, f"请告诉我您要转账多少钱给 {name}?(请输入数字金额)")
+            
+            if not amount_str:
+                print("⚠️  无法获取转账金额,转账操作取消")
+                return
+                
+            try:
+                # 从用户输入中提取数字
+                number_match = re.search(r'\d+(?:\.\d+)?', amount_str)
+                if number_match:
+                    amount_float = float(number_match.group())
+                    if amount_float > 0:
+                        validated_amount = str(amount_float)
+                        print(f"✅ 确认转账金额: ¥{validated_amount}")
+                        break
+                    else:
+                        print("⚠️  转账金额必须大于0")
+                else:
+                    print("⚠️  无法从输入中识别有效的金额数字")
+                    
+            except ValueError:
+                print("⚠️  金额格式错误,请重新输入")
+
+    # 创建转账信息JSON
+    transfer_info = {
+        "recipient_name": name,
+        "recipient_phone": phone,
+        "amount": validated_amount,
+        "timestamp": __import__('datetime').datetime.now().isoformat()
+    }
+    
+    # 显示转账信息
+    print("\n" + "="*50)
+    print("📋 转账信息确认:")
+    print(f"  收款人: {transfer_info['recipient_name']}")
+    print(f"  电话号码: {transfer_info['recipient_phone']}")
+    print(f"  转账金额: ¥{transfer_info['amount']}")
+    print(f"  时间: {transfer_info['timestamp']}")
+    print("="*50)
+    
+    # 确认转账
+    confirm_response = input("请确认以上转账信息是否正确?(回答:y/n)").strip()
+    if confirm_response:
+        confirm_response_str_raw = str(confirm_response).strip().lower()
+        if confirm_response_str_raw == "y":
+            # 用户确认,保存转账信息
+            try:
+                transfers_file = "transfer_records.json"
+                if os.path.exists(transfers_file):
+                    with open(transfers_file, 'r', encoding='utf-8') as f:
+                        transfers = json.load(f)
+                else:
+                    transfers = []
+
+                # 添加新转账记录,并附加用户确认回复
+                transfer_info_with_confirm = dict(transfer_info)
+                transfer_info_with_confirm["user_confirm_response"] = '{"is_transfer": true}'
+                transfers.append(transfer_info_with_confirm)
+
+                with open(transfers_file, 'w', encoding='utf-8') as f:
+                    json.dump(transfers, f, ensure_ascii=False, indent=2)
+
+                print("✅ 转账信息已保存!")
+                print(f"📄 转账记录已保存到: {transfers_file}")
+            except Exception as e:
+                print(f"❌ 保存转账记录时出错: {e}")
+        elif confirm_response_str_raw == "n":
+            print("❌ 用户未确认转账,未保存转账信息。")
+        else:
+            print("⚠️  无法识别的回复,转账操作取消")
+    else:
+        print("⚠️  未收到确认回复,转账操作取消")
+
+def print_welcome():
+    """打印欢迎信息"""
+    print("=" * 60)
+    print("🤖 欢迎使用Agent对话系统!")
+    print("=" * 60)
+    print("💡 使用说明:")
+    print("  - 直接输入您的问题进行对话")
+    print("  - 输入 'exit', 'quit', 'bye' 或 '退出' 结束对话")
+    print("  - 输入 'clear' 或 '清屏' 清空屏幕")
+    print("  - 输入 'help' 或 '帮助' 查看帮助信息")
+    print("  - 说出转账相关的话(如:给张三转100块钱)进行转账操作")
+    print("=" * 60)
+
+def print_help():
+    """打印帮助信息"""
+    print("\n📋 帮助信息:")
+    print("  exit/quit/bye/退出  - 退出程序")
+    print("  clear/清屏          - 清空屏幕")
+    print("  help/帮助           - 显示此帮助信息")
+    print("  转账相关自然语言    - AI智能识别转账意图")
+    print("  例:给张三转100块   - 转账功能示例")
+    print("  其他任何内容        - 与Agent对话")
+
+def clear_screen():
+    """清空屏幕"""
+    os.system('cls' if os.name == 'nt' else 'clear')
+
+def chat_loop():
+    """主对话循环"""
+    agent = create_agent()
+    print_welcome()
+    
+    while True:
+        try:
+            # 获取用户输入
+            user_input = input("\n🙋 您: ").strip()
+            
+            # 检查退出命令
+            if user_input.lower() in ['exit', 'quit', 'bye', '退出']:
+                print("\n👋 再见! 感谢使用Agent对话系统!")
+                break
+            
+            # 检查清屏命令
+            if user_input.lower() in ['clear', '清屏']:
+                clear_screen()
+                print_welcome()
+                continue
+            
+            # 检查帮助命令
+            if user_input.lower() in ['help', '帮助']:
+                print_help()
+                continue
+            
+            # 检查是否包含转账意图(让AI判断)
+            is_transfer, name, amount = check_transfer_intent(user_input, agent)
+            
+            if is_transfer:
+                handle_transfer_with_extracted_info(agent, name, amount)
+                continue
+            
+            # 检查空输入
+            if not user_input:
+                print("⚠️  请输入您的问题或命令")
+                continue
+            
+            print(f"\n🤖 Agent: ")
+            print("-" * 50)
+            
+            # 运行agent并获取响应流
+            response_stream: Iterator[RunResponseEvent] = agent.run(
+                user_input,
+                stream=True
+            )
+            
+            # 打印响应
+            pprint_run_response(response_stream, markdown=True)
+            
+        except KeyboardInterrupt:
+            print("\n\n👋 检测到 Ctrl+C,正在退出...")
+            break
+        except Exception as e:
+            print(f"\n❌ 发生错误: {e}")
+            print("请重试或联系技术支持")
+
+def main():
+    """主函数"""
+    try:
+        # 检查环境变量
+        if not os.getenv("BAILIAN_API_KEY") or not os.getenv("BAILIAN_API_BASE_URL"):
+            print("❌ 错误: 请确保设置了以下环境变量:")
+            print("  - BAILIAN_API_KEY")
+            print("  - BAILIAN_API_BASE_URL")
+            print("\n💡 您可以创建 .env 文件来设置这些变量")
+            sys.exit(1)
+        
+        # 开始对话
+        chat_loop()
+        
+    except Exception as e:
+        print(f"❌ 启动失败: {e}")
+        sys.exit(1)
+
+if __name__ == "__main__":
+    main() 

+ 6 - 0
林兆新/2/file_word_count.csv

@@ -0,0 +1,6 @@
+file_path,file_name,file_extension,file_size_bytes,timestamp,total_characters,characters_no_spaces,total_lines,empty_lines,non_empty_lines,total_words,chinese_characters,english_words,numbers,punctuation
+../README_emotion_table.md,README_emotion_table.md,.md,3448,2025-07-07 18:45:20,2212,1809,120,28,92,213,590,60,77,336
+../table_integration_code.py,table_integration_code.py,.py,2808,2025-07-07 18:45:20,2298,1959,76,12,64,181,251,36,26,466
+../generate_emotion_table.py,generate_emotion_table.py,.py,5348,2025-07-07 18:45:20,4518,3596,147,29,118,351,409,67,143,896
+../emotion_results.csv,emotion_results.csv,.csv,152965,2025-07-07 18:45:20,152124,127885,111,0,111,24350,318,19911,874,9067
+../user_info_extracted.csv,user_info_extracted.csv,.csv,699,2025-07-07 18:45:20,429,420,5,0,5,14,119,0,78,87

+ 116 - 0
林兆新/2/file_word_count.json

@@ -0,0 +1,116 @@
+{
+  "summary": {
+    "total_files": 5,
+    "total_characters": 161581,
+    "total_words": 25109,
+    "total_lines": 459,
+    "total_chinese_chars": 1687,
+    "total_english_words": 20074,
+    "total_file_size": 165268,
+    "file_types": {
+      ".md": {
+        "count": 1,
+        "total_chars": 2212,
+        "total_words": 213
+      },
+      ".py": {
+        "count": 2,
+        "total_chars": 6816,
+        "total_words": 532
+      },
+      ".csv": {
+        "count": 2,
+        "total_chars": 152553,
+        "total_words": 24364
+      }
+    }
+  },
+  "details": [
+    {
+      "file_path": "../README_emotion_table.md",
+      "file_name": "README_emotion_table.md",
+      "file_extension": ".md",
+      "file_size_bytes": 3448,
+      "timestamp": "2025-07-07 18:45:20",
+      "total_characters": 2212,
+      "characters_no_spaces": 1809,
+      "total_lines": 120,
+      "empty_lines": 28,
+      "non_empty_lines": 92,
+      "total_words": 213,
+      "chinese_characters": 590,
+      "english_words": 60,
+      "numbers": 77,
+      "punctuation": 336
+    },
+    {
+      "file_path": "../table_integration_code.py",
+      "file_name": "table_integration_code.py",
+      "file_extension": ".py",
+      "file_size_bytes": 2808,
+      "timestamp": "2025-07-07 18:45:20",
+      "total_characters": 2298,
+      "characters_no_spaces": 1959,
+      "total_lines": 76,
+      "empty_lines": 12,
+      "non_empty_lines": 64,
+      "total_words": 181,
+      "chinese_characters": 251,
+      "english_words": 36,
+      "numbers": 26,
+      "punctuation": 466
+    },
+    {
+      "file_path": "../generate_emotion_table.py",
+      "file_name": "generate_emotion_table.py",
+      "file_extension": ".py",
+      "file_size_bytes": 5348,
+      "timestamp": "2025-07-07 18:45:20",
+      "total_characters": 4518,
+      "characters_no_spaces": 3596,
+      "total_lines": 147,
+      "empty_lines": 29,
+      "non_empty_lines": 118,
+      "total_words": 351,
+      "chinese_characters": 409,
+      "english_words": 67,
+      "numbers": 143,
+      "punctuation": 896
+    },
+    {
+      "file_path": "../emotion_results.csv",
+      "file_name": "emotion_results.csv",
+      "file_extension": ".csv",
+      "file_size_bytes": 152965,
+      "timestamp": "2025-07-07 18:45:20",
+      "total_characters": 152124,
+      "characters_no_spaces": 127885,
+      "total_lines": 111,
+      "empty_lines": 0,
+      "non_empty_lines": 111,
+      "total_words": 24350,
+      "chinese_characters": 318,
+      "english_words": 19911,
+      "numbers": 874,
+      "punctuation": 9067
+    },
+    {
+      "file_path": "../user_info_extracted.csv",
+      "file_name": "user_info_extracted.csv",
+      "file_extension": ".csv",
+      "file_size_bytes": 699,
+      "timestamp": "2025-07-07 18:45:20",
+      "total_characters": 429,
+      "characters_no_spaces": 420,
+      "total_lines": 5,
+      "empty_lines": 0,
+      "non_empty_lines": 5,
+      "total_words": 14,
+      "chinese_characters": 119,
+      "english_words": 0,
+      "numbers": 78,
+      "punctuation": 87
+    }
+  ],
+  "export_time": "2025-07-07 18:45:20"
+}