agentica 0.0.1__tar.gz → 0.1.0__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.
- agentica-0.1.0/PKG-INFO +199 -0
- agentica-0.1.0/README.md +175 -0
- agentica-0.1.0/agentica/__init__.py +16 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/assistant.py +33 -35
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/config.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/document.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/azure_emb.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/hash_emb.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/ollama_emb.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/openai_emb.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/text2vec_emb.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/together_emb.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/word2vec_emb.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/file/csv.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/file/txt.py +1 -1
- agentica-0.0.1/actionflow/documents.py → agentica-0.1.0/agentica/knowledge_base.py +199 -141
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/llm/anthropic_llm.py +5 -5
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/llm/azure_llm.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/llm/base.py +4 -4
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/llm/ollama_llm.py +5 -5
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/llm/openai_llm.py +8 -10
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/llm/together_llm.py +5 -5
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/memory.py +5 -5
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/message.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/python_assistant.py +4 -4
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/sqlite_storage.py +3 -3
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/task.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tool.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/airflow.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/analyze_image.py +3 -3
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/apify.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/create_image.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/duckduckgo.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/file.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/jina.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/ocr.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/run_nb_code.py +3 -3
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/run_python_code.py +2 -2
- agentica-0.1.0/agentica/tools/search_arxiv.py +124 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/search_exa.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/search_serper.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/shell.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/sql.py +2 -2
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/url_crawler.py +4 -4
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/wikipedia.py +3 -3
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/yfinance.py +1 -1
- agentica-0.1.0/agentica/utils/file_parser.py +126 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/utils/log.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/utils/misc.py +0 -42
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/utils/shell.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/vectordb/base.py +1 -1
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/vectordb/lancedb.py +9 -7
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/vectordb/pgvector.py +8 -7
- agentica-0.1.0/agentica/version.py +1 -0
- agentica-0.0.1/actionflow/actionflow.py → agentica-0.1.0/agentica/workflow.py +21 -22
- agentica-0.1.0/agentica.egg-info/PKG-INFO +199 -0
- agentica-0.1.0/agentica.egg-info/SOURCES.txt +83 -0
- agentica-0.1.0/agentica.egg-info/top_level.txt +2 -0
- {agentica-0.0.1 → agentica-0.1.0}/setup.py +4 -4
- {agentica-0.0.1 → agentica-0.1.0}/tests/test_function_create_image.py +3 -3
- {agentica-0.0.1 → agentica-0.1.0}/tests/test_function_get_url.py +3 -3
- {agentica-0.0.1 → agentica-0.1.0}/tests/test_function_save_file.py +3 -3
- agentica-0.1.0/tests/test_llm.py +31 -0
- {agentica-0.0.1 → agentica-0.1.0}/tests/test_run_nb_code.py +1 -1
- {agentica-0.0.1 → agentica-0.1.0}/tests/test_sqlite_storage.py +2 -2
- {agentica-0.0.1 → agentica-0.1.0}/tests/test_write_code.py +2 -2
- {agentica-0.0.1 → agentica-0.1.0}/tests/test_write_plan.py +4 -4
- agentica-0.0.1/PKG-INFO +0 -179
- agentica-0.0.1/README.md +0 -155
- agentica-0.0.1/actionflow/__init__.py +0 -16
- agentica-0.0.1/actionflow/version.py +0 -1
- agentica-0.0.1/agentica.egg-info/PKG-INFO +0 -179
- agentica-0.0.1/agentica.egg-info/SOURCES.txt +0 -85
- agentica-0.0.1/agentica.egg-info/top_level.txt +0 -2
- agentica-0.0.1/tests/test_flow.py +0 -183
- agentica-0.0.1/tests/test_function.py +0 -31
- agentica-0.0.1/tests/test_function_summarize_text.py +0 -63
- agentica-0.0.1/tests/test_llm.py +0 -47
- agentica-0.0.1/tests/test_output.py +0 -49
- {agentica-0.0.1 → agentica-0.1.0}/LICENSE +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/__init__.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/emb/base.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/file/__init__.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/file/base.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/llm/__init__.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/references.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/run_record.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/tools/__init__.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/utils/__init__.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/utils/timer.py +0 -0
- {agentica-0.0.1/actionflow → agentica-0.1.0/agentica}/vectordb/__init__.py +0 -0
- {agentica-0.0.1 → agentica-0.1.0}/agentica.egg-info/dependency_links.txt +0 -0
- {agentica-0.0.1 → agentica-0.1.0}/agentica.egg-info/entry_points.txt +0 -0
- {agentica-0.0.1 → agentica-0.1.0}/agentica.egg-info/not-zip-safe +0 -0
- {agentica-0.0.1 → agentica-0.1.0}/agentica.egg-info/requires.txt +0 -0
- {agentica-0.0.1 → agentica-0.1.0}/setup.cfg +0 -0
- {agentica-0.0.1 → agentica-0.1.0}/tests/__init__.py +0 -0
agentica-0.1.0/PKG-INFO
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: agentica
|
3
|
+
Version: 0.1.0
|
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
|
+
Platform: UNKNOWN
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
12
|
+
Classifier: Intended Audience :: Developers
|
13
|
+
Classifier: Intended Audience :: Education
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
16
|
+
Classifier: Operating System :: OS Independent
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
19
|
+
Requires-Python: >=3.8.0
|
20
|
+
Description-Content-Type: text/markdown
|
21
|
+
License-File: LICENSE
|
22
|
+
|
23
|
+
[**🇨🇳中文**](https://github.com/shibing624/agentica/blob/main/README.md) | [**🌐English**](https://github.com/shibing624/agentica/blob/main/README_EN.md)
|
24
|
+
|
25
|
+
<div align="center">
|
26
|
+
<a href="https://github.com/shibing624/agentica">
|
27
|
+
<img src="https://raw.githubusercontent.com/shibing624/agentica/main/docs/logo.png" height="150" alt="Logo">
|
28
|
+
</a>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
-----------------
|
32
|
+
|
33
|
+
# Agentica: Build AI Agents
|
34
|
+
[](https://badge.fury.io/py/agentica)
|
35
|
+
[](https://pepy.tech/project/agentica)
|
36
|
+
[](CONTRIBUTING.md)
|
37
|
+
[](LICENSE)
|
38
|
+
[](requirements.txt)
|
39
|
+
[](https://github.com/shibing624/agentica/issues)
|
40
|
+
[](#Contact)
|
41
|
+
|
42
|
+
|
43
|
+
**agentica**: A Human-Centric Framework for Large Language Model Agent Building.
|
44
|
+
|
45
|
+
**agentica**: 构建你自己的Agent
|
46
|
+
|
47
|
+
## Overview
|
48
|
+
|
49
|
+
#### LLM Agent
|
50
|
+

|
51
|
+
|
52
|
+
- **规划(Planning)**:任务拆解、生成计划、反思
|
53
|
+
- **记忆(Memory)**:短期记忆(prompt实现)、长期记忆(RAG实现)
|
54
|
+
- **工具使用(Tool use)**:function call能力,调用外部API,以获取外部信息,包括当前日期、日历、代码执行能力、对专用信息源的访问等
|
55
|
+
|
56
|
+
#### agentica架构
|
57
|
+

|
58
|
+
|
59
|
+
- **Planner**:负责让LLM生成一个多步计划来完成复杂任务,生成相互依赖的“链式计划”,定义每一步所依赖的上一步的输出
|
60
|
+
- **Worker**:接受“链式计划”,循环遍历计划中的每个子任务,并调用工具完成任务,可以自动反思纠错以完成任务
|
61
|
+
- **Solver**:求解器将所有这些输出整合为最终答案
|
62
|
+
|
63
|
+
## Features
|
64
|
+
`agentica`是一个Agent构建工具,功能:
|
65
|
+
|
66
|
+
- 简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Multi-Role、Workflow等功能
|
67
|
+
- Agent支持prompt自定义,支持多种工具调用(tool_calls)
|
68
|
+
- 支持OpenAI/Azure/Claude/Ollama/Together API调用
|
69
|
+
|
70
|
+
## Installation
|
71
|
+
|
72
|
+
```bash
|
73
|
+
pip install -U agentica
|
74
|
+
```
|
75
|
+
|
76
|
+
or
|
77
|
+
|
78
|
+
```bash
|
79
|
+
git clone https://github.com/shibing624/agentica.git
|
80
|
+
cd agentica
|
81
|
+
pip install .
|
82
|
+
```
|
83
|
+
|
84
|
+
## Getting Started
|
85
|
+
|
86
|
+
1. 复制[example.env](https://github.com/shibing624/agentica/blob/main/example.env)文件为`.env`,并粘贴OpenAI API key或者Moonshoot API key。
|
87
|
+
|
88
|
+
2. 使用`agentica`构建Agent,拆解任务并执行:
|
89
|
+
|
90
|
+
自动调用google搜索工具,示例[examples/web_search_demo.py](https://github.com/shibing624/agentica/blob/main/examples/web_search_demo.py)
|
91
|
+
|
92
|
+
```python
|
93
|
+
from agentica import Assistant, OpenAILLM, AzureOpenAILLM
|
94
|
+
from agentica.tools.search_serper import SearchSerperTool
|
95
|
+
|
96
|
+
m = Assistant(
|
97
|
+
llm=AzureOpenAILLM(),
|
98
|
+
description="You are a helpful ai assistant.",
|
99
|
+
show_tool_calls=True,
|
100
|
+
# Enable the assistant to search the knowledge base
|
101
|
+
search_knowledge=False,
|
102
|
+
tools=[SearchSerperTool()],
|
103
|
+
# Enable the assistant to read the chat history
|
104
|
+
read_chat_history=True,
|
105
|
+
debug_mode=True,
|
106
|
+
)
|
107
|
+
|
108
|
+
r = m.run("一句话介绍林黛玉")
|
109
|
+
print(r, "".join(r))
|
110
|
+
r = m.run("北京最近的新闻", stream=True, print_output=True)
|
111
|
+
print(r, "".join(r))
|
112
|
+
r = m.run("总结前面的问答", stream=False, print_output=False)
|
113
|
+
print(r)
|
114
|
+
```
|
115
|
+
|
116
|
+
|
117
|
+
## Examples
|
118
|
+
|
119
|
+
| 示例 | 描述 |
|
120
|
+
|---------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
|
121
|
+
| [examples/naive_rag_demo.py](https://github.com/shibing624/agentica/blob/main/examples/naive_rag_demo.py) | 实现了基础版RAG,基于Txt文档回答问题 |
|
122
|
+
| [examples/advanced_rag_demo.py](https://github.com/shibing624/agentica/blob/main/examples/advanced_rag_demo.py) | 实现了高级版RAG,基于PDF文档回答问题,新增功能:pdf文件解析、query改写,字面+语义多路召回,召回排序(rerank) |
|
123
|
+
| [examples/python_assistant_demo.py](https://github.com/shibing624/agentica/blob/main/examples/python_assistant_demo.py) | 实现了Code Interpreter功能,自动生成python代码,并执行 |
|
124
|
+
| [examples/research_demo.py](https://github.com/shibing624/agentica/blob/main/examples/research_demo.py) | 实现了Research功能,自动调用搜索工具,汇总信息后撰写科技报告 |
|
125
|
+
| [examples/team_news_article_demo.py](https://github.com/shibing624/agentica/blob/main/examples/team_news_article_demo.py) | 实现了写新闻稿的team协作,multi-role实现,委托不用角色完成各自任务:研究员检索分析文章,撰写员根据排版写文章,汇总多角色成果输出结果 |
|
126
|
+
| [examples/workflow_news_article_demo.py](https://github.com/shibing624/agentica/blob/main/examples/workflow_news_article_demo.py) | 实现了写新闻稿的工作流,multi-agent的实现,定义了多个Assistant和Task,多次调用搜索工具,并生成高级排版的新闻文章 |
|
127
|
+
| [examples/workflow_investment_demo.py](https://github.com/shibing624/agentica/blob/main/examples/workflow_investment_demo.py) | 实现了投资研究的工作流:股票信息收集 - 股票分析 - 撰写分析报告 - 复查报告等多个Task |
|
128
|
+
| [examples/crawl_webpage_demo.py](https://github.com/shibing624/agentica/blob/main/examples/crawl_webpage_demo.py) | 实现了网页分析工作流:从Url爬取融资快讯 - 分析网页内容和格式 - 提取核心信息 - 汇总保存为md文件 |
|
129
|
+
| [examples/find_paper_from_arxiv_demo.py](https://github.com/shibing624/agentica/blob/main/examples/find_paper_from_arxiv_demo.py) | 实现了论文推荐工作流:自动从arxiv搜索多组论文 - 相似论文去重 - 提取核心论文信息 - 保存为csv文件 |
|
130
|
+
| [examples/remove_image_background_demo.py](https://github.com/shibing624/agentica/blob/main/examples/remove_image_background_demo.py) | 实现了自动去除图片背景功能,包括自动通过pip安装库,调用库实现去除图片背景 |
|
131
|
+
| [examples/text_classification_demo.py](https://github.com/shibing624/agentica/blob/main/examples/text_classification_demo.py) | 实现了自动训练分类模型的工作流:读取训练集文件并理解格式 - 谷歌搜索pytextclassifier库 - 爬取github页面了解pytextclassifier的调用方法 - 写代码并执行fasttext模型训练 - check训练好的模型预测结果 |
|
132
|
+
| [examples/llm_os_demo.py](https://github.com/shibing624/agentica/blob/main/examples/llm_os_demo.py) | 实现了LLM OS的初步设计,基于LLM设计操作系统,可以通过LLM调用RAG、代码执行器、Shell等工具,并协同代码解释器、研究助手、投资助手等来解决问题。 |
|
133
|
+
|
134
|
+
|
135
|
+
### LLM OS
|
136
|
+
The LLM OS design:
|
137
|
+
<img alt="LLM OS" src="https://github.com/shibing624/agentica/blob/main/docs/llmos.png" width="600" />
|
138
|
+
|
139
|
+
#### Run the LLM OS App
|
140
|
+
|
141
|
+
```shell
|
142
|
+
cd examples
|
143
|
+
streamlit run llm_os_demo.py
|
144
|
+
```
|
145
|
+
|
146
|
+

|
147
|
+
|
148
|
+
## Contact
|
149
|
+
|
150
|
+
- Issue(建议)
|
151
|
+
:[](https://github.com/shibing624/agentica/issues)
|
152
|
+
- 邮件我:xuming: xuming624@qq.com
|
153
|
+
- 微信我: 加我*微信号:xuming624, 备注:姓名-公司-NLP* 进NLP交流群。
|
154
|
+
|
155
|
+
<img src="https://github.com/shibing624/agentica/blob/main/docs/wechat.jpeg" width="200" />
|
156
|
+
|
157
|
+
## Citation
|
158
|
+
|
159
|
+
如果你在研究中使用了`agentica`,请按如下格式引用:
|
160
|
+
|
161
|
+
APA:
|
162
|
+
|
163
|
+
```
|
164
|
+
Xu, M. agentica: A Human-Centric Framework for Large Language Model Agent Workflows (Version 0.0.2) [Computer software]. https://github.com/shibing624/agentica
|
165
|
+
```
|
166
|
+
|
167
|
+
BibTeX:
|
168
|
+
|
169
|
+
```
|
170
|
+
@misc{Xu_agentica,
|
171
|
+
title={agentica: A Human-Centric Framework for Large Language Model Agent Workflows},
|
172
|
+
author={Xu Ming},
|
173
|
+
year={2024},
|
174
|
+
howpublished={\url{https://github.com/shibing624/agentica}},
|
175
|
+
}
|
176
|
+
```
|
177
|
+
|
178
|
+
## License
|
179
|
+
|
180
|
+
授权协议为 [The Apache License 2.0](/LICENSE),可免费用做商业用途。请在产品说明中附加`agentica`的链接和授权协议。
|
181
|
+
## Contribute
|
182
|
+
|
183
|
+
项目代码还很粗糙,如果大家对代码有所改进,欢迎提交回本项目,在提交之前,注意以下两点:
|
184
|
+
|
185
|
+
- 在`tests`添加相应的单元测试
|
186
|
+
- 使用`python -m pytest`来运行所有单元测试,确保所有单测都是通过的
|
187
|
+
|
188
|
+
之后即可提交PR。
|
189
|
+
|
190
|
+
## Acknowledgements
|
191
|
+
|
192
|
+
- [https://github.com/langchain-ai/langchain](https://github.com/langchain-ai/langchain)
|
193
|
+
- [https://github.com/simonmesmith/agentflow](https://github.com/simonmesmith/agentflow)
|
194
|
+
- [https://github.com/phidatahq/phidata](https://github.com/phidatahq/phidata)
|
195
|
+
|
196
|
+
|
197
|
+
Thanks for their great work!
|
198
|
+
|
199
|
+
|
agentica-0.1.0/README.md
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
[**🇨🇳中文**](https://github.com/shibing624/agentica/blob/main/README.md) | [**🌐English**](https://github.com/shibing624/agentica/blob/main/README_EN.md)
|
2
|
+
|
3
|
+
<div align="center">
|
4
|
+
<a href="https://github.com/shibing624/agentica">
|
5
|
+
<img src="https://raw.githubusercontent.com/shibing624/agentica/main/docs/logo.png" height="150" alt="Logo">
|
6
|
+
</a>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
-----------------
|
10
|
+
|
11
|
+
# Agentica: Build AI Agents
|
12
|
+
[](https://badge.fury.io/py/agentica)
|
13
|
+
[](https://pepy.tech/project/agentica)
|
14
|
+
[](CONTRIBUTING.md)
|
15
|
+
[](LICENSE)
|
16
|
+
[](requirements.txt)
|
17
|
+
[](https://github.com/shibing624/agentica/issues)
|
18
|
+
[](#Contact)
|
19
|
+
|
20
|
+
|
21
|
+
**agentica**: A Human-Centric Framework for Large Language Model Agent Building.
|
22
|
+
|
23
|
+
**agentica**: 构建你自己的Agent
|
24
|
+
|
25
|
+
## Overview
|
26
|
+
|
27
|
+
#### LLM Agent
|
28
|
+

|
29
|
+
|
30
|
+
- **规划(Planning)**:任务拆解、生成计划、反思
|
31
|
+
- **记忆(Memory)**:短期记忆(prompt实现)、长期记忆(RAG实现)
|
32
|
+
- **工具使用(Tool use)**:function call能力,调用外部API,以获取外部信息,包括当前日期、日历、代码执行能力、对专用信息源的访问等
|
33
|
+
|
34
|
+
#### agentica架构
|
35
|
+

|
36
|
+
|
37
|
+
- **Planner**:负责让LLM生成一个多步计划来完成复杂任务,生成相互依赖的“链式计划”,定义每一步所依赖的上一步的输出
|
38
|
+
- **Worker**:接受“链式计划”,循环遍历计划中的每个子任务,并调用工具完成任务,可以自动反思纠错以完成任务
|
39
|
+
- **Solver**:求解器将所有这些输出整合为最终答案
|
40
|
+
|
41
|
+
## Features
|
42
|
+
`agentica`是一个Agent构建工具,功能:
|
43
|
+
|
44
|
+
- 简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Multi-Role、Workflow等功能
|
45
|
+
- Agent支持prompt自定义,支持多种工具调用(tool_calls)
|
46
|
+
- 支持OpenAI/Azure/Claude/Ollama/Together API调用
|
47
|
+
|
48
|
+
## Installation
|
49
|
+
|
50
|
+
```bash
|
51
|
+
pip install -U agentica
|
52
|
+
```
|
53
|
+
|
54
|
+
or
|
55
|
+
|
56
|
+
```bash
|
57
|
+
git clone https://github.com/shibing624/agentica.git
|
58
|
+
cd agentica
|
59
|
+
pip install .
|
60
|
+
```
|
61
|
+
|
62
|
+
## Getting Started
|
63
|
+
|
64
|
+
1. 复制[example.env](https://github.com/shibing624/agentica/blob/main/example.env)文件为`.env`,并粘贴OpenAI API key或者Moonshoot API key。
|
65
|
+
|
66
|
+
2. 使用`agentica`构建Agent,拆解任务并执行:
|
67
|
+
|
68
|
+
自动调用google搜索工具,示例[examples/web_search_demo.py](https://github.com/shibing624/agentica/blob/main/examples/web_search_demo.py)
|
69
|
+
|
70
|
+
```python
|
71
|
+
from agentica import Assistant, OpenAILLM, AzureOpenAILLM
|
72
|
+
from agentica.tools.search_serper import SearchSerperTool
|
73
|
+
|
74
|
+
m = Assistant(
|
75
|
+
llm=AzureOpenAILLM(),
|
76
|
+
description="You are a helpful ai assistant.",
|
77
|
+
show_tool_calls=True,
|
78
|
+
# Enable the assistant to search the knowledge base
|
79
|
+
search_knowledge=False,
|
80
|
+
tools=[SearchSerperTool()],
|
81
|
+
# Enable the assistant to read the chat history
|
82
|
+
read_chat_history=True,
|
83
|
+
debug_mode=True,
|
84
|
+
)
|
85
|
+
|
86
|
+
r = m.run("一句话介绍林黛玉")
|
87
|
+
print(r, "".join(r))
|
88
|
+
r = m.run("北京最近的新闻", stream=True, print_output=True)
|
89
|
+
print(r, "".join(r))
|
90
|
+
r = m.run("总结前面的问答", stream=False, print_output=False)
|
91
|
+
print(r)
|
92
|
+
```
|
93
|
+
|
94
|
+
|
95
|
+
## Examples
|
96
|
+
|
97
|
+
| 示例 | 描述 |
|
98
|
+
|---------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
|
99
|
+
| [examples/naive_rag_demo.py](https://github.com/shibing624/agentica/blob/main/examples/naive_rag_demo.py) | 实现了基础版RAG,基于Txt文档回答问题 |
|
100
|
+
| [examples/advanced_rag_demo.py](https://github.com/shibing624/agentica/blob/main/examples/advanced_rag_demo.py) | 实现了高级版RAG,基于PDF文档回答问题,新增功能:pdf文件解析、query改写,字面+语义多路召回,召回排序(rerank) |
|
101
|
+
| [examples/python_assistant_demo.py](https://github.com/shibing624/agentica/blob/main/examples/python_assistant_demo.py) | 实现了Code Interpreter功能,自动生成python代码,并执行 |
|
102
|
+
| [examples/research_demo.py](https://github.com/shibing624/agentica/blob/main/examples/research_demo.py) | 实现了Research功能,自动调用搜索工具,汇总信息后撰写科技报告 |
|
103
|
+
| [examples/team_news_article_demo.py](https://github.com/shibing624/agentica/blob/main/examples/team_news_article_demo.py) | 实现了写新闻稿的team协作,multi-role实现,委托不用角色完成各自任务:研究员检索分析文章,撰写员根据排版写文章,汇总多角色成果输出结果 |
|
104
|
+
| [examples/workflow_news_article_demo.py](https://github.com/shibing624/agentica/blob/main/examples/workflow_news_article_demo.py) | 实现了写新闻稿的工作流,multi-agent的实现,定义了多个Assistant和Task,多次调用搜索工具,并生成高级排版的新闻文章 |
|
105
|
+
| [examples/workflow_investment_demo.py](https://github.com/shibing624/agentica/blob/main/examples/workflow_investment_demo.py) | 实现了投资研究的工作流:股票信息收集 - 股票分析 - 撰写分析报告 - 复查报告等多个Task |
|
106
|
+
| [examples/crawl_webpage_demo.py](https://github.com/shibing624/agentica/blob/main/examples/crawl_webpage_demo.py) | 实现了网页分析工作流:从Url爬取融资快讯 - 分析网页内容和格式 - 提取核心信息 - 汇总保存为md文件 |
|
107
|
+
| [examples/find_paper_from_arxiv_demo.py](https://github.com/shibing624/agentica/blob/main/examples/find_paper_from_arxiv_demo.py) | 实现了论文推荐工作流:自动从arxiv搜索多组论文 - 相似论文去重 - 提取核心论文信息 - 保存为csv文件 |
|
108
|
+
| [examples/remove_image_background_demo.py](https://github.com/shibing624/agentica/blob/main/examples/remove_image_background_demo.py) | 实现了自动去除图片背景功能,包括自动通过pip安装库,调用库实现去除图片背景 |
|
109
|
+
| [examples/text_classification_demo.py](https://github.com/shibing624/agentica/blob/main/examples/text_classification_demo.py) | 实现了自动训练分类模型的工作流:读取训练集文件并理解格式 - 谷歌搜索pytextclassifier库 - 爬取github页面了解pytextclassifier的调用方法 - 写代码并执行fasttext模型训练 - check训练好的模型预测结果 |
|
110
|
+
| [examples/llm_os_demo.py](https://github.com/shibing624/agentica/blob/main/examples/llm_os_demo.py) | 实现了LLM OS的初步设计,基于LLM设计操作系统,可以通过LLM调用RAG、代码执行器、Shell等工具,并协同代码解释器、研究助手、投资助手等来解决问题。 |
|
111
|
+
|
112
|
+
|
113
|
+
### LLM OS
|
114
|
+
The LLM OS design:
|
115
|
+
<img alt="LLM OS" src="https://github.com/shibing624/agentica/blob/main/docs/llmos.png" width="600" />
|
116
|
+
|
117
|
+
#### Run the LLM OS App
|
118
|
+
|
119
|
+
```shell
|
120
|
+
cd examples
|
121
|
+
streamlit run llm_os_demo.py
|
122
|
+
```
|
123
|
+
|
124
|
+

|
125
|
+
|
126
|
+
## Contact
|
127
|
+
|
128
|
+
- Issue(建议)
|
129
|
+
:[](https://github.com/shibing624/agentica/issues)
|
130
|
+
- 邮件我:xuming: xuming624@qq.com
|
131
|
+
- 微信我: 加我*微信号:xuming624, 备注:姓名-公司-NLP* 进NLP交流群。
|
132
|
+
|
133
|
+
<img src="https://github.com/shibing624/agentica/blob/main/docs/wechat.jpeg" width="200" />
|
134
|
+
|
135
|
+
## Citation
|
136
|
+
|
137
|
+
如果你在研究中使用了`agentica`,请按如下格式引用:
|
138
|
+
|
139
|
+
APA:
|
140
|
+
|
141
|
+
```
|
142
|
+
Xu, M. agentica: A Human-Centric Framework for Large Language Model Agent Workflows (Version 0.0.2) [Computer software]. https://github.com/shibing624/agentica
|
143
|
+
```
|
144
|
+
|
145
|
+
BibTeX:
|
146
|
+
|
147
|
+
```
|
148
|
+
@misc{Xu_agentica,
|
149
|
+
title={agentica: A Human-Centric Framework for Large Language Model Agent Workflows},
|
150
|
+
author={Xu Ming},
|
151
|
+
year={2024},
|
152
|
+
howpublished={\url{https://github.com/shibing624/agentica}},
|
153
|
+
}
|
154
|
+
```
|
155
|
+
|
156
|
+
## License
|
157
|
+
|
158
|
+
授权协议为 [The Apache License 2.0](/LICENSE),可免费用做商业用途。请在产品说明中附加`agentica`的链接和授权协议。
|
159
|
+
## Contribute
|
160
|
+
|
161
|
+
项目代码还很粗糙,如果大家对代码有所改进,欢迎提交回本项目,在提交之前,注意以下两点:
|
162
|
+
|
163
|
+
- 在`tests`添加相应的单元测试
|
164
|
+
- 使用`python -m pytest`来运行所有单元测试,确保所有单测都是通过的
|
165
|
+
|
166
|
+
之后即可提交PR。
|
167
|
+
|
168
|
+
## Acknowledgements
|
169
|
+
|
170
|
+
- [https://github.com/langchain-ai/langchain](https://github.com/langchain-ai/langchain)
|
171
|
+
- [https://github.com/simonmesmith/agentflow](https://github.com/simonmesmith/agentflow)
|
172
|
+
- [https://github.com/phidatahq/phidata](https://github.com/phidatahq/phidata)
|
173
|
+
|
174
|
+
|
175
|
+
Thanks for their great work!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
@author:XuMing(xuming624@qq.com)
|
4
|
+
@description:
|
5
|
+
"""
|
6
|
+
from agentica.version import __version__ # noqa, isort: skip
|
7
|
+
from agentica.config import DOTENV_PATH, SMART_LLM, FAST_LLM # noqa, isort: skip
|
8
|
+
from agentica.assistant import Assistant
|
9
|
+
from agentica.python_assistant import PythonAssistant
|
10
|
+
from agentica.document import Document
|
11
|
+
from agentica.knowledge_base import KnowledgeBase
|
12
|
+
from agentica.llm.openai_llm import OpenAILLM
|
13
|
+
from agentica.llm.azure_llm import AzureOpenAILLM
|
14
|
+
from agentica.task import Task
|
15
|
+
from agentica.workflow import Workflow
|
16
|
+
|
@@ -28,18 +28,18 @@ from uuid import uuid4
|
|
28
28
|
|
29
29
|
from pydantic import BaseModel, ConfigDict, field_validator, ValidationError
|
30
30
|
|
31
|
-
from
|
32
|
-
from
|
33
|
-
from
|
34
|
-
from
|
35
|
-
from
|
36
|
-
from
|
37
|
-
from
|
38
|
-
from
|
39
|
-
from
|
40
|
-
from
|
41
|
-
from
|
42
|
-
from
|
31
|
+
from agentica.document import Document
|
32
|
+
from agentica.knowledge_base import KnowledgeBase
|
33
|
+
from agentica.llm.base import LLM
|
34
|
+
from agentica.memory import AssistantMemory, Memory
|
35
|
+
from agentica.message import Message
|
36
|
+
from agentica.references import References
|
37
|
+
from agentica.run_record import RunRecord
|
38
|
+
from agentica.sqlite_storage import SqliteStorage
|
39
|
+
from agentica.tool import Tool, Toolkit, Function
|
40
|
+
from agentica.utils.log import logger, set_log_level_to_debug, print_llm_stream
|
41
|
+
from agentica.utils.misc import merge_dictionaries, remove_indent
|
42
|
+
from agentica.utils.timer import Timer
|
43
43
|
|
44
44
|
|
45
45
|
class Assistant(BaseModel):
|
@@ -81,7 +81,7 @@ class Assistant(BaseModel):
|
|
81
81
|
update_memory_after_run: bool = True
|
82
82
|
|
83
83
|
# -*- Assistant Knowledge Base
|
84
|
-
knowledge_base: Optional[
|
84
|
+
knowledge_base: Optional[KnowledgeBase] = None
|
85
85
|
# Enable RAG by adding references from the knowledge base to the prompt.
|
86
86
|
add_references_to_prompt: bool = False
|
87
87
|
|
@@ -269,7 +269,7 @@ class Assistant(BaseModel):
|
|
269
269
|
def update_llm(self) -> None:
|
270
270
|
if self.llm is None:
|
271
271
|
try:
|
272
|
-
from
|
272
|
+
from agentica.llm.openai_llm import OpenAILLM
|
273
273
|
except ModuleNotFoundError as e:
|
274
274
|
logger.exception(e)
|
275
275
|
logger.error("use `openai` as the default LLM. ")
|
@@ -790,6 +790,7 @@ class Assistant(BaseModel):
|
|
790
790
|
*,
|
791
791
|
stream: bool = True,
|
792
792
|
messages: Optional[List[Union[Dict, Message]]] = None,
|
793
|
+
print_output: bool = True,
|
793
794
|
**kwargs: Any,
|
794
795
|
) -> Iterator[str]:
|
795
796
|
logger.debug(f"*********** Assistant Run Start: {self.run_id} ***********")
|
@@ -865,6 +866,8 @@ class Assistant(BaseModel):
|
|
865
866
|
self.llm = cast(LLM, self.llm)
|
866
867
|
if stream and self.streamable:
|
867
868
|
for response_chunk in self.llm.response_stream(messages=llm_messages):
|
869
|
+
if print_output:
|
870
|
+
print_llm_stream(response_chunk)
|
868
871
|
llm_response += response_chunk
|
869
872
|
yield response_chunk
|
870
873
|
else:
|
@@ -922,6 +925,8 @@ class Assistant(BaseModel):
|
|
922
925
|
|
923
926
|
# -*- Yield final response if not streaming
|
924
927
|
if not stream:
|
928
|
+
if print_output:
|
929
|
+
print(llm_response)
|
925
930
|
yield llm_response
|
926
931
|
|
927
932
|
def run(
|
@@ -929,8 +934,8 @@ class Assistant(BaseModel):
|
|
929
934
|
message: Optional[Union[List, Dict, str]] = None,
|
930
935
|
*,
|
931
936
|
stream: bool = True,
|
932
|
-
print_output: bool = True,
|
933
937
|
messages: Optional[List[Union[Dict, Message]]] = None,
|
938
|
+
print_output: bool = True,
|
934
939
|
**kwargs: Any,
|
935
940
|
) -> Union[Iterator[str], str, BaseModel]:
|
936
941
|
# Convert response to structured output if output_model is set
|
@@ -959,16 +964,11 @@ class Assistant(BaseModel):
|
|
959
964
|
return self.output or json_resp
|
960
965
|
else:
|
961
966
|
if stream and self.streamable:
|
962
|
-
resp = self._run(message=message, messages=messages, stream=True, **kwargs)
|
963
|
-
if print_output:
|
964
|
-
for chunk in resp:
|
965
|
-
print_llm_stream(chunk)
|
967
|
+
resp = self._run(message=message, messages=messages, stream=True, print_output=print_output, **kwargs)
|
966
968
|
return resp
|
967
969
|
else:
|
968
|
-
resp = self._run(message=message, messages=messages, stream=False, **kwargs)
|
970
|
+
resp = self._run(message=message, messages=messages, stream=False, print_output=print_output, **kwargs)
|
969
971
|
resp = next(resp)
|
970
|
-
if print_output:
|
971
|
-
print(resp)
|
972
972
|
return resp
|
973
973
|
|
974
974
|
async def _arun(
|
@@ -977,6 +977,7 @@ class Assistant(BaseModel):
|
|
977
977
|
*,
|
978
978
|
stream: bool = True,
|
979
979
|
messages: Optional[List[Union[Dict, Message]]] = None,
|
980
|
+
print_output: bool = True,
|
980
981
|
**kwargs: Any,
|
981
982
|
) -> AsyncIterator[str]:
|
982
983
|
logger.debug(f"*********** Run Start: {self.run_id} ***********")
|
@@ -1055,6 +1056,8 @@ class Assistant(BaseModel):
|
|
1055
1056
|
response_stream = self.llm.aresponse_stream(messages=llm_messages)
|
1056
1057
|
async for response_chunk in response_stream: # type: ignore
|
1057
1058
|
llm_response += response_chunk
|
1059
|
+
if print_output:
|
1060
|
+
print_llm_stream(response_chunk)
|
1058
1061
|
yield response_chunk
|
1059
1062
|
else:
|
1060
1063
|
llm_response = await self.llm.aresponse(messages=llm_messages)
|
@@ -1089,6 +1092,8 @@ class Assistant(BaseModel):
|
|
1089
1092
|
|
1090
1093
|
# -*- Yield final response if not streaming
|
1091
1094
|
if not stream:
|
1095
|
+
if print_output:
|
1096
|
+
print(llm_response)
|
1092
1097
|
yield llm_response
|
1093
1098
|
|
1094
1099
|
async def arun(
|
@@ -1096,8 +1101,8 @@ class Assistant(BaseModel):
|
|
1096
1101
|
message: Optional[Union[List, Dict, str]] = None,
|
1097
1102
|
*,
|
1098
1103
|
stream: bool = True,
|
1099
|
-
print_output: bool = True,
|
1100
1104
|
messages: Optional[List[Union[Dict, Message]]] = None,
|
1105
|
+
print_output: bool = True,
|
1101
1106
|
**kwargs: Any,
|
1102
1107
|
) -> Union[AsyncIterator[str], str, BaseModel]:
|
1103
1108
|
# Convert response to structured output if output_model is set
|
@@ -1127,17 +1132,11 @@ class Assistant(BaseModel):
|
|
1127
1132
|
return self.output or json_resp
|
1128
1133
|
else:
|
1129
1134
|
if stream and self.streamable:
|
1130
|
-
resp = self._arun(message=message, messages=messages, stream=True, **kwargs)
|
1131
|
-
if print_output:
|
1132
|
-
async for chunk in resp:
|
1133
|
-
print_llm_stream(chunk)
|
1135
|
+
resp = self._arun(message=message, messages=messages, stream=True, print_output=print_output, **kwargs)
|
1134
1136
|
return resp
|
1135
1137
|
else:
|
1136
|
-
resp = self._arun(message=message, messages=messages, stream=False, **kwargs)
|
1137
|
-
|
1138
|
-
if print_output:
|
1139
|
-
print(r)
|
1140
|
-
return r
|
1138
|
+
resp = self._arun(message=message, messages=messages, stream=False, print_output=print_output, **kwargs)
|
1139
|
+
return await resp.__anext__()
|
1141
1140
|
|
1142
1141
|
def chat(
|
1143
1142
|
self, message: Union[List, Dict, str], stream: bool = True, **kwargs: Any
|
@@ -1334,7 +1333,6 @@ class Assistant(BaseModel):
|
|
1334
1333
|
user: str = "User",
|
1335
1334
|
emoji: str = ":sunglasses:",
|
1336
1335
|
stream: bool = True,
|
1337
|
-
markdown: bool = False,
|
1338
1336
|
exit_on: Optional[List[str]] = None,
|
1339
1337
|
**kwargs: Any,
|
1340
1338
|
) -> None:
|
@@ -1342,11 +1340,11 @@ class Assistant(BaseModel):
|
|
1342
1340
|
_exit_on = exit_on or ["exit", "quit", "bye"]
|
1343
1341
|
logger.debug(f"Enable cli, exit with {_exit_on[0]}")
|
1344
1342
|
if message:
|
1345
|
-
self.run(message=message, stream=stream,
|
1343
|
+
self.run(message=message, stream=stream, **kwargs)
|
1346
1344
|
|
1347
1345
|
while True:
|
1348
1346
|
message = Prompt.ask(f"[bold] {emoji} {user} [/bold]")
|
1349
1347
|
if message in _exit_on:
|
1350
1348
|
break
|
1351
1349
|
|
1352
|
-
self.run(message=message, stream=stream,
|
1350
|
+
self.run(message=message, stream=stream, **kwargs)
|
@@ -19,10 +19,10 @@ try:
|
|
19
19
|
except ImportError:
|
20
20
|
logger.debug("dotenv not installed, skipping...")
|
21
21
|
|
22
|
-
|
22
|
+
AGENTICA_HOME = os.environ.get("AGENTICA_HOME", os.path.realpath(os.path.curdir))
|
23
23
|
current_date = datetime.now()
|
24
24
|
formatted_date = current_date.strftime("%Y%m%d")
|
25
|
-
LOG_FILE = os.environ.get("LOG_FILE", f"{
|
25
|
+
LOG_FILE = os.environ.get("LOG_FILE", f"{AGENTICA_HOME}/logs/{formatted_date}.log")
|
26
26
|
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
|
27
27
|
SMART_LLM = os.environ.get("SMART_LLM")
|
28
28
|
FAST_LLM = os.environ.get("FAST_LLM")
|
@@ -8,8 +8,8 @@ from os import getenv
|
|
8
8
|
from typing import Optional, Dict, List, Tuple, Any
|
9
9
|
from typing_extensions import Literal
|
10
10
|
|
11
|
-
from
|
12
|
-
from
|
11
|
+
from agentica.emb.base import Emb
|
12
|
+
from agentica.utils.log import logger
|
13
13
|
|
14
14
|
try:
|
15
15
|
from openai import AzureOpenAI as AzureOpenAIClient
|
@@ -6,8 +6,8 @@ part of the code from https://github.com/phidatahq/phidata
|
|
6
6
|
"""
|
7
7
|
from typing import Optional, Dict, List, Any
|
8
8
|
|
9
|
-
from
|
10
|
-
from
|
9
|
+
from agentica.emb.base import Emb
|
10
|
+
from agentica.utils.log import logger
|
11
11
|
|
12
12
|
try:
|
13
13
|
from ollama import Client as OllamaClient
|
@@ -9,8 +9,8 @@ from typing import Optional, Dict, List, Tuple, Any
|
|
9
9
|
|
10
10
|
from typing_extensions import Literal
|
11
11
|
|
12
|
-
from
|
13
|
-
from
|
12
|
+
from agentica.emb.base import Emb
|
13
|
+
from agentica.utils.log import logger
|
14
14
|
|
15
15
|
try:
|
16
16
|
from openai import OpenAI as OpenAIClient
|