Skip to content

Commit c5c3af5

Browse files
authored
Merge pull request #138 from alipay/dev
feat: Version 0.0.12 Release
2 parents cf15bea + 11efe76 commit c5c3af5

File tree

123 files changed

+2559
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+2559
-90
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ Note - Additional remarks regarding the version.
2424
***************************************************
2525

2626
# Version Update History
27+
## [0.0.12] - 2024-08-14
28+
### Added
29+
- agentUniverse Product Version Offering
30+
- The current version provides basic capabilities for agent construction, modification, and debugging, jointly launched by the difizen project. For more details, please refer to the documentation in the product platform section.
31+
- Monitor Component: Added knowledge and tool instance collection, supporting full-link trace sequence concatenation and providing token consumption monitoring.
32+
- New Web Session Module: Provides session and message persistence management capabilities.
33+
34+
### Note
35+
- Optimized Knowledge Component: Users can configure and specify any number of recall results (similarity_top_k).
36+
- Fixed Chroma Component: Resolved issues where the embedding module was not specified.
37+
- Various code optimizations and documentation updates.
38+
2739
## [0.0.11] - 2024-07-11
2840
### Added
2941
- DataAgent Autonomous Data Agent MVP Version Released

CHANGELOG_zh.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ Note - 对于版本的额外说明。
2424
***************************************************
2525

2626
# 版本更新记录
27+
## [0.0.12] - 2024-08-14
28+
### Added
29+
- agentUniverse产品化版本提供
30+
- 当前版本提供智能体构建、修改、调试等基础能力,由difizen项目联合推出,更多详情请见文档产品化平台部分。
31+
- monitor组件新增对于知识、工具实例采集,支持全链路trace时序串联并提供token消耗监控
32+
- 新增web会话模块,提供session与message持久化管理能力
33+
34+
### Note
35+
- 优化知识组件,可由用户配置指定任意召回结果数量(similarity_top_k)
36+
- 修复chroma组件未指定embedding模块出现异常
37+
- 其他部分代码优化与文档更新
38+
2739
## [0.0.11] - 2024-07-11
2840
### Added
2941
- DataAgent数据自治智能体MVP版本发布

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Language version: [English](./README.md) | [中文](./README_zh.md) | [日本語
55
![](https://img.shields.io/badge/framework-agentUniverse-pink)
66
![](https://img.shields.io/badge/python-3.10%2B-blue?logo=Python)
77
[![](https://img.shields.io/badge/%20license-Apache--2.0-yellow)](LICENSE)
8-
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.11-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
8+
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.12-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
99

1010
![](docs/guidebook/_picture/logo_bar.jpg)
1111
****************************************
@@ -55,6 +55,24 @@ We will show you how to:
5555
For more details, please read the [Quick Start](./docs/guidebook/en/1_3_Quick_Start.md).
5656

5757
****************************************
58+
## Using the Product Platform
59+
agentUniverse provides a local product platform capability. Please follow the steps below for a quick start:
60+
61+
**Install via pip**
62+
```shell
63+
pip install magent-ui ruamel.yaml
64+
```
65+
66+
**One-click Run**
67+
68+
Run the [product_application.py](sample_standard_app/app/bootstrap/product_application.py) file located in sample_standard_app/app/bootstrap for a one-click start.
69+
70+
For more details, refer to [Quick Start for Product Platform](./docs/guidebook/en/10_1_1_Product%20Platform%20Quick%20Start.md).
71+
72+
This feature is jointly launched by [difizen](https://github.com/difizen/magent) and agentUniverse.
73+
74+
****************************************
75+
5876
## Cases and Example Projects
5977
### 🌟 Use Cases
6078
[Legal Consultation Agent](./docs/guidebook/en/7_1_1_Legal_Consultation_Case.md)

README_zh.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![](https://img.shields.io/badge/framework-agentUniverse-pink)
66
![](https://img.shields.io/badge/python-3.10%2B-blue?logo=Python)
77
[![](https://img.shields.io/badge/%20license-Apache--2.0-yellow)](LICENSE)
8-
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.11-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
8+
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.12-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
99

1010
![](docs/guidebook/_picture/logo_bar.jpg)
1111
****************************************
@@ -51,6 +51,23 @@ pip install agentUniverse
5151
* 对agent进行快速服务化
5252

5353
详情请阅读[快速开始](docs/guidebook/zh/1_3_%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B.md)
54+
****************************************
55+
## 产品化平台使用
56+
agentUniverse提供基于本地的产品化平台能力,请按照如下步骤快速启动
57+
58+
**通过pip安装**
59+
```shell
60+
pip install magent-ui ruamel.yaml
61+
```
62+
63+
**一键运行**
64+
65+
运行sample_standard_app/app/boostrap下的[product_application.py](sample_standard_app/app/bootstrap/product_application.py)文件,一键启动。
66+
67+
更多详情参考 [产品化平台快速开始](./docs/guidebook/zh/10_1_1_产品化平台快速开始.md)
68+
69+
本功能由 [difizen](https://github.com/difizen/magent) X agentUniverse联合推出。
70+
5471
****************************************
5572
## 案例与样例工程
5673
### 🌟 使用案例

agentuniverse/agent/action/knowledge/knowledge.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from agentuniverse.agent.action.knowledge.store.document import Document
1515
from agentuniverse.agent.action.knowledge.store.query import Query
1616
from agentuniverse.agent.action.knowledge.store.store import Store
17+
from agentuniverse.base.annotation.trace import trace_knowledge
1718
from agentuniverse.base.component.component_base import ComponentBase
1819
from agentuniverse.base.component.component_enum import ComponentEnum
1920
from agentuniverse.base.config.application_configer.application_config_manager import ApplicationConfigManager
@@ -53,6 +54,7 @@ def insert_knowledge(self, **kwargs) -> None:
5354
document_list: List[Document] = self.reader.load_data()
5455
self.store.insert_documents(document_list, **kwargs)
5556

57+
@trace_knowledge
5658
def query_knowledge(self, **kwargs) -> List[Document]:
5759
"""Query the knowledge.
5860

agentuniverse/agent/action/knowledge/store/chroma_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def insert_documents(self, documents: List[Document], **kwargs: Any):
9696
self.collection.add(
9797
documents=[document.text],
9898
metadatas=[document.metadata],
99-
embeddings=[embedding] if embedding is not None else None,
99+
embeddings=[embedding] if len(embedding) > 0 else None,
100100
ids=[document.id]
101101
)
102102

agentuniverse/agent/action/tool/tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from langchain.tools import Tool as LangchainTool
1414

1515
from agentuniverse.agent.action.tool.enum import ToolTypeEnum
16+
from agentuniverse.base.annotation.trace import trace_tool
1617
from agentuniverse.base.component.component_base import ComponentBase
1718
from agentuniverse.base.component.component_enum import ComponentEnum
1819
from agentuniverse.base.config.application_configer.application_config_manager import ApplicationConfigManager
@@ -61,6 +62,7 @@ class Tool(ComponentBase):
6162
def __init__(self, **kwargs):
6263
super().__init__(component_type=ComponentEnum.TOOL, **kwargs)
6364

65+
@trace_tool
6466
def run(self, **kwargs):
6567
"""The callable method that runs the tool."""
6668
self.input_check(kwargs)
@@ -73,6 +75,7 @@ def input_check(self, kwargs: dict) -> None:
7375
if key not in kwargs.keys():
7476
raise Exception(f'{self.get_instance_code()} - The input must include key: {key}.')
7577

78+
@trace_tool
7679
def langchain_run(self, *args, callbacks=None, **kwargs):
7780
"""The callable method that runs the tool."""
7881
kwargs["callbacks"] = callbacks

agentuniverse/agent/default/executing_agent/executing_agent.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@
55
# @Email : lc299034@antgroup.com
66
# @FileName: executing_agent.py
77
"""Executing Agent module."""
8-
import copy
98
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
109
from typing import Optional, Any
1110

1211
from agentuniverse.agent.action.tool.tool_manager import ToolManager
1312
from agentuniverse.agent.agent import Agent
13+
from agentuniverse.agent.agent_model import AgentModel
1414
from agentuniverse.agent.input_object import InputObject
1515
from agentuniverse.agent.plan.planner.planner import Planner
1616
from agentuniverse.agent.plan.planner.planner_manager import PlannerManager
17+
from agentuniverse.base.context.framework_context_manager import FrameworkContextManager
1718

1819

1920
class ExecutingAgent(Agent):
2021
"""Executing Agent class."""
2122

2223
executor: Optional[Any] = ThreadPoolExecutor(max_workers=10, thread_name_prefix="executing_agent")
24+
_context_values: Optional[dict] = {}
2325

2426
def input_keys(self) -> list[str]:
2527
"""Return the input keys of the Agent."""
@@ -54,12 +56,16 @@ def parse_result(self, planner_result: dict) -> dict:
5456
llm_result = []
5557
executing_result = []
5658
futures = planner_result.get('futures')
59+
index = 1
60+
# assemble results of the execution process.
5761
for future in futures:
5862
task_result = future.result()
5963
llm_result.append(task_result)
6064
executing_result.append({
61-
'input': task_result['input'], 'output': task_result['output']
65+
'input': f"Question {index}: " + task_result.get('input', ''),
66+
'output': f"Answer {index}: " + task_result.get('output', '')
6267
})
68+
index += 1
6369

6470
return {'executing_result': executing_result, 'llm_result': llm_result}
6571

@@ -73,6 +79,7 @@ def execute(self, input_object: InputObject, agent_input: dict) -> dict:
7379
Returns:
7480
dict: Agent result object.
7581
"""
82+
self._context_values: dict = FrameworkContextManager().get_all_contexts()
7683
framework = agent_input.get('framework', [])
7784
futures = []
7885
for task in framework:
@@ -81,11 +88,37 @@ def execute(self, input_object: InputObject, agent_input: dict) -> dict:
8188
agent_input_copy['input'] = task
8289
planner: Planner = PlannerManager().get_instance_obj(self.agent_model.plan.get('planner').get('name'))
8390
futures.append(
84-
self.executor.submit(planner.invoke, self.agent_model, agent_input_copy,
91+
self.executor.submit(self.run_in_executor, planner, self.agent_model, agent_input_copy,
8592
self.process_intput_object(input_object, task, planner.input_key)))
8693
wait(futures, return_when=ALL_COMPLETED)
8794
return {'futures': futures}
8895

96+
def run_in_executor(self, planner: Planner, agent_model: AgentModel, planner_input: dict,
97+
input_object: InputObject) -> dict:
98+
"""The execution function of the thread pool.
99+
100+
Args:
101+
planner(Planner): The planner object.
102+
agent_model (AgentModel): The agent model object.
103+
planner_input (dict): The planner input dict.
104+
input_object (InputObject): The input parameters passed by the user.
105+
Returns:
106+
dict: The planner execution result.
107+
"""
108+
context_tokens = {}
109+
try:
110+
# pass the framework context into the thread.
111+
for var_name, var_value in self._context_values.items():
112+
token = FrameworkContextManager().set_context(var_name, var_value)
113+
context_tokens[var_name] = token
114+
# invoke planner
115+
res = planner.invoke(agent_model, planner_input, input_object)
116+
return res
117+
finally:
118+
# clear the framework context.
119+
for var_name, token in context_tokens.items():
120+
FrameworkContextManager().reset_context(var_name, token)
121+
89122
def process_intput_object(self, input_object: InputObject, subtask: str, planner_input_key: str) -> InputObject:
90123
"""Process input object for the executing agent.
91124

agentuniverse/agent/memory/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Message(BaseModel):
2424
"""
2525

2626
type: Optional[str] = None
27-
content: Union[str, List[Union[str, Dict]]] = None
27+
content: Optional[Union[str, List[Union[str, Dict]]]] = None
2828

2929
def as_langchain(self):
3030
"""Convert the agentUniverse(aU) message class to the langchain message class."""

agentuniverse/agent/plan/planner/peer_planner/peer_planner.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# @FileName: peer_planner.py
77
"""Peer planner module."""
88
from agentuniverse.agent.action.tool.tool_manager import ToolManager
9+
from agentuniverse.agent.agent import Agent
910
from agentuniverse.agent.agent_manager import AgentManager
1011
from agentuniverse.agent.agent_model import AgentModel
1112
from agentuniverse.agent.input_object import InputObject
@@ -42,7 +43,7 @@ def invoke(self, agent_model: AgentModel, planner_input: dict, input_object: Inp
4243
"""
4344
planner_config = agent_model.plan.get('planner')
4445
sub_agents = self.generate_sub_agents(planner_config)
45-
return self.agents_run(agent_model, sub_agents, planner_config, planner_input, input_object)
46+
return self.agents_run(sub_agents, planner_config, planner_input, input_object)
4647

4748
@staticmethod
4849
def generate_sub_agents(planner_config: dict) -> dict:
@@ -79,7 +80,7 @@ def build_expert_framework(planner_config: dict, input_object: InputObject):
7980
elif context:
8081
input_object.add_data('expert_framework', context)
8182

82-
def agents_run(self, agent_mode: AgentModel, agents: dict, planner_config: dict, agent_input: dict,
83+
def agents_run(self, agents: dict, planner_config: dict, agent_input: dict,
8384
input_object: InputObject) -> dict:
8485
"""Planner agents run.
8586
@@ -105,10 +106,10 @@ def agents_run(self, agent_mode: AgentModel, agents: dict, planner_config: dict,
105106

106107
self.build_expert_framework(planner_config, input_object)
107108

108-
planningAgent = agents.get('planning')
109-
executingAgent = agents.get('executing')
110-
expressingAgent = agents.get('expressing')
111-
reviewingAgent = agents.get('reviewing')
109+
planningAgent: Agent = agents.get('planning')
110+
executingAgent: Agent = agents.get('executing')
111+
expressingAgent: Agent = agents.get('expressing')
112+
reviewingAgent: Agent = agents.get('reviewing')
112113

113114
for _ in range(retry_count):
114115
LOGGER.info(f"Starting peer agents, retry_count is {_ + 1}.")
@@ -126,10 +127,13 @@ def agents_run(self, agent_mode: AgentModel, agents: dict, planner_config: dict,
126127
for index, one_framework in enumerate(planning_result.get_data('framework')):
127128
logger_info += f"[{index + 1}] {one_framework} \n"
128129
LOGGER.info(logger_info)
129-
self.stream_output(input_object, {"data": {
130-
'output': planning_result.to_dict(),
131-
"agent_info": agent_mode.info
132-
}, "type": "planning"})
130+
131+
# add planning agent intermediate steps
132+
if planningAgent:
133+
self.stream_output(input_object, {"data": {
134+
'output': planning_result.get_data('framework'),
135+
"agent_info": planningAgent.agent_model.info
136+
}, "type": "planning"})
133137

134138
if not executing_result or jump_step in ["planning", "executing"]:
135139
if not executingAgent:
@@ -148,10 +152,13 @@ def agents_run(self, agent_mode: AgentModel, agents: dict, planner_config: dict,
148152
one_exec_log_info += f"[{index + 1}] output: {one_exec_res['output']}\n"
149153
logger_info += one_exec_log_info
150154
LOGGER.info(logger_info)
151-
self.stream_output(input_object, {"data": {
152-
'output': executing_result.to_dict(),
153-
"agent_info": agent_mode.info
154-
}, "type": "executing"})
155+
156+
# add executing agent intermediate steps
157+
if executingAgent:
158+
self.stream_output(input_object, {"data": {
159+
'output': executing_result.get_data('executing_result'),
160+
"agent_info": executingAgent.agent_model.info
161+
}, "type": "executing"})
155162

156163
if not expressing_result or jump_step in ["planning", "executing", "expressing"]:
157164
if not expressingAgent:
@@ -166,10 +173,13 @@ def agents_run(self, agent_mode: AgentModel, agents: dict, planner_config: dict,
166173
logger_info = f"\nExpressing agent execution result is :\n"
167174
logger_info += f"{expressing_result.get_data('output')}"
168175
LOGGER.info(logger_info)
169-
self.stream_output(input_object, {"data": {
170-
'output': expressing_result.get_data('output'),
171-
"agent_info": agent_mode.info
172-
}, "type": "expressing"})
176+
177+
# add expressing agent intermediate steps
178+
if expressingAgent:
179+
self.stream_output(input_object, {"data": {
180+
'output': expressing_result.get_data('output'),
181+
"agent_info": expressingAgent.agent_model.info
182+
}, "type": "expressing"})
173183

174184
if not reviewing_result or jump_step in ["planning", "executing", "expressing", "reviewing"]:
175185
if not reviewingAgent:
@@ -193,7 +203,14 @@ def agents_run(self, agent_mode: AgentModel, agents: dict, planner_config: dict,
193203
reviewing_info_str = f"review suggestion: {reviewing_result.get_data('suggestion')} \n"
194204
reviewing_info_str += f"review score: {reviewing_result.get_data('score')} \n"
195205
LOGGER.info(logger_info + reviewing_info_str)
196-
self.stream_output(input_object, {"data": reviewing_result.to_dict(), "type": "reviewing"})
206+
207+
# add reviewing agent intermediate steps
208+
self.stream_output(input_object,
209+
{"data": {
210+
'output': reviewing_result.get_data('suggestion'),
211+
"agent_info": reviewingAgent.agent_model.info
212+
}, "type": "reviewing"})
213+
197214
if reviewing_result.get_data('score') and reviewing_result.get_data('score') >= eval_threshold:
198215
loopResults.append({
199216
"planning_result": planning_result,

0 commit comments

Comments
 (0)