adam-community 1.0.12__py3-none-any.whl → 1.0.14__py3-none-any.whl
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.
- adam_community/__version__.py +1 -1
- adam_community/cli/build.py +2 -2
- adam_community/cli/cli.py +1 -0
- adam_community/cli/init.py +62 -16
- adam_community/cli/templates/README_agent.md.j2 +338 -0
- adam_community/cli/templates/agent_python.py.j2 +139 -0
- adam_community/cli/templates/initial_assistant_message.md.j2 +4 -4
- adam_community/cli/templates/rag_python.py.j2 +76 -0
- {adam_community-1.0.12.dist-info → adam_community-1.0.14.dist-info}/METADATA +1 -1
- {adam_community-1.0.12.dist-info → adam_community-1.0.14.dist-info}/RECORD +13 -10
- {adam_community-1.0.12.dist-info → adam_community-1.0.14.dist-info}/WHEEL +0 -0
- {adam_community-1.0.12.dist-info → adam_community-1.0.14.dist-info}/entry_points.txt +0 -0
- {adam_community-1.0.12.dist-info → adam_community-1.0.14.dist-info}/top_level.txt +0 -0
adam_community/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.0.
|
|
1
|
+
__version__ = "1.0.14"
|
adam_community/cli/build.py
CHANGED
|
@@ -54,9 +54,9 @@ def check_python_files(directory: Path) -> Tuple[bool, List[str]]:
|
|
|
54
54
|
# 检查参数类型是否都是有效的JSON Schema类型
|
|
55
55
|
param_errors = []
|
|
56
56
|
for param_name, param_info in func_info["parameters"]["properties"].items():
|
|
57
|
-
if "type" not in param_info:
|
|
57
|
+
if "type" not in param_info and "oneOf" not in param_info:
|
|
58
58
|
param_errors.append(f"参数 '{param_name}' 缺少类型定义")
|
|
59
|
-
elif param_info["type"] not in ["string", "integer", "number", "boolean", "array", "object", "null"]:
|
|
59
|
+
elif "type" in param_info and param_info["type"] not in ["string", "integer", "number", "boolean", "array", "object", "null"]:
|
|
60
60
|
param_errors.append(f"参数 '{param_name}' 类型 '{param_info['type']}' 不是有效的JSON Schema类型")
|
|
61
61
|
|
|
62
62
|
if param_errors:
|
adam_community/cli/cli.py
CHANGED
adam_community/cli/init.py
CHANGED
|
@@ -4,6 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
from jinja2 import Environment, FileSystemLoader
|
|
5
5
|
from typing import Dict, Any
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
@click.command()
|
|
8
9
|
@click.option('--name', prompt='项目名称(仅支持字母、数字、连字符,不能有空格)', help='项目的英文名称(用于文件夹和配置)')
|
|
9
10
|
@click.option('--display-name', prompt='显示名称', help='项目的中文显示名称')
|
|
@@ -11,11 +12,11 @@ from typing import Dict, Any
|
|
|
11
12
|
@click.option('--version', default='1.0.0', prompt='版本号', help='项目版本号')
|
|
12
13
|
@click.option('--author', prompt='作者', help='项目作者')
|
|
13
14
|
@click.option('--type',
|
|
14
|
-
type=click.Choice(['kit', '
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
type=click.Choice(['kit', 'agent'], case_sensitive=False),
|
|
16
|
+
help='选择项目类型: kit(表单工具) 或 agent(智能体工具)')
|
|
17
|
+
@click.option('--collection', help='知识库名称(仅当启用 RAG 功能时使用)')
|
|
17
18
|
@click.argument('directory', type=click.Path(exists=True, file_okay=False, dir_okay=True), default='.')
|
|
18
|
-
def init(name: str, display_name: str, description: str, version: str, author: str, type: str, directory: str):
|
|
19
|
+
def init(name: str, display_name: str, description: str, version: str, author: str, type: str, collection: str, directory: str):
|
|
19
20
|
"""初始化一个新的 Adam 工具项目"""
|
|
20
21
|
|
|
21
22
|
# 验证项目名称格式
|
|
@@ -25,6 +26,17 @@ def init(name: str, display_name: str, description: str, version: str, author: s
|
|
|
25
26
|
click.echo("示例: my-tool, data-processor, image-analyzer")
|
|
26
27
|
return
|
|
27
28
|
|
|
29
|
+
# 如果没有提供项目类型,显示选择菜单
|
|
30
|
+
if not type:
|
|
31
|
+
type = select_project_type()
|
|
32
|
+
|
|
33
|
+
# 如果是 agent 类型,询问是否需要 RAG 功能
|
|
34
|
+
enable_rag = False
|
|
35
|
+
if type == 'agent':
|
|
36
|
+
enable_rag = click.confirm('是否需要启用 RAG 知识库搜索功能?', default=False)
|
|
37
|
+
if enable_rag and not collection:
|
|
38
|
+
collection = click.prompt('知识库名称')
|
|
39
|
+
|
|
28
40
|
directory_path = Path(directory)
|
|
29
41
|
project_path = directory_path / name
|
|
30
42
|
|
|
@@ -52,7 +64,11 @@ def init(name: str, display_name: str, description: str, version: str, author: s
|
|
|
52
64
|
'description': description,
|
|
53
65
|
'version': version,
|
|
54
66
|
'author': author,
|
|
55
|
-
'project_type': type
|
|
67
|
+
'project_type': type,
|
|
68
|
+
'enable_rag': enable_rag,
|
|
69
|
+
'collection_name': collection if enable_rag else '',
|
|
70
|
+
'class_name': name.replace('-', '_').title(),
|
|
71
|
+
'rag_class_name': name.replace('-', '_').replace('_', '').title() + 'RAG' if enable_rag else ''
|
|
56
72
|
}
|
|
57
73
|
|
|
58
74
|
# 生成配置文件
|
|
@@ -65,8 +81,11 @@ def init(name: str, display_name: str, description: str, version: str, author: s
|
|
|
65
81
|
|
|
66
82
|
if type == 'kit':
|
|
67
83
|
generate_kit_files(env, project_path, config_path, template_vars)
|
|
68
|
-
else:
|
|
69
|
-
|
|
84
|
+
else: # agent
|
|
85
|
+
generate_agent_files(env, project_path, config_path, template_vars)
|
|
86
|
+
# 如果启用了 RAG 功能,额外生成 RAG 文件
|
|
87
|
+
if enable_rag:
|
|
88
|
+
generate_rag_files(env, project_path, config_path, template_vars)
|
|
70
89
|
|
|
71
90
|
# 生成 Makefile
|
|
72
91
|
render_and_save(env, 'Makefile.j2', project_path / "Makefile", template_vars)
|
|
@@ -75,8 +94,8 @@ def init(name: str, display_name: str, description: str, version: str, author: s
|
|
|
75
94
|
# 生成 README 文件
|
|
76
95
|
if type == 'kit':
|
|
77
96
|
render_and_save(env, 'README_kit.md.j2', project_path / "README.md", template_vars)
|
|
78
|
-
else:
|
|
79
|
-
render_and_save(env, '
|
|
97
|
+
else: # agent
|
|
98
|
+
render_and_save(env, 'README_agent.md.j2', project_path / "README.md", template_vars)
|
|
80
99
|
click.echo(f"生成项目文档: README.md")
|
|
81
100
|
|
|
82
101
|
click.echo(f"\n✅ 项目 '{name}' 初始化完成!")
|
|
@@ -88,10 +107,12 @@ def init(name: str, display_name: str, description: str, version: str, author: s
|
|
|
88
107
|
click.echo("3. 📝 自定义 config/input.json 表单配置")
|
|
89
108
|
else:
|
|
90
109
|
click.echo("3. 🤖 自定义 config/initial_system_prompt.md 和 config/initial_assistant_message.md")
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
click.echo("
|
|
94
|
-
click.echo(f"
|
|
110
|
+
if enable_rag:
|
|
111
|
+
click.echo("4. 🔍 根据需要修改 RAG 知识库搜索功能")
|
|
112
|
+
click.echo(f"{4 if type == 'kit' else 5}. 📄 完善 config/long_description.md 描述文档")
|
|
113
|
+
click.echo(f"{5 if type == 'kit' else 6}. ⚙️ 运行 'make parse' 生成 functions.json")
|
|
114
|
+
click.echo(f"{6 if type == 'kit' else 7}. 📦 运行 'make build' 打包项目")
|
|
115
|
+
click.echo(f"\n💡 详细的开发指南请查看: https://sidereus-ai.feishu.cn/wiki/FVMowiyGCi4qYGkr131cPNzVnQd")
|
|
95
116
|
|
|
96
117
|
|
|
97
118
|
def render_and_save(env: Environment, template_name: str, output_path: Path, template_vars: Dict[str, Any]):
|
|
@@ -115,8 +136,8 @@ def generate_kit_files(env: Environment, project_path: Path, config_path: Path,
|
|
|
115
136
|
click.echo(f"生成主要实现文件: {python_filename}")
|
|
116
137
|
|
|
117
138
|
|
|
118
|
-
def
|
|
119
|
-
"""生成
|
|
139
|
+
def generate_agent_files(env: Environment, project_path: Path, config_path: Path, template_vars: Dict[str, Any]):
|
|
140
|
+
"""生成 agent 项目的特定文件"""
|
|
120
141
|
|
|
121
142
|
# 生成 initial_system_prompt.md
|
|
122
143
|
render_and_save(env, 'initial_system_prompt.md.j2', config_path / "initial_system_prompt.md", template_vars)
|
|
@@ -128,10 +149,35 @@ def generate_toolbox_files(env: Environment, project_path: Path, config_path: Pa
|
|
|
128
149
|
|
|
129
150
|
# 生成主要的Python实现文件
|
|
130
151
|
python_filename = f"{template_vars['name'].replace('-', '_')}.py"
|
|
131
|
-
render_and_save(env, '
|
|
152
|
+
render_and_save(env, 'agent_python.py.j2', project_path / python_filename, template_vars)
|
|
132
153
|
click.echo(f"生成主要实现文件: {python_filename}")
|
|
133
154
|
|
|
134
155
|
|
|
156
|
+
def generate_rag_files(env: Environment, project_path: Path, config_path: Path, template_vars: Dict[str, Any]):
|
|
157
|
+
"""生成 RAG 功能的额外文件"""
|
|
158
|
+
|
|
159
|
+
# 生成 RAG 功能的 Python 实现文件
|
|
160
|
+
rag_filename = f"{template_vars['name'].replace('-', '_')}_rag.py"
|
|
161
|
+
render_and_save(env, 'rag_python.py.j2', project_path / rag_filename, template_vars)
|
|
162
|
+
click.echo(f"生成 RAG 功能文件: {rag_filename}")
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def select_project_type() -> str:
|
|
166
|
+
"""显示项目类型选择菜单"""
|
|
167
|
+
click.echo("\n请选择项目类型:")
|
|
168
|
+
click.echo("1. kit (表单工具)")
|
|
169
|
+
click.echo("2. agent (智能体工具)")
|
|
170
|
+
|
|
171
|
+
while True:
|
|
172
|
+
choice = click.prompt("请输入选项编号 (1 或 2)", type=str)
|
|
173
|
+
if choice == '1':
|
|
174
|
+
return 'kit'
|
|
175
|
+
elif choice == '2':
|
|
176
|
+
return 'agent'
|
|
177
|
+
else:
|
|
178
|
+
click.echo("❌ 无效选择,请输入 1 或 2")
|
|
179
|
+
|
|
180
|
+
|
|
135
181
|
def validate_project_name(name: str) -> bool:
|
|
136
182
|
"""验证项目名称格式"""
|
|
137
183
|
# 项目名称只能包含字母、数字和连字符,不能有空格
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# {{ display_name }}
|
|
2
|
+
|
|
3
|
+
{{ description }}
|
|
4
|
+
|
|
5
|
+
这是一个基于 Adam Tool Protocol (ATP) 开发的 Toolbox 智能体项目,通过对话方式为用户提供智能化服务。
|
|
6
|
+
|
|
7
|
+
## 项目信息
|
|
8
|
+
|
|
9
|
+
- **项目名称**: {{ name }}
|
|
10
|
+
- **显示名称**: {{ display_name }}
|
|
11
|
+
- **版本**: {{ version }}
|
|
12
|
+
- **作者**: {{ author }}
|
|
13
|
+
- **类型**: Toolbox (智能体工具)
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
### 1. 环境准备
|
|
18
|
+
|
|
19
|
+
确保你已经安装了 adam-community:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# 在项目根目录安装依赖
|
|
23
|
+
cd /path/to/adam-community
|
|
24
|
+
python setup.py develop
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 2. 开发智能体流程
|
|
28
|
+
|
|
29
|
+
#### 2.1 修改工具实现
|
|
30
|
+
编辑 `{{ name.replace('-', '_') }}.py` 文件,实现你的工具逻辑。项目包含两种工具类型:
|
|
31
|
+
|
|
32
|
+
**Bash 类型工具 (默认)**:
|
|
33
|
+
```python
|
|
34
|
+
class {{ name.replace("-", "_") }}_tool(Tool):
|
|
35
|
+
def call(self, kwargs):
|
|
36
|
+
# 获取用户输入参数
|
|
37
|
+
input_text = kwargs['args']['input_text']
|
|
38
|
+
|
|
39
|
+
# 返回要执行的 bash 命令
|
|
40
|
+
bash_script = f'''
|
|
41
|
+
# 你的 bash 脚本
|
|
42
|
+
echo "处理: {input_text}"
|
|
43
|
+
# 添加你的命令...
|
|
44
|
+
'''
|
|
45
|
+
return bash_script
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Python 类型工具**:
|
|
49
|
+
```python
|
|
50
|
+
class {{ name.replace("-", "_") }}_advanced_tool(Tool, calltype="python"):
|
|
51
|
+
DISPLAY_NAME = "{{ display_name }}高级工具"
|
|
52
|
+
NETWORK = False # 是否需要网络访问
|
|
53
|
+
CPU = 1 # 需要的CPU数量
|
|
54
|
+
GPU = 0 # 需要的GPU数量
|
|
55
|
+
SIF = "adam-base:1.0.0" # 容器镜像
|
|
56
|
+
CONDA_ENV = "base" # 指定运行环境
|
|
57
|
+
|
|
58
|
+
def call(self, kwargs):
|
|
59
|
+
# Python 代码逻辑
|
|
60
|
+
result = your_python_logic()
|
|
61
|
+
|
|
62
|
+
# 必须使用 print 输出结果
|
|
63
|
+
print(f"处理结果: {result}")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### 2.2 配置智能体提示词
|
|
67
|
+
编辑以下文件来配置智能体的行为:
|
|
68
|
+
|
|
69
|
+
**`config/initial_system_prompt.md`** - 系统提示词:
|
|
70
|
+
```markdown
|
|
71
|
+
# 你的信息
|
|
72
|
+
您是一位专业的{{ display_name }}专家...
|
|
73
|
+
|
|
74
|
+
# 你的任务范围
|
|
75
|
+
1. 理解用户需求
|
|
76
|
+
2. 选择合适工具
|
|
77
|
+
3. 执行操作
|
|
78
|
+
4. 生成报告
|
|
79
|
+
|
|
80
|
+
# 工作流程
|
|
81
|
+
1. 分析需求
|
|
82
|
+
2. 制定计划
|
|
83
|
+
3. 执行工具
|
|
84
|
+
4. 分析结果
|
|
85
|
+
5. 生成报告
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**`config/initial_assistant_message.md`** - 欢迎消息:
|
|
89
|
+
```markdown
|
|
90
|
+
# 欢迎使用{{ display_name }}工具!
|
|
91
|
+
|
|
92
|
+
我可以帮助您:
|
|
93
|
+
- 功能1:描述
|
|
94
|
+
- 功能2:描述
|
|
95
|
+
- 功能3:描述
|
|
96
|
+
|
|
97
|
+
请告诉我您的需求...
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### 2.3 完善项目描述
|
|
101
|
+
编辑 `config/long_description.md` 来完善项目的详细描述。
|
|
102
|
+
|
|
103
|
+
### 3. 构建和测试
|
|
104
|
+
|
|
105
|
+
#### 3.1 解析工具函数
|
|
106
|
+
```bash
|
|
107
|
+
# 生成 functions.json
|
|
108
|
+
make parse
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### 3.2 构建项目包
|
|
112
|
+
```bash
|
|
113
|
+
# 构建 ZIP 包
|
|
114
|
+
make build
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### 3.3 本地调试
|
|
118
|
+
|
|
119
|
+
**测试 Bash 工具**:
|
|
120
|
+
```python
|
|
121
|
+
# 创建测试脚本 test_bash_tool.py
|
|
122
|
+
from {{ name.replace('-', '_') }} import {{ name.replace("-", "_") }}_tool
|
|
123
|
+
|
|
124
|
+
# 模拟参数
|
|
125
|
+
test_kwargs = {
|
|
126
|
+
'args': {
|
|
127
|
+
'input_text': '测试输入',
|
|
128
|
+
'mode': 'basic'
|
|
129
|
+
},
|
|
130
|
+
'message': '用户消息',
|
|
131
|
+
'files': [],
|
|
132
|
+
'user': '测试用户',
|
|
133
|
+
'task_id': 'test_task'
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# 测试工具
|
|
137
|
+
tool = {{ name.replace("-", "_") }}_tool()
|
|
138
|
+
bash_script = tool.call(test_kwargs)
|
|
139
|
+
print(f"生成的 bash 脚本:\n{bash_script}")
|
|
140
|
+
|
|
141
|
+
# 测试输出显示
|
|
142
|
+
output_kwargs = {
|
|
143
|
+
'stdout': '命令执行输出',
|
|
144
|
+
'stderr': '',
|
|
145
|
+
'exitcode': 0
|
|
146
|
+
}
|
|
147
|
+
display_text, file_list = tool.outputShow(output_kwargs)
|
|
148
|
+
print(f"显示文本:\n{display_text}")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**测试 Python 工具**:
|
|
152
|
+
```python
|
|
153
|
+
# 创建测试脚本 test_python_tool.py
|
|
154
|
+
from {{ name.replace('-', '_') }} import {{ name.replace("-", "_") }}_advanced_tool
|
|
155
|
+
|
|
156
|
+
# 模拟参数
|
|
157
|
+
test_kwargs = {
|
|
158
|
+
'args': {
|
|
159
|
+
'input_file': 'test.txt',
|
|
160
|
+
'output_format': 'json'
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# 测试工具
|
|
165
|
+
tool = {{ name.replace("-", "_") }}_advanced_tool()
|
|
166
|
+
tool.call(test_kwargs) # Python工具直接执行
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 4. 部署和发布
|
|
170
|
+
|
|
171
|
+
#### 4.1 上传到平台
|
|
172
|
+
1. 运行 `make build` 生成 ZIP 包
|
|
173
|
+
2. 在 Adam 平台控制台选择生成的 ZIP 包
|
|
174
|
+
3. 点击发布
|
|
175
|
+
4. 设置为可见状态
|
|
176
|
+
|
|
177
|
+
#### 4.2 测试智能体
|
|
178
|
+
1. 在平台的「智能体」页面找到你的智能体
|
|
179
|
+
2. 通过对话方式测试功能
|
|
180
|
+
3. 观察智能体如何调用你的工具
|
|
181
|
+
|
|
182
|
+
## 开发指南
|
|
183
|
+
|
|
184
|
+
### Toolbox 智能体特点
|
|
185
|
+
- **对话驱动**: 用户通过自然语言对话与智能体交互
|
|
186
|
+
- **工具调用**: 智能体根据需要调用相应的工具函数
|
|
187
|
+
- **多轮对话**: 支持复杂的多轮对话场景
|
|
188
|
+
- **智能决策**: AI 自动决定何时调用哪个工具
|
|
189
|
+
|
|
190
|
+
### 工具类型说明
|
|
191
|
+
|
|
192
|
+
#### Bash 工具 (`calltype = "bash"`)
|
|
193
|
+
- 适用于系统命令、脚本执行、文件操作等
|
|
194
|
+
- `call` 方法返回要执行的 bash 命令字符串
|
|
195
|
+
- 系统会执行返回的命令并捕获输出
|
|
196
|
+
|
|
197
|
+
#### Python 工具 (`calltype = "python"`)
|
|
198
|
+
- 适用于复杂的 Python 逻辑、数据处理、API 调用等
|
|
199
|
+
- `call` 方法直接执行 Python 代码
|
|
200
|
+
- 必须使用 `print()` 输出结果
|
|
201
|
+
- 需要指定 `CONDA_ENV` 运行环境
|
|
202
|
+
|
|
203
|
+
### 重要配置项
|
|
204
|
+
|
|
205
|
+
#### 工具属性(必填配置)
|
|
206
|
+
```python
|
|
207
|
+
DISPLAY_NAME = "工具显示名称" # 工具的显示名称
|
|
208
|
+
NETWORK = True/False # 是否需要网络访问
|
|
209
|
+
CPU = 1 # 需要的CPU数量(必填)
|
|
210
|
+
GPU = 0 # 需要的GPU数量(必填)
|
|
211
|
+
SIF = "adam-base:1.0.0" # 容器镜像(必填)
|
|
212
|
+
CONDA_ENV = "base" # Conda环境(仅Python工具)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### docstring 格式
|
|
216
|
+
```python
|
|
217
|
+
"""
|
|
218
|
+
工具的功能描述
|
|
219
|
+
|
|
220
|
+
:param str input_text: 必需参数描述
|
|
221
|
+
:param str? mode: 可选参数描述(注意?标记)
|
|
222
|
+
"""
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 重要方法说明
|
|
226
|
+
|
|
227
|
+
#### `call(self, kwargs)` - 核心执行方法
|
|
228
|
+
- **必须实现**
|
|
229
|
+
- Bash工具:返回要执行的命令字符串
|
|
230
|
+
- Python工具:直接执行逻辑并用print输出
|
|
231
|
+
|
|
232
|
+
#### `inputShow(self, **kwargs)` - 输入显示
|
|
233
|
+
- **可选实现**
|
|
234
|
+
- 自定义用户看到的输入格式
|
|
235
|
+
- 默认显示完整的命令或代码
|
|
236
|
+
|
|
237
|
+
#### `outputShow(self, kwargs)` - 输出显示
|
|
238
|
+
- **可选实现**
|
|
239
|
+
- 自定义用户看到的输出格式
|
|
240
|
+
- 返回 `(display_text, file_list)` 元组
|
|
241
|
+
|
|
242
|
+
#### `summary(self, kwargs)` - AI摘要
|
|
243
|
+
- **可选实现**
|
|
244
|
+
- 为 AI 生成执行摘要,用于后续决策
|
|
245
|
+
- 控制输出长度,避免上下文过长
|
|
246
|
+
|
|
247
|
+
#### `monitor(self, process, kwargs)` - 进度监控
|
|
248
|
+
- **可选实现**
|
|
249
|
+
- 监控长时间运行的任务进度
|
|
250
|
+
- 设置 `kwargs["PIPELINE"]` 和 `kwargs["PROCESS"]`
|
|
251
|
+
|
|
252
|
+
### 智能体提示词编写指南
|
|
253
|
+
|
|
254
|
+
#### 系统提示词 (`initial_system_prompt.md`)
|
|
255
|
+
- 定义智能体的身份和专业领域
|
|
256
|
+
- 描述任务范围和工作流程
|
|
257
|
+
- 设置工具调用的优先级和策略
|
|
258
|
+
- 包含重要的注意事项和限制
|
|
259
|
+
|
|
260
|
+
#### 欢迎消息 (`initial_assistant_message.md`)
|
|
261
|
+
- 向用户介绍智能体的功能
|
|
262
|
+
- 提供使用建议和最佳实践
|
|
263
|
+
- 引导用户正确描述需求
|
|
264
|
+
|
|
265
|
+
### 常见问题
|
|
266
|
+
|
|
267
|
+
#### Q: 如何处理长时间运行的任务?
|
|
268
|
+
A: 实现 `monitor` 方法来报告进度,或者将任务分解为多个步骤。
|
|
269
|
+
|
|
270
|
+
#### Q: 如何让智能体调用特定工具?
|
|
271
|
+
A: 在系统提示词中明确工具的使用场景和调用条件。
|
|
272
|
+
|
|
273
|
+
#### Q: 如何处理错误和异常?
|
|
274
|
+
A: 在工具中使用适当的错误处理,通过 stderr 输出错误信息。
|
|
275
|
+
|
|
276
|
+
#### Q: 如何优化智能体的响应质量?
|
|
277
|
+
A: 精心设计 docstring 和系统提示词,提供清晰的工具描述和使用指导。
|
|
278
|
+
|
|
279
|
+
#### Q: Python工具的依赖如何管理?
|
|
280
|
+
A: 确保指定的 CONDA_ENV 环境中安装了所有需要的依赖包。
|
|
281
|
+
|
|
282
|
+
## 文件结构说明
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
{{ name }}/
|
|
286
|
+
├── config/
|
|
287
|
+
│ ├── configure.json # 智能体基本配置
|
|
288
|
+
│ ├── initial_system_prompt.md # 系统提示词
|
|
289
|
+
│ ├── initial_assistant_message.md # 欢迎消息
|
|
290
|
+
│ └── long_description.md # 详细描述
|
|
291
|
+
├── {{ name.replace('-', '_') }}.py # 主要实现文件
|
|
292
|
+
├── functions.json # 自动生成的工具描述
|
|
293
|
+
├── Makefile # 构建脚本
|
|
294
|
+
└── README.md # 本文件
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## 调试技巧
|
|
298
|
+
|
|
299
|
+
### 1. 单独测试工具
|
|
300
|
+
创建独立的测试脚本来验证工具逻辑:
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
# test_individual_tool.py
|
|
304
|
+
if __name__ == "__main__":
|
|
305
|
+
from your_module import your_tool
|
|
306
|
+
|
|
307
|
+
# 模拟真实调用场景
|
|
308
|
+
tool = your_tool()
|
|
309
|
+
result = tool.call(mock_kwargs)
|
|
310
|
+
print(result)
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### 2. 输出调试信息
|
|
314
|
+
在工具中添加详细的调试输出:
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
def call(self, kwargs):
|
|
318
|
+
print(f"DEBUG: 收到参数: {kwargs}")
|
|
319
|
+
# 你的逻辑
|
|
320
|
+
print(f"DEBUG: 处理结果: {result}")
|
|
321
|
+
return result
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 3. 测试提示词效果
|
|
325
|
+
在本地模拟对话场景,测试智能体的响应质量。
|
|
326
|
+
|
|
327
|
+
## 参考资源
|
|
328
|
+
|
|
329
|
+
- [Adam Tool Protocol 文档](https://docs.example.com/atp)
|
|
330
|
+
- [智能体开发指南](https://docs.example.com/agent-guide)
|
|
331
|
+
- [现有智能体示例](https://github.com/example/adam-tools)
|
|
332
|
+
|
|
333
|
+
## 贡献和支持
|
|
334
|
+
|
|
335
|
+
如有问题或建议,请联系:{{ author }}
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
Generated by Adam CLI - {{ name }} v{{ version }}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from adam_community.tool import Tool
|
|
2
|
+
from adam_community.util import runCmd
|
|
3
|
+
|
|
4
|
+
class {{ name.replace("-", "_") }}_tool(Tool):
|
|
5
|
+
"""
|
|
6
|
+
{{ description }}
|
|
7
|
+
|
|
8
|
+
:param str input_text: 输入的文本内容
|
|
9
|
+
:param str? mode: 处理模式,可选值:basic、advanced
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
DISPLAY_NAME = "{{ display_name }}工具"
|
|
13
|
+
NETWORK = False # 根据需要设置是否需要网络访问
|
|
14
|
+
CPU = 1 # 需要的CPU数量
|
|
15
|
+
GPU = 0 # 需要的GPU数量
|
|
16
|
+
SIF = "adam-base:1.0.0" # 指定容器镜像(必填)
|
|
17
|
+
|
|
18
|
+
def call(self, kwargs):
|
|
19
|
+
"""
|
|
20
|
+
工具的主要实现函数
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
kwargs: 包含args、message、files、user、task_id等参数的字典
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
执行结果字符串(bash命令)或直接执行结果
|
|
27
|
+
"""
|
|
28
|
+
# 获取用户输入的参数
|
|
29
|
+
input_text = kwargs['args']['input_text']
|
|
30
|
+
mode = kwargs['args'].get('mode', 'basic')
|
|
31
|
+
|
|
32
|
+
# TODO: 在这里实现你的主要逻辑
|
|
33
|
+
if mode == 'advanced':
|
|
34
|
+
result = f"高级模式处理: {input_text}"
|
|
35
|
+
else:
|
|
36
|
+
result = f"基础模式处理: {input_text}"
|
|
37
|
+
|
|
38
|
+
# 生成bash命令
|
|
39
|
+
bash_script = f'''
|
|
40
|
+
# {{ display_name }} 处理脚本
|
|
41
|
+
echo "开始处理: {input_text}"
|
|
42
|
+
echo "处理模式: {mode}"
|
|
43
|
+
|
|
44
|
+
# TODO: 在这里添加实际的处理命令
|
|
45
|
+
echo "{result}"
|
|
46
|
+
|
|
47
|
+
# 生成输出文件
|
|
48
|
+
echo "处理完成" > output.txt
|
|
49
|
+
echo "结果: {result}" >> output.txt
|
|
50
|
+
|
|
51
|
+
echo "处理完成,结果已保存到 output.txt"
|
|
52
|
+
'''
|
|
53
|
+
|
|
54
|
+
return runCmd(bash_script)
|
|
55
|
+
|
|
56
|
+
def outputShow(self, kwargs):
|
|
57
|
+
"""
|
|
58
|
+
自定义输出显示格式(可选)
|
|
59
|
+
"""
|
|
60
|
+
stdout = kwargs.get('stdout', '')
|
|
61
|
+
stderr = kwargs.get('stderr', '')
|
|
62
|
+
|
|
63
|
+
display_text = f"""## 🎉 {{ display_name }} 处理完成
|
|
64
|
+
|
|
65
|
+
### 📋 处理结果
|
|
66
|
+
```
|
|
67
|
+
{stdout}
|
|
68
|
+
```
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
if stderr:
|
|
72
|
+
display_text += f"""
|
|
73
|
+
### ⚠️ 警告信息
|
|
74
|
+
```
|
|
75
|
+
{stderr}
|
|
76
|
+
```
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
# 返回可能生成的文件
|
|
80
|
+
file_list = ['output.txt'] if 'output.txt' in stdout else []
|
|
81
|
+
|
|
82
|
+
return display_text, file_list
|
|
83
|
+
|
|
84
|
+
def summary(self, kwargs):
|
|
85
|
+
"""
|
|
86
|
+
为AI生成简短的执行摘要
|
|
87
|
+
"""
|
|
88
|
+
stdout = kwargs.get('stdout', '')
|
|
89
|
+
stderr = kwargs.get('stderr', '')
|
|
90
|
+
|
|
91
|
+
if stderr:
|
|
92
|
+
return f"{{ display_name }}工具执行完成但有警告: {stdout[:200]}...。警告: {stderr[:100]}"
|
|
93
|
+
else:
|
|
94
|
+
return f"{{ display_name }}工具执行成功: {stdout[:200]}..."
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class {{ name.replace("-", "_") }}_advanced_tool(Tool, calltype="python"):
|
|
98
|
+
"""
|
|
99
|
+
{{ description }} - 高级功能
|
|
100
|
+
|
|
101
|
+
:param str input_file: 输入文件路径
|
|
102
|
+
:param str output_format: 输出格式,可选值:json、csv、txt
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
DISPLAY_NAME = "{{ display_name }}高级工具"
|
|
106
|
+
NETWORK = False # 根据需要设置是否需要网络访问
|
|
107
|
+
CPU = 1 # 需要的CPU数量
|
|
108
|
+
GPU = 0 # 需要的GPU数量
|
|
109
|
+
SIF = "adam-base:1.0.0" # 指定容器镜像(必填)
|
|
110
|
+
CONDA_ENV = "base" # 指定conda环境
|
|
111
|
+
|
|
112
|
+
def call(self, kwargs):
|
|
113
|
+
"""
|
|
114
|
+
Python类型工具的实现
|
|
115
|
+
"""
|
|
116
|
+
import json
|
|
117
|
+
import datetime
|
|
118
|
+
|
|
119
|
+
input_file = kwargs['args']['input_file']
|
|
120
|
+
output_format = kwargs['args'].get('output_format', 'json')
|
|
121
|
+
|
|
122
|
+
# TODO: 在这里实现你的Python逻辑
|
|
123
|
+
result = {
|
|
124
|
+
'input_file': input_file,
|
|
125
|
+
'output_format': output_format,
|
|
126
|
+
'processed_at': datetime.datetime.now().isoformat(),
|
|
127
|
+
'result': 'Python工具处理完成'
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# 对于Python工具,必须使用print输出结果
|
|
131
|
+
print(f"Python工具处理完成,输入文件: {input_file}")
|
|
132
|
+
print(f"输出格式: {output_format}")
|
|
133
|
+
print(f"处理结果: {result}")
|
|
134
|
+
|
|
135
|
+
# 生成输出文件
|
|
136
|
+
if output_format == 'json':
|
|
137
|
+
with open('result.json', 'w', encoding='utf-8') as f:
|
|
138
|
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
|
139
|
+
print("结果已保存到 result.json")
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
## 欢迎使用{{ display_name }}工具!
|
|
2
2
|
|
|
3
3
|
我是您的专业{{ display_name }}助手,可以帮助您完成以下任务:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### 🔧 主要功能
|
|
6
6
|
- 功能1: 基础处理功能
|
|
7
7
|
- 功能2: 高级分析功能
|
|
8
8
|
- 功能3: 结果导出功能
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
### 🚀 快速开始
|
|
11
11
|
1. 描述您的需求
|
|
12
12
|
2. 提供必要的输入数据
|
|
13
13
|
3. 我将为您执行相应操作
|
|
14
14
|
4. 获取详细的分析结果
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
### 💡 使用建议
|
|
17
17
|
- 请详细描述您的需求
|
|
18
18
|
- 如有文件需要处理,请上传相关文件
|
|
19
19
|
- 我会为您提供详细的操作步骤和结果分析
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from adam_community.tool import Tool
|
|
2
|
+
from adam_community.util import knowledgeSearch
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
class {{ class_name }}(Tool, calltype="python"):
|
|
6
|
+
"""
|
|
7
|
+
{{ description }}
|
|
8
|
+
|
|
9
|
+
:param str query: 搜索的关键词
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
DISPLAY_NAME = "{{ display_name }}"
|
|
13
|
+
NETWORK = True
|
|
14
|
+
CONDA_ENV = "knowledgebase"
|
|
15
|
+
SIF = "akb:1.0.0"
|
|
16
|
+
COLLECTION_NAME = "{{ collection_name }}"
|
|
17
|
+
PROJECT_NAME = "default"
|
|
18
|
+
|
|
19
|
+
# 基础提示词模板
|
|
20
|
+
BASIC_PROMPT = """
|
|
21
|
+
# 参考资料
|
|
22
|
+
<context>
|
|
23
|
+
{}
|
|
24
|
+
</context>
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def call(self, kwargs):
|
|
28
|
+
"""
|
|
29
|
+
执行知识库搜索并生成提示词
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
kwargs: 包含查询参数的字典
|
|
33
|
+
"""
|
|
34
|
+
query = kwargs.get('args', {}).get('query')
|
|
35
|
+
if not query:
|
|
36
|
+
self.logger.error("查询参数为空")
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
self.logger.debug(f"搜索知识库 {self.COLLECTION_NAME}: {query}")
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
# 调用知识库搜索(messages_prev 参数在本地实现中未使用,传 None 即可)
|
|
43
|
+
response_text = knowledgeSearch(query, None, self.PROJECT_NAME, self.COLLECTION_NAME)
|
|
44
|
+
|
|
45
|
+
# 解析响应并提取内容
|
|
46
|
+
response = json.loads(response_text)
|
|
47
|
+
if response.get("code") != 0:
|
|
48
|
+
self.logger.warning(f"知识库搜索返回错误: {response.get('message', '未知错误')}")
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
# 提取知识库内容
|
|
52
|
+
result_list = response.get("data", {}).get("result_list", [])
|
|
53
|
+
context_content = ""
|
|
54
|
+
|
|
55
|
+
for point in result_list:
|
|
56
|
+
content = point.get("content", "")
|
|
57
|
+
if content:
|
|
58
|
+
context_content += f"{content}\n---\n"
|
|
59
|
+
|
|
60
|
+
# 生成最终提示词
|
|
61
|
+
prompt = self.BASIC_PROMPT.format(context_content)
|
|
62
|
+
print(prompt)
|
|
63
|
+
|
|
64
|
+
except Exception as e:
|
|
65
|
+
self.logger.error(f"知识库搜索失败: {e}")
|
|
66
|
+
|
|
67
|
+
def inputShow(self, **kwargs):
|
|
68
|
+
"""显示输入信息"""
|
|
69
|
+
query = kwargs.get('args', {}).get('query', '')
|
|
70
|
+
return f"Searching knowledge base {self.COLLECTION_NAME}: {query}"
|
|
71
|
+
|
|
72
|
+
def outputShow(self, kwargs):
|
|
73
|
+
"""显示输出信息"""
|
|
74
|
+
query = kwargs.get('args', {}).get('query', '')
|
|
75
|
+
stderr = kwargs.get('stderr', '')
|
|
76
|
+
return f"Done searching knowledge base {self.COLLECTION_NAME}: {query}", stderr
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
adam_community/__init__.py,sha256=vAmF9VQR6D4peppH0hnrHDmZK5cFeFPh11GIsTKUXhE,429
|
|
2
|
-
adam_community/__version__.py,sha256=
|
|
2
|
+
adam_community/__version__.py,sha256=tmJFcbWnlgNwXFCrgJHkNSJZmxR67rAjso_lz91m_vc,23
|
|
3
3
|
adam_community/tool.py,sha256=CCzWosxtuZ0yk7mupmnlgMpO59jr1hl-a_brSGIqhDI,4867
|
|
4
4
|
adam_community/util.py,sha256=CAyMS-UNFjDcdSRWNCIOseAvprP0GEpfJzhO3l5VY1U,11051
|
|
5
5
|
adam_community/cli/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
6
|
-
adam_community/cli/build.py,sha256=
|
|
7
|
-
adam_community/cli/cli.py,sha256=
|
|
8
|
-
adam_community/cli/init.py,sha256=
|
|
6
|
+
adam_community/cli/build.py,sha256=ODytrSldY6Psgw3ESBzx7NESijpnDceGH1kB4xnUbZE,11269
|
|
7
|
+
adam_community/cli/cli.py,sha256=xlPvn0aq3TpAPjA7z9shsCqR1aHDVtZuhvtc_SNA_cQ,2811
|
|
8
|
+
adam_community/cli/init.py,sha256=hzzz5Tus9_L5YKE10ii7s2x9znDxfqBvjDOmPn-0KvY,8632
|
|
9
9
|
adam_community/cli/parser.py,sha256=LWYVW69z4ICFXgvD5Vtcy1P-rEUxV_Rs4X96n34i3gE,17732
|
|
10
10
|
adam_community/cli/updater.py,sha256=zN521c-G20MKz63wm7h16quBxiEZp4vQ6AbyV-IqtXk,6304
|
|
11
11
|
adam_community/cli/templates/Makefile.j2,sha256=arpo9AzOZTmjxIYiya9S_G_ldHYVVvf4cVOxNooQeGs,113
|
|
12
|
+
adam_community/cli/templates/README_agent.md.j2,sha256=lbhaEPZrgbCfUG-T7GItkgfIV9h1rqxyfRQuGhcdOqU,8901
|
|
12
13
|
adam_community/cli/templates/README_kit.md.j2,sha256=5_1ISGUxJKdDild2vNSWTC_hNhZHnEHvyN9Ez4Xbqwk,5715
|
|
13
14
|
adam_community/cli/templates/README_toolbox.md.j2,sha256=lbhaEPZrgbCfUG-T7GItkgfIV9h1rqxyfRQuGhcdOqU,8901
|
|
14
15
|
adam_community/cli/templates/__init__.py,sha256=43rU9rFkpsVrWjxR-brDnT2eakgRtb4XpnunbE-ais4,34
|
|
16
|
+
adam_community/cli/templates/agent_python.py.j2,sha256=EOnmsJUvQRrcO7K7c88kI42gMmcM0Z4ab46qwOJXbH8,4192
|
|
15
17
|
adam_community/cli/templates/configure.json.j2,sha256=HWhhFGEZsXxDJCkciehY8SqaV7kSPQ4588TR9WN__cI,354
|
|
16
|
-
adam_community/cli/templates/initial_assistant_message.md.j2,sha256=
|
|
18
|
+
adam_community/cli/templates/initial_assistant_message.md.j2,sha256=R17qhco2Ds5es2HMlAPcinVi5Z-vLfyyu1lY9HMBFk4,595
|
|
17
19
|
adam_community/cli/templates/initial_system_prompt.md.j2,sha256=mF7wdVVfvPmPgoskSv4tnLrnyDC4WOrhSx1Ud7mn0Pk,679
|
|
18
20
|
adam_community/cli/templates/input.json.j2,sha256=LRkIhPln3BnmPRrFebsjUa5t9vcED_7Uimp1Esb1ThU,607
|
|
19
21
|
adam_community/cli/templates/kit_python.py.j2,sha256=fVQ8EVDMaxPCv9CzYjjoV8NLJMmtVCx5tFaM9eO7f8M,2788
|
|
20
22
|
adam_community/cli/templates/long_description.md.j2,sha256=Rj6hcuNzEL0Sp17GQVCRJyNytxO22KcKFvEnZlGpevE,1385
|
|
23
|
+
adam_community/cli/templates/rag_python.py.j2,sha256=YJL7-WIx-Dumt7lHuUGxl3Rbaw0kpkh8hpcCJ5lz9lA,2494
|
|
21
24
|
adam_community/cli/templates/toolbox_python.py.j2,sha256=EOnmsJUvQRrcO7K7c88kI42gMmcM0Z4ab46qwOJXbH8,4192
|
|
22
|
-
adam_community-1.0.
|
|
23
|
-
adam_community-1.0.
|
|
24
|
-
adam_community-1.0.
|
|
25
|
-
adam_community-1.0.
|
|
26
|
-
adam_community-1.0.
|
|
25
|
+
adam_community-1.0.14.dist-info/METADATA,sha256=Ko_SKJ9Yq-FGw0PpKJva4Eoeq4F4opZ4ntEiRbSaU1o,2172
|
|
26
|
+
adam_community-1.0.14.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
27
|
+
adam_community-1.0.14.dist-info/entry_points.txt,sha256=4I7yRkn7cHwPY8-fWQLeAvKjc24zUy8Z65VsZNs0Wos,56
|
|
28
|
+
adam_community-1.0.14.dist-info/top_level.txt,sha256=MS8jbePXKZChih9kGizNVX0I1MFZFGWBMCIW_r86qhU,15
|
|
29
|
+
adam_community-1.0.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|