agentica 0.2.3__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 (187) hide show
  1. {agentica-0.2.3 → agentica-0.2.5}/PKG-INFO +91 -9
  2. agentica-0.2.3/agentica.egg-info/PKG-INFO → agentica-0.2.5/README.md +74 -37
  3. {agentica-0.2.3 → agentica-0.2.5}/agentica/__init__.py +24 -7
  4. {agentica-0.2.3 → agentica-0.2.5}/agentica/agent.py +24 -47
  5. agentica-0.2.5/agentica/cli.py +151 -0
  6. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/azure_openai_emb.py +4 -3
  7. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/base.py +3 -5
  8. {agentica-0.2.3 → 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.3 → agentica-0.2.5}/agentica/emb/hash_emb.py +2 -0
  11. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/huggingface_emb.py +9 -8
  12. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/ollama_emb.py +2 -0
  13. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/openai_emb.py +4 -1
  14. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/sentence_transformer_emb.py +2 -0
  15. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/text2vec_emb.py +2 -0
  16. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/together_emb.py +2 -0
  17. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/word2vec_emb.py +7 -5
  18. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/zhipuai_emb.py +2 -0
  19. {agentica-0.2.3 → agentica-0.2.5}/agentica/file/base.py +5 -4
  20. {agentica-0.2.3 → agentica-0.2.5}/agentica/file/csv.py +4 -2
  21. {agentica-0.2.3 → 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.3 → 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.3 → agentica-0.2.5}/agentica/model/deepseek/chat.py +2 -2
  27. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/doubao/chat.py +2 -2
  28. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/fireworks/fireworks.py +0 -17
  29. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/message.py +39 -3
  30. agentica-0.2.5/agentica/model/moonshot/__init__.py +1 -0
  31. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/moonshot/chat.py +2 -2
  32. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/nvidia/chat.py +1 -1
  33. {agentica-0.2.3 → 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.3 → 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.3/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.3 → 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.3 → 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.3 → agentica-0.2.5}/agentica/model/zhipuai/chat.py +2 -2
  44. {agentica-0.2.3 → agentica-0.2.5}/agentica/react_agent.py +1 -1
  45. agentica-0.2.5/agentica/storage/__init__.py +0 -0
  46. agentica-0.2.5/agentica/tools/__init__.py +0 -0
  47. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/jina_tool.py +1 -9
  48. agentica-0.2.5/agentica/tools/weather_tool.py +46 -0
  49. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/log.py +19 -0
  50. agentica-0.2.5/agentica/utils/message.py +43 -0
  51. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/misc.py +11 -42
  52. agentica-0.2.5/agentica/utils/string.py +73 -0
  53. agentica-0.2.5/agentica/version.py +1 -0
  54. agentica-0.2.3/README.md → agentica-0.2.5/agentica.egg-info/PKG-INFO +119 -6
  55. {agentica-0.2.3 → agentica-0.2.5}/agentica.egg-info/SOURCES.txt +8 -1
  56. {agentica-0.2.3 → agentica-0.2.5}/agentica.egg-info/requires.txt +4 -1
  57. {agentica-0.2.3 → agentica-0.2.5}/setup.py +4 -1
  58. agentica-0.2.3/agentica/emb/genimi_emb.py +0 -60
  59. agentica-0.2.3/agentica/model/cohere/__init__.py +0 -1
  60. agentica-0.2.3/agentica/model/deepseek/__init__.py +0 -1
  61. agentica-0.2.3/agentica/model/doubao/__init__.py +0 -1
  62. agentica-0.2.3/agentica/model/moonshot/__init__.py +0 -1
  63. agentica-0.2.3/agentica/model/together/__init__.py +0 -1
  64. agentica-0.2.3/agentica/model/xai/__init__.py +0 -1
  65. agentica-0.2.3/agentica/model/yi/__init__.py +0 -1
  66. agentica-0.2.3/agentica/model/zhipuai/__init__.py +0 -1
  67. agentica-0.2.3/agentica/version.py +0 -1
  68. {agentica-0.2.3 → agentica-0.2.5}/LICENSE +0 -0
  69. {agentica-0.2.3 → agentica-0.2.5}/MANIFEST.in +0 -0
  70. {agentica-0.2.3 → agentica-0.2.5}/agentica/agent_session.py +0 -0
  71. {agentica-0.2.3 → agentica-0.2.5}/agentica/config.py +0 -0
  72. {agentica-0.2.3 → agentica-0.2.5}/agentica/document.py +0 -0
  73. {agentica-0.2.3 → agentica-0.2.5}/agentica/emb/__init__.py +0 -0
  74. {agentica-0.2.3 → agentica-0.2.5}/agentica/file/__init__.py +0 -0
  75. {agentica-0.2.3 → agentica-0.2.5}/agentica/knowledge/__init__.py +0 -0
  76. {agentica-0.2.3 → agentica-0.2.5}/agentica/knowledge/base.py +0 -0
  77. {agentica-0.2.3 → agentica-0.2.5}/agentica/knowledge/langchain_knowledge.py +0 -0
  78. {agentica-0.2.3 → agentica-0.2.5}/agentica/knowledge/llamaindex_knowledge.py +0 -0
  79. {agentica-0.2.3 → agentica-0.2.5}/agentica/memory.py +0 -0
  80. {agentica-0.2.3 → agentica-0.2.5}/agentica/memorydb.py +0 -0
  81. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/__init__.py +0 -0
  82. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/anthropic/__init__.py +0 -0
  83. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/anthropic/claude.py +0 -0
  84. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/aws/__init__.py +0 -0
  85. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/aws/api_client.py +0 -0
  86. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/aws/bedrock.py +0 -0
  87. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/aws/claude.py +0 -0
  88. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/azure/__init__.py +0 -0
  89. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/azure/openai_chat.py +0 -0
  90. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/base.py +0 -0
  91. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/content.py +0 -0
  92. {agentica-0.2.3/agentica/reranker → agentica-0.2.5/agentica/model/doubao}/__init__.py +0 -0
  93. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/fireworks/__init__.py +0 -0
  94. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/google/__init__.py +0 -0
  95. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/google/gemini.py +0 -0
  96. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/google/gemini_openai.py +0 -0
  97. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/groq/__init__.py +0 -0
  98. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/groq/groq.py +0 -0
  99. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/huggingface/__init__.py +0 -0
  100. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/huggingface/hf.py +0 -0
  101. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/internlm/__init__.py +0 -0
  102. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/internlm/chat.py +0 -0
  103. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/mistral/__init__.py +0 -0
  104. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/mistral/mistral.py +0 -0
  105. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/nvidia/__init__.py +0 -0
  106. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/ollama/__init__.py +0 -0
  107. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/ollama/chat.py +0 -0
  108. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/ollama/hermes.py +0 -0
  109. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/ollama/tools.py +0 -0
  110. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/openai/__init__.py +0 -0
  111. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/openai/like.py +0 -0
  112. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/openrouter/__init__.py +0 -0
  113. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/openrouter/openrouter.py +0 -0
  114. {agentica-0.2.3/agentica/storage → agentica-0.2.5/agentica/model/qwen}/__init__.py +0 -0
  115. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/sambanova/__init__.py +0 -0
  116. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/sambanova/sambanova.py +0 -0
  117. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/vertexai/__init__.py +0 -0
  118. {agentica-0.2.3 → agentica-0.2.5}/agentica/model/vertexai/gemini.py +0 -0
  119. {agentica-0.2.3 → agentica-0.2.5}/agentica/python_agent.py +0 -0
  120. {agentica-0.2.3 → agentica-0.2.5}/agentica/reasoning.py +0 -0
  121. {agentica-0.2.3/agentica/tools → agentica-0.2.5/agentica/reranker}/__init__.py +0 -0
  122. {agentica-0.2.3 → agentica-0.2.5}/agentica/reranker/base.py +0 -0
  123. {agentica-0.2.3 → agentica-0.2.5}/agentica/reranker/bge.py +0 -0
  124. {agentica-0.2.3 → agentica-0.2.5}/agentica/reranker/cohere.py +0 -0
  125. {agentica-0.2.3 → agentica-0.2.5}/agentica/run_response.py +0 -0
  126. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/agent/__init__.py +0 -0
  127. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/agent/base.py +0 -0
  128. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/agent/json_file.py +0 -0
  129. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/agent/postgres.py +0 -0
  130. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/agent/sqlite.py +0 -0
  131. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/agent/yaml_file.py +0 -0
  132. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/workflow/__init__.py +0 -0
  133. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/workflow/base.py +0 -0
  134. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/workflow/postgres.py +0 -0
  135. {agentica-0.2.3 → agentica-0.2.5}/agentica/storage/workflow/sqlite.py +0 -0
  136. {agentica-0.2.3 → agentica-0.2.5}/agentica/template.py +0 -0
  137. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/airflow_tool.py +0 -0
  138. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/analyze_image_tool.py +0 -0
  139. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/apify_tool.py +0 -0
  140. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/arxiv_tool.py +0 -0
  141. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/baidusearch_tool.py +0 -0
  142. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/base.py +0 -0
  143. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/calculator_tool.py +0 -0
  144. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/cogvideo_tool.py +0 -0
  145. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/cogview_tool.py +0 -0
  146. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/dalle_tool.py +0 -0
  147. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/dblp_tool.py +0 -0
  148. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/duckduckgo_tool.py +0 -0
  149. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/file_tool.py +0 -0
  150. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/hackernews_tool.py +0 -0
  151. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/newspaper_tool.py +0 -0
  152. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/ocr_tool.py +0 -0
  153. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/resend_tools.py +0 -0
  154. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/run_nb_code_tool.py +0 -0
  155. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/run_python_code_tool.py +0 -0
  156. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/search_exa_tool.py +0 -0
  157. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/search_serper_tool.py +0 -0
  158. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/shell_tool.py +0 -0
  159. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/sql_tool.py +0 -0
  160. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/string_tool.py +0 -0
  161. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/text_analysis_tool.py +0 -0
  162. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/url_crawler_tool.py +0 -0
  163. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/web_search_pro_tool.py +0 -0
  164. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/wikipedia_tool.py +0 -0
  165. {agentica-0.2.3 → agentica-0.2.5}/agentica/tools/yfinance_tool.py +0 -0
  166. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/__init__.py +0 -0
  167. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/console.py +0 -0
  168. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/file_parser.py +0 -0
  169. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/io.py +0 -0
  170. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/json_util.py +0 -0
  171. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/shell.py +0 -0
  172. {agentica-0.2.3 → agentica-0.2.5}/agentica/utils/timer.py +0 -0
  173. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/__init__.py +0 -0
  174. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/base.py +0 -0
  175. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/chromadb_vectordb.py +0 -0
  176. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/lancedb_vectordb.py +0 -0
  177. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/memory_vectordb.py +0 -0
  178. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/pgvectordb.py +0 -0
  179. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/pineconedb.py +0 -0
  180. {agentica-0.2.3 → agentica-0.2.5}/agentica/vectordb/qdrantdb.py +0 -0
  181. {agentica-0.2.3 → agentica-0.2.5}/agentica/workflow.py +0 -0
  182. {agentica-0.2.3 → agentica-0.2.5}/agentica/workflow_session.py +0 -0
  183. {agentica-0.2.3 → agentica-0.2.5}/agentica.egg-info/dependency_links.txt +0 -0
  184. {agentica-0.2.3 → agentica-0.2.5}/agentica.egg-info/entry_points.txt +0 -0
  185. {agentica-0.2.3 → agentica-0.2.5}/agentica.egg-info/not-zip-safe +0 -0
  186. {agentica-0.2.3 → agentica-0.2.5}/agentica.egg-info/top_level.txt +0 -0
  187. {agentica-0.2.3 → 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.3
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
 
@@ -88,7 +102,7 @@ Requires-Dist: rich
88
102
 
89
103
  - **Agent编排**:通过简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Team、Workflow等功能
90
104
  - **自定义prompt**:Agent支持自定义prompt和多种工具调用(tool_calls)
91
- - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、Claude、Ollama、Together等多方大模型厂商的API
105
+ - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、AnthropicZhipuAI、Ollama、Together等多方大模型厂商的API
92
106
  - **记忆功能**:包括短期记忆和长期记忆功能
93
107
  - **Multi-Agent协作**:支持多Agent和任务委托(Team)的团队协作。
94
108
  - **Workflow工作流**:拆解复杂任务为多个Agent,基于工作流自动化串行逐步完成任务,如投资研究、新闻文章撰写和技术教程创建
@@ -117,7 +131,7 @@ pip install .
117
131
  cp .env.example ~/.agentica/.env
118
132
 
119
133
  cd examples
120
- python web_search_moonshot_demo.py
134
+ python 12_web_search_moonshot_demo.py
121
135
  ```
122
136
 
123
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`命令设置环境变量:
@@ -132,13 +146,23 @@ python web_search_moonshot_demo.py
132
146
  自动调用google搜索工具,示例[examples/12_web_search_moonshot_demo.py](https://github.com/shibing624/agentica/blob/main/examples/12_web_search_moonshot_demo.py)
133
147
 
134
148
  ```python
135
- from agentica import Agent, MoonshotChat, SearchSerperTool
149
+ from agentica import Agent, Moonshot, WeatherTool
136
150
 
137
- m = Agent(model=MoonshotChat(), tools=[SearchSerperTool()], add_datetime_to_instructions=True)
138
- r = m.run("下一届奥运会在哪里举办")
139
- print(r)
151
+ m = Agent(model=Moonshot(), tools=[WeatherTool()], add_datetime_to_instructions=True)
152
+ m.print_response("明天北京天气咋样")
140
153
  ```
141
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
+ ```
142
166
 
143
167
  ## ▶️ Web UI
144
168
 
@@ -203,6 +227,7 @@ bash start.sh
203
227
  | [examples/37_workflow_write_novel_demo.py](https://github.com/shibing624/agentica/blob/main/examples/37_workflow_write_novel_demo.py) | 实现了写小说的工作流:定小说提纲 - 搜索谷歌反思提纲 - 撰写小说内容 - 保存为md文件 |
204
228
  | [examples/38_workflow_write_tutorial_demo.py](https://github.com/shibing624/agentica/blob/main/examples/38_workflow_write_tutorial_demo.py) | 实现了写技术教程的工作流:定教程目录 - 反思目录内容 - 撰写教程内容 - 保存为md文件 |
205
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 |
206
231
 
207
232
 
208
233
  ### Self-evolving Agent
@@ -243,6 +268,63 @@ streamlit run 34_llm_os_demo.py
243
268
 
244
269
  <img alt="LLM OS" src="https://github.com/shibing624/agentica/blob/main/docs/llm_os_snap.png" width="800" />
245
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
+
246
328
  ## ☎️ Contact
247
329
 
248
330
  - Issue(建议)
@@ -1,34 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: agentica
3
- Version: 0.2.3
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">
@@ -88,7 +57,7 @@ Requires-Dist: rich
88
57
 
89
58
  - **Agent编排**:通过简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Team、Workflow等功能
90
59
  - **自定义prompt**:Agent支持自定义prompt和多种工具调用(tool_calls)
91
- - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、Claude、Ollama、Together等多方大模型厂商的API
60
+ - **LLM集成**:支持OpenAI、Azure、Deepseek、Moonshot、AnthropicZhipuAI、Ollama、Together等多方大模型厂商的API
92
61
  - **记忆功能**:包括短期记忆和长期记忆功能
93
62
  - **Multi-Agent协作**:支持多Agent和任务委托(Team)的团队协作。
94
63
  - **Workflow工作流**:拆解复杂任务为多个Agent,基于工作流自动化串行逐步完成任务,如投资研究、新闻文章撰写和技术教程创建
@@ -117,7 +86,7 @@ pip install .
117
86
  cp .env.example ~/.agentica/.env
118
87
 
119
88
  cd examples
120
- python web_search_moonshot_demo.py
89
+ python 12_web_search_moonshot_demo.py
121
90
  ```
122
91
 
123
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`命令设置环境变量:
@@ -132,13 +101,23 @@ python web_search_moonshot_demo.py
132
101
  自动调用google搜索工具,示例[examples/12_web_search_moonshot_demo.py](https://github.com/shibing624/agentica/blob/main/examples/12_web_search_moonshot_demo.py)
133
102
 
134
103
  ```python
135
- from agentica import Agent, MoonshotChat, SearchSerperTool
104
+ from agentica import Agent, Moonshot, WeatherTool
136
105
 
137
- m = Agent(model=MoonshotChat(), tools=[SearchSerperTool()], add_datetime_to_instructions=True)
138
- r = m.run("下一届奥运会在哪里举办")
139
- print(r)
106
+ m = Agent(model=Moonshot(), tools=[WeatherTool()], add_datetime_to_instructions=True)
107
+ m.print_response("明天北京天气咋样")
140
108
  ```
141
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
+ ```
142
121
 
143
122
  ## ▶️ Web UI
144
123
 
@@ -203,6 +182,7 @@ bash start.sh
203
182
  | [examples/37_workflow_write_novel_demo.py](https://github.com/shibing624/agentica/blob/main/examples/37_workflow_write_novel_demo.py) | 实现了写小说的工作流:定小说提纲 - 搜索谷歌反思提纲 - 撰写小说内容 - 保存为md文件 |
204
183
  | [examples/38_workflow_write_tutorial_demo.py](https://github.com/shibing624/agentica/blob/main/examples/38_workflow_write_tutorial_demo.py) | 实现了写技术教程的工作流:定教程目录 - 反思目录内容 - 撰写教程内容 - 保存为md文件 |
205
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 |
206
186
 
207
187
 
208
188
  ### Self-evolving Agent
@@ -243,6 +223,63 @@ streamlit run 34_llm_os_demo.py
243
223
 
244
224
  <img alt="LLM OS" src="https://github.com/shibing624/agentica/blob/main/docs/llm_os_snap.png" width="800" />
245
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
+
246
283
  ## ☎️ Contact
247
284
 
248
285
  - Issue(建议)
@@ -14,14 +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
24
- from agentica.model.zhipuai.chat import ZhipuAIChat
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
25
41
 
26
42
  # memory
27
43
  from agentica.model.base import Model
@@ -102,6 +118,7 @@ from agentica.tools.hackernews_tool import HackerNewsTool
102
118
  from agentica.tools.jina_tool import JinaTool
103
119
  from agentica.tools.shell_tool import ShellTool
104
120
  from agentica.tools.text_analysis_tool import TextAnalysisTool
121
+ from agentica.tools.weather_tool import WeatherTool
105
122
 
106
123
  # agent
107
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,21 +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(
2002
- "```json\n", "").replace("\n```", "")
2003
- try:
2004
- structured_output = self.response_model.model_validate_json(run_response.content)
2005
- except ValidationError as exc:
2006
- logger.warning(f"Failed to convert response to pydantic model: {exc}")
1984
+ structured_output = parse_structured_output(run_response.content, self.response_model)
2007
1985
 
2008
- # -*- Update Agent response
1986
+ # Update RunResponse
2009
1987
  if structured_output is not None:
2010
1988
  run_response.content = structured_output
2011
1989
  run_response.content_type = self.response_model.__name__
@@ -3091,4 +3069,3 @@ class Agent(BaseModel):
3091
3069
  break
3092
3070
 
3093
3071
  self.print_response(message=message, stream=stream, markdown=markdown, **kwargs)
3094
-
@@ -0,0 +1,151 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ @author:XuMing(xuming624@qq.com)
4
+ @description: command line interface for agentica
5
+ """
6
+ import argparse
7
+ from rich.console import Console
8
+ from rich.text import Text
9
+ from agentica import Agent, OpenAIChat, Moonshot, AzureOpenAIChat, Yi, ZhipuAI, DeepSeek, PythonAgent
10
+ from agentica.tools.search_serper_tool import SearchSerperTool
11
+ from agentica.tools.file_tool import FileTool
12
+ from agentica.tools.shell_tool import ShellTool
13
+ from agentica.tools.jina_tool import JinaTool
14
+ from agentica.tools.wikipedia_tool import WikipediaTool
15
+
16
+ console = Console()
17
+
18
+
19
+ def parse_args():
20
+ parser = argparse.ArgumentParser(description='CLI for agentica')
21
+ parser.add_argument('--query', type=str, help='Question to ask the LLM', default=None)
22
+ parser.add_argument('--model_provider', type=str,
23
+ choices=['openai', 'azure', 'moonshot', 'zhipuai', 'deepseek', 'yi'],
24
+ help='LLM model provider', default='openai')
25
+ parser.add_argument('--model_name', type=str,
26
+ help='LLM model name to use, can be gpt-4o/glm-4-flash/deepseek-chat/yi-lightning/...',
27
+ default='gpt-4o-mini')
28
+ parser.add_argument('--api_base', type=str, help='API base URL for the LLM')
29
+ parser.add_argument('--api_key', type=str, help='API key for the LLM')
30
+ parser.add_argument('--max_tokens', type=int, help='Maximum number of tokens for the LLM')
31
+ parser.add_argument('--temperature', type=float, help='Temperature for the LLM')
32
+ parser.add_argument('--verbose', type=int, help='enable verbose mode', default=0)
33
+ parser.add_argument('--tools', nargs='*',
34
+ choices=['search_serper', 'file', 'shell', 'yfinance', 'web_search_pro',
35
+ 'cogview', 'cogvideo', 'jina', 'wikipedia', 'python'], help='Tools to enable')
36
+ return parser.parse_args()
37
+
38
+
39
+ def get_model(model_provider, model_name, api_base=None, api_key=None, max_tokens=None, temperature=None):
40
+ params = {"id": model_name}
41
+ if api_base is not None:
42
+ params["api_base"] = api_base
43
+ if api_key is not None:
44
+ params["api_key"] = api_key
45
+ if max_tokens is not None:
46
+ params["max_tokens"] = max_tokens
47
+ if temperature is not None:
48
+ params["temperature"] = temperature
49
+ if model_provider == 'openai':
50
+ model = OpenAIChat(**params)
51
+ elif model_provider == 'azure':
52
+ model = AzureOpenAIChat(**params)
53
+ elif model_provider == 'moonshot':
54
+ model = Moonshot(**params)
55
+ elif model_provider == 'zhipuai':
56
+ model = ZhipuAI(**params)
57
+ elif model_provider == 'deepseek':
58
+ model = DeepSeek(**params)
59
+ elif model_provider == 'yi':
60
+ model = Yi(**params)
61
+ else:
62
+ raise ValueError(f"Unsupported model: {model_name}")
63
+ return model
64
+
65
+
66
+ def configure_tools(tool_names):
67
+ """
68
+ Configure tools to enable
69
+ :param tool_names: list of tool names
70
+ :return: list of tool instances
71
+ """
72
+ tools = []
73
+ if 'search_serper' in tool_names:
74
+ tools.append(SearchSerperTool())
75
+ if 'file' in tool_names:
76
+ tools.append(FileTool())
77
+ if 'shell' in tool_names:
78
+ tools.append(ShellTool())
79
+ if 'yfinance' in tool_names:
80
+ from agentica.tools.yfinance_tool import YFinanceTool
81
+ tools.append(YFinanceTool())
82
+ if 'web_search_pro' in tool_names:
83
+ from agentica.tools.web_search_pro_tool import WebSearchProTool
84
+ tools.append(WebSearchProTool())
85
+ if 'cogview' in tool_names:
86
+ from agentica.tools.cogview_tool import CogViewTool
87
+ tools.append(CogViewTool())
88
+ if 'cogvideo' in tool_names:
89
+ from agentica.tools.cogvideo_tool import CogVideoTool
90
+ tools.append(CogVideoTool())
91
+ if 'jina' in tool_names:
92
+ tools.append(JinaTool())
93
+ if 'wikipedia' in tool_names:
94
+ tools.append(WikipediaTool())
95
+ return tools
96
+
97
+
98
+ def run_interactive(agent):
99
+ first_prompt = True
100
+ while True:
101
+ try:
102
+ if first_prompt:
103
+ console.print(Text("Enter your question (type 'exit' to quit):", style="green"))
104
+ console.print(Text("> ", style="green"), end="")
105
+ first_prompt = False
106
+ else:
107
+ console.print(Text("> ", style="green"), end="")
108
+
109
+ line = console.input()
110
+ query = line.strip()
111
+
112
+ if query.lower() == 'exit':
113
+ break
114
+ if query:
115
+ response = agent.run(query, stream=True)
116
+ console.print(Text("\n", style="green"), end="")
117
+ for chunk in response:
118
+ console.print(chunk.content, end="")
119
+ console.print("\n")
120
+ except KeyboardInterrupt:
121
+ break
122
+ except Exception as e:
123
+ console.print(e)
124
+ break
125
+
126
+
127
+ def main():
128
+ args = parse_args()
129
+ model = get_model(args.model_provider, args.model_name, api_base=args.api_base,
130
+ api_key=args.api_key, max_tokens=args.max_tokens)
131
+ tools = configure_tools(args.tools) if args.tools else None
132
+ debug_mode = args.verbose > 0
133
+ if args.tools and 'python' in args.tools:
134
+ agent = PythonAgent(model=model, add_datetime_to_instructions=True, add_history_to_messages=True,
135
+ tools=tools, debug_mode=debug_mode)
136
+ else:
137
+ agent = Agent(model=model, add_datetime_to_instructions=True, add_history_to_messages=True,
138
+ tools=tools, debug_mode=debug_mode)
139
+ console.print(Text("Welcome to Agentica CLI!", style="bold green"))
140
+ console.print(Text(f"Model provider: {args.model_provider}, Model name: {args.model_name}, "
141
+ f"tools: {args.tools}", style="red"))
142
+ if args.query:
143
+ response = agent.run(args.query, stream=True)
144
+ for chunk in response:
145
+ console.print(chunk.content, end="")
146
+ else:
147
+ run_interactive(agent)
148
+
149
+
150
+ if __name__ == "__main__":
151
+ main()