Skip to content

Commit a4eb490

Browse files
authored
Merge pull request #109 from alipay/dev
feat: Version 0.0.10 Release
2 parents 0a97104 + a665f8d commit a4eb490

Some content is hidden

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

56 files changed

+1797
-46
lines changed

CHANGELOG.md

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

2626
# Version Update History
27+
## [0.0.10] - 2024-06-28
28+
### Added
29+
- Added standard integration for the DeepSeek model in the LLM module.
30+
- Added a new OpenAI general protocol wrapper class, OpenAIStyleLLM.
31+
- Models using the OpenAI protocol can be configured directly.
32+
- Added a new LangChain tool wrapper class, LangChainTool, with several example tools for search and execution.
33+
- LangChain tools can be configured directly.
34+
- Added Agent information collection capability in the monitor module.
35+
36+
### Note
37+
- Added use cases.
38+
- Supplemented documentation with a financial event analysis case study using PEER collaborative mode.
39+
- Added several new documents for LLM components, tool components, and the Monitor module.
40+
- Updated the new README.
41+
- Some code optimizations and documentation updates.
42+
2743
## [0.0.9] - 2024-06-14
2844
### Added
2945
- Added standard integration for Claude and Ollama LLM components

CHANGELOG_zh.md

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

2626
# 版本更新记录
27+
## [0.0.10] - 2024-06-28
28+
### Added
29+
- LLM组件新增DeepSeek模型标准接入
30+
- 新增OpenAI通用协议包装类OpenAIStyleLLM
31+
- openai协议类模型接入可直接配置
32+
- 新增LangChain工具包装类LangChainTool,新增搜索类、执行类示例工具若干
33+
- LangChain工具接入可直接配置
34+
- monitor模块新增Agent纬度信息采集能力
35+
36+
### Note
37+
- 新增使用案例
38+
- PEER协同模式的金融事件分析案例文档补充
39+
- 新增若干LLM组件、工具组件、Monitor模块文档
40+
- 新版README更新
41+
- 部分代码优化与文档更新
42+
2743
## [0.0.9] - 2024-06-14
2844
### Added
2945
- LLM组件新增claude、ollama标准接入

README.md

Lines changed: 1 addition & 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.9-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
8+
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.10-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
99

1010
![](docs/guidebook/_picture/logo_bar.jpg)
1111
****************************************

README_jp.md

Lines changed: 1 addition & 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.9-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
8+
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.10-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
99

1010
![](docs/guidebook/_picture/logo_bar.jpg)
1111
****************************************

README_zh.md

Lines changed: 1 addition & 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.9-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
8+
[![Static Badge](https://img.shields.io/badge/pypi-v0.0.10-blue?logo=pypi)](https://pypi.org/project/agentUniverse/)
99

1010
![](docs/guidebook/_picture/logo_bar.jpg)
1111
****************************************

agentuniverse/agent/action/knowledge/knowledge.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
# @Author : wangchongshi
66
# @Email : wangchongshi.wcs@antgroup.com
77
# @FileName: knowledge.py
8-
from typing import Optional, Dict, List, Any
8+
from typing import Optional, Dict, List
9+
10+
from langchain_core.utils.json import parse_json_markdown
11+
from langchain.tools import Tool as LangchainTool
912

1013
from agentuniverse.agent.action.knowledge.reader.reader import Reader
1114
from agentuniverse.agent.action.knowledge.store.document import Document
@@ -77,3 +80,37 @@ def initialize_by_component_configer(self, component_configer: KnowledgeConfiger
7780
if component_configer.ext_info:
7881
self.ext_info = component_configer.ext_info
7982
return self
83+
84+
def langchain_query(self, query: str) -> str:
85+
"""Query the knowledge using LangChain.
86+
87+
Query documents from the store and return the results.
88+
"""
89+
parse_query = parse_json_markdown(query)
90+
query = Query(**parse_query)
91+
knowledge = self.store.query(query)
92+
res = ['This is Query Result']
93+
for doc in knowledge:
94+
res.append(doc.text)
95+
return "\n=========================================\n".join(res)
96+
97+
def as_langchain_tool(self) -> LangchainTool:
98+
"""Convert the Knowledge object to a LangChain tool.
99+
100+
Returns:
101+
Any: the LangChain tool object
102+
"""
103+
args_description = """
104+
This is a knowledge base tool, which stores the content you may need. To use this tool, you need to give a json string with the following format:
105+
```json
106+
{
107+
"query_str": "<your query here>",
108+
"top_k": <number of results to return>,
109+
}
110+
```
111+
"""
112+
return LangchainTool(
113+
name=self.name,
114+
description=self.description + args_description,
115+
func=self.langchain_query,
116+
)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# @Email : wangchongshi.wcs@antgroup.com
77
# @FileName: chroma_store.py
88
from typing import List, Any, Optional
9+
from pydantic import SkipValidation
910

1011
import chromadb
1112
from chromadb import QueryResult
12-
from chromadb.api.models import Collection
13+
from chromadb.api.models.Collection import Collection
1314

1415
from agentuniverse.agent.action.knowledge.store.document import Document
1516
from agentuniverse.agent.action.knowledge.store.query import Query
@@ -28,7 +29,7 @@ class ChromaStore(Store):
2829
"""
2930

3031
collection_name: Optional[str] = 'chroma_db'
31-
collection: Collection = None
32+
collection: SkipValidation[Collection] = None
3233
persist_path: Optional[str] = None
3334

3435
def __init__(self, **kwargs):

agentuniverse/agent/agent.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@
66
# @Email : lc299034@antgroup.com
77
# @FileName: agent.py
88
"""The definition of agent paradigm."""
9+
import json
910
from abc import abstractmethod
1011
from datetime import datetime
1112
from typing import Optional
1213

14+
from langchain_core.utils.json import parse_json_markdown
15+
1316
from agentuniverse.agent.agent_model import AgentModel
1417
from agentuniverse.agent.input_object import InputObject
1518
from agentuniverse.agent.output_object import OutputObject
1619
from agentuniverse.agent.plan.planner.planner import Planner
1720
from agentuniverse.agent.plan.planner.planner_manager import PlannerManager
21+
from agentuniverse.base.annotation.trace import trace_agent
1822
from agentuniverse.base.component.component_base import ComponentBase
1923
from agentuniverse.base.component.component_enum import ComponentEnum
2024
from agentuniverse.base.config.application_configer.application_config_manager \
2125
import ApplicationConfigManager
2226
from agentuniverse.base.config.component_configer.configers.agent_configer \
2327
import AgentConfiger
28+
from agentuniverse.base.util.logging.logging_util import LOGGER
2429
from agentuniverse.llm.llm import LLM
2530

2631

@@ -66,6 +71,7 @@ def parse_result(self, planner_result: dict) -> dict:
6671
"""
6772
pass
6873

74+
@trace_agent
6975
def run(self, **kwargs) -> OutputObject:
7076
"""Agent instance running entry.
7177
@@ -156,3 +162,35 @@ def initialize_by_component_configer(self, component_configer: AgentConfiger) ->
156162
plan=plan, memory=memory, action=action)
157163
self.agent_model = agent_model
158164
return self
165+
166+
def langchain_run(self, input: str, callbacks=None, **kwargs):
167+
"""Run the agent model using LangChain."""
168+
try:
169+
parse_result = parse_json_markdown(input)
170+
except Exception as e:
171+
LOGGER.error(f"langchain run parse_json_markdown error,input(parse_result) error({str(e)})")
172+
return "Error , Your Action Input is not a valid JSON string"
173+
output_object = self.run(**parse_result, callbacks=callbacks, **kwargs)
174+
result_dict = {}
175+
for key in self.output_keys():
176+
result_dict[key] = output_object.get_data(key)
177+
return result_dict
178+
179+
def as_langchain_tool(self):
180+
"""Convert to LangChain tool."""
181+
from langchain.agents.tools import Tool
182+
format_dict = {}
183+
for key in self.input_keys():
184+
format_dict.setdefault(key, "input val")
185+
format_str = json.dumps(format_dict)
186+
187+
args_description = f"""
188+
to use this tool,your input must be a json string,must contain all keys of {self.input_keys()},
189+
and the value of the key must be a json string,the format of the json string is as follows:
190+
```{format_str}```
191+
"""
192+
return Tool(
193+
name=self.agent_model.info.get("name"),
194+
func=self.langchain_run,
195+
description=self.agent_model.info.get("description") + args_description
196+
)

agentuniverse/agent/default/executing_agent/executing_agent.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
import copy
99
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
1010
from typing import Optional, Any
11+
12+
from agentuniverse.agent.action.tool.tool_manager import ToolManager
1113
from agentuniverse.agent.agent import Agent
1214
from agentuniverse.agent.input_object import InputObject
15+
from agentuniverse.agent.plan.planner.planner import Planner
1316
from agentuniverse.agent.plan.planner.planner_manager import PlannerManager
1417

1518

@@ -75,9 +78,35 @@ def execute(self, input_object: InputObject, agent_input: dict) -> dict:
7578
for task in framework:
7679
agent_input_copy: dict = copy.deepcopy(agent_input)
7780
agent_input_copy['input'] = task
81+
planner: Planner = PlannerManager().get_instance_obj(self.agent_model.plan.get('planner').get('name'))
7882
futures.append(
79-
self.executor.submit(
80-
PlannerManager().get_instance_obj(self.agent_model.plan.get('planner').get('name')).invoke,
81-
self.agent_model, agent_input_copy, input_object))
83+
self.executor.submit(planner.invoke, self.agent_model, agent_input_copy,
84+
self.process_intput_object(input_object, task, planner.input_key)))
8285
wait(futures, return_when=ALL_COMPLETED)
8386
return {'futures': futures}
87+
88+
def process_intput_object(self, input_object: InputObject, subtask: str, planner_input_key: str) -> InputObject:
89+
"""Process input object for the executing agent.
90+
91+
Args:
92+
input_object (InputObject): input parameters passed by the user.
93+
subtask (str): subtask to be executed.
94+
planner_input_key (str): planner input key.
95+
96+
Returns:
97+
input_object (InputObject): processed input object.
98+
"""
99+
# get agent toolsets.
100+
action: dict = self.agent_model.action or dict()
101+
tools: list = action.get('tool') or list()
102+
input_object_copy: InputObject = copy.deepcopy(input_object)
103+
# wrap input_object for agent knowledge.
104+
input_object_copy.add_data(planner_input_key, subtask)
105+
# wrap input_object for agent toolsets.
106+
for tool_name in tools:
107+
tool = ToolManager().get_instance_obj(tool_name)
108+
if tool is None:
109+
continue
110+
# note: only insert the first key of tool input.
111+
input_object_copy.add_data(tool.input_keys[0], subtask)
112+
return input_object_copy

agentuniverse/agent/memory/langchain_instance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from langchain_core.messages import BaseMessage, get_buffer_string
1111
from langchain.memory import ConversationSummaryBufferMemory, ConversationTokenBufferMemory
12+
from langchain_core.output_parsers import StrOutputParser
1213

1314
from agentuniverse.agent.memory.enum import ChatMessageEnum
1415
from agentuniverse.agent.memory.message import Message
@@ -115,9 +116,8 @@ def predict_new_summary(
115116
)
116117
prompt_version = self.prompt_version if self.prompt_version else 'chat_memory.summarizer_cn'
117118
prompt: Prompt = PromptManager().get_instance_obj(prompt_version)
118-
chain = prompt.as_langchain() | self.llm
119-
res = chain.invoke(input={'summary': existing_summary, 'new_lines': new_lines})
120-
return res.content
119+
chain = prompt.as_langchain() | self.llm | StrOutputParser()
120+
return chain.invoke(input={'summary': existing_summary, 'new_lines': new_lines})
121121

122122

123123
class AuConversationTokenBufferMemory(ConversationTokenBufferMemory):

0 commit comments

Comments
 (0)