Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #91

Merged
merged 37 commits into from
Jun 17, 2024
Merged

Dev #91

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6e6b891
feat: add reAct agent in agentUniverse.
EdwinInAu Jun 7, 2024
6e0e996
feat: add reAct agent in agentUniverse.
EdwinInAu Jun 7, 2024
2d0277d
add react
weizjajj Jun 12, 2024
eb87a8e
add react
weizjajj Jun 12, 2024
40ffa4b
add ollama support react
weizjajj Jun 13, 2024
7e3120b
fix config
weizjajj Jun 13, 2024
b530f63
fix tool problem
weizjajj Jun 13, 2024
7b3ce11
fix tool input
weizjajj Jun 13, 2024
dda5a4e
support config react max_iterations
weizjajj Jun 13, 2024
abf3d20
add claude support
weizjajj Jun 13, 2024
5b22812
fix support
weizjajj Jun 13, 2024
05c0323
remove used file
weizjajj Jun 13, 2024
430378f
Merge pull request #74 from alipay/dev_chongshi_react
LandJerry Jun 13, 2024
9095624
fix tool name
weizjajj Jun 14, 2024
17ddfe7
Merge pull request #79 from alipay/dev_search_api
LandJerry Jun 14, 2024
c5e2beb
improvement: tweak prompts of the discussion group agents
EdwinInAu Jun 14, 2024
de7891a
Merge pull request #80 from alipay/dev_chongshi_0614
LandJerry Jun 14, 2024
5b78717
add doc
weizjajj Jun 14, 2024
bc97dd9
Merge pull request #82 from alipay/dev_search_api
LandJerry Jun 14, 2024
333f0ca
add result picture
weizjajj Jun 14, 2024
24f97bd
improvement: add demo pictures of the discussion group agents.
EdwinInAu Jun 14, 2024
e215134
improvement: add demo pictures of the discussion group agents.
EdwinInAu Jun 14, 2024
82bb8fd
improvement: add demo pictures of the discussion group agents.
EdwinInAu Jun 14, 2024
d20b6d7
improvement: add demo pictures of the discussion group agents.
EdwinInAu Jun 14, 2024
d847abb
Merge pull request #83 from alipay/dev_search_api
LandJerry Jun 14, 2024
3bb6088
Merge pull request #84 from alipay/dev_chongshi_2
LandJerry Jun 14, 2024
1d69041
improvement: add demo pictures of the discussion group agents.
EdwinInAu Jun 14, 2024
8276b71
Merge pull request #85 from alipay/dev_chongshi_2
LandJerry Jun 14, 2024
d0a9684
add step info
weizjajj Jun 14, 2024
b2df632
add step info
weizjajj Jun 14, 2024
c6662ac
Merge pull request #86 from alipay/dev_search_api
LandJerry Jun 14, 2024
2170b86
压缩图片
weizjajj Jun 14, 2024
34cdfe4
docs: update agentUniverse framework pic.
LandJerry Jun 14, 2024
3debc68
Merge pull request #87 from alipay/dev_search_api
LandJerry Jun 14, 2024
96393f7
docs: update readme & guidebook
LandJerry Jun 14, 2024
f32ff36
feat: Release version 0.0.9
LandJerry Jun 14, 2024
39c40f0
feat: Release version 0.0.9
LandJerry Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ Note - Additional remarks regarding the version.
***************************************************

# Version Update History
## [0.0.9] - 2024-06-14
### Added
- Added standard integration for Claude and Ollama LLM components
- Added new Qwen embedding module
- Added default agents for ReAct-Type and NL2API-Type

### Note
- Added new use cases
- RAG-Type Agent Examples: Legal Consultation Agent
- ReAct-Type Agent Examples: Python Code Generation and Execution Agent
- Multi-Agent: Discussion Group Based on Multi-Turn Multi-Agent Mode

For more details, please refer to the use case section in the user documentation.
- Some code optimizations and documentation updates.

## [0.0.8] - 2024-06-06
### Added
- Introduced a new monitor module
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ Note - 对于版本的额外说明。
***************************************************

# 版本更新记录
## [0.0.9] - 2024-06-14
### Added
- LLM组件新增claude、ollama标准接入
- 新增qwen embedding模块
- 新增ReAct、nl2api默认agent

### Note
- 新增使用案例
- RAG类Agent案例-法律咨询Agent
- ReAct类Agent案例-Python代码生成与执行Agent
- 多智能体案例-基于多轮多Agent的讨论小组

详情请看用户文档案例部分。
- 部分代码优化与文档更新

## [0.0.8] - 2024-06-06
### Added
- 新增monitor模块
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Language version: [English](./README.md) | [中文](./README_zh.md) | [日本語
![](https://img.shields.io/badge/framework-agentUniverse-pink)
![](https://img.shields.io/badge/python-3.10%2B-blue?logo=Python)
[![](https://img.shields.io/badge/%20license-Apache--2.0-yellow)](LICENSE)
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.8-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.9-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)

![](docs/guidebook/_picture/logo_bar.jpg)
****************************************
Expand Down Expand Up @@ -44,6 +44,11 @@ We will show you how to:
* Quickly serve the agent
For details, please read [Quick Start](docs/guidebook/en/1_3_Quick_Start.md).

## Use Cases
[Legal Consultation Agent](./docs/guidebook/en/7_1_1_Legal_Consultation_Case.md)
[Python Code Generation and Execution Agent](./docs/guidebook/en/7_1_1_Python_Auto_Runner.md)
[Discussion Group Based on Multi-Turn Multi-Agent Mode](./docs/guidebook/en/6_2_1_Discussion_Group.md)

## Guidebook
For more detailed information, please refer to the [Guidebook](docs/guidebook/en/0_index.md).

Expand Down
7 changes: 6 additions & 1 deletion README_jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![](https://img.shields.io/badge/framework-agentUniverse-pink)
![](https://img.shields.io/badge/python-3.10%2B-blue?logo=Python)
[![](https://img.shields.io/badge/%20license-Apache--2.0-yellow)](LICENSE)
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.8-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.9-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)

![](docs/guidebook/_picture/logo_bar.jpg)
****************************************
Expand Down Expand Up @@ -43,6 +43,11 @@ pip install agentUniverse
* エージェントを迅速に提供する
詳細は、[クイックスタート](docs/guidebook/en/1_3_Quick_Start.md)をご覧ください。

## 使用ケース
[法律相談Agent](./docs/guidebook/en/7_1_1_Legal_Consultation_Case.md)
[Pythonコード生成と実行Agent](./docs/guidebook/en/7_1_1_Python_Auto_Runner.md)
[多回多Agentによるディスカッショングループ](./docs/guidebook/en/6_2_1_Discussion_Group.md)

## ガイドブック
詳細情報については、[ガイドブック](docs/guidebook/en/0_index.md)を参照してください。

Expand Down
7 changes: 6 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![](https://img.shields.io/badge/framework-agentUniverse-pink)
![](https://img.shields.io/badge/python-3.10%2B-blue?logo=Python)
[![](https://img.shields.io/badge/%20license-Apache--2.0-yellow)](LICENSE)
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.8-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.9-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)

![](docs/guidebook/_picture/logo_bar.jpg)
****************************************
Expand Down Expand Up @@ -47,6 +47,11 @@ pip install agentUniverse

详情请阅读[快速开始](docs/guidebook/zh/1_3_%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B.md) 。

## 使用案例
[法律咨询Agent](./docs/guidebook/zh/7_1_1_法律咨询案例.md)
[Python代码生成与执行Agent](./docs/guidebook/zh/7_1_1_Python自动执行案例.md)
[基于多轮多Agent的讨论小组](./docs/guidebook/zh/6_2_1_讨论组.md)

## 用户指南
更多详细信息,请参阅[指南](docs/guidebook/zh/0_%E7%9B%AE%E5%BD%95.md) 。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# @Author : wangchongshi
# @Email : wangchongshi.wcs@antgroup.com
# @FileName: openai_embedding.py

from typing import List, Optional, Any

from langchain_community.embeddings.openai import OpenAIEmbeddings
Expand Down
20 changes: 19 additions & 1 deletion agentuniverse/agent/action/tool/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,32 @@ def input_check(self, kwargs: dict) -> None:
if key not in kwargs.keys():
raise Exception(f'{self.get_instance_code()} - The input must include key: {key}.')

def langchain_run(self, *args, callbacks=None, **kwargs):
"""The callable method that runs the tool."""
kwargs["callbacks"] = callbacks
tool_input = ToolInput(kwargs)
parse_result = self.parse_react_input(args[0])
for key in self.input_keys:
tool_input.add_data(key, parse_result[key])
return self.execute(tool_input)

def parse_react_input(self, input_str: str):
"""
parse react string to you input
you can define your own logic here by override this function
"""
return {
self.input_keys[0]: input_str
}

@abstractmethod
def execute(self, tool_input: ToolInput):
raise NotImplementedError

def as_langchain(self) -> LangchainTool:
"""Convert the agentUniverse(aU) tool class to the langchain tool class."""
return LangchainTool(name=self.name,
func=self.run,
func=self.langchain_run,
description=self.description)

def get_instance_code(self) -> str:
Expand Down
Empty file.
27 changes: 27 additions & 0 deletions agentuniverse/agent/default/nl2api_agent/default_cn_prompt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
introduction: 你是一位精通工具选择ai助手。
target: 你的目标是根据用户的问题选择出合适的工具。
instruction: |
你需要根据问题和用户提供的工具,选择其中的一个或几个工具用来回答用户提出的问题。
你必须从多个角度、维度分析用户的问题,需要根据背景和问题,决定使用哪些工具可以回答用户问题。

您可以使用以下工具:
{tools}

之前的对话:
{chat_history}

背景信息是:
{background}

回答必须是按照以下格式化的Json代码片段。
1. tools字段代表选择的几个工具的完整名称,列表格式。例如:[add, sub, mul, div]
2. thought字段代表选择工具的思考过程和原因。
```{{
"tools": list,
"thought": string
}}```

当前的问题:{input}
metadata:
type: 'PROMPT'
version: 'default_nl2api_agent.cn'
26 changes: 26 additions & 0 deletions agentuniverse/agent/default/nl2api_agent/default_en_prompt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
introduction: You are an AI assistant proficient in tool selection.
target: Your goal is to select the appropriate tools based on the user's questions.
instruction: |
Your task is to select one or several tools from those provided by the user, based on their question and the context, in order to answer the user's query.
You must analyze the user's problem from multiple angles and dimensions, taking into account the background and context of the question, and decide which tools can be used to answer the user's question.
You may use the following tools:
{tools}

Previous conversation:
{chat_history}

The background information is:
{background}

The response must follow the format below as a formatted JSON code snippet.
1. The tools field represents the full names of the selected tools in a list format, such as:[add, sub, mul, div]
2. The thought field represents the thinking process and reasons behind the selection of tools.
```{{
"tools": list,
"thought": string
}}```

Question: {input}
metadata:
type: 'PROMPT'
version: 'default_nl2api_agent.en'
45 changes: 45 additions & 0 deletions agentuniverse/agent/default/nl2api_agent/nl2api_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/6/11 17:14
# @Author : weizjajj
# @Email : weizhongjie.wzj@antgroup.com
# @FileName: nl2api_agent.py

from agentuniverse.agent.agent import Agent
from agentuniverse.agent.input_object import InputObject


class Nl2ApiAgent(Agent):
"""ReAct Agent class."""

def input_keys(self) -> list[str]:
"""Return the input keys of the Agent."""
return ['input']

def output_keys(self) -> list[str]:
"""Return the output keys of the Agent."""
return ['output']

def parse_input(self, input_object: InputObject, agent_input: dict) -> dict:
"""Agent parameter parsing.

Args:
input_object (InputObject): input parameters passed by the user.
agent_input (dict): agent input preparsed by the agent.
Returns:
dict: agent input parsed from `input_object` by the user.
"""
agent_input['input'] = input_object.get_data('input')
self.agent_model.profile.setdefault('prompt_version', 'default_nl2api_agent.cn')
return agent_input

def parse_result(self, planner_result: dict) -> dict:
"""Planner result parser.

Args:
planner_result(dict): Planner result
Returns:
dict: Agent result object.
"""
return planner_result
17 changes: 17 additions & 0 deletions agentuniverse/agent/default/nl2api_agent/nl2api_agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
info:
name: 'nl2api_agent'
description: 'nl2api agent'
profile:
llm_model:
name: 'default_openai_llm'
model_name: 'gpt-4o'
action:
tool:
- ''
plan:
planner:
name: 'nl2api_planner'
metadata:
type: 'AGENT'
module: 'agentuniverse.agent.default.nl2api_agent.nl2api_agent'
class: 'Nl2ApiAgent'
7 changes: 7 additions & 0 deletions agentuniverse/agent/default/react_agent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/6/4 21:21
# @Author : wangchongshi
# @Email : wangchongshi.wcs@antgroup.com
# @FileName: __init__.py.py
35 changes: 35 additions & 0 deletions agentuniverse/agent/default/react_agent/default_cn_prompt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
introduction: 你是一位精通信息分析的ai助手。
target: 你的目标是根据用户的问题以及给出的背景信息给出答案。
instruction: |
你必须优先选择使用提供的工具回答用户提出的问题,若用户没有提供工具可以根据你的通识能力解决问题。
你在回答时问题必须使用中文回答。
你必须从多个角度、维度分析用户的问题,帮助用户获取最全面的信息,需要根据背景和问题,决定搜索哪些信息可以回答问题。
请注意: 你在给出最终答案时需要从多角度给出更详细的原因,而不是一个简单的结论。

您可以使用以下工具:
{tools}

你的回答必须严格使用以下格式:

Question: 您必须回答的问题
Thought: 你应该经常想想该怎么做
Action: 要采取的行动应该是 one of [{tool_names}]
Action Input: 行动的输入
Observation: 行动的结果
... (Thought/Action/Action Input/Observation 的过程可以重复 N 次)
Thought: 我现在知道最终答案了
Final Answer: 原输入问题的最终答案

之前的对话:
{chat_history}

背景信息是:
{background}

开始!

Question: {input}
Thought:{agent_scratchpad}
metadata:
type: 'PROMPT'
version: 'default_react_agent.cn'
31 changes: 31 additions & 0 deletions agentuniverse/agent/default/react_agent/default_en_prompt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
introduction: You are an AI assistant who is proficient in information analysis.
target: Your goal is to give answers based on the user's question and the context given.
instruction: |
Answer the following questions as best you can. You have access to the following tools:

{tools}

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Previous conversion:
{chat_history}

Background:
{background}

Begin!

Question: {input}
Thought:{agent_scratchpad}
metadata:
type: 'PROMPT'
version: 'default_react_agent.en'
44 changes: 44 additions & 0 deletions agentuniverse/agent/default/react_agent/react_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/5/31 21:22
# @Author : wangchongshi
# @Email : wangchongshi.wcs@antgroup.com
# @FileName: react_agent.py
from agentuniverse.agent.agent import Agent
from agentuniverse.agent.input_object import InputObject


class ReActAgent(Agent):
"""ReAct Agent class."""

def input_keys(self) -> list[str]:
"""Return the input keys of the Agent."""
return ['input']

def output_keys(self) -> list[str]:
"""Return the output keys of the Agent."""
return ['output']

def parse_input(self, input_object: InputObject, agent_input: dict) -> dict:
"""Agent parameter parsing.

Args:
input_object (InputObject): input parameters passed by the user.
agent_input (dict): agent input preparsed by the agent.
Returns:
dict: agent input parsed from `input_object` by the user.
"""
agent_input['input'] = input_object.get_data('input')
self.agent_model.profile.setdefault('prompt_version', 'default_react_agent.cn')
return agent_input

def parse_result(self, planner_result: dict) -> dict:
"""Planner result parser.

Args:
planner_result(dict): Planner result
Returns:
dict: Agent result object.
"""
return planner_result
Loading