Skip to content

Commit 6a87090

Browse files
committed
新增muagentv0.1.0文档内容
1 parent b417bb1 commit 6a87090

File tree

68 files changed

+8677
-245
lines changed

Some content is hidden

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

68 files changed

+8677
-245
lines changed

docs/blogDetails/20241231.en-US.md

Lines changed: 350 additions & 0 deletions
Large diffs are not rendered by default.

docs/blogDetails/20241231.zh-CN.md

Lines changed: 369 additions & 0 deletions
Large diffs are not rendered by default.

docs/blogs/blogs.en-US.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ publish:
1313
desc: For complex SOPs requiring constant redefinition of agents and numerous post-processing stages, this procedure can become cumbersome and challenging. Striving to lift this weight and accelerate the execution of SOP workflows,this system streamlines the construction process with a suite of core components, enabling a more convenient and rapid build procedure. It spares users the need to delve into the intricacies of internal prompt construction logic. At last, The paper highlights muAgent's implementation for automating Code Q&A functionalities within Java code repositories, enabling query execution, API documentation, and test case generation.
1414
link: /blogDetails/20240423
1515

16+
- time: '2024-12-31'
17+
title: muAgent series 2
18+
desc: release muagent v2.2~
19+
link: /blogDetails/20241231
20+
1621
# 技术
1722
develop:
1823
- time: '2024-09-05'
@@ -29,10 +34,10 @@ products:
2934

3035
# 使用
3136
use:
32-
- time: '2024-04-23'
33-
title: Multi-Agent Framework MuAgent Unlocks New Paradigms in Code Development
34-
desc: For complex SOPs requiring constant redefinition of agents and numerous post-processing stages, this procedure can become cumbersome and challenging. Striving to lift this weight and accelerate the execution of SOP workflows,this system streamlines the construction process with a suite of core components, enabling a more convenient and rapid build procedure. It spares users the need to delve into the intricacies of internal prompt construction logic. At last, The paper highlights muAgent's implementation for automating Code Q&A functionalities within Java code repositories, enabling query execution, API documentation, and test case generation.
35-
link: /blogDetails/20240423
37+
- time: '2024-09-15'
38+
title: Not updated yet
39+
desc: Not updated yet
40+
link: /blogDetails/001
3641

3742
# 活动咨询
3843
EventConsultation:

docs/blogs/blogs.zh-CN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ publish:
2828
desc: 在这个信息技术爆炸的时代,我们都知道大型语言模型(LLM)拥有处理复杂问题的能力,但当遇到编程难题这种更高级的挑战时,单独的LLM Agent可能就不够看了。社区里动起了脑筋,玩出了新花样——组合多个Agent来应对高难度挑战!正如Multi Agent的构建过程所示,与其说我们是在设计Agents,不如说是对当前需求的深入理解后去构建出一条专属于某个场景的SOP。
2929
link: /zh-CN/blogDetails/20240423
3030

31+
- time: '2024-12-31'
32+
title: muAgent系列文章·二
33+
desc: muagent v2.2 版本发布啦!~~
34+
link: /zh-CN/blogDetails/20241231
35+
3136
# 技术
3237
develop:
3338
- time: '2024-01-23'
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
group:
3+
title: Agent
4+
order: 5
5+
title: BaseAgent
6+
order: -1
7+
toc: content
8+
---
9+
10+
Here is the English translation of the usage documentation for the BaseAgent class, including the code content description, functionality overview, and SDK interface documentation.
11+
12+
# `BaseAgent` Documentation
13+
14+
## Code Content Description
15+
16+
The `BaseAgent` class is a foundational class for implementing agents, providing initialization and interaction methods. Users can customize the agent as needed to handle specific tasks and inquiries.
17+
18+
### Functionality Overview
19+
20+
The `BaseAgent` class primarily serves as a foundational building block for agents. It supports interaction with large language models, prompt management, memory management, and response generation. Below are the main functionalities provided by this class:
21+
22+
- **Task Execution**: Provides `step` and `step_stream` methods for processing user requests and returning agent responses.
23+
- **Memory Management**: Implements management of historical messages, allowing for optional clearing or restoration of historical records.
24+
- **Prompt Management**: Generates dynamic prompts based on input queries and session contexts.
25+
26+
**Basic Attributes**:
27+
28+
- `agent_type`: String that defines the type of the agent (default is `BaseAgent`).
29+
- `agent_name`: String representing the agent's name.
30+
- `system_prompt`: String containing the system's prompt message.
31+
- `input_template`: Input template, which can be a string or a base model.
32+
- `output_template`: Output template, which can be a string or a base model.
33+
- `prompt`: Optional string for prompt information.
34+
- `agents`: List of agents for multi-agent interaction.
35+
- `tools`: List of tools available for external use.
36+
- `agent_desc`: Description of the agent.
37+
- `agent_config`: Optional agent configuration.
38+
- `model_config`: Optional model configuration.
39+
- `prompt_config`: Prompt configuration (default is `PromptConfig()`).
40+
- `project_config`: Optional project configuration.
41+
42+
**Class Methods**:
43+
44+
- `init_from_project_config`: Creates a new instance of the agent based on project configuration.
45+
- `get_wrapper`: Retrieves the appropriate class wrapper based on the agent type.
46+
47+
**Instance Methods**:
48+
49+
- `step`: Processes a query and returns the agent's response.
50+
- `step_stream`: Streams the agent's responses.
51+
- `pre_print`: Generates and prints the agent's prompt format.
52+
- `copy_config`: Creates a copy of the agent's configuration.
53+
- `clear_history`: Clears the agent's memory history.
54+
- `get_memory`: Retrieves memory for a specified session index.
55+
- `append_history`: Appends new messages to the agent's history.
56+
- `update_memory_manager`: Updates the memory manager to store the latest messages.
57+
- `memory_to_format_messages`: Formats stored memory into specific message formats.
58+
59+
### SDK Interface Documentation
60+
61+
#### `__init__(agent_name: str = "codefuse_baser", system_prompt: str = "you are a helpful assistant!\n", input_template: Union[str, BaseModel] = "", output_template: Union[str, BaseModel] = "", prompt: Optional[str] = None, agents: List[str] = [], tools: List[str] = [], agent_desc: str = "", *, agent_config: Optional[AgentConfig] = None, model_config: Optional[ModelConfig] = None, prompt_config: Optional[PromptConfig] = PromptConfig(), project_config: Optional[ProjectConfig] = None, log_verbose: str = "0")`
62+
63+
- **Description**: Initializes the basic properties of the agent.
64+
- **Parameters**:
65+
- `agent_name`: The name of the agent (default is "codefuse_baser").
66+
- `system_prompt`: The system's prompt message (default is "you are a helpful assistant!\n").
67+
- `input_template`: Input template, supporting string or base model types.
68+
- `output_template`: Output template, supporting string or base model types.
69+
- `prompt`: Optional prompt information.
70+
- `agents`: List of agents.
71+
- `tools`: List of tools.
72+
- `agent_desc`: Description of the agent.
73+
- `agent_config`: Optional agent configuration.
74+
- `model_config`: Optional model configuration.
75+
- `prompt_config`: Prompt configuration, default is `PromptConfig()`.
76+
- `project_config`: Optional project configuration.
77+
- `log_verbose`: Verbosity of logs (default is "0").
78+
79+
#### `step(query: Message, memory_manager: Optional[BaseMemoryManager]=None, session_index: str = "default", **kwargs) -> Optional[Message]`
80+
81+
- **Description**: Responds to user input and returns the agent's response.
82+
- **Parameters**:
83+
- `query`: A user input message.
84+
- `memory_manager`: An optional memory manager instance for managing message history.
85+
- `session_index`: A string representing the session index (default is "default").
86+
- `kwargs`: Additional keyword arguments for extended functionality.
87+
- **Returns**: Returns the message instance processed by the agent, or `None` if there is no response.
88+
89+
#### `step_stream(query: Message, memory_manager: Optional[BaseMemoryManager]=None, session_index: str = "default") -> Generator[Message, None, None]`
90+
91+
- **Description**: Responds to user input and returns the agent's streaming response.
92+
- **Parameters**:
93+
- `query`: A user input message.
94+
- `memory_manager`: An optional memory manager instance for managing message history.
95+
- `session_index`: A string representing the session index (default is "default").
96+
- **Returns**: Returns a generator for outputting messages one by one.
97+
98+
#### `pre_print(query: Message, memory_manager: Optional[BaseMemoryManager]=None, session_index: str = "default", **kwargs) -> None`
99+
100+
- **Description**: Generates and prints the agent's prompt format and performs pre-processing.
101+
- **Parameters**:
102+
- `query`: A user input message.
103+
- `memory_manager`: An optional memory manager instance for managing message history.
104+
- `session_index`: A string representing the session index (default is "default").
105+
- `kwargs`: Additional keyword arguments for extended functionality.
106+
- **Returns**: No return value.
107+
108+
#### `clear_history()`
109+
110+
- **Description**: Clears the agent's memory.
111+
- **Returns**: No return value.
112+
113+
#### `get_memory(session_index: str, memory_manager: Optional[BaseMemoryManager] = None) -> Memory`
114+
115+
- **Description**: Retrieves memory for the specified session index.
116+
- **Parameters**:
117+
- `session_index`: A string representing the session index.
118+
- `memory_manager`: An optional memory manager instance.
119+
- **Returns**: Returns the `Memory` instance corresponding to the specified index.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
group:
3+
title: 智能体
4+
order: 5
5+
title: 基础·智能体
6+
order: -1
7+
toc: content
8+
---
9+
10+
以下是对于 `BaseAgen` 类的中文使用文档,包含代码内容说明、功能介绍,以及 SDK 接口文档。
11+
12+
# BaseAgent 类使用
13+
14+
## 代码内容说明
15+
16+
`BaseAgent` 类是一个用于实现 Agent 的基础类,提供了初始化和交互方法。用户可以根据需要自定义智能体,处理特定的任务和查询。
17+
18+
### 功能介绍
19+
20+
`BaseAgent` 类主要用于提高 agent 的基础构建块。它支持与大语言模型的交互,提示词管理,记忆管理,以及响应生成。以下是该类提供的主要功能:
21+
22+
- **任务执行**:提供 `step``step_stream` 方法,用于处理用户请求,并返回 agent 响应。
23+
- **记忆管理**:实现对历史消息的管理,可以选择清除或恢复历史记录。
24+
- **提示词管理**:基于输入的查询和会话上下文,生成动态提示。
25+
26+
**基本属性**:
27+
28+
- `agent_type`: 字符串,定义 agent 的类型(默认为 `BaseAgent`)。
29+
- `agent_name`: 字符串,agent 的名称。
30+
- `system_prompt`: 字符串,系统的提示信息。
31+
- `input_template`: 输入模板,可以是字符串或基础模型。
32+
- `output_template`: 输出模板,可以是字符串或基础模型。
33+
- `prompt`: 可选字符串,提示信息。
34+
- `agents`: 智能体列表,可进行多智能体交互。
35+
- `tools`: 工具列表,可以使用外部工具。
36+
- `agent_desc`: 智能体描述信息。
37+
- `agent_config`: 可选智能体配置。
38+
- `model_config`: 可选模型配置。
39+
- `prompt_config`: 提示配置(默认为 `PromptConfig()`)。
40+
- `project_config`: 可选项目配置。
41+
42+
**类方法**:
43+
44+
- `init_from_project_config`: 根据项目配置创建智能体的新实例。
45+
- `get_wrapper`: 根据智能体类型获取相应的类包装器。
46+
47+
**实例方法**:
48+
49+
- `step`: 处理查询并返回智能体响应。
50+
- `step_stream`: 流式处理智能体的响应。
51+
- `pre_print`: 生成并打印智能体的提示格式。
52+
- `copy_config`: 创建智能体配置的副本。
53+
- `clear_history`: 清除智能体的内存历史。
54+
- `get_memory`: 获取指定会话索引的记忆。
55+
- `append_history`: 向智能体的历史记录中追加新消息。
56+
- `update_memory_manager`: 更新内存管理器,以存储最新消息。
57+
- `memory_to_format_messages`: 将存储的记忆格式化为特定消息格式。
58+
59+
### SDK 接口文档
60+
61+
#### `__init__(agent_name: str = "codefuse_baser", system_prompt: str = "you are a helpful assistant!\n", input_template: Union[str, BaseModel] = "", output_template: Union[str, BaseModel] = "", prompt: Optional[str] = None, agents: List[str] = [], tools: List[str] = [], agent_desc: str = "", *, agent_config: Optional[AgentConfig] = None, model_config: Optional[ModelConfig] = None, prompt_config: Optional[PromptConfig] = PromptConfig(), project_config: Optional[ProjectConfig] = None, log_verbose: str = "0")`
62+
63+
- **描述**: 初始化 agent 的基本属性。
64+
- **参数**:
65+
- `agent_name`: agent 的名称(默认为 "codefuse_baser")。
66+
- `system_prompt`: 系统的提示信息(默认为 "you are a helpful assistant!\n")。
67+
- `input_template`: 输入模板,支持字符串或基础模型类型。
68+
- `output_template`: 输出模板,支持字符串或基础模型类型。
69+
- `prompt`: 可选的提示信息。
70+
- `agents`: 智能体列表。
71+
- `tools`: 工具列表。
72+
- `agent_desc`: agent 描述信息。
73+
- `agent_config`: 可选的 agent 配置。
74+
- `model_config`: 可选的模型配置。
75+
- `prompt_config`: 提示配置,默认为 `PromptConfig()`
76+
- `project_config`: 可选的项目配置。
77+
- `log_verbose`: 日志详细程度(默认为 "0")。
78+
79+
#### `step(query: Message, memory_manager: Optional[BaseMemoryManager]=None, session_index: str = "default", **kwargs) -> Optional[Message]`
80+
81+
- **描述**: 回答用户的输入并返回 agent 的响应。
82+
- **参数**:
83+
- `query`: 一条用户输入消息。
84+
- `memory_manager`: 可选的内存管理器实例,用于管理消息历史。
85+
- `session_index`: 字符串,表示会话索引(默认为 "default")。
86+
- `kwargs`: 其他扩展功能的关键字参数。
87+
- **返回**: 返回智能体处理后的消息实例,或在没有响应时返回 `None`
88+
89+
#### `step_stream(query: Message, memory_manager: Optional[BaseMemoryManager]=None, session_index: str = "default") -> Generator[Message, None, None]`
90+
91+
- **描述**: 回答用户输入并返回 agent 的流式响应。
92+
- **参数**:
93+
- `query`: 一条用户输入消息。
94+
- `memory_manager`: 可选的内存管理器实例,用于管理消息历史。
95+
- `session_index`: 字符串,表示会话索引(默认为 "default")。
96+
- **返回**: 返回一个生成器,用于逐条输出消息。
97+
98+
#### `pre_print(query: Message, memory_manager: Optional[BaseMemoryManager]=None, session_index: str = "default", **kwargs) -> None`
99+
100+
- **描述**: 生成并打印 agent 的提示词格式,执行前置操作。
101+
- **参数**:
102+
- `query`: 一条用户输入消息。
103+
- `memory_manager`: 可选的内存管理器实例,用于管理消息历史。
104+
- `session_index`: 字符串,表示会话索引(默认为 "default")。
105+
- `kwargs`: 其他扩展功能的关键字参数。
106+
- **返回**: 无返回值。
107+
108+
#### `clear_history()`
109+
110+
- **描述**: 清除 agent 的记忆。
111+
- **返回**: 无返回值。
112+
113+
#### `get_memory(session_index: str, memory_manager: Optional[BaseMemoryManager] = None) -> Memory`
114+
115+
- **描述**: 获取指定会话索引的记忆。
116+
- **参数**:
117+
- `session_index`: 字符串,表示会话索引。
118+
- `memory_manager`: 可选的内存管理器实例。
119+
- **返回**: 返回对应索引的 `Memory` 实例。
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
group:
3+
title: Agent
4+
order: 5
5+
title: SingleAgent
6+
order: 3
7+
toc: content
8+
---
9+
10+
`GroupAgent` provides functionalities for basic question-answering, tool usage, and code execution, facilitating a group scheduling execution process: input => agent => output.
11+
12+
<div align=center>
13+
<img src="../../../../static/api-docs/muAgent/selectoragent.webp" alt="Image" style="width: 800px; height:auto;" >
14+
</div>
15+
16+
## Usage of GroupAgent
17+
18+
### Configure the Model
19+
20+
```python
21+
from muagent.schemas import ModelConfig
22+
import json, os
23+
24+
MODEL_CONFIGS = {
25+
"qwen_chat": {
26+
"model_type": "qwen_chat",
27+
"model_name": "qwen2.5-72b-instruct",
28+
"api_key": "sk-xxx",
29+
},
30+
}
31+
os.environ["MODEL_CONFIGS"] = json.dumps(MODEL_CONFIGS)
32+
```
33+
34+
### Configure the Agents
35+
36+
```python
37+
tools = ["KSigmaDetector", "MetricsQuery"]
38+
role_prompt = "You are a helpful assistant!"
39+
40+
AGENT_CONFIGS = {
41+
"grouper": {
42+
"agent_type": "GroupAgent",
43+
"agent_name": "grouper",
44+
"agents": ["codefuse_reacter_1", "codefuse_reacter_2"]
45+
},
46+
"codefuse_reacter_1": {
47+
"agent_type": "ReactAgent",
48+
"agent_name": "codefuse_reacter_1",
49+
"tools": tools,
50+
},
51+
"codefuse_reacter_2": {
52+
"agent_type": "ReactAgent",
53+
"agent_name": "codefuse_reacter_2",
54+
"tools": tools,
55+
}
56+
}
57+
os.environ["AGENT_CONFIGS"] = json.dumps(AGENT_CONFIGS)
58+
```
59+
60+
### Initialize Configuration
61+
62+
```python
63+
from muagent import get_ekg_project_config_from_env
64+
project_config = get_ekg_project_config_from_env()
65+
```
66+
67+
### Initialize the Agent
68+
69+
```python
70+
from muagent.agents import BaseAgent
71+
agent = BaseAgent.init_from_project_config(
72+
"grouper", project_config
73+
)
74+
```
75+
76+
### Respond to User Requests
77+
78+
```python
79+
query_content = "Please help me check if there are any anomalies on the server at 127.0.0.1 at 10 o'clock."
80+
query = Message(
81+
role_name="human",
82+
role_type="user",
83+
content=query_content,
84+
)
85+
# agent.pre_print(query)
86+
output_message = agent.step(query)
87+
print("input:", output_message.input_text)
88+
print("content:", output_message.content)
89+
print("step_content:", output_message.step_content)
90+
```

0 commit comments

Comments
 (0)