agentica 0.2.2__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. {agentica-0.2.2 → agentica-0.2.5}/PKG-INFO +95 -14
  2. agentica-0.2.2/agentica.egg-info/PKG-INFO → agentica-0.2.5/README.md +78 -42
  3. {agentica-0.2.2 → agentica-0.2.5}/agentica/__init__.py +26 -7
  4. {agentica-0.2.2 → agentica-0.2.5}/agentica/agent.py +26 -47
  5. agentica-0.2.5/agentica/cli.py +151 -0
  6. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/azure_openai_emb.py +4 -3
  7. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/base.py +3 -5
  8. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/fireworks_emb.py +2 -0
  9. agentica-0.2.5/agentica/emb/genimi_emb.py +88 -0
  10. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/hash_emb.py +2 -0
  11. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/huggingface_emb.py +9 -8
  12. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/ollama_emb.py +2 -0
  13. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/openai_emb.py +4 -1
  14. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/sentence_transformer_emb.py +2 -0
  15. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/text2vec_emb.py +2 -0
  16. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/together_emb.py +2 -0
  17. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/word2vec_emb.py +7 -5
  18. agentica-0.2.5/agentica/emb/zhipuai_emb.py +17 -0
  19. {agentica-0.2.2 → agentica-0.2.5}/agentica/file/base.py +5 -4
  20. {agentica-0.2.2 → agentica-0.2.5}/agentica/file/csv.py +4 -2
  21. {agentica-0.2.2 → agentica-0.2.5}/agentica/file/txt.py +4 -2
  22. agentica-0.2.5/agentica/media.py +257 -0
  23. agentica-0.2.5/agentica/model/cohere/__init__.py +1 -0
  24. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/cohere/chat.py +1 -1
  25. agentica-0.2.5/agentica/model/deepseek/__init__.py +1 -0
  26. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/deepseek/chat.py +2 -2
  27. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/doubao/chat.py +3 -3
  28. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/fireworks/fireworks.py +0 -17
  29. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/message.py +43 -6
  30. agentica-0.2.5/agentica/model/moonshot/__init__.py +1 -0
  31. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/moonshot/chat.py +2 -2
  32. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/nvidia/chat.py +1 -1
  33. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/openai/chat.py +18 -2
  34. agentica-0.2.5/agentica/model/qwen/chat.py +24 -0
  35. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/response.py +2 -0
  36. agentica-0.2.5/agentica/model/together/__init__.py +1 -0
  37. agentica-0.2.2/agentica/model/together/togetherchat.py → agentica-0.2.5/agentica/model/together/together.py +1 -1
  38. agentica-0.2.5/agentica/model/xai/__init__.py +1 -0
  39. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/xai/grok.py +2 -2
  40. agentica-0.2.5/agentica/model/yi/__init__.py +1 -0
  41. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/yi/chat.py +2 -2
  42. agentica-0.2.5/agentica/model/zhipuai/__init__.py +1 -0
  43. agentica-0.2.5/agentica/model/zhipuai/chat.py +24 -0
  44. {agentica-0.2.2 → agentica-0.2.5}/agentica/python_agent.py +5 -0
  45. agentica-0.2.5/agentica/react_agent.py +195 -0
  46. agentica-0.2.5/agentica/storage/__init__.py +0 -0
  47. agentica-0.2.5/agentica/tools/__init__.py +0 -0
  48. agentica-0.2.5/agentica/tools/cogvideo_tool.py +153 -0
  49. agentica-0.2.5/agentica/tools/cogview_tool.py +127 -0
  50. agentica-0.2.2/agentica/tools/create_image_tool.py → agentica-0.2.5/agentica/tools/dalle_tool.py +5 -5
  51. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/jina_tool.py +1 -9
  52. agentica-0.2.5/agentica/tools/string_tool.py +61 -0
  53. agentica-0.2.5/agentica/tools/weather_tool.py +46 -0
  54. agentica-0.2.5/agentica/tools/web_search_pro_tool.py +81 -0
  55. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/log.py +19 -0
  56. agentica-0.2.5/agentica/utils/message.py +43 -0
  57. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/misc.py +11 -42
  58. agentica-0.2.5/agentica/utils/string.py +73 -0
  59. agentica-0.2.5/agentica/version.py +1 -0
  60. agentica-0.2.2/README.md → agentica-0.2.5/agentica.egg-info/PKG-INFO +123 -11
  61. {agentica-0.2.2 → agentica-0.2.5}/agentica.egg-info/SOURCES.txt +17 -2
  62. {agentica-0.2.2 → agentica-0.2.5}/agentica.egg-info/requires.txt +4 -1
  63. {agentica-0.2.2 → agentica-0.2.5}/setup.py +4 -1
  64. agentica-0.2.2/agentica/emb/genimi_emb.py +0 -60
  65. agentica-0.2.2/agentica/model/cohere/__init__.py +0 -1
  66. agentica-0.2.2/agentica/model/deepseek/__init__.py +0 -1
  67. agentica-0.2.2/agentica/model/doubao/__init__.py +0 -1
  68. agentica-0.2.2/agentica/model/moonshot/__init__.py +0 -1
  69. agentica-0.2.2/agentica/model/together/__init__.py +0 -1
  70. agentica-0.2.2/agentica/model/xai/__init__.py +0 -1
  71. agentica-0.2.2/agentica/model/yi/__init__.py +0 -1
  72. agentica-0.2.2/agentica/version.py +0 -1
  73. {agentica-0.2.2 → agentica-0.2.5}/LICENSE +0 -0
  74. {agentica-0.2.2 → agentica-0.2.5}/MANIFEST.in +0 -0
  75. {agentica-0.2.2 → agentica-0.2.5}/agentica/agent_session.py +0 -0
  76. {agentica-0.2.2 → agentica-0.2.5}/agentica/config.py +0 -0
  77. {agentica-0.2.2 → agentica-0.2.5}/agentica/document.py +0 -0
  78. {agentica-0.2.2 → agentica-0.2.5}/agentica/emb/__init__.py +0 -0
  79. {agentica-0.2.2 → agentica-0.2.5}/agentica/file/__init__.py +0 -0
  80. {agentica-0.2.2 → agentica-0.2.5}/agentica/knowledge/__init__.py +0 -0
  81. {agentica-0.2.2 → agentica-0.2.5}/agentica/knowledge/base.py +0 -0
  82. {agentica-0.2.2 → agentica-0.2.5}/agentica/knowledge/langchain_knowledge.py +0 -0
  83. {agentica-0.2.2 → agentica-0.2.5}/agentica/knowledge/llamaindex_knowledge.py +0 -0
  84. {agentica-0.2.2 → agentica-0.2.5}/agentica/memory.py +0 -0
  85. {agentica-0.2.2 → agentica-0.2.5}/agentica/memorydb.py +0 -0
  86. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/__init__.py +0 -0
  87. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/anthropic/__init__.py +0 -0
  88. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/anthropic/claude.py +0 -0
  89. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/aws/__init__.py +0 -0
  90. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/aws/api_client.py +0 -0
  91. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/aws/bedrock.py +0 -0
  92. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/aws/claude.py +0 -0
  93. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/azure/__init__.py +0 -0
  94. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/azure/openai_chat.py +0 -0
  95. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/base.py +0 -0
  96. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/content.py +0 -0
  97. {agentica-0.2.2/agentica/reranker → agentica-0.2.5/agentica/model/doubao}/__init__.py +0 -0
  98. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/fireworks/__init__.py +0 -0
  99. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/google/__init__.py +0 -0
  100. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/google/gemini.py +0 -0
  101. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/google/gemini_openai.py +0 -0
  102. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/groq/__init__.py +0 -0
  103. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/groq/groq.py +0 -0
  104. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/huggingface/__init__.py +0 -0
  105. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/huggingface/hf.py +0 -0
  106. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/internlm/__init__.py +0 -0
  107. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/internlm/chat.py +0 -0
  108. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/mistral/__init__.py +0 -0
  109. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/mistral/mistral.py +0 -0
  110. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/nvidia/__init__.py +0 -0
  111. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/ollama/__init__.py +0 -0
  112. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/ollama/chat.py +0 -0
  113. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/ollama/hermes.py +0 -0
  114. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/ollama/tools.py +0 -0
  115. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/openai/__init__.py +0 -0
  116. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/openai/like.py +0 -0
  117. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/openrouter/__init__.py +0 -0
  118. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/openrouter/openrouter.py +0 -0
  119. {agentica-0.2.2/agentica/storage → agentica-0.2.5/agentica/model/qwen}/__init__.py +0 -0
  120. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/sambanova/__init__.py +0 -0
  121. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/sambanova/sambanova.py +0 -0
  122. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/vertexai/__init__.py +0 -0
  123. {agentica-0.2.2 → agentica-0.2.5}/agentica/model/vertexai/gemini.py +0 -0
  124. {agentica-0.2.2 → agentica-0.2.5}/agentica/reasoning.py +0 -0
  125. {agentica-0.2.2/agentica/tools → agentica-0.2.5/agentica/reranker}/__init__.py +0 -0
  126. {agentica-0.2.2 → agentica-0.2.5}/agentica/reranker/base.py +0 -0
  127. {agentica-0.2.2 → agentica-0.2.5}/agentica/reranker/bge.py +0 -0
  128. {agentica-0.2.2 → agentica-0.2.5}/agentica/reranker/cohere.py +0 -0
  129. {agentica-0.2.2 → agentica-0.2.5}/agentica/run_response.py +0 -0
  130. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/agent/__init__.py +0 -0
  131. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/agent/base.py +0 -0
  132. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/agent/json_file.py +0 -0
  133. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/agent/postgres.py +0 -0
  134. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/agent/sqlite.py +0 -0
  135. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/agent/yaml_file.py +0 -0
  136. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/workflow/__init__.py +0 -0
  137. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/workflow/base.py +0 -0
  138. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/workflow/postgres.py +0 -0
  139. {agentica-0.2.2 → agentica-0.2.5}/agentica/storage/workflow/sqlite.py +0 -0
  140. {agentica-0.2.2 → agentica-0.2.5}/agentica/template.py +0 -0
  141. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/airflow_tool.py +0 -0
  142. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/analyze_image_tool.py +0 -0
  143. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/apify_tool.py +0 -0
  144. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/arxiv_tool.py +0 -0
  145. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/baidusearch_tool.py +0 -0
  146. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/base.py +0 -0
  147. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/calculator_tool.py +0 -0
  148. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/dblp_tool.py +0 -0
  149. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/duckduckgo_tool.py +0 -0
  150. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/file_tool.py +0 -0
  151. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/hackernews_tool.py +0 -0
  152. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/newspaper_tool.py +0 -0
  153. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/ocr_tool.py +0 -0
  154. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/resend_tools.py +0 -0
  155. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/run_nb_code_tool.py +0 -0
  156. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/run_python_code_tool.py +0 -0
  157. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/search_exa_tool.py +0 -0
  158. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/search_serper_tool.py +0 -0
  159. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/shell_tool.py +0 -0
  160. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/sql_tool.py +0 -0
  161. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/text_analysis_tool.py +0 -0
  162. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/url_crawler_tool.py +0 -0
  163. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/wikipedia_tool.py +0 -0
  164. {agentica-0.2.2 → agentica-0.2.5}/agentica/tools/yfinance_tool.py +0 -0
  165. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/__init__.py +0 -0
  166. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/console.py +0 -0
  167. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/file_parser.py +0 -0
  168. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/io.py +0 -0
  169. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/json_util.py +0 -0
  170. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/shell.py +0 -0
  171. {agentica-0.2.2 → agentica-0.2.5}/agentica/utils/timer.py +0 -0
  172. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/__init__.py +0 -0
  173. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/base.py +0 -0
  174. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/chromadb_vectordb.py +0 -0
  175. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/lancedb_vectordb.py +0 -0
  176. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/memory_vectordb.py +0 -0
  177. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/pgvectordb.py +0 -0
  178. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/pineconedb.py +0 -0
  179. {agentica-0.2.2 → agentica-0.2.5}/agentica/vectordb/qdrantdb.py +0 -0
  180. {agentica-0.2.2 → agentica-0.2.5}/agentica/workflow.py +0 -0
  181. {agentica-0.2.2 → agentica-0.2.5}/agentica/workflow_session.py +0 -0
  182. {agentica-0.2.2 → agentica-0.2.5}/agentica.egg-info/dependency_links.txt +0 -0
  183. {agentica-0.2.2 → agentica-0.2.5}/agentica.egg-info/entry_points.txt +0 -0
  184. {agentica-0.2.2 → agentica-0.2.5}/agentica.egg-info/not-zip-safe +0 -0
  185. {agentica-0.2.2 → agentica-0.2.5}/agentica.egg-info/top_level.txt +0 -0
  186. {agentica-0.2.2 → agentica-0.2.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: agentica
3
- Version: 0.2.2
3
+ Version: 0.2.5
4
4
  Summary: LLM agents
5
5
  Home-page: https://github.com/shibing624/agentica
6
6
  Author: XuMing
@@ -18,16 +18,30 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
18
  Requires-Python: >=3.8.0
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
+ Requires-Dist: httpx
21
22
  Requires-Dist: loguru
22
- Requires-Dist: markdownify
23
+ Requires-Dist: beautifulsoup4
23
24
  Requires-Dist: openai
24
25
  Requires-Dist: python-dotenv
25
26
  Requires-Dist: pydantic
26
27
  Requires-Dist: requests
27
28
  Requires-Dist: sqlalchemy
28
29
  Requires-Dist: scikit-learn
30
+ Requires-Dist: markdownify
29
31
  Requires-Dist: tqdm
30
32
  Requires-Dist: rich
33
+ Requires-Dist: pyyaml
34
+ Dynamic: author
35
+ Dynamic: author-email
36
+ Dynamic: classifier
37
+ Dynamic: description
38
+ Dynamic: description-content-type
39
+ Dynamic: home-page
40
+ Dynamic: keywords
41
+ Dynamic: license
42
+ Dynamic: requires-dist
43
+ Dynamic: requires-python
44
+ Dynamic: summary
31
45
 
32
46
  [**🇨🇳中文**](https://github.com/shibing624/agentica/blob/main/README.md) | [**🌐English**](https://github.com/shibing624/agentica/blob/main/README_EN.md) | [**🇯🇵日本語**](https://github.com/shibing624/agentica/blob/main/README_JP.md)
33
47
 
@@ -49,14 +63,11 @@ Requires-Dist: rich
49
63
  [![Wechat Group](https://img.shields.io/badge/wechat-group-green.svg?logo=wechat)](#Contact)
50
64
 
51
65
 
52
- **Agentica**: Build Smarter, Reflective, and Collaborative AI Agents with Ease!
66
+ **Agentica**: 轻松构建智能、具备反思能力、可协作的多模态AI Agent。
53
67
 
54
- **Agentica**: 快速打造智能、能反思、协作的AI Agent。
55
68
 
56
69
  ## 📖 Introduction
57
70
 
58
- **Agentica** can build AI agent, which have the components of planning, memory, and tool use.
59
-
60
71
  **Agentica** 可以构建AI Agent,包括规划、记忆和工具使用、执行等组件。
61
72
 
62
73
  #### Agent Components
@@ -79,6 +90,8 @@ Requires-Dist: rich
79
90
  - **Solver**:求解器将所有这些输出整合为最终答案
80
91
 
81
92
  ## 🔥 News
93
+ [2024/12/29] v0.2.3版本: 支持了`ZhipuAI`的api调用,包括免费模型和工具使用,详见[Release-v0.2.3](https://github.com/shibing624/agentica/releases/tag/0.2.3)
94
+
82
95
  [2024/12/25] v0.2.0版本: 支持了多模态模型,输入可以是文本、图片、音频、视频,升级Assistant为Agent,Workflow支持拆解并实现复杂任务,详见[Release-v0.2.0](https://github.com/shibing624/agentica/releases/tag/0.2.0)
83
96
 
84
97
  [2024/07/02] v0.1.0版本:实现了基于LLM的Assistant,可以快速用function call搭建大语言模型助手,详见[Release-v0.1.0](https://github.com/shibing624/agentica/releases/tag/0.1.0)
@@ -89,7 +102,7 @@ Requires-Dist: rich
89
102
 
90
103
  - **Agent编排**:通过简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Team、Workflow等功能
91
104
  - **自定义prompt**:Agent支持自定义prompt和多种工具调用(tool_calls)
92
- - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、Claude、Ollama、Together等多方大模型厂商的API
105
+ - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、AnthropicZhipuAI、Ollama、Together等多方大模型厂商的API
93
106
  - **记忆功能**:包括短期记忆和长期记忆功能
94
107
  - **Multi-Agent协作**:支持多Agent和任务委托(Team)的团队协作。
95
108
  - **Workflow工作流**:拆解复杂任务为多个Agent,基于工作流自动化串行逐步完成任务,如投资研究、新闻文章撰写和技术教程创建
@@ -118,10 +131,10 @@ pip install .
118
131
  cp .env.example ~/.agentica/.env
119
132
 
120
133
  cd examples
121
- python web_search_moonshot_demo.py
134
+ python 12_web_search_moonshot_demo.py
122
135
  ```
123
136
 
124
- 1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
137
+ 1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY、ZHIPUAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
125
138
 
126
139
  ```shell
127
140
  export MOONSHOT_API_KEY=your_moonshot_api_key
@@ -133,13 +146,23 @@ python web_search_moonshot_demo.py
133
146
  自动调用google搜索工具,示例[examples/12_web_search_moonshot_demo.py](https://github.com/shibing624/agentica/blob/main/examples/12_web_search_moonshot_demo.py)
134
147
 
135
148
  ```python
136
- from agentica import Agent, MoonshotChat, SearchSerperTool
149
+ from agentica import Agent, Moonshot, WeatherTool
137
150
 
138
- m = Agent(model=MoonshotChat(), tools=[SearchSerperTool()], add_datetime_to_instructions=True)
139
- r = m.run("下一届奥运会在哪里举办")
140
- print(r)
151
+ m = Agent(model=Moonshot(), tools=[WeatherTool()], add_datetime_to_instructions=True)
152
+ m.print_response("明天北京天气咋样")
141
153
  ```
142
154
 
155
+ output:
156
+ ```markdown
157
+ 明天北京的天气预报如下:
158
+
159
+ - 早晨:晴朗,气温约18°C,风速较小,约为3 km/h。
160
+ - 中午:晴朗,气温升至23°C,风速6-7 km/h。
161
+ - 傍晚:晴朗,气温略降至21°C,风速较大,为35-44 km/h。
162
+ - 夜晚:晴朗转晴,气温下降至15°C,风速32-39 km/h。
163
+
164
+ 全天无降水,能见度良好。请注意傍晚时分的风速较大,外出时需注意安全。
165
+ ```
143
166
 
144
167
  ## ▶️ Web UI
145
168
 
@@ -204,6 +227,7 @@ bash start.sh
204
227
  | [examples/37_workflow_write_novel_demo.py](https://github.com/shibing624/agentica/blob/main/examples/37_workflow_write_novel_demo.py) | 实现了写小说的工作流:定小说提纲 - 搜索谷歌反思提纲 - 撰写小说内容 - 保存为md文件 |
205
228
  | [examples/38_workflow_write_tutorial_demo.py](https://github.com/shibing624/agentica/blob/main/examples/38_workflow_write_tutorial_demo.py) | 实现了写技术教程的工作流:定教程目录 - 反思目录内容 - 撰写教程内容 - 保存为md文件 |
206
229
  | [examples/39_audio_multi_turn_demo.py](https://github.com/shibing624/agentica/blob/main/examples/39_audio_multi_turn_demo.py) | 基于openai的语音api做多轮音频对话的Demo |
230
+ | [examples/40_weather_zhipuai_demo.py](https://github.com/shibing624/agentica/blob/main/examples/40_web_search_zhipuai_demo.py) | 基于智谱AI的api做天气查询的Demo |
207
231
 
208
232
 
209
233
  ### Self-evolving Agent
@@ -244,6 +268,63 @@ streamlit run 34_llm_os_demo.py
244
268
 
245
269
  <img alt="LLM OS" src="https://github.com/shibing624/agentica/blob/main/docs/llm_os_snap.png" width="800" />
246
270
 
271
+
272
+ ### 命令行模式(CLI)
273
+
274
+ 支持终端命令行快速搭建并体验Agent
275
+
276
+ code: [cli.py](https://github.com/shibing624/agentica/blob/main/agentica/cli.py)
277
+
278
+ ```
279
+ > agentica -h
280
+ usage: cli.py [-h] [--query QUERY]
281
+ [--model_provider {openai,azure,moonshot,zhipuai,deepseek,yi}]
282
+ [--model_name MODEL_NAME] [--api_base API_BASE]
283
+ [--api_key API_KEY] [--max_tokens MAX_TOKENS]
284
+ [--temperature TEMPERATURE] [--verbose VERBOSE]
285
+ [--tools [{search_serper,file_tool,shell_tool,yfinance_tool,web_search_pro,cogview,cogvideo,jina,wikipedia} ...]]
286
+
287
+ CLI for agentica
288
+
289
+ options:
290
+ -h, --help show this help message and exit
291
+ --query QUERY Question to ask the LLM
292
+ --model_provider {openai,azure,moonshot,zhipuai,deepseek,yi}
293
+ LLM model provider
294
+ --model_name MODEL_NAME
295
+ LLM model name to use, can be
296
+ gpt-4o/glm-4-flash/deepseek-chat/yi-lightning/...
297
+ --api_base API_BASE API base URL for the LLM
298
+ --api_key API_KEY API key for the LLM
299
+ --max_tokens MAX_TOKENS
300
+ Maximum number of tokens for the LLM
301
+ --temperature TEMPERATURE
302
+ Temperature for the LLM
303
+ --verbose VERBOSE enable verbose mode
304
+ --tools [{search_serper,file_tool,shell_tool,yfinance_tool,web_search_pro,cogview,cogvideo,jina,wikipedia} ...]
305
+ Tools to enable
306
+ ```
307
+
308
+ run:
309
+
310
+ ```shell
311
+ pip install agentica -U
312
+ # 单次调用,填入`--query`参数
313
+ agentica --query "下一届奥运会在哪里举办" --model_provider zhipuai --model_name glm-4-flash --tools web_search_pro
314
+ # 多次调用,多轮对话,不填`--query`参数
315
+ agentica --model_provider zhipuai --model_name glm-4-flash --tools web_search_pro cogview --verbose 1
316
+ ```
317
+
318
+ output:
319
+ ```shell
320
+ 2024-12-30 21:59:15,000 - agentica - INFO - Agentica CLI
321
+ >>> 帮我画个大象在月球上的图
322
+
323
+ > 我帮你画了一张大象在月球上的图,它看起来既滑稽又可爱。大象穿着宇航服,站在月球表面,背景是广阔的星空和地球。这张图色彩明亮,细节丰富,具有卡通风格。你可以点击下面的链接查看和下载这张图片:
324
+
325
+ ![大象在月球上的图](https://aigc-files.bigmodel.cn/api/cogview/20241230215915cfa22f46425e4cb0_0.png)
326
+ ```
327
+
247
328
  ## ☎️ Contact
248
329
 
249
330
  - Issue(建议)
@@ -1,34 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: agentica
3
- Version: 0.2.2
4
- Summary: LLM agents
5
- Home-page: https://github.com/shibing624/agentica
6
- Author: XuMing
7
- Author-email: xuming624@qq.com
8
- License: Apache License 2.0
9
- Keywords: Agentica,Agent Tool,action,agent,agentica
10
- Classifier: Development Status :: 5 - Production/Stable
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Intended Audience :: Education
13
- Classifier: Intended Audience :: Science/Research
14
- Classifier: License :: OSI Approved :: Apache Software License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3
17
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
- Requires-Python: >=3.8.0
19
- Description-Content-Type: text/markdown
20
- License-File: LICENSE
21
- Requires-Dist: loguru
22
- Requires-Dist: markdownify
23
- Requires-Dist: openai
24
- Requires-Dist: python-dotenv
25
- Requires-Dist: pydantic
26
- Requires-Dist: requests
27
- Requires-Dist: sqlalchemy
28
- Requires-Dist: scikit-learn
29
- Requires-Dist: tqdm
30
- Requires-Dist: rich
31
-
32
1
  [**🇨🇳中文**](https://github.com/shibing624/agentica/blob/main/README.md) | [**🌐English**](https://github.com/shibing624/agentica/blob/main/README_EN.md) | [**🇯🇵日本語**](https://github.com/shibing624/agentica/blob/main/README_JP.md)
33
2
 
34
3
  <div align="center">
@@ -49,14 +18,11 @@ Requires-Dist: rich
49
18
  [![Wechat Group](https://img.shields.io/badge/wechat-group-green.svg?logo=wechat)](#Contact)
50
19
 
51
20
 
52
- **Agentica**: Build Smarter, Reflective, and Collaborative AI Agents with Ease!
21
+ **Agentica**: 轻松构建智能、具备反思能力、可协作的多模态AI Agent。
53
22
 
54
- **Agentica**: 快速打造智能、能反思、协作的AI Agent。
55
23
 
56
24
  ## 📖 Introduction
57
25
 
58
- **Agentica** can build AI agent, which have the components of planning, memory, and tool use.
59
-
60
26
  **Agentica** 可以构建AI Agent,包括规划、记忆和工具使用、执行等组件。
61
27
 
62
28
  #### Agent Components
@@ -79,6 +45,8 @@ Requires-Dist: rich
79
45
  - **Solver**:求解器将所有这些输出整合为最终答案
80
46
 
81
47
  ## 🔥 News
48
+ [2024/12/29] v0.2.3版本: 支持了`ZhipuAI`的api调用,包括免费模型和工具使用,详见[Release-v0.2.3](https://github.com/shibing624/agentica/releases/tag/0.2.3)
49
+
82
50
  [2024/12/25] v0.2.0版本: 支持了多模态模型,输入可以是文本、图片、音频、视频,升级Assistant为Agent,Workflow支持拆解并实现复杂任务,详见[Release-v0.2.0](https://github.com/shibing624/agentica/releases/tag/0.2.0)
83
51
 
84
52
  [2024/07/02] v0.1.0版本:实现了基于LLM的Assistant,可以快速用function call搭建大语言模型助手,详见[Release-v0.1.0](https://github.com/shibing624/agentica/releases/tag/0.1.0)
@@ -89,7 +57,7 @@ Requires-Dist: rich
89
57
 
90
58
  - **Agent编排**:通过简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Team、Workflow等功能
91
59
  - **自定义prompt**:Agent支持自定义prompt和多种工具调用(tool_calls)
92
- - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、Claude、Ollama、Together等多方大模型厂商的API
60
+ - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、AnthropicZhipuAI、Ollama、Together等多方大模型厂商的API
93
61
  - **记忆功能**:包括短期记忆和长期记忆功能
94
62
  - **Multi-Agent协作**:支持多Agent和任务委托(Team)的团队协作。
95
63
  - **Workflow工作流**:拆解复杂任务为多个Agent,基于工作流自动化串行逐步完成任务,如投资研究、新闻文章撰写和技术教程创建
@@ -118,10 +86,10 @@ pip install .
118
86
  cp .env.example ~/.agentica/.env
119
87
 
120
88
  cd examples
121
- python web_search_moonshot_demo.py
89
+ python 12_web_search_moonshot_demo.py
122
90
  ```
123
91
 
124
- 1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
92
+ 1. 复制[.env.example](https://github.com/shibing624/agentica/blob/main/.env.example)文件为`~/.agentica/.env`,并填写LLM api key(选填DEEPSEEK_API_KEY、MOONSHOT_API_KEY、OPENAI_API_KEY、ZHIPUAI_API_KEY等任一个即可)。或者使用`export`命令设置环境变量:
125
93
 
126
94
  ```shell
127
95
  export MOONSHOT_API_KEY=your_moonshot_api_key
@@ -133,13 +101,23 @@ python web_search_moonshot_demo.py
133
101
  自动调用google搜索工具,示例[examples/12_web_search_moonshot_demo.py](https://github.com/shibing624/agentica/blob/main/examples/12_web_search_moonshot_demo.py)
134
102
 
135
103
  ```python
136
- from agentica import Agent, MoonshotChat, SearchSerperTool
104
+ from agentica import Agent, Moonshot, WeatherTool
137
105
 
138
- m = Agent(model=MoonshotChat(), tools=[SearchSerperTool()], add_datetime_to_instructions=True)
139
- r = m.run("下一届奥运会在哪里举办")
140
- print(r)
106
+ m = Agent(model=Moonshot(), tools=[WeatherTool()], add_datetime_to_instructions=True)
107
+ m.print_response("明天北京天气咋样")
141
108
  ```
142
109
 
110
+ output:
111
+ ```markdown
112
+ 明天北京的天气预报如下:
113
+
114
+ - 早晨:晴朗,气温约18°C,风速较小,约为3 km/h。
115
+ - 中午:晴朗,气温升至23°C,风速6-7 km/h。
116
+ - 傍晚:晴朗,气温略降至21°C,风速较大,为35-44 km/h。
117
+ - 夜晚:晴朗转晴,气温下降至15°C,风速32-39 km/h。
118
+
119
+ 全天无降水,能见度良好。请注意傍晚时分的风速较大,外出时需注意安全。
120
+ ```
143
121
 
144
122
  ## ▶️ Web UI
145
123
 
@@ -204,6 +182,7 @@ bash start.sh
204
182
  | [examples/37_workflow_write_novel_demo.py](https://github.com/shibing624/agentica/blob/main/examples/37_workflow_write_novel_demo.py) | 实现了写小说的工作流:定小说提纲 - 搜索谷歌反思提纲 - 撰写小说内容 - 保存为md文件 |
205
183
  | [examples/38_workflow_write_tutorial_demo.py](https://github.com/shibing624/agentica/blob/main/examples/38_workflow_write_tutorial_demo.py) | 实现了写技术教程的工作流:定教程目录 - 反思目录内容 - 撰写教程内容 - 保存为md文件 |
206
184
  | [examples/39_audio_multi_turn_demo.py](https://github.com/shibing624/agentica/blob/main/examples/39_audio_multi_turn_demo.py) | 基于openai的语音api做多轮音频对话的Demo |
185
+ | [examples/40_weather_zhipuai_demo.py](https://github.com/shibing624/agentica/blob/main/examples/40_web_search_zhipuai_demo.py) | 基于智谱AI的api做天气查询的Demo |
207
186
 
208
187
 
209
188
  ### Self-evolving Agent
@@ -244,6 +223,63 @@ streamlit run 34_llm_os_demo.py
244
223
 
245
224
  <img alt="LLM OS" src="https://github.com/shibing624/agentica/blob/main/docs/llm_os_snap.png" width="800" />
246
225
 
226
+
227
+ ### 命令行模式(CLI)
228
+
229
+ 支持终端命令行快速搭建并体验Agent
230
+
231
+ code: [cli.py](https://github.com/shibing624/agentica/blob/main/agentica/cli.py)
232
+
233
+ ```
234
+ > agentica -h
235
+ usage: cli.py [-h] [--query QUERY]
236
+ [--model_provider {openai,azure,moonshot,zhipuai,deepseek,yi}]
237
+ [--model_name MODEL_NAME] [--api_base API_BASE]
238
+ [--api_key API_KEY] [--max_tokens MAX_TOKENS]
239
+ [--temperature TEMPERATURE] [--verbose VERBOSE]
240
+ [--tools [{search_serper,file_tool,shell_tool,yfinance_tool,web_search_pro,cogview,cogvideo,jina,wikipedia} ...]]
241
+
242
+ CLI for agentica
243
+
244
+ options:
245
+ -h, --help show this help message and exit
246
+ --query QUERY Question to ask the LLM
247
+ --model_provider {openai,azure,moonshot,zhipuai,deepseek,yi}
248
+ LLM model provider
249
+ --model_name MODEL_NAME
250
+ LLM model name to use, can be
251
+ gpt-4o/glm-4-flash/deepseek-chat/yi-lightning/...
252
+ --api_base API_BASE API base URL for the LLM
253
+ --api_key API_KEY API key for the LLM
254
+ --max_tokens MAX_TOKENS
255
+ Maximum number of tokens for the LLM
256
+ --temperature TEMPERATURE
257
+ Temperature for the LLM
258
+ --verbose VERBOSE enable verbose mode
259
+ --tools [{search_serper,file_tool,shell_tool,yfinance_tool,web_search_pro,cogview,cogvideo,jina,wikipedia} ...]
260
+ Tools to enable
261
+ ```
262
+
263
+ run:
264
+
265
+ ```shell
266
+ pip install agentica -U
267
+ # 单次调用,填入`--query`参数
268
+ agentica --query "下一届奥运会在哪里举办" --model_provider zhipuai --model_name glm-4-flash --tools web_search_pro
269
+ # 多次调用,多轮对话,不填`--query`参数
270
+ agentica --model_provider zhipuai --model_name glm-4-flash --tools web_search_pro cogview --verbose 1
271
+ ```
272
+
273
+ output:
274
+ ```shell
275
+ 2024-12-30 21:59:15,000 - agentica - INFO - Agentica CLI
276
+ >>> 帮我画个大象在月球上的图
277
+
278
+ > 我帮你画了一张大象在月球上的图,它看起来既滑稽又可爱。大象穿着宇航服,站在月球表面,背景是广阔的星空和地球。这张图色彩明亮,细节丰富,具有卡通风格。你可以点击下面的链接查看和下载这张图片:
279
+
280
+ ![大象在月球上的图](https://aigc-files.bigmodel.cn/api/cogview/20241230215915cfa22f46425e4cb0_0.png)
281
+ ```
282
+
247
283
  ## ☎️ Contact
248
284
 
249
285
  - Issue(建议)
@@ -14,13 +14,30 @@ from agentica.utils.log import set_log_level_to_debug, logger
14
14
  from agentica.utils.io import write_audio_to_file
15
15
  # model
16
16
  from agentica.model.openai.chat import OpenAIChat
17
+ from agentica.model.openai.chat import OpenAIChat as OpenAILLM
18
+ from agentica.model.openai.like import OpenAILike
17
19
  from agentica.model.azure.openai_chat import AzureOpenAIChat
18
- from agentica.model.moonshot import MoonshotChat
19
- from agentica.model.deepseek.chat import DeepSeekChat
20
- from agentica.model.doubao.chat import DoubaoChat
21
- from agentica.model.together.togetherchat import TogetherChat
22
- from agentica.model.xai.grok import GrokChat
23
- from agentica.model.yi.chat import YiChat
20
+ from agentica.model.azure.openai_chat import AzureOpenAIChat as AzureOpenAILLM
21
+ from agentica.model.moonshot import Moonshot
22
+ from agentica.model.moonshot import Moonshot as MoonshotChat
23
+ from agentica.model.moonshot import Moonshot as MoonshotLLM
24
+ from agentica.model.deepseek.chat import DeepSeek
25
+ from agentica.model.deepseek.chat import DeepSeek as DeepSeekChat
26
+ from agentica.model.deepseek.chat import DeepSeek as DeepSeekLLM
27
+ from agentica.model.doubao.chat import Doubao
28
+ from agentica.model.doubao.chat import Doubao as DoubaoChat
29
+ from agentica.model.together.together import Together
30
+ from agentica.model.together.together import Together as TogetherChat
31
+ from agentica.model.together.together import Together as TogetherLLM
32
+ from agentica.model.xai.grok import Grok
33
+ from agentica.model.xai.grok import Grok as GrokChat
34
+ from agentica.model.yi.chat import Yi
35
+ from agentica.model.yi.chat import Yi as YiChat
36
+ from agentica.model.yi.chat import Yi as YiLLM
37
+ from agentica.model.qwen.chat import Qwen
38
+ from agentica.model.zhipuai.chat import ZhipuAI
39
+ from agentica.model.zhipuai.chat import ZhipuAI as ZhipuAIChat
40
+ from agentica.model.zhipuai.chat import ZhipuAI as ZhipuAILLM
24
41
 
25
42
  # memory
26
43
  from agentica.model.base import Model
@@ -72,6 +89,7 @@ from agentica.emb.hash_emb import HashEmb
72
89
  from agentica.emb.ollama_emb import OllamaEmb
73
90
  from agentica.emb.together_emb import TogetherEmb
74
91
  from agentica.emb.fireworks_emb import FireworksEmb
92
+ from agentica.emb.zhipuai_emb import ZhipuAIEmb
75
93
 
76
94
  # file
77
95
  from agentica.file.base import File
@@ -94,12 +112,13 @@ from agentica.tools.search_serper_tool import SearchSerperTool
94
112
  from agentica.tools.run_python_code_tool import RunPythonCodeTool
95
113
  from agentica.tools.analyze_image_tool import AnalyzeImageTool
96
114
  from agentica.tools.calculator_tool import CalculatorTool
97
- from agentica.tools.create_image_tool import CreateImageTool
115
+ from agentica.tools.dalle_tool import DalleTool
98
116
  from agentica.tools.file_tool import FileTool
99
117
  from agentica.tools.hackernews_tool import HackerNewsTool
100
118
  from agentica.tools.jina_tool import JinaTool
101
119
  from agentica.tools.shell_tool import ShellTool
102
120
  from agentica.tools.text_analysis_tool import TextAnalysisTool
121
+ from agentica.tools.weather_tool import WeatherTool
103
122
 
104
123
  # agent
105
124
  from agentica.agent import Agent
@@ -7,6 +7,7 @@ part of the code from https://github.com/phidatahq/phidata
7
7
  from __future__ import annotations
8
8
 
9
9
  import json
10
+ import os
10
11
  from datetime import datetime
11
12
  from textwrap import dedent
12
13
  from collections import defaultdict, deque
@@ -30,6 +31,7 @@ from uuid import uuid4
30
31
  from pathlib import Path
31
32
  from pydantic import BaseModel, ConfigDict, field_validator, Field, ValidationError
32
33
 
34
+ from agentica.utils.log import logger, set_log_level_to_debug, set_log_level_to_info
33
35
  from agentica.document import Document
34
36
  from agentica.knowledge.base import Knowledge
35
37
  from agentica.model.openai import OpenAIChat
@@ -44,10 +46,11 @@ from agentica.reasoning import ReasoningStep, ReasoningSteps, NextAction
44
46
  from agentica.run_response import RunEvent, RunResponse, RunResponseExtraData
45
47
  from agentica.memory import AgentMemory, Memory, AgentRun, SessionSummary
46
48
  from agentica.storage.agent.base import AgentStorage
47
- from agentica.utils.log import logger, set_log_level_to_debug
48
- from agentica.utils.misc import get_text_from_message
49
+ from agentica.utils.message import get_text_from_message
49
50
  from agentica.utils.timer import Timer
50
51
  from agentica.agent_session import AgentSession
52
+ from agentica.media import AudioResponse
53
+ from agentica.utils.string import parse_structured_output
51
54
 
52
55
 
53
56
  class Agent(BaseModel):
@@ -200,9 +203,6 @@ class Agent(BaseModel):
200
203
  add_datetime_to_instructions: bool = False
201
204
 
202
205
  # -*- User Prompt Settings
203
- # User prompt: provide the user prompt as a string
204
- # Note: this will ignore the message sent to the run function
205
- user_prompt: Optional[Union[List, Dict, str, Callable]] = None
206
206
  # User prompt template: provide the user prompt as a PromptTemplate
207
207
  user_prompt_template: Optional[PromptTemplate] = None
208
208
  # If True, build a default user prompt using references and chat history
@@ -234,7 +234,7 @@ class Agent(BaseModel):
234
234
  team_response_separator: str = "\n"
235
235
 
236
236
  # debug_mode=True enables debug logs
237
- debug_mode: bool = Field(False, validate_default=True)
237
+ debug_mode: bool = Field(False, validate_default=True, alias="debug")
238
238
  # monitoring=True logs Agent information
239
239
  monitoring: bool = False
240
240
 
@@ -252,6 +252,15 @@ class Agent(BaseModel):
252
252
 
253
253
  model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True, extra="allow")
254
254
 
255
+ @field_validator("debug_mode", mode="before")
256
+ def set_log_level(cls, v: bool) -> bool:
257
+ if v:
258
+ set_log_level_to_debug()
259
+ logger.debug("Debug logs enabled")
260
+ elif v is False:
261
+ set_log_level_to_info()
262
+ return v
263
+
255
264
  @field_validator("agent_id", mode="before")
256
265
  def set_agent_id(cls, v: Optional[str]) -> str:
257
266
  agent_id = v or str(uuid4())
@@ -264,13 +273,6 @@ class Agent(BaseModel):
264
273
  logger.debug(f"*********** Session ID: {session_id} ***********")
265
274
  return session_id
266
275
 
267
- @field_validator("debug_mode", mode="before")
268
- def set_log_level(cls, v: bool) -> bool:
269
- if v:
270
- set_log_level_to_debug()
271
- logger.debug("Debug logs enabled")
272
- return v
273
-
274
276
  @property
275
277
  def is_streamable(self) -> bool:
276
278
  """Determines if the response from the Model is streamable
@@ -1126,14 +1128,14 @@ class Agent(BaseModel):
1126
1128
  ) -> Optional[Message]:
1127
1129
  """Return the user message for the Agent.
1128
1130
 
1129
- 1. If the user_prompt is provided, use that.
1131
+ 1. Get references.
1130
1132
  2. If the user_prompt_template is provided, build the user_message using the template.
1131
1133
  3. If the message is None, return None.
1132
1134
  4. 4. If use_default_user_message is False or If the message is not a string, return the message as is.
1133
1135
  5. If add_references is False or references is None, return the message as is.
1134
1136
  6. Build the default user message for the Agent
1135
1137
  """
1136
- # Get references from the knowledge base to use in the user message
1138
+ # 1. Get references from the knowledge base to use in the user message
1137
1139
  references = None
1138
1140
  if self.add_references and message and isinstance(message, str):
1139
1141
  retrieval_timer = Timer()
@@ -1152,23 +1154,6 @@ class Agent(BaseModel):
1152
1154
  retrieval_timer.stop()
1153
1155
  logger.debug(f"Time to get references: {retrieval_timer.elapsed:.4f}s")
1154
1156
 
1155
- # 1. If the user_prompt is provided, use that.
1156
- if self.user_prompt is not None:
1157
- user_prompt_content = self.user_prompt
1158
- if callable(self.user_prompt):
1159
- user_prompt_kwargs = {"agent": self, "message": message, "references": references}
1160
- user_prompt_content = self.user_prompt(**user_prompt_kwargs)
1161
- if not isinstance(user_prompt_content, str):
1162
- raise Exception("User prompt must return a string")
1163
- return Message(
1164
- role=self.user_message_role,
1165
- content=user_prompt_content,
1166
- audio=audio,
1167
- images=images,
1168
- videos=videos,
1169
- **kwargs,
1170
- )
1171
-
1172
1157
  # 2. If the user_prompt_template is provided, build the user_message using the template.
1173
1158
  if self.user_prompt_template is not None:
1174
1159
  user_prompt_kwargs = {"agent": self, "message": message, "references": references}
@@ -1784,6 +1769,11 @@ class Agent(BaseModel):
1784
1769
  model_response = ModelResponse(content="")
1785
1770
  for model_response_chunk in self.model.response_stream(messages=messages_for_model):
1786
1771
  if model_response_chunk.event == ModelResponseEvent.assistant_response.value:
1772
+ if model_response_chunk.reasoning_content is not None:
1773
+ model_response.content += model_response_chunk.reasoning_content
1774
+ self.run_response.content = model_response_chunk.reasoning_content
1775
+ self.run_response.created_at = model_response_chunk.created_at
1776
+ yield self.run_response
1787
1777
  if model_response_chunk.content is not None and model_response.content is not None:
1788
1778
  model_response.content += model_response_chunk.content
1789
1779
  self.run_response.content = model_response_chunk.content
@@ -1991,20 +1981,9 @@ class Agent(BaseModel):
1991
1981
  # Otherwise convert the response to the structured format
1992
1982
  if isinstance(run_response.content, str):
1993
1983
  try:
1994
- structured_output = None
1995
- try:
1996
- structured_output = self.response_model.model_validate_json(run_response.content)
1997
- except ValidationError as exc:
1998
- logger.warning(f"Failed to convert response to pydantic model: {exc}")
1999
- # Check if response starts with ```json
2000
- if run_response.content.startswith("```json"):
2001
- run_response.content = run_response.content.replace("```json\n", "").replace("\n```", "")
2002
- try:
2003
- structured_output = self.response_model.model_validate_json(run_response.content)
2004
- except ValidationError as exc:
2005
- logger.warning(f"Failed to convert response to pydantic model: {exc}")
1984
+ structured_output = parse_structured_output(run_response.content, self.response_model)
2006
1985
 
2007
- # -*- Update Agent response
1986
+ # Update RunResponse
2008
1987
  if structured_output is not None:
2009
1988
  run_response.content = structured_output
2010
1989
  run_response.content_type = self.response_model.__name__
@@ -2307,7 +2286,8 @@ class Agent(BaseModel):
2307
2286
  logger.warning(f"Failed to convert response to pydantic model: {exc}")
2308
2287
  # Check if response starts with ```json
2309
2288
  if run_response.content.startswith("```json"):
2310
- run_response.content = run_response.content.replace("```json\n", "").replace("\n```", "")
2289
+ run_response.content = run_response.content.replace(
2290
+ "```json\n", "").replace("\n```", "")
2311
2291
  try:
2312
2292
  structured_output = self.response_model.model_validate_json(run_response.content)
2313
2293
  except ValidationError as exc:
@@ -3089,4 +3069,3 @@ class Agent(BaseModel):
3089
3069
  break
3090
3070
 
3091
3071
  self.print_response(message=message, stream=stream, markdown=markdown, **kwargs)
3092
-