CodeFuse-muAgent,全新体验的 Agent 框架,将 KG 从知识来源直接升级为 Agent 编排引擎!基于 LLM+ EKG(事理图谱承载行业知识)驱动,协同多智能体、工具学习等技术,通过画布式拖拽、轻文字编写,让大模型在人的经验指导下实现各类复杂 SOP 流程。支持复杂推理、在线协同、人工交互、知识即用四大核心差异技术。这套框架目前在蚂蚁集团内多个复杂 DevOps 场景落地验证。
💡CodeFuse muAgent 仓库地址:https://github.com/codefuse-ai/CodeFuse-muAgent
版本简介
新增功能
- EKG支持并行执行
- muAgent-sdk v0.1.0,更加完善的model、prompt manager、agent等基础类,更易继承和自定义开发,可快速配置
- EKG的SDK使用版本,无需前后端直接体验谁是卧底、狼人杀!
新增Demo
- 谁是卧底的执行速度提升
- 新增狼人杀Demo
- muAgent sdk文档
技术详解
执行模式升级
任务节点的执行模式由单次模式和串行模式新增并行模式和计划模式。详细介绍如下:
在谁是卧底场景下,时间消耗缩减为原本的59%
狼人杀实现
新增狼人杀SOP
新增变量功能
包含变量初始化、变量更新以及变量填充,增强大模型在复杂任务链中的稳定运行
muAgent-sdk-v0.1.0
Model
在这里我们借鉴了阿里开源框架 agentscope 中的 ModelWrapperBase 基类,它能够在编写的同时即可完成注册模型类的接入,简化开发难度。
在muAgent中,已接入的大语言模型可支持 openai、qwen、moonshot、lingyiwanwu、ollama,向量模型支持openai、qwen、ollama。使用文档见:https://codefuse.ai/docs/api-docs/MuAgent/overview/multi-agent
有其他模型接入需求可到 https://github.com/codefuse-ai/CodeFuse-muAgent/issues 提出,我们会尽快适配!
模型类型 | 大模型/向量模型 | 可支持功能(含流式输出) |
---|---|---|
openai_chat | 大模型 | generate、chat、function_call |
yi_chat | 大模型 | generate、chat、function_call |
qwen_chat | 大模型 | generate、chat、function_call |
dashscope_chat | 大模型 | generate、chat、function_call |
moonshot_chat | 大模型 | generate、chat、function_call |
ollama_chat | 大模型 | generate、chat、function_call |
dashscope_text_embedding | 向量模型 | embed_query、embed_documents |
ollama_embedding | 向量模型 | embed_query、embed_documents |
openai_embedding | 向量模型 | embed_query、embed_documents |
qwen_text_embedding | 向量模型 | embed_query、embed_documents |
model_config = ModelConfig(
model_type="ollama_chat",
model_name="qwen2.5:0.5b",
api_key="",
)
model = get_model(model_config)
model.generate("输出 '今天你好'", stop="你", format_type='str')
Prompt Manager
Multi Agent框架 将 当前 agent/human 与另外的 agent/human 进行连接,其本质上就是状态流转和信息传递,其中状态流流转由EKG的图谱推理过程完成,在这里不再额外赘述;信息传递则是将执行过程中所有agent/human的输入/输出进行存储传递并转换成语言模型输入的过程即 Memory + Prompt Engineer
也就是说,Agent的相互协作实质上就是<< 接受信息->转换Prompt->请求LLM->产生输出->解析输出->执行动作 >>。大语言模型的魅力就在于,我们能够对已知信息(memory)进行自由组装,构建出多样性的自然语言表达来请求LLM获取期望答案。然而又因为自然语言表达的多样性,导致在编写Prompt的时候非常个性化。这就可能造成,我们每实现一条agent sop链路就需要编写一次Prompt和解析模块。
那有没有可能能够对历史的Prompt进行复用呢?在crewai框架的方案中,它对Prompt框架进行多个关键字的预设诸如system、role、task、context、memory等,能够减轻开发者编写Prompt的负担。但同时对Prompt框架产生了无形的约束,开发者想要在此基础上改动也非常困难。
这为muAgent演进Prompt Manager模块提供了一个更好管理Prompt的思路。muAgent通过将Prompt框架进行碎片化管理,可在不同情形下对碎片prompt自由组装以实现多样性的prompt,而无需重新编写里面的组装逻辑。
以这个functioncall的prompt为例,通过几个关键字构成一个简易多层级的prompt结构,开发者只需在这个既定框架内编写,即可完成Prompt Engineer。
#### AGENT PROFILE
### ROLE
you are a helpful assistant!
### AGENT INFORMATION
### TOOL INFORMATION
Below is a list of tools that are available for your use:谁是卧底-座位分配: 谁是卧底的座位分配工具,可以将玩家顺序打乱随机分配座位, args: {'title': 'ToolInputArgs', 'description': 'Input for SeatAssigner.', 'type': 'object', 'properties': {}}
谁是卧底-角色分配: 谁是卧底的角色分配工具,可以为每一位玩家分配一个单词和人物角色。, args: {'title': 'ToolInputArgs', 'description': 'Input for assigning roles.', 'type': 'object', 'properties': {}}
谁是卧底-结果输出: 谁是卧底的结果输出工具,判断谁是卧底游戏中最终的胜利方是谁。, args: {'title': 'ToolInputArgs', 'type': 'object', 'properties': {}}
谁是卧底-胜利条件判断: 谁是卧底的胜利条件判断工具,判断当前谁是卧底游戏是否结束。, args: {'title': 'ToolInputArgs', 'type': 'object', 'properties': {}}
谁是卧底-张伟: 你是一个智能体(Agent),你正在模拟玩家参与谁是卧底这场游戏,在游戏中你的名字是李静, args: {'title': 'ToolInputArgs', 'type': 'object', 'properties': {}}
谁是卧底-李静: 你是一个智能体(Agent),你正在模拟玩家参与谁是卧底这场游戏,在游戏中你的名字是李静, args: {'title': 'ToolInputArgs', 'type': 'object', 'properties': {}}
谁是卧底-王鹏: 你是一个智能体(Agent),你正在模拟玩家参与谁是卧底这场游戏,在游戏中你的名字是李静, args: {'title': 'ToolInputArgs', 'type': 'object', 'properties': {}}
valid "tool_name" value is:
谁是卧底-座位分配, 谁是卧底-角色分配, 谁是卧底-结果输出, 谁是卧底-胜利条件判断, 谁是卧底-张伟, 谁是卧底-李静, 谁是卧底-王鹏
#### CONTEXT FORMAT
Use the content provided in the context.
### SESSION RECORDS
In this part, we will supply with the context about this question.
### CURRENT QUERY
In this part, we will supply with current question to do.
#### INPUT FORMAT
#### RESPONSE OUTPUT FORMAT
**Thoughts:** According the previous context, plan the approach for using the tool effectively.
**Action Status:** stoped, tool_using or code_executing
Use 'stopped' when the task has been completed, and no further use of tools or execution of code is necessary.
Use 'tool_using' when the current step in the process involves utilizing a tool to proceed.
**Action:**
If Action Status is 'tool_using', format the tool action in JSON from Question and Observation, enclosed in a code block, like this:
```json
{
"tool_name": "$TOOL_NAME",
"tool_params": $args
}
If Action Status is 'stopped', provide the final response or instructions in written form, enclosed in a code block, like this:
The final response or instructions to the user question.
Thoughts: According the previous context, plan the approach for using the tool effectively.
Action Status: stoped, tool_using or code_executing Use 'stopped' when the task has been completed, and no further use of tools or execution of code is necessary. Use 'tool_using' when the current step in the process involves utilizing a tool to proceed.
Action: If Action Status is 'tool_using', format the tool action in JSON from Question and Observation, enclosed in a code block, like this:
{
"tool_name": "$TOOL_NAME",
"tool_params": $args
}
If Action Status is 'stopped', provide the final response or instructions in written form, enclosed in a code block, like this:
The final response or instructions to the user question.
BEGIN!!!
CONTEXT
SESSION RECORDS
<user-human-message> 我要使用工具,工具描述为agent_张伟 </user-human-message>
CURRENT QUERY
INPUT
RESPONSE OUTPUT
Thoughts:
Action Status:
Action:
1. AGENT PROFILE:角色大纲
1. ROLE:角色的基本设定
2. AGENT INFORMATION:所关联的智能体信息
3. TOOL INFORMATION:所关联的工具信息
2. CONTEXT FORMAT:上下文信息
1. SESSION RECORDS:会话记录
2. CURRENT QUERY:当前问题
3. INPUT FORMAT:输入信息
4. RESPONSE OUTPUT FORMAT:输出信息
那无论是何种Prompt编写模板,总归是由碎片化的prompt组成,例如`ROLE`、`AGENT INFORMATION`、`TOOL INFORMATION`也可以被其他Agent进行使用。
下面将介绍muAgent Prompt Manager中的碎片化管理过程:
由于Prompt实际上由层级数据结构进行呈现,近似于树形结构(实际实现采用了有向无环图),我们便可以通过Title配置注册节点、Edge注册边,从而初始化出完整的prompt,再针对每一个title设定description或者由function构建,即可完成内容构建,这些function or description 也可以直接多次复用,无需每一个新增agent都要编写。

Prompt Engineer与语言模型的输出解析几乎也是强绑定的过程,所以也需要在prompt manager类中直接实现所需的parser方法。
最终,我们便可以在muAgent的Prompt Manager模块中,支持以下功能:
+ 支持多种语言Prompt的自由切换
+ 支持自由设定Prompt Title层级
+ 支持自定义Prompt函数
+ 支持Prompt预打印,明确 prompt 输出,加速调试
+ 已封装了markdown风格的prompt模版
#### Agent
Agent模块基于新的model、prompt manager、memory manager,对之前的四种agent模式(SingleAgent单步执行流、<font style="color:rgb(51, 51, 51);">ReactAgent多步循环流、TaskAgent任务执行流、GroupAgent小组讨论流</font>)进行了修改,同时新增FunctioncallAgent、UserAgent两种新的agent模式,能够支持更多复杂场景的适配。
同时优化了环境配置快速初始化Agent的过程,示例如下
```python
# 填写模型配置
MODEL_CONFIGS = {
"dashscope_chat": {
"model_type": "dashscope_chat",
"model_name": "qwen2.5-72b-instruct" ,
"api_key": "sk-xxx",
},
"qwen_text_embedding": {
"model_type": "dashscope_text_embedding",
"model_name": "text-embedding-v3",
"api_key": "sk-xx",
},
}
os.environ["MODEL_CONFIGS"] = json.dumps(MODEL_CONFIGS)
# 填写智能体配置
tools = ["KSigmaDetector", "MetricsQuery"]
AGENT_CONFIGS = {
"codefuse_simpler": {
"agent_type": "SingleAgent",
"agent_name": "codefuse_simpler",
"tools": tools,
"llm_config_name": "dashscope_chat"
}
}
os.environ["AGENT_CONFIGS"] = json.dumps(AGENT_CONFIGS)
# 配置初始化
project_config = get_project_config_from_env()
agent = BaseAgent.init_from_project_config(
"codefuse_simpler", project_config
)
# 快速问答
query_content = "帮我确认下127.0.0.1这个服务器的在10点是否存在异常,请帮我判断一下"
query = Message(
role_name="human",
role_type="user",
input_text=query_content,
)
# base_agent.pre_print(query)
output_message = agent.step(query)
print("### intput ###\n", output_message.input_text)
print("### content ###\n", output_message.content)
print("### step content ###\n", output_message.step_content)
EKG
EKG是一个包含前端、后端、算法服务的三方应用,它作为协调者初始化了EKG服务所需的基本环境,同时集成了多个功能服务,旨在管理复杂的工作流SOP,包括智能体、工具和事件图谱等,最终支持Multi Agent中所需的状态流转以及信息传递过程。
- 状态流转
- 节点:多种节点类型行使不同职能;
- 边(节点交互):由核心的图谱推理和llm决定节点执行机制,支持并发、串行、分支执行等多种情况
- 信息传递
- 消息传递(Memory):抽象归纳出 8 种讨论模式,可同时满足不同场景信息隔离诉求,公开咨询、公开通知、私下咨询、私下通知、顺序发言、同时发言、自由讨论、私下讨论
- 提示词工程(Prompt Enginerr):取决于节点的描述,可自由定义多种prompt模板
在 muAgent v2.1 时仍缺少可直接使用的python-sdk,不利于广大开发者便捷地使用 muAgent 进行二次开发。于是在 muAgent v2.1 中,新增了EKG
类,由python-sdk直接对外提供接口能力:支持节点和边的录入和编辑、支持图谱推理和泛化、支持多种复杂应用的编写开发。
muAgent v2.0详细介绍:轻松搭建AI版“谁是卧底”游戏,muAgent框架让知识图谱秒变编排引擎,支持复杂推理+在线协同
from muagent.schemas import ModelConfig
import json
# 填写模型配置
MODEL_CONFIGS = {
"dashscope_chat": {
"model_type": "dashscope_chat",
"model_name": "qwen2.5-72b-instruct" ,
"api_key": "sk-xxx",
},
"qwen_text_embedding": {
"model_type": "dashscope_text_embedding",
"model_name": "text-embedding-v3",
"api_key": "sk-xx",
},
}
os.environ["MODEL_CONFIGS"] = json.dumps(MODEL_CONFIGS)
# 填写智能体配置
AGENT_CONFIGS = {
"codefuse_function_caller": {
"config_name": "codefuse_function_caller",
"agent_type": "FunctioncallAgent",
"agent_name": "codefuse_function_caller",
"llm_config_name": "qwen_chat"
}
}
os.environ["AGENT_CONFIGS"] = json.dumps(AGENT_CONFIGS)
# 初始化配置
from muagent import get_ekg_project_config_from_env
project_config = get_ekg_project_config_from_env()
# 初始化 ekg
from muagent import EKG
ekg = EKG(project_config=project_config, initialize_space=False)
# 添加节点和边
ekg.add_node(node)
ekg.add_edge(start_id, end_id)
# 开始图谱推理
response = ekg.run("xxx")
持续演进
有任何疑问和需求可到 https://github.com/codefuse-ai/CodeFuse-muAgent/issues 提出!
框架对比
在这里我们列出了与其他Agent框架的多项功能对比,也有一些需要持续迭代完善和下个版本会更新的。
Modules | 模块说明 | muAgent | metagpt | AgentScope | langgraph | crewai |
---|---|---|---|---|---|---|
Models | 语言模型的适配程度 | ✅ | ✅ | ✅ | ✅ | ✅ |
Agent | 智能体的适配程度 | ✅ | ✅ | ✅ | ✅ | ✅ |
Memory | 记忆管理能力 | ✅ | ✅ | ✅ | ✅ | ✅ |
Prompt Engineer | 提示词工程的能力 | ✅ | ✅ | ✅ | ✅ | ✅ |
LLM Parse | 指定数据结构解析,例如json、schema解析 | ✅ | ✅ | ✅ | ✅ | ✅ |
Rag | Rag能力 | ✅ | ✅ | ✅ | ✅ | ❌ |
Tool | 工具封装程度 | ✅ | ✅ | ✅ | ✅ | ✅ |
Execute Type | 可支持的执行方式,如分支、并发、串行、计划 | ✅ | ✅ | ✅ | ✅ | ✅ |
Pipelines | 链路执行能力 | 持续更新中... | ✅ | ✅ | ✅ | ✅ |
Project manager | 由agent框架构建出来的应用,所得到的项目管理能力 | ✅ | ✅ | ✅ | ✅ | ✅ |
webAgent | 有agent框架构建可对页面直接进行操作 | 持续更新中... | ❌ | ✅ | ❌ | ❌ |
Http/GRpc(可选) | 构建出的agent应用对外暴露接口 | 持续更新中... | ❌ | ✅ | ✅ | ✅ |
下个版本迭代:muAgent v2.3
- 工具和智能体注册和管理
- 泛化推理
- muAgent-sdk-v0.1.1:Pipelines
开源共建
做出开源不易,做好开源更难,从原来纯面向内部服务,到内部基础组件剥离,内外部版本一致研发,muAgent 目前还有很多功能的不完善和规划的研发进行中,我们欢迎您的任何建议、意见(包括批评)和贡献,可以通过 GitHub 的 Issues 提出。
参与 Codefuse 项目并为其作出贡献的方法有很多:代码实现、测试编写、文档完善等等。任何贡献我们都会非常欢迎,详见Contribution Guide。