基于大语言模型的多智能体平台,提供开发者友好的消息交换机制和分布式部署能力

Apache-2.0Pythonagentscopeagentscope-ai 11.0k Last Updated: September 11, 2025

AgentScope - 灵活强大的多智能体开发平台

项目概述

AgentScope 是一个创新的多智能体平台,专门为开发者设计,用于构建基于大语言模型(LLM)的多智能体应用程序。该平台以消息交换作为核心通信机制,显著降低了开发和理解的门槛。

GitHub地址: https://github.com/agentscope-ai/agentscope

核心特性

1. 开发者友好的设计原则

  • 透明性优先:对开发者完全透明,包括提示工程、API调用、智能体构建、工作流编排等都可见可控
  • 实时控制:可以在任何时刻中断智能体并自定义处理方式
  • 模型无关性:一次编程,可与所有模型配合使用
  • LEGO式智能体构建:所有组件都是模块化和独立的

2. 多智能体导向设计

  • 显式消息传递:专为多智能体设计,支持明确的消息传递和工作流编排
  • 无深度封装:避免复杂的封装,保持代码的可读性和可维护性
  • 高度可定制:工具、提示、智能体、工作流、第三方库和可视化都支持自定义

3. 强大的容错机制

AgentScope提供内置和可定制的容错机制,同时配备系统级支持来管理和利用多模态数据、工具和外部知识。包括:

  • 服务级重试机制确保API可靠性
  • 基于规则的校正工具处理LLM响应中的格式问题
  • 可自定义的容错配置(parse_func、fault_handler、max_retries等)
  • 多智能体应用专用的日志系统

4. 分布式架构支持

  • 基于Actor的分布式框架:支持本地和分布式部署之间的轻松转换
  • 自动并行优化:无需额外努力即可实现并行优化
  • 大规模仿真支持:能够在4台设备上仿真100万个智能体

AgentScope 1.0 新特性

异步执行支持

  • 完全拥抱异步执行模式
  • 提供多种新功能和改进

核心模块功能

模块 功能 描述
Model 异步调用支持 支持各种LLM的异步调用
Tool 工具集成 丰富的工具函数库
MCP 模型控制协议 支持模型控制协议集成
Tracing 跟踪监控 应用程序执行跟踪和可视化
Memory 长期记忆 智能体的长期记忆管理
Session 会话管理 状态和会话管理
Evaluation 评估系统 智能体性能评估
Prompt Formatter 提示格式化 智能提示格式化工具

技术架构

消息交换机制

AgentScope采用基于消息的通信机制:

from agentscope.message import Msg


message_from_alice = Msg("Alice", "Hi!")
message_with_media = Msg("Bob", "What about this picture?", url="/path/to/picture.jpg")

智能体创建

from agentscope.agent import ReActAgent, UserAgent
from agentscope.model import DashScopeChatModel
from agentscope.formatter import DashScopeChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.tool import Toolkit, execute_python_code

import os, asyncio

async def main():
    toolkit = Toolkit()
    toolkit.register_tool_function(execute_python_code)
    
    agent = ReActAgent(
        name="Friday",
        sys_prompt="You're a helpful assistant named Friday.",
        model=DashScopeChatModel(
            model_name="qwen-max",
            api_key=os.environ["DASHSCOPE_API_KEY"],
            stream=True,
        ),
        memory=InMemoryMemory(),
        formatter=DashScopeChatFormatter(),
        toolkit=toolkit,
    )
    
    user = UserAgent(name="user")
    
    msg = None
    while True:
        msg = await agent(msg)
        msg = await user(msg)
        if msg.get_text_content() == "exit":
            break

asyncio.run(main())

管道和工作流

from agentscope.pipeline import MsgHub, sequential_pipeline
from agentscope.message import Msg

async def multi_agent_conversation():
 
    agent1 = ...
    agent2 = ...
    agent3 = ...
    
   
    pipeline = sequential_pipeline([agent1, agent2, agent3])
    result = await pipeline(initial_message)

MCP(模型控制协议)集成

from agentscope.mcp import HttpStatelessClient
from agentscope.tool import Toolkit
import os

async def fine_grained_mcp_control():

    client = HttpStatelessClient(
        name="gaode_mcp",
        transport="streamable_http",
        url=f"https://mcp.amap.com/mcp?key={os.environ['GAODE_API_KEY']}",
    )
    
  
    func = await client.get_callable_function(func_name="maps_geo")
    

    await func(address="Tiananmen Square", city="Beijing")
    

    toolkit = Toolkit()
    toolkit.register_tool_function(func)

多模态数据支持

AgentScope采用延迟加载策略,通过在消息中提供统一的基于URL的属性来将多模态数据传输与存储解耦。支持:

  • 文本、图像、音频、视频数据处理
  • 基于URL的数据引用
  • 按需加载机制

工具和服务生态

内置服务功能

  • Python代码执行
  • Web搜索
  • 文件操作
  • 外部知识集成

RAG(检索增强生成)支持

  • 端到端的知识处理模块
  • 高度可配置的检索系统
  • 可共享的知识处理组件

安装和使用

系统要求

  • Python 3.10 或更高版本

安装方式

从源码安装(推荐)


git clone -b main https://github.com/agentscope-ai/agentscope.git


cd agentscope
pip install -e .

从PyPI安装

pip install agentscope

AgentScope Studio


npm install -g @agentscope/studio
as_studio

模型支持

AgentScope支持广泛的大语言模型:

云端API

  • OpenAI GPT系列
  • DashScope(阿里云)
  • Google Gemini
  • ZhipuAI
  • LiteLLM API

本地部署

  • Ollama
  • Flask + Transformers/ModelScope
  • FastChat
  • vLLM

应用场景

大规模仿真

  • 金融市场仿真
  • 城市规划建模
  • 政策效果分析
  • 社会行为研究

协作任务

  • 软件开发团队仿真
  • 多轮对话系统
  • 复杂问题求解
  • 知识协作处理

企业应用

  • 客户服务自动化
  • 业务流程优化
  • 智能决策支持
  • 风险管理建模

社区和支持

AgentScope代表了多智能体系统开发的重大进步,为研究人员和开发者提供了一个强大、灵活且易于使用的平台,以充分发挥智能体的潜力。

Star History Chart