mirror of
https://github.com/agentuniverse-ai/agentUniverse.git
synced 2026-02-09 01:59:19 +08:00
docs: add aU new version guide.
This commit is contained in:
@@ -30,7 +30,8 @@ result: 《舒伯特小夜曲》是奥地利作曲家舒伯特(1797-1828)创
|
||||
|
||||
```yaml
|
||||
name: 'parallel_search_detail_api'
|
||||
description: '使用该工具可以在bing中并发搜索多条信息
|
||||
description: |
|
||||
使用该工具可以在bing中并发搜索多条信息
|
||||
<输入描述>
|
||||
入参inputs是一个json字符串,内容是一个待检索list,每个元素表示一条需要搜索的信息。
|
||||
|
||||
|
||||
62
docs/guidebook/zh/开始使用/7.aU新老工程迁移指南.md
Normal file
62
docs/guidebook/zh/开始使用/7.aU新老工程迁移指南.md
Normal file
@@ -0,0 +1,62 @@
|
||||
## 背景
|
||||
对于使用agentUniverse包版本小于等于0.0.13的用户,我们鼓励您将包版本升级到0.0.14。
|
||||
|
||||
0.0.14版本的agentUniverse在原有框架功能基础上做了架构升级,增加了智能体模版、工作模式等新智能体构建范式,并提供了新的aU示例工程[examples](../../../../examples)以及升级后的标准应用工程结构。
|
||||
|
||||
本篇文章为迁移指南,帮助用户更快捷的完成aU版本升级工作。
|
||||
|
||||
## 新标准应用工程结构
|
||||
0.0.14版本,我们推荐的标准应用工程结构如下,每个层级包目录具体含义请参见[标准应用工程结构说明](1.标准应用工程结构说明.md):
|
||||
```
|
||||
/
|
||||
├── bootstrap/
|
||||
│ ├── intelligence/
|
||||
│ │ └── server_application.py
|
||||
│ ├── platform/
|
||||
│ │ └── product_application.py
|
||||
├── intelligence/
|
||||
│ ├── agentic/
|
||||
│ │ ├── agent
|
||||
│ │ │ └── agent_instance
|
||||
│ │ │ └── agent_template
|
||||
│ │ ├── knowledge
|
||||
│ │ │ └── store/
|
||||
│ │ │ └── rag_router/
|
||||
│ │ │ └── doc_processor/
|
||||
│ │ ├── llm
|
||||
│ │ ├── prompt
|
||||
│ │ ├── memory
|
||||
│ │ ├── tool
|
||||
│ │ └── work_pattern
|
||||
│ ├── service/
|
||||
│ │ └── agent_service
|
||||
│ │ └── classic_service
|
||||
│ ├── dal/
|
||||
│ ├── integration/
|
||||
│ ├── utils/
|
||||
│ └── test/
|
||||
├── platform/
|
||||
├── config
|
||||
├── pyproject.toml
|
||||
└── other project files...
|
||||
```
|
||||
|
||||
我们考虑到新老工程目录结构迁移存在一定成本,提供了便捷的迁移脚本,方便您参考使用[au_dir_structure_updater](../../../../examples/sample_standard_app/au_dir_structure_updater.py)。
|
||||
|
||||
脚本使用步骤:
|
||||
1. 将脚本文件移动到您的应用根目录下,例如您的应用根目录为sample_standard_app,则将au_dir_structure_updater.py文件移动到sample_standard_app下。
|
||||
2. 启动脚本文件,脚本文件会创建新目录结构dir(create_directory_structure方法)。
|
||||
3. 之后根据脚本文件中配置的migration_rules(您可自定义添加或删除migration_rules),迁移老工程文件到新目录结构(migrate_files方法)。
|
||||
4. 迁移过程会同时更新新yaml文件中的metadata路径,以及各python文件中的import package路径。
|
||||
5. 更改config.toml中的包扫描路径,参考[sample_config](../../../../examples/sample_standard_app/config/config.toml)中的CORE_PACKAGE。
|
||||
6. 运行本地测试文件,校验智能体是否运行成功。
|
||||
|
||||
## 智能体模版
|
||||
智能体模版替代原aU中的planner计划组件,具体原理文档参见:[agentTemplate](../../../../agentuniverse/agent/template/agent_template.py)。
|
||||
|
||||
使用智能体模版构建智能体文档参见:[沉淀与使用智能体模版](../开始使用/5.沉淀与使用智能体模版.md)。
|
||||
|
||||
当智能体执行流程存在很强的复用性,我们可以将其从agent的execute方法中抽象出来,封装成标准的智能体模版,方便后续的复用与共享。
|
||||
|
||||
## 工作模式
|
||||
aU中的工作模式为智能体模版再上一层级抽象,具体原理文档参见:[workPattern](../../../../agentuniverse/agent/work_pattern/work_pattern.py),agentUniverse中内置的工作模式为[PeerWorkPattern](../../../../agentuniverse/agent/work_pattern/peer_work_pattern.py)。
|
||||
263
examples/sample_standard_app/au_dir_structure_updater.py
Normal file
263
examples/sample_standard_app/au_dir_structure_updater.py
Normal file
@@ -0,0 +1,263 @@
|
||||
# !/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
# @Time : 2024/12/17 20:54
|
||||
# @Author : wangchongshi
|
||||
# @Email : wangchongshi.wcs@antgroup.com
|
||||
# @FileName: dir_structure_updater.py
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
|
||||
def create_directory_structure(base_path):
|
||||
"""Create new directory structure"""
|
||||
directories = [
|
||||
'boostrap/intelligence',
|
||||
'boostrap/platform',
|
||||
'intelligence/agentic/agent/agent_instance',
|
||||
'intelligence/agentic/agent/agent_template',
|
||||
'intelligence/agentic/knowledge/store',
|
||||
'intelligence/agentic/knowledge/rag_router',
|
||||
'intelligence/agentic/knowledge/doc_processor',
|
||||
'intelligence/agentic/knowledge/query_paraphraser',
|
||||
'intelligence/agentic/knowledge/raw_knowledge_file',
|
||||
'intelligence/agentic/llm',
|
||||
'intelligence/agentic/prompt',
|
||||
'intelligence/agentic/memory',
|
||||
'intelligence/agentic/memory/memory_compressor',
|
||||
'intelligence/agentic/memory/memory_storage',
|
||||
'intelligence/agentic/tool',
|
||||
'intelligence/agentic/planner',
|
||||
'intelligence/agentic/work_pattern',
|
||||
'intelligence/service',
|
||||
'intelligence/service/agent_service',
|
||||
'intelligence/service/classic_service',
|
||||
'intelligence/dal',
|
||||
'intelligence/integration',
|
||||
'intelligence/utils',
|
||||
'intelligence/test',
|
||||
'platform/difizen/product/agent',
|
||||
'platform/difizen/product/knowledge',
|
||||
'platform/difizen/product/tool',
|
||||
'platform/difizen/product/plugin',
|
||||
'platform/difizen/product/planner',
|
||||
'platform/difizen/product/llm',
|
||||
'platform/difizen/resources',
|
||||
'platform/difizen/workflow',
|
||||
]
|
||||
|
||||
for directory in directories:
|
||||
Path(os.path.join(base_path, directory)).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def update_yaml_file(file_path, migration_rules):
|
||||
"""Update metadata module info in the YAML file"""
|
||||
yaml = YAML()
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
content = yaml.load(file)
|
||||
|
||||
update_yaml_flag = False
|
||||
if 'metadata' in content and 'module' in content['metadata']:
|
||||
original_module = content['metadata']['module']
|
||||
for rule in migration_rules:
|
||||
if rule['source'].replace('/', '.') in original_module:
|
||||
new_module = original_module.replace(
|
||||
rule['source'].replace('/', '.'),
|
||||
rule['target'].replace('/', '.')
|
||||
)
|
||||
content['metadata']['module'] = new_module
|
||||
update_yaml_flag = True
|
||||
break
|
||||
if update_yaml_flag:
|
||||
with open(file_path, 'w', encoding='utf-8') as file:
|
||||
yaml.dump(content, file)
|
||||
|
||||
|
||||
def update_python_file(file_path, migration_rules):
|
||||
"""Update import paths in the Python files"""
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
with open(file_path, 'w', encoding='utf-8') as file:
|
||||
for line in lines:
|
||||
for rule in migration_rules:
|
||||
source_module = rule['source'].replace('/', '.')
|
||||
target_module = rule['target'].replace('/', '.')
|
||||
|
||||
if line.startswith('from ') or line.startswith('import '):
|
||||
if source_module in line:
|
||||
line = line.replace(source_module, target_module)
|
||||
file.write(line)
|
||||
|
||||
|
||||
def migrate_files(source_root, target_root):
|
||||
"""Migrate files from source to target directory."""
|
||||
migration_rules = [
|
||||
{
|
||||
'source': 'app/core/agent',
|
||||
'target': 'intelligence/agentic/agent/agent_instance'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/knowledge',
|
||||
'target': 'intelligence/agentic/knowledge'
|
||||
},
|
||||
{
|
||||
'source': 'app/util',
|
||||
'target': 'intelligence/utils'
|
||||
},
|
||||
{
|
||||
'source': 'app/examples',
|
||||
'target': 'intelligence/test'
|
||||
},
|
||||
{
|
||||
'source': 'app/resources',
|
||||
'target': 'platform/difizen/resources'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/llm',
|
||||
'target': 'intelligence/agentic/llm'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/prompt',
|
||||
'target': 'intelligence/agentic/prompt'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/memory',
|
||||
'target': 'intelligence/agentic/memory'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/store',
|
||||
'target': 'intelligence/agentic/knowledge/store'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/doc_processor',
|
||||
'target': 'intelligence/agentic/knowledge/doc_processor'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/query_paraphraser',
|
||||
'target': 'intelligence/agentic/knowledge/query_paraphraser'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/rag_router',
|
||||
'target': 'intelligence/agentic/knowledge/rag_router'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/workflow',
|
||||
'target': 'platform/difizen/workflow'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/planner',
|
||||
'target': 'intelligence/agentic/planner'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/tool',
|
||||
'target': 'intelligence/agentic/tool'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/service',
|
||||
'target': 'intelligence/service/agent_service'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/product/agent',
|
||||
'target': 'platform/difizen/product/agent'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/product/knowledge',
|
||||
'target': 'platform/difizen/product/knowledge'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/product/planner',
|
||||
'target': 'platform/difizen/product/planner'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/product/llm',
|
||||
'target': 'platform/difizen/product/llm'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/product/plugin',
|
||||
'target': 'platform/difizen/product/plugin'
|
||||
},
|
||||
{
|
||||
'source': 'app/core/product/tool',
|
||||
'target': 'platform/difizen/product/tool'
|
||||
},
|
||||
{
|
||||
'source': 'app/test',
|
||||
'target': 'intelligence/test'
|
||||
},
|
||||
{
|
||||
'source': 'app/bootstrap/product_application.py',
|
||||
'target': 'boostrap/platform'
|
||||
},
|
||||
{
|
||||
'source': 'app/boostrap/product_application.py',
|
||||
'target': 'boostrap/platform'
|
||||
},
|
||||
{
|
||||
'source': 'app/bootstrap/server_application.py',
|
||||
'target': 'boostrap/intelligence'
|
||||
},
|
||||
{
|
||||
'source': 'app/boostrap/server_application.py',
|
||||
'target': 'boostrap/intelligence'
|
||||
},
|
||||
]
|
||||
|
||||
for rule in migration_rules:
|
||||
source_path = os.path.join(source_root, rule['source'])
|
||||
target_path = os.path.join(target_root, rule['target'])
|
||||
|
||||
if os.path.exists(source_path):
|
||||
print(f"Migrating from {source_path} to {target_path}")
|
||||
|
||||
if os.path.isfile(source_path):
|
||||
# If the source path is a file, then move it directly.
|
||||
os.makedirs(target_path, exist_ok=True)
|
||||
shutil.move(source_path, os.path.join(target_path, os.path.basename(source_path)))
|
||||
print(f"Moving {source_path} to {target_path}")
|
||||
if source_path.endswith('.yaml'):
|
||||
update_yaml_file(os.path.join(target_path, os.path.basename(source_path)), migration_rules)
|
||||
elif source_path.endswith('.py'):
|
||||
update_python_file(os.path.join(target_path, os.path.basename(source_path)), migration_rules)
|
||||
else:
|
||||
# Retrieve all files from the source directory.
|
||||
for root, _, files in os.walk(source_path):
|
||||
for file in files:
|
||||
source_file = os.path.join(root, file)
|
||||
relative_path = os.path.relpath(root, source_path)
|
||||
target_dir = os.path.join(target_path, relative_path)
|
||||
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
|
||||
# Move file
|
||||
target_file = os.path.join(target_dir, file)
|
||||
shutil.move(source_file, target_file)
|
||||
print(f"Moving {source_file} to {target_file}")
|
||||
|
||||
if source_file.endswith('.yaml'):
|
||||
update_yaml_file(target_file, migration_rules)
|
||||
elif source_file.endswith('.py'):
|
||||
update_python_file(target_file, migration_rules)
|
||||
|
||||
|
||||
def main():
|
||||
# Get the current working directory.
|
||||
current_dir = os.getcwd()
|
||||
|
||||
# Create a new directory structure.
|
||||
create_directory_structure(current_dir)
|
||||
|
||||
# Perform file migration.
|
||||
migrate_files(current_dir, current_dir)
|
||||
|
||||
print("Migration completed successfully!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
Reference in New Issue
Block a user