|
@@ -2,7 +2,11 @@
|
|
|
"cells": [
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
+<<<<<<< HEAD
|
|
|
"execution_count": 1,
|
|
|
+=======
|
|
|
+ "execution_count": 11,
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"id": "a4856341",
|
|
|
"metadata": {},
|
|
|
"outputs": [
|
|
@@ -12,13 +16,18 @@
|
|
|
"True"
|
|
|
]
|
|
|
},
|
|
|
+<<<<<<< HEAD
|
|
|
"execution_count": 1,
|
|
|
+=======
|
|
|
+ "execution_count": 11,
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"metadata": {},
|
|
|
"output_type": "execute_result"
|
|
|
}
|
|
|
],
|
|
|
"source": [
|
|
|
"from textwrap import dedent\n",
|
|
|
+<<<<<<< HEAD
|
|
|
"\n",
|
|
|
"from agno.agent import Agent\n",
|
|
|
"from agno.models.openai import OpenAILike\n",
|
|
@@ -42,6 +51,20 @@
|
|
|
"import os\n",
|
|
|
"import json\n",
|
|
|
"load_dotenv()\n"
|
|
|
+=======
|
|
|
+ "from agno.agent import Agent\n",
|
|
|
+ "from dotenv import load_dotenv \n",
|
|
|
+ "from agno.models.openai import OpenAILike\n",
|
|
|
+ "from agno.memory.v2.db.sqlite import SqliteMemoryDb\n",
|
|
|
+ "from agno.memory.v2.memory import Memory\n",
|
|
|
+ "from rich.pretty import pprint\n",
|
|
|
+ "from agno.storage.sqlite import SqliteStorage\n",
|
|
|
+ "from typing import List,Dict\n",
|
|
|
+ "from pydantic import BaseModel, Field\n",
|
|
|
+ "import os\n",
|
|
|
+ "load_dotenv()\n",
|
|
|
+ "\n"
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -54,14 +77,22 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
+<<<<<<< HEAD
|
|
|
"execution_count": 2,
|
|
|
+=======
|
|
|
+ "execution_count": null,
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"id": "46403d1a",
|
|
|
"metadata": {},
|
|
|
"outputs": [
|
|
|
{
|
|
|
"data": {
|
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
|
+<<<<<<< HEAD
|
|
|
"model_id": "b5e36e3099374134807dcb494a113ff1",
|
|
|
+=======
|
|
|
+ "model_id": "9b3d2e36a97047dcaf90b8a373c1c2c1",
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"version_major": 2,
|
|
|
"version_minor": 0
|
|
|
},
|
|
@@ -86,7 +117,11 @@
|
|
|
"name": "stdout",
|
|
|
"output_type": "stream",
|
|
|
"text": [
|
|
|
+<<<<<<< HEAD
|
|
|
"Final session state: {'shopping_list': ['milk', 'eggs', 'bread'], 'current_session_id': 'c0e056e2-5ea1-4e62-a955-227f6485ffa6'}\n"
|
|
|
+=======
|
|
|
+ "Final session state: {'shopping_list': ['milk', 'eggs', 'bread'], 'current_session_id': 'fb205638-5e39-40e7-8722-1aedcd7995e0'}\n"
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
]
|
|
|
}
|
|
|
],
|
|
@@ -124,6 +159,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
+<<<<<<< HEAD
|
|
|
"execution_count": null,
|
|
|
"id": "8e7e7a5b",
|
|
|
"metadata": {},
|
|
@@ -131,6 +167,170 @@
|
|
|
"source": [
|
|
|
"# Define tools to manage our shopping list\n",
|
|
|
"@tool(description=\"Add an item to the shopping list.\")\n",
|
|
|
+=======
|
|
|
+ "execution_count": 6,
|
|
|
+ "id": "8e7e7a5b",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "1dbdd22b0ef44e0ca820d7469715ad9c",
|
|
|
+ "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": [
|
|
|
+ "Session state: {'shopping_list': ['milk', 'eggs', 'bread'], 'current_session_id': '7d5889cc-c85a-46a8-bd6d-617eb4fc56fb'}\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "df0130bb33ad4782a54af20fd62e96ca",
|
|
|
+ "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": [
|
|
|
+ "Session state: {'shopping_list': ['milk', 'eggs'], 'current_session_id': '7d5889cc-c85a-46a8-bd6d-617eb4fc56fb'}\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "33b95577fd9a41f4b1ba01af0d8c9d16",
|
|
|
+ "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": [
|
|
|
+ "Session state: {'shopping_list': ['milk', 'eggs', 'apples', 'oranges'], 'current_session_id': '7d5889cc-c85a-46a8-bd6d-617eb4fc56fb'}\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "22a01dc2c8cf44ca8fee0e64115ccf46",
|
|
|
+ "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": [
|
|
|
+ "Session state: {'shopping_list': ['milk', 'eggs', 'apples', 'oranges'], 'current_session_id': '7d5889cc-c85a-46a8-bd6d-617eb4fc56fb'}\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "c3f890d603fa4dbb9497ec8481340014",
|
|
|
+ "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": [
|
|
|
+ "Session state: {'shopping_list': ['bananas', 'yogurt'], 'current_session_id': '7d5889cc-c85a-46a8-bd6d-617eb4fc56fb'}\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "# Define tools to manage our shopping list\n",
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"def add_item(agent: Agent, item: str) -> str:\n",
|
|
|
" \"\"\"Add an item to the shopping list and return confirmation.\"\"\"\n",
|
|
|
" # Add the item if it's not already in the list\n",
|
|
@@ -146,7 +346,11 @@
|
|
|
" else:\n",
|
|
|
" return f\"'{item}' is already in the shopping list\"\n",
|
|
|
"\n",
|
|
|
+<<<<<<< HEAD
|
|
|
"@tool(description=\"Remove an item from the shopping list by name.\")\n",
|
|
|
+=======
|
|
|
+ "\n",
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"def remove_item(agent: Agent, item: str) -> str:\n",
|
|
|
" \"\"\"Remove an item from the shopping list by name.\"\"\"\n",
|
|
|
" # Case-insensitive search\n",
|
|
@@ -162,7 +366,11 @@
|
|
|
"\n",
|
|
|
" return f\"'{item}' was not found in the shopping list\"\n",
|
|
|
"\n",
|
|
|
+<<<<<<< HEAD
|
|
|
"@tool(description=\"List all items in the shopping list.\")\n",
|
|
|
+=======
|
|
|
+ "\n",
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"def list_items(agent: Agent) -> str:\n",
|
|
|
" \"\"\"List all items in the shopping list.\"\"\"\n",
|
|
|
" if agent.session_state is None:\n",
|
|
@@ -228,10 +436,138 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
+<<<<<<< HEAD
|
|
|
"execution_count": null,
|
|
|
"id": "1f118e71",
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
+=======
|
|
|
+ "execution_count": 14,
|
|
|
+ "id": "1f118e71",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "c3b320b12c3540849310be03a5e4ae27",
|
|
|
+ "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": [
|
|
|
+ "Memories about Ava:\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: #800080; text-decoration-color: #800080; font-weight: bold\">UserMemory</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\">memory</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'Ava likes to ski.'</span>,\n",
|
|
|
+ "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ </span><span style=\"color: #808000; text-decoration-color: #808000\">topics</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\">'hobbies'</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</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My name is Ava and I like to ski.'</span>,\n",
|
|
|
+ "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ </span><span style=\"color: #808000; text-decoration-color: #808000\">last_updated</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">datetime</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">.datetime</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2025</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">14</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">48</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">101965</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\">memory_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'c97cfac1-5166-49c3-b002-dac0530182ab'</span>\n",
|
|
|
+ "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </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[1;35mUserMemory\u001b[0m\u001b[1m(\u001b[0m\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mmemory\u001b[0m=\u001b[32m'Ava likes to ski.'\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mtopics\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'name'\u001b[0m, \u001b[32m'hobbies'\u001b[0m\u001b[1m]\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33minput\u001b[0m=\u001b[32m'My name is Ava and I like to ski.'\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mlast_updated\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m7\u001b[0m, \u001b[1;36m14\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m3\u001b[0m, \u001b[1;36m101965\u001b[0m\u001b[1m)\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mmemory_id\u001b[0m=\u001b[32m'c97cfac1-5166-49c3-b002-dac0530182ab'\u001b[0m\n",
|
|
|
+ "\u001b[2;32m│ \u001b[0m\u001b[1m)\u001b[0m\n",
|
|
|
+ "\u001b[1m]\u001b[0m\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "display_data"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "3bda0ba0f3a64809bd63d042d95fd2a3",
|
|
|
+ "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": [
|
|
|
+ "Memories about Ava:\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: #800080; text-decoration-color: #800080; font-weight: bold\">UserMemory</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\">memory</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'Ava likes to ski.'</span>,\n",
|
|
|
+ "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ </span><span style=\"color: #808000; text-decoration-color: #808000\">topics</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\">'hobbies'</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</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'My name is Ava and I like to ski.'</span>,\n",
|
|
|
+ "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ </span><span style=\"color: #808000; text-decoration-color: #808000\">last_updated</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">datetime</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">.datetime</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2025</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">14</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">48</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">101965</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\">memory_id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'c97cfac1-5166-49c3-b002-dac0530182ab'</span>\n",
|
|
|
+ "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </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[1;35mUserMemory\u001b[0m\u001b[1m(\u001b[0m\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mmemory\u001b[0m=\u001b[32m'Ava likes to ski.'\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mtopics\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'name'\u001b[0m, \u001b[32m'hobbies'\u001b[0m\u001b[1m]\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33minput\u001b[0m=\u001b[32m'My name is Ava and I like to ski.'\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mlast_updated\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m7\u001b[0m, \u001b[1;36m14\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m3\u001b[0m, \u001b[1;36m101965\u001b[0m\u001b[1m)\u001b[0m,\n",
|
|
|
+ "\u001b[2;32m│ │ \u001b[0m\u001b[33mmemory_id\u001b[0m=\u001b[32m'c97cfac1-5166-49c3-b002-dac0530182ab'\u001b[0m\n",
|
|
|
+ "\u001b[2;32m│ \u001b[0m\u001b[1m)\u001b[0m\n",
|
|
|
+ "\u001b[1m]\u001b[0m\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "display_data"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
"source": [
|
|
|
"# UserId for the memories\n",
|
|
|
"user_id = \"ava\"\n",
|
|
@@ -242,9 +578,15 @@
|
|
|
"memory = Memory(\n",
|
|
|
" # Use any model for creating memories\n",
|
|
|
" model=OpenAILike(id=\"qwen3-30b-a3b\", \n",
|
|
|
+<<<<<<< HEAD
|
|
|
" 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",
|
|
|
+=======
|
|
|
+ " 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",
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
" db=SqliteMemoryDb(table_name=\"user_memories\", db_file=db_file),\n",
|
|
|
")\n",
|
|
|
"# Initialize storage\n",
|
|
@@ -301,6 +643,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
+<<<<<<< HEAD
|
|
|
"execution_count": null,
|
|
|
"id": "5cddde6d",
|
|
|
"metadata": {},
|
|
@@ -445,6 +788,222 @@
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
"**Multimodal Agent**"
|
|
|
+=======
|
|
|
+ "execution_count": 13,
|
|
|
+ "id": "5cddde6d",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "application/vnd.jupyter.widget-view+json": {
|
|
|
+ "model_id": "7745304024a946c3b1e7bcba04f464ca",
|
|
|
+ "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: #808000; text-decoration-color: #808000\">WARNING </span> Failed to parse cleaned JSON: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span> validation errors for MovieScript \n",
|
|
|
+ " setting \n",
|
|
|
+ " Input should be a valid string <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">string_type</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'New York Ci...t hold hidden </span>\n",
|
|
|
+ " <span style=\"color: #008000; text-decoration-color: #008000\">stories.'</span><span style=\"font-weight: bold\">}</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/string_type</span> \n",
|
|
|
+ " ending \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'New York'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'ge...s a central character.'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " name \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'New York'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'ge...s a central character.'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " characters \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'New York'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'ge...s a central character.'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " storyline \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'New York'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'ge...s a central character.'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " rating \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'New York'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'ge...s a central character.'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ "</pre>\n"
|
|
|
+ ],
|
|
|
+ "text/plain": [
|
|
|
+ "\u001b[33mWARNING \u001b[0m Failed to parse cleaned JSON: \u001b[1;36m6\u001b[0m validation errors for MovieScript \n",
|
|
|
+ " setting \n",
|
|
|
+ " Input should be a valid string \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mstring_type\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'location'\u001b[0m: \u001b[32m'New York Ci...t hold hidden \u001b[0m\n",
|
|
|
+ " \u001b[32mstories.'\u001b[0m\u001b[1m}\u001b[0m, \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/string_type\u001b[0m \n",
|
|
|
+ " ending \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'title'\u001b[0m: \u001b[32m'New York'\u001b[0m, \u001b[32m'ge...s a central character.'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " name \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'title'\u001b[0m: \u001b[32m'New York'\u001b[0m, \u001b[32m'ge...s a central character.'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " characters \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'title'\u001b[0m: \u001b[32m'New York'\u001b[0m, \u001b[32m'ge...s a central character.'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " storyline \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'title'\u001b[0m: \u001b[32m'New York'\u001b[0m, \u001b[32m'ge...s a central character.'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " rating \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'title'\u001b[0m: \u001b[32m'New York'\u001b[0m, \u001b[32m'ge...s a central character.'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\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: #808000; text-decoration-color: #808000\">WARNING </span> Validation failed on merged data: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span> validation errors for MovieScript \n",
|
|
|
+ " setting \n",
|
|
|
+ " Input should be a valid string <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">string_type</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'location'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'New York Ci...t hold hidden </span>\n",
|
|
|
+ " <span style=\"color: #008000; text-decoration-color: #008000\">stories.'</span><span style=\"font-weight: bold\">}</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/string_type</span> \n",
|
|
|
+ " ending \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'setting'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'location'</span>: <span style=\"color: #808000; text-decoration-color: #808000\">...</span>genre': <span style=\"color: #008000; text-decoration-color: #008000\">'Drama / Crime'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " name \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'setting'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'location'</span>: <span style=\"color: #808000; text-decoration-color: #808000\">...</span>genre': <span style=\"color: #008000; text-decoration-color: #008000\">'Drama / Crime'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " characters \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'setting'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'location'</span>: <span style=\"color: #808000; text-decoration-color: #808000\">...</span>genre': <span style=\"color: #008000; text-decoration-color: #008000\">'Drama / Crime'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " storyline \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'setting'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'location'</span>: <span style=\"color: #808000; text-decoration-color: #808000\">...</span>genre': <span style=\"color: #008000; text-decoration-color: #008000\">'Drama / Crime'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ " rating \n",
|
|
|
+ " Field required <span style=\"font-weight: bold\">[</span><span style=\"color: #808000; text-decoration-color: #808000\">type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">missing</span>, <span style=\"color: #808000; text-decoration-color: #808000\">input_value</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'setting'</span>: <span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'location'</span>: <span style=\"color: #808000; text-decoration-color: #808000\">...</span>genre': <span style=\"color: #008000; text-decoration-color: #008000\">'Drama / Crime'</span><span style=\"font-weight: bold\">}</span>, \n",
|
|
|
+ " <span style=\"color: #808000; text-decoration-color: #808000\">input_type</span>=<span style=\"color: #800080; text-decoration-color: #800080\">dict</span><span style=\"font-weight: bold\">]</span> \n",
|
|
|
+ " For further information visit <span style=\"color: #0000ff; text-decoration-color: #0000ff; text-decoration: underline\">https://errors.pydantic.dev/2.11/v/missing</span> \n",
|
|
|
+ "</pre>\n"
|
|
|
+ ],
|
|
|
+ "text/plain": [
|
|
|
+ "\u001b[33mWARNING \u001b[0m Validation failed on merged data: \u001b[1;36m6\u001b[0m validation errors for MovieScript \n",
|
|
|
+ " setting \n",
|
|
|
+ " Input should be a valid string \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mstring_type\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'location'\u001b[0m: \u001b[32m'New York Ci...t hold hidden \u001b[0m\n",
|
|
|
+ " \u001b[32mstories.'\u001b[0m\u001b[1m}\u001b[0m, \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/string_type\u001b[0m \n",
|
|
|
+ " ending \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'setting'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'location'\u001b[0m: \u001b[33m...\u001b[0mgenre': \u001b[32m'Drama / Crime'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " name \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'setting'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'location'\u001b[0m: \u001b[33m...\u001b[0mgenre': \u001b[32m'Drama / Crime'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " characters \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'setting'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'location'\u001b[0m: \u001b[33m...\u001b[0mgenre': \u001b[32m'Drama / Crime'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " storyline \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'setting'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'location'\u001b[0m: \u001b[33m...\u001b[0mgenre': \u001b[32m'Drama / Crime'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\u001b[0m \n",
|
|
|
+ " rating \n",
|
|
|
+ " Field required \u001b[1m[\u001b[0m\u001b[33mtype\u001b[0m=\u001b[35mmissing\u001b[0m, \u001b[33minput_value\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'setting'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'location'\u001b[0m: \u001b[33m...\u001b[0mgenre': \u001b[32m'Drama / Crime'\u001b[0m\u001b[1m}\u001b[0m, \n",
|
|
|
+ " \u001b[33minput_type\u001b[0m=\u001b[35mdict\u001b[0m\u001b[1m]\u001b[0m \n",
|
|
|
+ " For further information visit \u001b[4;94mhttps://errors.pydantic.dev/2.11/v/missing\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: #808000; text-decoration-color: #808000\">WARNING </span> All parsing attempts failed. \n",
|
|
|
+ "</pre>\n"
|
|
|
+ ],
|
|
|
+ "text/plain": [
|
|
|
+ "\u001b[33mWARNING \u001b[0m All parsing attempts failed. \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: #808000; text-decoration-color: #808000\">WARNING </span> Failed to convert response to response_model \n",
|
|
|
+ "</pre>\n"
|
|
|
+ ],
|
|
|
+ "text/plain": [
|
|
|
+ "\u001b[33mWARNING \u001b[0m Failed to convert response to response_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\"></pre>\n"
|
|
|
+ ],
|
|
|
+ "text/plain": []
|
|
|
+ },
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "display_data"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "class MovieScript(BaseModel):\n",
|
|
|
+ " setting: str = Field(\n",
|
|
|
+ " ..., description=\"Provide a nice setting for a blockbuster movie.\"\n",
|
|
|
+ " )\n",
|
|
|
+ " ending: str = Field(\n",
|
|
|
+ " ...,\n",
|
|
|
+ " description=\"Ending of the movie. If not available, provide a happy ending.\",\n",
|
|
|
+ " )\n",
|
|
|
+ " genre: str = Field(\n",
|
|
|
+ " ...,\n",
|
|
|
+ " description=\"Genre of the movie. If not available, select action, thriller or romantic comedy.\",\n",
|
|
|
+ " )\n",
|
|
|
+ " name: str = Field(..., description=\"Give a name to this movie\")\n",
|
|
|
+ " characters: List[str] = Field(..., description=\"Name of characters for this movie.\")\n",
|
|
|
+ " storyline: str = Field(\n",
|
|
|
+ " ..., description=\"3 sentence storyline for the movie. Make it exciting!\"\n",
|
|
|
+ " )\n",
|
|
|
+ " rating: Dict[str, int] = Field(\n",
|
|
|
+ " ...,\n",
|
|
|
+ " description=\"Your own rating of the movie. 1-10. Return a dictionary with the keys 'story' and 'acting'.\",\n",
|
|
|
+ " )\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "# Agent that uses structured outputs with streaming\n",
|
|
|
+ "structured_output_agent = Agent(\n",
|
|
|
+ " model=OpenAILike(id=\"qwen3-30b-a3b\", \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",
|
|
|
+ " description=\"You write movie json scripts.\",\n",
|
|
|
+ " response_model=MovieScript,\n",
|
|
|
+ ")\n",
|
|
|
+ "\n",
|
|
|
+ "structured_output_agent.print_response(\n",
|
|
|
+ " \"New York\", stream=True, stream_intermediate_steps=True\n",
|
|
|
+ ")"
|
|
|
+>>>>>>> bad0e67 (多轮对话+agno agent学习实践)
|
|
|
]
|
|
|
},
|
|
|
{
|