浏览代码

多轮对话+agno agent学习实践

iTTsShuu 1 月之前
父节点
当前提交
78ef6c7312
共有 10 个文件被更改,包括 2091 次插入28 次删除
  1. 2 0
      pyproject.toml
  2. 270 0
      uv.lock
  3. 76 27
      曹航/1/sentiment_prediction.ipynb
  4. 190 0
      曹航/2/chatbot.ipynb
  5. 738 0
      曹航/3/agent_test1.ipynb
  6. 815 0
      曹航/3/agent_test2.ipynb
  7. 二进制
      曹航/3/temp/agent.db
  8. 二进制
      曹航/3/temp/agent_history.db
  9. 二进制
      曹航/3/tmp/agent.db
  10. 0 1
      曹航/caohang.ipynb

+ 2 - 0
pyproject.toml

@@ -6,7 +6,9 @@ readme = "README.md"
 requires-python = ">=3.11"
 dependencies = [
     "agno>=1.7.1",
+    "agno>=1.7.2",
     "dotenv>=0.9.9",
+    "ipywidgets>=8.1.7",
     "openai>=1.93.0",
     "duckduckgo-search>=6.0.0",
     "pandas",

+ 270 - 0
uv.lock

@@ -7,11 +7,36 @@ resolution-markers = [
 ]
 
 [[package]]
+name = "agno"
+version = "1.7.2"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "docstring-parser" },
+    { name = "gitpython" },
+    { name = "httpx" },
+    { name = "pydantic" },
+    { name = "pydantic-settings" },
+    { name = "python-dotenv" },
+    { name = "python-multipart" },
+    { name = "pyyaml" },
+    { name = "rich" },
+    { name = "tomli" },
+    { name = "typer" },
+    { name = "typing-extensions" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/50/64/6a82d2375145fd733009db0ada531b595fc2f3c1712ac91c91b2e5fcf02f/agno-1.7.2.tar.gz", hash = "sha256:f4f97e5ea1f9c0781d9bb8396862c82671381386c1569cdb456d70f6c8d3a108" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/7d/24/884cbd1133e3b9985d53733250251098caead365bb8706af8da105813abe/agno-1.7.2-py3-none-any.whl", hash = "sha256:37a1985e67762f0d8016318ba5d8b8697c855827d7c86b21a41cdff088294cc2" },
+]
+
+[[package]]
 name = "ai-learning"
 version = "0.1.0"
 source = { virtual = "." }
 dependencies = [
+    { name = "agno" },
     { name = "dotenv" },
+    { name = "ipywidgets" },
     { name = "openai" },
     { name = "pandas" },
 ]
@@ -23,7 +48,9 @@ dev = [
 
 [package.metadata]
 requires-dist = [
+    { name = "agno", specifier = ">=1.7.2" },
     { name = "dotenv", specifier = ">=0.9.9" },
+    { name = "ipywidgets", specifier = ">=8.1.7" },
     { name = "openai", specifier = ">=1.93.0" },
     { name = "pandas", specifier = ">=2.3.1" },
 ]
@@ -127,6 +154,18 @@ wheels = [
 ]
 
 [[package]]
+name = "click"
+version = "8.2.1"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "colorama", marker = "sys_platform == 'win32'" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/60/6c/8ca2efa64cf75a977a0d7fac081354553ebe483345c734fb6b6515d96bbc/click-8.2.1.tar.gz", hash = "sha256:27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/85/32/10bb5764d90a8eee674e9dc6f4db6a0ab47c8c4d0d83c27f7c39ac415a4d/click-8.2.1-py3-none-any.whl", hash = "sha256:61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b" },
+]
+
+[[package]]
 name = "colorama"
 version = "0.4.6"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -187,6 +226,15 @@ wheels = [
 ]
 
 [[package]]
+name = "docstring-parser"
+version = "0.16"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/08/12/9c22a58c0b1e29271051222d8906257616da84135af9ed167c9e28f85cb3/docstring_parser-0.16.tar.gz", hash = "sha256:538beabd0af1e2db0146b6bd3caa526c35a34d61af9fd2887f3a8a27a739aa6e" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/d5/7c/e9fcff7623954d86bdc17782036cbf715ecab1bec4847c008557affe1ca8/docstring_parser-0.16-py3-none-any.whl", hash = "sha256:bf0a1387354d3691d102edef7ec124f219ef639982d096e26e3b60aeffa90637" },
+]
+
+[[package]]
 name = "dotenv"
 version = "0.9.9"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -207,6 +255,30 @@ wheels = [
 ]
 
 [[package]]
+name = "gitdb"
+version = "4.0.12"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "smmap" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/72/94/63b0fc47eb32792c7ba1fe1b694daec9a63620db1e313033d18140c2320a/gitdb-4.0.12.tar.gz", hash = "sha256:5ef71f855d191a3326fcfbc0d5da835f26b13fbcba60c32c21091c349ffdb571" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/a0/61/5c78b91c3143ed5c14207f463aecfc8f9dbb5092fb2869baf37c273b2705/gitdb-4.0.12-py3-none-any.whl", hash = "sha256:67073e15955400952c6565cc3e707c554a4eea2e428946f7a4c162fab9bd9bcf" },
+]
+
+[[package]]
+name = "gitpython"
+version = "3.1.44"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "gitdb" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/c0/89/37df0b71473153574a5cdef8f242de422a0f5d26d7a9e231e6f169b4ad14/gitpython-3.1.44.tar.gz", hash = "sha256:c87e30b26253bf5418b01b0660f818967f3c503193838337fe5e573331249269" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/1d/9a/4114a9057db2f1462d5c8f8390ab7383925fe1ac012eaa42402ad65c2963/GitPython-3.1.44-py3-none-any.whl", hash = "sha256:9e0e10cda9bed1ee64bc9a6de50e7e38a9c9943241cd7f585f6df3ed28011110" },
+]
+
+[[package]]
 name = "h11"
 version = "0.16.0"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -311,6 +383,22 @@ wheels = [
 ]
 
 [[package]]
+name = "ipywidgets"
+version = "8.1.7"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "comm" },
+    { name = "ipython" },
+    { name = "jupyterlab-widgets" },
+    { name = "traitlets" },
+    { name = "widgetsnbextension" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/3e/48/d3dbac45c2814cb73812f98dd6b38bbcc957a4e7bb31d6ea9c03bf94ed87/ipywidgets-8.1.7.tar.gz", hash = "sha256:15f1ac050b9ccbefd45dccfbb2ef6bed0029d8278682d569d71b8dd96bee0376" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/58/6a/9166369a2f092bd286d24e6307de555d63616e8ddb373ebad2b5635ca4cd/ipywidgets-8.1.7-py3-none-any.whl", hash = "sha256:764f2602d25471c213919b8a1997df04bef869251db4ca8efba1b76b1bd9f7bb" },
+]
+
+[[package]]
 name = "jedi"
 version = "0.19.2"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -413,6 +501,27 @@ wheels = [
 ]
 
 [[package]]
+name = "jupyterlab-widgets"
+version = "3.0.15"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/b9/7d/160595ca88ee87ac6ba95d82177d29ec60aaa63821d3077babb22ce031a5/jupyterlab_widgets-3.0.15.tar.gz", hash = "sha256:2920888a0c2922351a9202817957a68c07d99673504d6cd37345299e971bb08b" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/43/6a/ca128561b22b60bd5a0c4ea26649e68c8556b82bc70a0c396eebc977fe86/jupyterlab_widgets-3.0.15-py3-none-any.whl", hash = "sha256:d59023d7d7ef71400d51e6fee9a88867f6e65e10a4201605d2d7f3e8f012a31c" },
+]
+
+[[package]]
+name = "markdown-it-py"
+version = "3.0.0"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "mdurl" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/38/71/3b932df36c1a044d397a1f92d1cf91ee0a503d91e470cbd670aa66b07ed0/markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/42/d7/1ec15b46af6af88f19b8e5ffea08fa375d433c998b8a7639e76935c14f1f/markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1" },
+]
+
+[[package]]
 name = "matplotlib-inline"
 version = "0.1.7"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -425,6 +534,15 @@ wheels = [
 ]
 
 [[package]]
+name = "mdurl"
+version = "0.1.2"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8" },
+]
+
+[[package]]
 name = "nest-asyncio"
 version = "1.6.0"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -725,6 +843,20 @@ wheels = [
 ]
 
 [[package]]
+name = "pydantic-settings"
+version = "2.10.1"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "pydantic" },
+    { name = "python-dotenv" },
+    { name = "typing-inspection" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/68/85/1ea668bbab3c50071ca613c6ab30047fb36ab0da1b92fa8f17bbc38fd36c/pydantic_settings-2.10.1.tar.gz", hash = "sha256:06f0062169818d0f5524420a360d632d5857b83cffd4d42fe29597807a1614ee" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/58/f0/427018098906416f580e3cf1366d3b1abfb408a0652e9f31600c24a1903c/pydantic_settings-2.10.1-py3-none-any.whl", hash = "sha256:a60952460b99cf661dc25c29c0ef171721f98bfcb52ef8d9ea4c943d7c8cc796" },
+]
+
+[[package]]
 name = "pygments"
 version = "2.19.2"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -755,6 +887,15 @@ wheels = [
 ]
 
 [[package]]
+name = "python-multipart"
+version = "0.0.20"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/f3/87/f44d7c9f274c7ee665a29b885ec97089ec5dc034c7f3fafa03da9e39a09e/python_multipart-0.0.20.tar.gz", hash = "sha256:8dd0cab45b8e23064ae09147625994d090fa46f5b0d1e13af944c331a7fa9d13" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/45/58/38b5afbc1a800eeea951b9285d3912613f2603bdf897a4ab0f4bd7f405fc/python_multipart-0.0.20-py3-none-any.whl", hash = "sha256:8a62d3a8335e06589fe01f2a3e178cdcc632f3fbe0d492ad9ee0ec35aab1f104" },
+]
+
+[[package]]
 name = "pytz"
 version = "2025.2"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -780,6 +921,41 @@ wheels = [
 ]
 
 [[package]]
+name = "pyyaml"
+version = "6.0.2"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/54/ed/79a089b6be93607fa5cdaedf301d7dfb23af5f25c398d5ead2525b063e17/pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/f8/aa/7af4e81f7acba21a4c6be026da38fd2b872ca46226673c89a758ebdc4fd2/PyYAML-6.0.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cc1c1159b3d456576af7a3e4d1ba7e6924cb39de8f67111c735f6fc832082774" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/8b/62/b9faa998fd185f65c1371643678e4d58254add437edb764a08c5a98fb986/PyYAML-6.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1e2120ef853f59c7419231f3bf4e7021f1b936f6ebd222406c3b60212205d2ee" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/ad/0c/c804f5f922a9a6563bab712d8dcc70251e8af811fce4524d57c2c0fd49a4/PyYAML-6.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d225db5a45f21e78dd9358e58a98702a0302f2659a3c6cd320564b75b86f47c" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/51/16/6af8d6a6b210c8e54f1406a6b9481febf9c64a3109c541567e35a49aa2e7/PyYAML-6.0.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5ac9328ec4831237bec75defaf839f7d4564be1e6b25ac710bd1a96321cc8317" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/75/e4/2c27590dfc9992f73aabbeb9241ae20220bd9452df27483b6e56d3975cc5/PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ad2a3decf9aaba3d29c8f537ac4b243e36bef957511b4766cb0057d32b0be85" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/9b/97/ecc1abf4a823f5ac61941a9c00fe501b02ac3ab0e373c3857f7d4b83e2b6/PyYAML-6.0.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/45/73/0f49dacd6e82c9430e46f4a027baa4ca205e8b0a9dce1397f44edc23559d/PyYAML-6.0.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:797b4f722ffa07cc8d62053e4cff1486fa6dc094105d13fea7b1de7d8bf71c9e" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/22/5f/956f0f9fc65223a58fbc14459bf34b4cc48dec52e00535c79b8db361aabd/PyYAML-6.0.2-cp311-cp311-win32.whl", hash = "sha256:11d8f3dd2b9c1207dcaf2ee0bbbfd5991f571186ec9cc78427ba5bd32afae4b5" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/ed/23/8da0bbe2ab9dcdd11f4f4557ccaf95c10b9811b13ecced089d43ce59c3c8/PyYAML-6.0.2-cp311-cp311-win_amd64.whl", hash = "sha256:e10ce637b18caea04431ce14fabcf5c64a1c61ec9c56b071a4b7ca131ca52d44" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/86/0c/c581167fc46d6d6d7ddcfb8c843a4de25bdd27e4466938109ca68492292c/PyYAML-6.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/a8/0c/38374f5bb272c051e2a69281d71cba6fdb983413e6758b84482905e29a5d/PyYAML-6.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/c3/93/9916574aa8c00aa06bbac729972eb1071d002b8e158bd0e83a3b9a20a1f7/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/95/0f/b8938f1cbd09739c6da569d172531567dbcc9789e0029aa070856f123984/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/b9/2b/614b4752f2e127db5cc206abc23a8c19678e92b23c3db30fc86ab731d3bd/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/d4/00/dd137d5bcc7efea1836d6264f049359861cf548469d18da90cd8216cf05f/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/c9/1f/4f998c900485e5c0ef43838363ba4a9723ac0ad73a9dc42068b12aaba4e4/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/df/d1/f5a275fdb252768b7a11ec63585bc38d0e87c9e05668a139fea92b80634c/PyYAML-6.0.2-cp312-cp312-win32.whl", hash = "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/0c/e8/4f648c598b17c3d06e8753d7d13d57542b30d56e6c2dedf9c331ae56312e/PyYAML-6.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/ef/e3/3af305b830494fa85d95f6d95ef7fa73f2ee1cc8ef5b495c7c3269fb835f/PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/45/9f/3b1c20a0b7a3200524eb0076cc027a970d320bd3a6592873c85c92a08731/PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/7c/9a/337322f27005c33bcb656c655fa78325b730324c78620e8328ae28b64d0c/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/a3/69/864fbe19e6c18ea3cc196cbe5d392175b4cf3d5d0ac1403ec3f2d237ebb5/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/04/24/b7721e4845c2f162d26f50521b825fb061bc0a5afcf9a386840f23ea19fa/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/2b/b2/e3234f59ba06559c6ff63c4e10baea10e5e7df868092bf9ab40e5b9c56b6/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/fe/0f/25911a9f080464c59fab9027482f822b86bf0608957a5fcc6eaac85aa515/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/14/0d/e2c3b43bbce3cf6bd97c840b46088a3031085179e596d4929729d8d68270/PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/fa/de/02b54f42487e3d3c6efb3f89428677074ca7bf43aae402517bc7cca949f3/PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563" },
+]
+
+[[package]]
 name = "pyzmq"
 version = "27.0.0"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -825,6 +1001,28 @@ wheels = [
 ]
 
 [[package]]
+name = "rich"
+version = "14.0.0"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "markdown-it-py" },
+    { name = "pygments" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/a1/53/830aa4c3066a8ab0ae9a9955976fb770fe9c6102117c8ec4ab3ea62d89e8/rich-14.0.0.tar.gz", hash = "sha256:82f1bc23a6a21ebca4ae0c45af9bdbc492ed20231dcb63f297d6d1021a9d5725" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/0d/9b/63f4c7ebc259242c89b3acafdb37b41d1185c07ff0011164674e9076b491/rich-14.0.0-py3-none-any.whl", hash = "sha256:1c9491e1951aac09caffd42f448ee3d04e58923ffe14993f6e83068dc395d7e0" },
+]
+
+[[package]]
+name = "shellingham"
+version = "1.5.4"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/58/15/8b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e/shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686" },
+]
+
+[[package]]
 name = "six"
 version = "1.17.0"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -834,6 +1032,15 @@ wheels = [
 ]
 
 [[package]]
+name = "smmap"
+version = "5.0.2"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/44/cd/a040c4b3119bbe532e5b0732286f805445375489fceaec1f48306068ee3b/smmap-5.0.2.tar.gz", hash = "sha256:26ea65a03958fa0c8a1c7e8c7a58fdc77221b8910f6be2131affade476898ad5" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/04/be/d09147ad1ec7934636ad912901c5fd7667e1c858e19d355237db0d0cd5e4/smmap-5.0.2-py3-none-any.whl", hash = "sha256:b30115f0def7d7531d22a0fb6502488d879e75b260a9db4d0819cfb25403af5e" },
+]
+
+[[package]]
 name = "sniffio"
 version = "1.3.1"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -857,6 +1064,45 @@ wheels = [
 ]
 
 [[package]]
+name = "tomli"
+version = "2.2.1"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/18/87/302344fed471e44a87289cf4967697d07e532f2421fdaf868a303cbae4ff/tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/43/ca/75707e6efa2b37c77dadb324ae7d9571cb424e61ea73fad7c56c2d14527f/tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/c7/16/51ae563a8615d472fdbffc43a3f3d46588c264ac4f024f63f01283becfbb/tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/f1/dd/4f6cd1e7b160041db83c694abc78e100473c15d54620083dbd5aae7b990e/tomli-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/a9/6b/c54ede5dc70d648cc6361eaf429304b02f2871a345bbdd51e993d6cdf550/tomli-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/1f/47/999514fa49cfaf7a92c805a86c3c43f4215621855d151b61c602abb38091/tomli-2.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/73/41/0a01279a7ae09ee1573b423318e7934674ce06eb33f50936655071d81a24/tomli-2.2.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/55/18/5d8bc5b0a0362311ce4d18830a5d28943667599a60d20118074ea1b01bb7/tomli-2.2.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/92/a3/7ade0576d17f3cdf5ff44d61390d4b3febb8a9fc2b480c75c47ea048c646/tomli-2.2.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/72/6f/fa64ef058ac1446a1e51110c375339b3ec6be245af9d14c87c4a6412dd32/tomli-2.2.1-cp311-cp311-win32.whl", hash = "sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/6a/1c/4a2dcde4a51b81be3530565e92eda625d94dafb46dbeb15069df4caffc34/tomli-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/52/e1/f8af4c2fcde17500422858155aeb0d7e93477a0d59a98e56cbfe75070fd0/tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/03/b8/152c68bb84fc00396b83e7bbddd5ec0bd3dd409db4195e2a9b3e398ad2e3/tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/c8/d6/fc9267af9166f79ac528ff7e8c55c8181ded34eb4b0e93daa767b8841573/tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/5c/51/51c3f2884d7bab89af25f678447ea7d297b53b5a3b5730a7cb2ef6069f07/tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/ab/df/bfa89627d13a5cc22402e441e8a931ef2108403db390ff3345c05253935e/tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/9e/6e/fa2b916dced65763a5168c6ccb91066f7639bdc88b48adda990db10c8c0b/tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/b4/04/885d3b1f650e1153cbb93a6a9782c58a972b94ea4483ae4ac5cedd5e4a09/tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/9c/de/6b432d66e986e501586da298e28ebeefd3edc2c780f3ad73d22566034239/tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/1c/9a/47c0449b98e6e7d1be6cbac02f93dd79003234ddc4aaab6ba07a9a7482e2/tomli-2.2.1-cp312-cp312-win32.whl", hash = "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/ef/60/9b9638f081c6f1261e2688bd487625cd1e660d0a85bd469e91d8db969734/tomli-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/04/90/2ee5f2e0362cb8a0b6499dc44f4d7d48f8fff06d28ba46e6f1eaa61a1388/tomli-2.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/c0/ec/46b4108816de6b385141f082ba99e315501ccd0a2ea23db4a100dd3990ea/tomli-2.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/a0/bd/b470466d0137b37b68d24556c38a0cc819e8febe392d5b199dcd7f578365/tomli-2.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/d9/e5/82e80ff3b751373f7cead2815bcbe2d51c895b3c990686741a8e56ec42ab/tomli-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/05/7e/2a110bc2713557d6a1bfb06af23dd01e7dde52b6ee7dadc589868f9abfac/tomli-2.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/64/7b/22d713946efe00e0adbcdfd6d1aa119ae03fd0b60ebed51ebb3fa9f5a2e5/tomli-2.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/38/31/3a76f67da4b0cf37b742ca76beaf819dca0ebef26d78fc794a576e08accf/tomli-2.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/07/10/5af1293da642aded87e8a988753945d0cf7e00a9452d3911dd3bb354c9e2/tomli-2.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/5b/b9/1ed31d167be802da0fc95020d04cd27b7d7065cc6fbefdd2f9186f60d7bd/tomli-2.2.1-cp313-cp313-win32.whl", hash = "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/c7/32/b0963458706accd9afcfeb867c0f9175a741bf7b19cd424230714d722198/tomli-2.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69" },
+    { url = "https://mirrors.aliyun.com/pypi/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc" },
+]
+
+[[package]]
 name = "tornado"
 version = "6.5.1"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -897,6 +1143,21 @@ wheels = [
 ]
 
 [[package]]
+name = "typer"
+version = "0.16.0"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+dependencies = [
+    { name = "click" },
+    { name = "rich" },
+    { name = "shellingham" },
+    { name = "typing-extensions" },
+]
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/c5/8c/7d682431efca5fd290017663ea4588bf6f2c6aad085c7f108c5dbc316e70/typer-0.16.0.tar.gz", hash = "sha256:af377ffaee1dbe37ae9440cb4e8f11686ea5ce4e9bae01b84ae7c63b87f1dd3b" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/76/42/3efaf858001d2c2913de7f354563e3a3a2f0decae3efe98427125a8f441e/typer-0.16.0-py3-none-any.whl", hash = "sha256:1f79bed11d4d02d4310e3c1b7ba594183bcedb0ac73b27a9e5f28f6fb5b98855" },
+]
+
+[[package]]
 name = "typing-extensions"
 version = "4.14.0"
 source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
@@ -934,3 +1195,12 @@ sdist = { url = "https://mirrors.aliyun.com/pypi/packages/6c/63/53559446a878410f
 wheels = [
     { url = "https://mirrors.aliyun.com/pypi/packages/fd/84/fd2ba7aafacbad3c4201d395674fc6348826569da3c0937e75505ead3528/wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859" },
 ]
+
+[[package]]
+name = "widgetsnbextension"
+version = "4.0.14"
+source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
+sdist = { url = "https://mirrors.aliyun.com/pypi/packages/41/53/2e0253c5efd69c9656b1843892052a31c36d37ad42812b5da45c62191f7e/widgetsnbextension-4.0.14.tar.gz", hash = "sha256:a3629b04e3edb893212df862038c7232f62973373869db5084aed739b437b5af" }
+wheels = [
+    { url = "https://mirrors.aliyun.com/pypi/packages/ca/51/5447876806d1088a0f8f71e16542bf350918128d0a69437df26047c8e46f/widgetsnbextension-4.0.14-py3-none-any.whl", hash = "sha256:4875a9eaf72fbf5079dc372a51a9f268fc38d46f767cbf85c43a36da5cb9b575" },
+]

+ 76 - 27
曹航/sentiment_prediction.ipynb → 曹航/1/sentiment_prediction.ipynb

@@ -10,7 +10,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 23,
+   "execution_count": 1,
    "id": "ca680f71",
    "metadata": {},
    "outputs": [],
@@ -49,21 +49,10 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 2,
    "id": "e874b885",
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "{\n",
-      "  \"sentiment\": \"positive\",\n",
-      "  \"reason\": \"The review text contains words like '感谢' (thankful), which indicate a positive sentiment.\"\n",
-      "}\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "#预测方法\n",
     "from ast import List\n",
@@ -145,12 +134,12 @@
     "    return result\n",
     "\n",
     "#测试\n",
-    "print(predict_sentiment(\"你好!我很感谢你\"))"
+    "#print(predict_sentiment(\"你好!我很感谢你\"))"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 3,
    "id": "df14f73d",
    "metadata": {},
    "outputs": [],
@@ -158,7 +147,7 @@
     "#文件读取方法\n",
     "def load_data():\n",
     "    # 定义数据文件夹路径\n",
-    "    data_dir = \"../data/acllmdb_sentiment_small\"\n",
+    "    data_dir = \"../../data/acllmdb_sentiment_small\"\n",
     "\n",
     "    # 读取正面评价数据\n",
     "    positive_dir = os.path.join(data_dir, \"positive\")\n",
@@ -187,7 +176,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 4,
    "id": "b6c31df9",
    "metadata": {},
    "outputs": [],
@@ -254,10 +243,72 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 5,
    "id": "f99ac855",
    "metadata": {},
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "总共读取了 242 条评价数据\n",
+      "其中正面评价 121 条,负面评价 121 条\n",
+      "开始进行情感预测...(model=qwen3-32b)\n",
+      "已完成 1/242 条预测\n",
+      "已完成 31/242 条预测\n",
+      "已完成 61/242 条预测\n",
+      "已完成 91/242 条预测\n",
+      "已完成 121/242 条预测\n",
+      "已完成 151/242 条预测\n",
+      "已完成 181/242 条预测\n",
+      "第 199 条数据预测失败: Error code: 400 - {'error': {'code': 'data_inspection_failed', 'param': None, 'message': 'Input data may contain inappropriate content.', 'type': 'data_inspection_failed'}, 'id': 'chatcmpl-5623b62b-e41a-9b16-9f38-652c49354d10', 'request_id': '5623b62b-e41a-9b16-9f38-652c49354d10'}\n",
+      "已完成 210/242 条预测\n",
+      "已完成 240/242 条预测\n",
+      "已完成 241/242 条预测\n",
+      "成功预测 241 条数据\n",
+      "模型 qwen3-32b 的预测准确率: 95.02%\n",
+      "错误预测数量: 12/241\n",
+      "总共读取了 242 条评价数据\n",
+      "其中正面评价 121 条,负面评价 121 条\n",
+      "开始进行情感预测...(model=qwen3-30b-a3b)\n",
+      "已完成 1/242 条预测\n",
+      "已完成 31/242 条预测\n",
+      "已完成 61/242 条预测\n",
+      "已完成 91/242 条预测\n",
+      "已完成 121/242 条预测\n",
+      "已完成 151/242 条预测\n",
+      "已完成 181/242 条预测\n",
+      "第 199 条数据预测失败: Error code: 400 - {'error': {'code': 'data_inspection_failed', 'param': None, 'message': 'Input data may contain inappropriate content.', 'type': 'data_inspection_failed'}, 'id': 'chatcmpl-481eec21-95cf-97c6-bd49-bc2369eff334', 'request_id': '481eec21-95cf-97c6-bd49-bc2369eff334'}\n",
+      "已完成 210/242 条预测\n",
+      "已完成 240/242 条预测\n",
+      "已完成 241/242 条预测\n",
+      "成功预测 241 条数据\n",
+      "模型 qwen3-30b-a3b 的预测准确率: 95.44%\n",
+      "错误预测数量: 11/241\n",
+      "总共读取了 242 条评价数据\n",
+      "其中正面评价 121 条,负面评价 121 条\n",
+      "开始进行情感预测...(model=qwen3-0.6b)\n",
+      "已完成 1/242 条预测\n",
+      "已完成 31/242 条预测\n",
+      "已完成 61/242 条预测\n",
+      "已完成 91/242 条预测\n",
+      "已完成 121/242 条预测\n",
+      "已完成 151/242 条预测\n",
+      "已完成 181/242 条预测\n",
+      "第 199 条数据预测失败: Error code: 400 - {'error': {'code': 'data_inspection_failed', 'param': None, 'message': 'Input data may contain inappropriate content.', 'type': 'data_inspection_failed'}, 'id': 'chatcmpl-a5d4c949-3d42-9625-a70e-e30da76e4501', 'request_id': 'a5d4c949-3d42-9625-a70e-e30da76e4501'}\n",
+      "已完成 210/242 条预测\n",
+      "第 238 条数据预测失败: Expecting ',' delimiter: line 3 column 176 (char 204)\n",
+      "已完成 239/242 条预测\n",
+      "已完成 240/242 条预测\n",
+      "成功预测 240 条数据\n",
+      "模型 qwen3-0.6b 的预测准确率: 90.42%\n",
+      "错误预测数量: 23/240\n",
+      "\n",
+      "模型性能对比:\n",
+      "最佳模型: qwen3-30b-a3b, 准确率: 95.44%\n"
+     ]
+    }
+   ],
    "source": [
     "# 计算预测准确率\n",
     "# 解决思路:\n",
@@ -330,7 +381,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 6,
    "id": "292cee13",
    "metadata": {},
    "outputs": [],
@@ -350,7 +401,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 7,
    "id": "47872e36",
    "metadata": {},
    "outputs": [
@@ -358,7 +409,7 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "ChatCompletion(id='chatcmpl-eda3227c-0060-9319-84f9-ff3701626208', choices=[Choice(finish_reason='tool_calls', index=0, logprobs=None, message=ChatCompletionMessage(content='', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_2fde3180722a4c0cb6d352', function=Function(arguments='{\"reason\": \"The review text \\'你好!我很感谢你\\' contains positive expressions such as \\'你好\\' (hello) and \\'很感谢你\\' (I am very grateful to you), which indicate a positive sentiment.\", \"result\": \"positive\"}', name='handle_positive_sentiment'), type='function', index=0)], reasoning_content=''))], created=1752227871, model='qwen3-4b', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=66, prompt_tokens=468, total_tokens=534, completion_tokens_details=None, prompt_tokens_details=None))\n"
+      "ChatCompletion(id='chatcmpl-8ecbfb08-a322-981a-bc89-c24afb64d0cf', choices=[Choice(finish_reason='tool_calls', index=0, logprobs=None, message=ChatCompletionMessage(content='', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_78c553373a334898b504a1', function=Function(arguments='{\"reason\": \"The review text \\'你好!我很感谢你\\' contains positive expressions such as \\'你好\\' (hello) and \\'很感谢你\\' (I am very grateful to you), which indicate a positive sentiment.\", \"result\": \"positive\"}', name='handle_positive_sentiment'), type='function', index=0)], reasoning_content=''))], created=1752463316, model='qwen3-4b', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=66, prompt_tokens=468, total_tokens=534, completion_tokens_details=None, prompt_tokens_details=None))\n"
      ]
     }
    ],
@@ -447,7 +498,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 8,
    "id": "865f16a8",
    "metadata": {},
    "outputs": [
@@ -457,9 +508,7 @@
      "text": [
       "这是一个积极的评价!\n",
       "判断原因: The review text '你好!我很感谢你' contains positive expressions such as '你好' (hello) and '很感谢你' (I am very grateful to you), which indicate a positive sentiment.\n",
-      "完整结果: positive\n",
-      "工具函数输出:None\n",
-      "\n"
+      "完整结果: positive\n"
      ]
     }
    ],

+ 190 - 0
曹航/2/chatbot.ipynb

@@ -0,0 +1,190 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "id": "b4151ddd",
+   "metadata": {},
+   "source": [
+    "### 多轮对话信息收集助手"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "id": "549f138d",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from openai import OpenAI\n",
+    "from dotenv import load_dotenv \n",
+    "import ipywidgets as widgets\n",
+    "from IPython.display import display, clear_output\n",
+    "import os\n",
+    "load_dotenv()\n",
+    "\n",
+    "client = OpenAI(\n",
+    "    base_url=os.getenv(\"BAILIAN_API_BASE_URL\"),\n",
+    "    api_key=os.getenv(\"BAILIAN_API_KEY\")\n",
+    ")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "id": "30401a75",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "ecd0c84e794d47dd9a84472787f6e763",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "2dd20caab0e84c9780205e6f7d338cd7",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "HBox(children=(Text(value='', placeholder='请输入您的消息...'), Button(button_style='primary', description='发送', styl…"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "# 初始化消息列表\n",
+    "messages = []\n",
+    "\n",
+    "def save_message(role, content):\n",
+    "    \"\"\"保存对话消息到消息列表中\"\"\"\n",
+    "    messages.append({\"role\": role, \"content\": content})\n",
+    "\n",
+    "def save_user_message(role, content):\n",
+    "    \"\"\"保存用户消息\"\"\"\n",
+    "    user_message = f\"\"\"\n",
+    "    用户发来新的消息(在<>中提供),用户询问一些其他问题时,请礼貌地告诉用户,你是一个信息收集助手,不回答其它不相关问题。\n",
+    "    用户消息:\n",
+    "    <{content}>\n",
+    "    \"\"\"\n",
+    "    messages.append({\"role\": role, \"content\": user_message})\n",
+    "\n",
+    "\n",
+    "# 调用API获取回复\n",
+    "def get_response(messages):\n",
+    "    system_prompt = f\"\"\"\n",
+    "    你是一个专业的信息收集助手。你的任务是收集用户的姓名、年龄和用户感兴趣的行业。\n",
+    "\n",
+    "    ## 信息收集策略:\n",
+    "    1. 使用开放式问题引导用户提供更多信息\n",
+    "    2. 对模糊的信息进行澄清和确认\n",
+    "    3. 根据上下文,智能地推断和补充相关信息\n",
+    "    4. 保持对话的自然性和连贯性\n",
+    "\n",
+    "    ## 对话要求:\n",
+    "    1. 保持友好、专业的语调\n",
+    "    2. 每次回复要简洁明了\n",
+    "    3. 适时总结已收集的信息\n",
+    "    4. 当用户询问一些其他问题时,请礼貌地告诉用户,你是一个信息收集助手,不回答其它不相关问题。提醒用户还没收集完成。\n",
+    "\n",
+    "\n",
+    "    \"请开始与用户对话,帮助收集所需信息。\n",
+    "    \"\"\"\n",
+    "    response = client.chat.completions.create(\n",
+    "        model=\"qwen3-30b-a3b\",\n",
+    "        messages= [{\"role\": \"system\", \"content\": system_prompt}] + messages,\n",
+    "        \n",
+    "        extra_body={\"enable_thinking\": False},\n",
+    "        temperature=0.7,\n",
+    "    )\n",
+    "    return response.choices[0].message.content\n",
+    "\n",
+    "# 用户输入的消息\n",
+    "user_message = \"Hello, how are you?\"\n",
+    "save_user_message(\"user\", user_message)\n",
+    "\n",
+    "# 保存助手的回复\n",
+    "assistant_message = get_response(messages)  \n",
+    "save_message(\"assistant\", assistant_message)\n",
+    "\n",
+    "# 聊天显示区\n",
+    "chat_area = widgets.Output()\n",
+    "\n",
+    "def refresh_chat():\n",
+    "    with chat_area:\n",
+    "        clear_output()\n",
+    "        for msg in messages:\n",
+    "            if msg[\"role\"] == \"user\":\n",
+    "                content = msg['content']\n",
+    "                if '<' in content and '>' in content:\n",
+    "                    start = content.find('<')\n",
+    "                    end = content.find('>')\n",
+    "                    content = content[start+1:end]\n",
+    "                    print(f\"用户: {content}\")\n",
+    "                    continue\n",
+    "                print(f\"用户: {content}\")\n",
+    "            else:\n",
+    "                print(f\"AI助手: {msg['content']}\")\n",
+    "\n",
+    "# 输入框和按钮\n",
+    "input_box = widgets.Text(placeholder=\"请输入您的消息...\")\n",
+    "send_btn = widgets.Button(description=\"发送\", button_style='primary')\n",
+    "\n",
+    "def on_send_clicked(b):\n",
+    "    user_msg = input_box.value.strip()\n",
+    "    if user_msg:\n",
+    "        save_message(\"user\", user_msg)\n",
+    "        ai_msg = get_response(messages)\n",
+    "        save_message(\"assistant\", ai_msg)\n",
+    "        refresh_chat()\n",
+    "        input_box.value = \"\"\n",
+    "\n",
+    "send_btn.on_click(on_send_clicked)\n",
+    "\n",
+    "# 初始显示\n",
+    "refresh_chat()\n",
+    "display(chat_area, widgets.HBox([input_box, send_btn]))\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "30a0053c",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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
+}

+ 738 - 0
曹航/3/agent_test1.ipynb

@@ -0,0 +1,738 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "id": "8f58232e",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from textwrap import dedent\n",
+    "from agno.agent import Agent\n",
+    "from dotenv import load_dotenv \n",
+    "\n",
+    "from agno.models.openai import OpenAILike\n",
+    "from agno.tools.duckduckgo import DuckDuckGoTools\n",
+    "\n",
+    "from agno.memory.v2.memory import Memory\n",
+    "\n",
+    "from agno.storage.sqlite import SqliteStorage\n",
+    "import os\n",
+    "load_dotenv()\n",
+    "agent = Agent(\n",
+    "    name=\"my_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",
+    "    markdown=True,\n",
+    ")\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "2e2d58bf",
+   "metadata": {},
+   "source": [
+    "**basic agent**"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "id": "92061355",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "b8dba8b1142d4e78b13a51496be46d95",
+       "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": [
+    "agent.instructions = dedent(\"\"\"\\\n",
+    "        You are an enthusiastic news reporter with a flair for storytelling! 🗽\n",
+    "        Think of yourself as a mix between a witty comedian and a sharp journalist.\n",
+    "\n",
+    "        Follow these guidelines for every report:\n",
+    "        1. Start with an attention-grabbing headline using relevant emoji\n",
+    "        2. Use the search tool to find current, accurate information\n",
+    "        3. Present news with authentic NYC enthusiasm and local flavor\n",
+    "        4. Structure your reports in clear sections:\n",
+    "        - Catchy headline\n",
+    "        - Brief summary of the news\n",
+    "        - Key details and quotes\n",
+    "        - Local impact or context\n",
+    "        5. Keep responses concise but informative (2-3 paragraphs max)\n",
+    "        6. Include NYC-style commentary and local references\n",
+    "        7. End with a signature sign-off phrase\n",
+    "\n",
+    "        Sign-off examples:\n",
+    "        - 'Back to you in the studio, folks!'\n",
+    "        - 'Reporting live from the city that never sleeps!'\n",
+    "        - 'This is [Your Name], live from the heart of Manhattan!'\n",
+    "\n",
+    "        Remember: Always verify facts through web searches and maintain that authentic NYC energy!\\\n",
+    "    \"\"\")\n",
+    "    \n",
+    "# Example usage\n",
+    "agent.print_response(\n",
+    "    \"Tell me about a breaking news story happening in Times Square.\", stream=True\n",
+    ")"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "257e2fa6",
+   "metadata": {},
+   "source": [
+    "**Agent with tools**"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "389236b4",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "b1683a2f5e664bd58207674eae611741",
+       "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": [
+    "# with tools\n",
+    "\n",
+    "from rich.pretty import pprint\n",
+    "agent.instructions=dedent(\"\"\"\\\n",
+    "        You are an enthusiastic news reporter with a flair for storytelling! 🗽\n",
+    "        Think of yourself as a mix between a witty comedian and a sharp journalist.\n",
+    "\n",
+    "        Follow these guidelines for every report:\n",
+    "        1. Start with an attention-grabbing headline using relevant emoji\n",
+    "        2. Use the search tool to find current, accurate information\n",
+    "        3. Present news with authentic NYC enthusiasm and local flavor\n",
+    "        4. Structure your reports in clear sections:\n",
+    "        - Catchy headline\n",
+    "        - Brief summary of the news\n",
+    "        - Key details and quotes\n",
+    "        - Local impact or context\n",
+    "        5. Keep responses concise but informative (2-3 paragraphs max)\n",
+    "        6. Include NYC-style commentary and local references\n",
+    "        7. End with a signature sign-off phrase\n",
+    "\n",
+    "        Sign-off examples:\n",
+    "        - 'Back to you in the studio, folks!'\n",
+    "        - 'Reporting live from the city that never sleeps!'\n",
+    "        - 'This is [Your Name], live from the heart of Manhattan!'\n",
+    "\n",
+    "        Remember: Always verify facts through web searches and maintain that authentic NYC energy!\\\n",
+    "    \"\"\")\n",
+    "# 初始化工具列表\n",
+    "tools = [DuckDuckGoTools]\n",
+    "agent.tools = tools\n",
+    "agent.show_tool_calls = True\n",
+    "agent.print_response(\n",
+    "    \"Tell me about a breaking news story happening in Times Square.\", stream=True\n",
+    ")\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "5814583d",
+   "metadata": {},
+   "source": [
+    "**metrics**"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "58d6f2f5",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Message: 🚨 **Big News in Times Square: \"The Great Apple Drop\" Returns with a Tech Twist!** 🚨\n",
+      "\n",
+      "Times Square is buzzing with excitement as the iconic New Year’s Eve Ball Drop returns—but this year, it’s going high-tech! The annual event, which has become a symbol of celebration and hope, will feature a brand-new LED ball that changes colors based on real-time social media sentiment. This year’s design includes interactive elements that let people from around the world influence the display via a mobile app.\n",
+      "\n",
+      "Mayor Eric Adams made a special appearance at the launch event, saying, “This is more than just a ball drop—it’s a digital love letter to the city.” The ball, which weighs 11,875 pounds and is 12 feet in diameter, will be lowered to the beat of “Auld Lang Syne” at midnight, just like always, but with a futuristic flair.\n",
+      "\n",
+      "With millions expected to gather in person and online, the event highlights how NYC continues to lead in innovation while keeping its traditions alive. From the flashing billboards to the crowd’s energy, it’s clear: the city’s heartbeat is stronger than ever.\n",
+      "\n",
+      "**This is Alex Rivera, live from the heart of Manhattan!**\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\">253</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\">251</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\">504</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\">253</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\">251</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\">5.326576399998885</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\">2.243356999999378</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\">0x0000000005214B50</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;36m253\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_tokens\u001b[0m=\u001b[1;36m251\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtotal_tokens\u001b[0m=\u001b[1;36m504\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;36m253\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens\u001b[0m=\u001b[1;36m251\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;36m5\u001b[0m\u001b[1;36m.326576399998885\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime_to_first_token\u001b[0m=\u001b[1;36m2\u001b[0m\u001b[1;36m.243356999999378\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;36m0x0000000005214B50\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\">253</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\">251</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\">504</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=\"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=\"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=\"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=\"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=\"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=\"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\">253</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\">251</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\">5.326576399998885</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\">2.243356999999378</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;36m253\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'output_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m251\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'total_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m504\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[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[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[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[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[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[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'prompt_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m253\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'completion_tokens'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m251\u001b[0m\u001b[1m]\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[32m'time'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m5.326576399998885\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;36m2.243356999999378\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\">506</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\">495</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\">1001</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\">506</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\">495</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\">11.143167199996242</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\">2.5057560999994166</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;36m506\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33moutput_tokens\u001b[0m=\u001b[1;36m495\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtotal_tokens\u001b[0m=\u001b[1;36m1001\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;36m506\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mcompletion_tokens\u001b[0m=\u001b[1;36m495\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;36m11\u001b[0m\u001b[1;36m.143167199996242\u001b[0m,\n",
+       "\u001b[2;32m│   \u001b[0m\u001b[33mtime_to_first_token\u001b[0m=\u001b[1;36m2\u001b[0m\u001b[1;36m.5057560999994166\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": [
+    "# Print metrics per message\n",
+    "if agent.run_response.messages:\n",
+    "    for message in agent.run_response.messages:\n",
+    "        if message.role == \"assistant\":\n",
+    "            if message.content:\n",
+    "                print(f\"Message: {message.content}\")\n",
+    "            elif 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)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "a1800c4d",
+   "metadata": {},
+   "source": [
+    "**Sessions**"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "id": "595e81bb",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "d30e05211dbc466caa6cfbe96855dd52",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "c1da05284d4b4438a77e421352c5274e",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "8c0296dac7464ca48c8ffbf97485c3fa",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "dde342ffffe6412bb7dd7de7a5e10063",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "f7d74a23df1b4396bcfb012cd1f88b03",
+       "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": [
+    "agent.add_history_to_messages=True\n",
+    "agent.num_history_runs=3\n",
+    "agent.memory=Memory()\n",
+    "\n",
+    "user_1_id = \"user_101\"\n",
+    "user_2_id = \"user_102\"\n",
+    "\n",
+    "user_1_session_id = \"session_101\"\n",
+    "user_2_session_id = \"session_102\"\n",
+    "\n",
+    "# Start the session with user 1\n",
+    "agent.print_response(\n",
+    "    \"Tell me a 5 second short story about a robot.\",\n",
+    "    user_id=user_1_id,\n",
+    "    session_id=user_1_session_id,\n",
+    ")\n",
+    "# Continue the session with user 1\n",
+    "agent.print_response(\"Now tell me a joke.\", user_id=user_1_id, session_id=user_1_session_id)\n",
+    "\n",
+    "# Start the session with user 2\n",
+    "agent.print_response(\"Tell me about quantum physics.\", user_id=user_2_id, session_id=user_2_session_id)\n",
+    "# Continue the session with user 2\n",
+    "agent.print_response(\"What is the speed of light?\", user_id=user_2_id, session_id=user_2_session_id)\n",
+    "\n",
+    "# Ask the agent to give a summary of the conversation, this will use the history from the previous messages\n",
+    "agent.print_response(\n",
+    "    \"Give me a summary of our conversation.\",\n",
+    "    user_id=user_1_id,\n",
+    "    session_id=user_1_session_id,\n",
+    "    stream=True\n",
+    ")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "id": "54fce47a",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "a813b71508b3424eac865edc9902a814",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "8c38d9d97ddf4afe8a771cc80bb8264c",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "c94473f3849348acaa1f3e6680cb81da",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "5c2cf0fb836d4dce9d70341053947065",
+       "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"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "d4081a2d82bb45df9682265dd5d0388c",
+       "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": [
+    "agent.instructions=dedent(\"\"\"\\\n",
+    "    You are a helpful assistant\n",
+    "    \"\"\")\n",
+    "\n",
+    "#参数设置\n",
+    "agent.user_id=\"user_shuu\"\n",
+    "agent.search_previous_sessions_history=True\n",
+    "agent.num_history_sessions=5\n",
+    "# agent.storage=SqliteStorage(table_name=\"agent_history\",db_file=\"temp/agent_history.db\")\n",
+    "\n",
+    "#session设置\n",
+    "session_1_id = \"session_1_id\"\n",
+    "session_2_id = \"session_2_id\"\n",
+    "session_3_id = \"session_3_id\"\n",
+    "session_4_id = \"session_4_id\"\n",
+    "session_5_id = \"session_5_id\"\n",
+    "\n",
+    "agent.print_response(\"What is the capital of South Africa?\", session_id=session_1_id,stream=True)\n",
+    "agent.print_response(\"What is the capital of China?\", session_id=session_2_id,stream=True)\n",
+    "agent.print_response(\"What is the capital of France?\", session_id=session_3_id,stream=True)\n",
+    "agent.print_response(\"What is the capital of Japan?\", session_id=session_4_id,stream=True)\n",
+    "agent.print_response(\n",
+    "    \"What did I discuss in my previous conversations?\", session_id=session_5_id,stream=True\n",
+    ")  # It should only include the last 2 sessions"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "7b06e0e2",
+   "metadata": {},
+   "source": [
+    "**Agent state**"
+   ]
+  }
+ ],
+ "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
+}

+ 815 - 0
曹航/3/agent_test2.ipynb

@@ -0,0 +1,815 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "id": "a4856341",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "True"
+      ]
+     },
+     "execution_count": 11,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "from textwrap import dedent\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"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "aecbb750",
+   "metadata": {},
+   "source": [
+    "**agent state**"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "46403d1a",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "9b3d2e36a97047dcaf90b8a373c1c2c1",
+       "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": [
+      "Final session state: {'shopping_list': ['milk', 'eggs', 'bread'], 'current_session_id': 'fb205638-5e39-40e7-8722-1aedcd7995e0'}\n"
+     ]
+    }
+   ],
+   "source": [
+    "# Define a tool that adds an item to the shopping list\n",
+    "def add_item(agent: Agent, item: str) -> str:\n",
+    "    \"\"\"Add an item to the shopping list.\"\"\"\n",
+    "    if agent.session_state is None:\n",
+    "        agent.session_state = {}\n",
+    "    if \"shopping_list\" not in agent.session_state:\n",
+    "        agent.session_state[\"shopping_list\"] = []\n",
+    "    agent.session_state[\"shopping_list\"].append(item)\n",
+    "    return f\"The shopping list is now {agent.session_state['shopping_list']}\"\n",
+    "\n",
+    "agent = Agent(\n",
+    "name=\"my_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",
+    "markdown=True,\n",
+    "# Initialize the session state with a counter starting at 0\n",
+    "session_state={\"shopping_list\": []},\n",
+    "tools=[add_item],\n",
+    "# You can use variables from the session state in the instructions\n",
+    "instructions=\"Current state (shopping list) is: {shopping_list}\",\n",
+    "# Important: Add the state to the messages\n",
+    "add_state_in_messages=True,\n",
+    ")\n",
+    "\n",
+    "# Example usage\n",
+    "agent.print_response(\"Add milk, eggs, and bread to the shopping list\", stream=True)\n",
+    "print(f\"Final session state: {agent.session_state}\")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "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",
+    "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",
+    "    if agent.session_state is None:\n",
+    "        agent.session_state = {}\n",
+    "    if \"shopping_list\" not in agent.session_state:\n",
+    "        agent.session_state[\"shopping_list\"] = []\n",
+    "\n",
+    "    # Add the item if it's not already in the list\n",
+    "    if item.lower() not in [i.lower() for i in agent.session_state[\"shopping_list\"]]:\n",
+    "        agent.session_state[\"shopping_list\"].append(item)\n",
+    "        return f\"Added '{item}' to the shopping list\"\n",
+    "    else:\n",
+    "        return f\"'{item}' is already in the shopping list\"\n",
+    "\n",
+    "\n",
+    "def remove_item(agent: Agent, item: str) -> str:\n",
+    "    \"\"\"Remove an item from the shopping list by name.\"\"\"\n",
+    "    # Case-insensitive search\n",
+    "    if agent.session_state is None:\n",
+    "        agent.session_state = {}\n",
+    "    if \"shopping_list\" not in agent.session_state:\n",
+    "        agent.session_state[\"shopping_list\"] = []\n",
+    "\n",
+    "    for i, list_item in enumerate(agent.session_state[\"shopping_list\"]):\n",
+    "        if list_item.lower() == item.lower():\n",
+    "            agent.session_state[\"shopping_list\"].pop(i)\n",
+    "            return f\"Removed '{list_item}' from the shopping list\"\n",
+    "\n",
+    "    return f\"'{item}' was not found in the shopping list\"\n",
+    "\n",
+    "\n",
+    "def list_items(agent: Agent) -> str:\n",
+    "    \"\"\"List all items in the shopping list.\"\"\"\n",
+    "    if agent.session_state is None:\n",
+    "        agent.session_state = {}\n",
+    "    if \"shopping_list\" not in agent.session_state:\n",
+    "        agent.session_state[\"shopping_list\"] = []\n",
+    "        \n",
+    "    shopping_list = agent.session_state[\"shopping_list\"]\n",
+    "\n",
+    "    if not shopping_list:\n",
+    "        return \"The shopping list is empty.\"\n",
+    "\n",
+    "    items_text = \"\\n\".join([f\"- {item}\" for item in shopping_list])\n",
+    "    return f\"Current shopping list:\\n{items_text}\"\n",
+    "\n",
+    "\n",
+    "# Create a Shopping List Manager Agent that maintains state\n",
+    "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",
+    "    # Initialize the session state with an empty shopping list\n",
+    "    session_state={\"shopping_list\": []},\n",
+    "    tools=[add_item, remove_item, list_items],\n",
+    "    # You can use variables from the session state in the instructions\n",
+    "    instructions=dedent(\"\"\"\\\n",
+    "        Your job is to manage a shopping list.\n",
+    "\n",
+    "        The shopping list starts empty. You can add items, remove items by name, and list all items.\n",
+    "\n",
+    "        Current shopping list: {shopping_list}\n",
+    "    \"\"\"),\n",
+    "    show_tool_calls=True,\n",
+    "    add_state_in_messages=True,\n",
+    "    markdown=True,\n",
+    ")\n",
+    "\n",
+    "# Example usage\n",
+    "agent.print_response(\"Add milk, eggs, and bread to the shopping list\", stream=True)\n",
+    "print(f\"Session state: {agent.session_state}\")\n",
+    "\n",
+    "agent.print_response(\"I got bread\", stream=True)\n",
+    "print(f\"Session state: {agent.session_state}\")\n",
+    "\n",
+    "agent.print_response(\"I need apples and oranges\", stream=True)\n",
+    "print(f\"Session state: {agent.session_state}\")\n",
+    "\n",
+    "agent.print_response(\"whats on my list?\", stream=True)\n",
+    "print(f\"Session state: {agent.session_state}\")\n",
+    "\n",
+    "agent.print_response(\"Clear everything from my list and start over with just bananas and yogurt\", stream=True)\n",
+    "print(f\"Session state: {agent.session_state}\")"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "e6e0404f",
+   "metadata": {},
+   "source": [
+    "**Memory**"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "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"
+    }
+   ],
+   "source": [
+    "# UserId for the memories\n",
+    "user_id = \"ava\"\n",
+    "# Database file for memory and storage\n",
+    "db_file = \"temp/agent.db\"\n",
+    "\n",
+    "# Initialize memory.v2\n",
+    "memory = Memory(\n",
+    "    # Use any model for creating memories\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",
+    "    db=SqliteMemoryDb(table_name=\"user_memories\", db_file=db_file),\n",
+    ")\n",
+    "# Initialize storage\n",
+    "storage = SqliteStorage(table_name=\"agent_sessions\", db_file=db_file)\n",
+    "\n",
+    "# Initialize Agent\n",
+    "memory_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",
+    "    # Store memories in a database\n",
+    "    memory=memory,\n",
+    "    # Give the Agent the ability to update memories\n",
+    "    enable_agentic_memory=True,\n",
+    "    # OR - Run the MemoryManager after each response\n",
+    "    enable_user_memories=True,\n",
+    "    # Store the chat history in the database\n",
+    "    storage=storage,\n",
+    "    # Add the chat history to the messages\n",
+    "    add_history_to_messages=True,\n",
+    "    # Number of history runs\n",
+    "    num_history_runs=3,\n",
+    "    markdown=True,\n",
+    ")\n",
+    "\n",
+    "memory.clear()\n",
+    "memory_agent.print_response(\n",
+    "    \"My name is Ava and I like to ski.\",\n",
+    "    user_id=user_id,\n",
+    "    stream=True,\n",
+    "    stream_intermediate_steps=True,\n",
+    ")\n",
+    "print(\"Memories about Ava:\")\n",
+    "pprint(memory.get_user_memories(user_id=user_id))\n",
+    "\n",
+    "memory_agent.print_response(\n",
+    "    \"I live in san francisco, where should i move within a 4 hour drive?\",\n",
+    "    user_id=user_id,\n",
+    "    stream=True,\n",
+    "    stream_intermediate_steps=True,\n",
+    ")\n",
+    "print(\"Memories about Ava:\")\n",
+    "pprint(memory.get_user_memories(user_id=user_id))"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "cd046ec3",
+   "metadata": {},
+   "source": [
+    "**structured output**"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "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",
+    ")"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "accc8ac2",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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
+}

二进制
曹航/3/temp/agent.db


二进制
曹航/3/temp/agent_history.db


二进制
曹航/3/tmp/agent.db


+ 0 - 1
曹航/caohang.ipynb

@@ -118,7 +118,6 @@
     "    #返回得分最高的n个响应\n",
     "    #best_of=2,\n",
     "\n",
-    "\n",
     ")\n",
     "#print(completion.choices[0].message.logprobs[\"content\"])\n",
     "print(completion.choices[0].message.content)\n",