轻量级 Python 多智能体编排框架,支持 A2A 通信与多 LLM 集成,通过 Agent、Clan 和 Tool 组件快速构建协作式 AI 系统。
UnisonAI#
项目概述#
UnisonAI 是一个轻量级 Python 框架,旨在简化单智能体与多智能体系统的开发。核心创新在于引入 Clan(团队) 概念编排多个智能体协作,支持类似团队分工的任务分发与 Agent-to-Agent (A2A) 通信。
核心标语: "Orchestrate the Future of Multi-Agent AI"
作者: Anant Sharma (E5Anant) 当前版本: v1.2 (Beta)
核心组件#
| 组件 | 用途 | 关键特性 |
|---|---|---|
| Agent | 独立智能体或团队成员 | 工具集成、历史记录、智能体间消息传递 |
| Clan | 多智能体编排 | 自动规划、任务分发、A2A 通信 |
| Tool System | 可扩展能力框架 | @tool 装饰器、BaseTool 类、类型验证 |
主要特性#
1. A2A 通信架构#
- 智能体间可像团队成员一样协作处理复杂任务
- 支持智能体间的消息传递和协调
2. 多 LLM 提供商支持#
原生支持:Google Gemini、OpenAI、Anthropic、Cohere、Groq、Mistral AI、xAI (Grok)、Cerebras,并支持通过扩展 BaseLLM 接入自定义模型。
3. 工具系统#
- 装饰器方式(推荐): 使用
@tool装饰器快速定义 - 类方式(复杂场景): 继承
BaseTool类 - 强类型验证: 基于
ToolParameterType和 Pydantic - 标准化结果: 统一返回
ToolResult对象
安装与快速开始#
pip install unisonai
单智能体示例#
from unisonai import Agent
from unisonai.llms import Gemini
agent = Agent(
llm=Gemini(model="gemini-2.0-flash"),
identity="Assistant",
description="A helpful AI assistant",
)
print(agent.unleash(task="Explain quantum computing in 3 sentences"))
多智能体团队(Clan)示例#
from unisonai import Agent, Clan
from unisonai.llms import Gemini
researcher = Agent(
llm=Gemini(model="gemini-2.0-flash"),
identity="Researcher",
description="Gathers information on topics",
)
writer = Agent(
llm=Gemini(model="gemini-2.0-flash"),
identity="Writer",
description="Writes clear reports from research",
)
clan = Clan(
clan_name="Research Team",
manager=researcher,
members=[researcher, writer],
shared_instruction="Researcher gathers info, Writer produces the report.",
goal="Write a brief report on AI in healthcare",
output_file="report.txt",
)
clan.unleash()
API 密钥配置#
# 方式 1: 配置系统
from unisonai import config
config.set_api_key("gemini", "your-key")
# 方式 2: 环境变量
# export GEMINI_API_KEY="your-key"
# 方式 3: 直接初始化
from unisonai.llms import Gemini
llm = Gemini(api_key="your-key")
自定义工具创建#
from unisonai.tools.tool import tool
@tool(name="calculator", description="Math operations")
def calculator(operation: str, a: float, b: float) -> str:
if operation == "add":
return str(a + b)
elif operation == "multiply":
return str(a * b)
return "Unknown operation"
适用场景#
- 复杂研究任务: 多智能体收集、分析和综合信息
- 工作流自动化: 协调多步骤业务流程
- 内容创作: 专门化智能体负责研究、写作、编辑
- 数据分析: 分布式智能体处理大型数据集
核心依赖#
- Pydantic (≥2.4.2) - 数据验证
- Rich, Colorama - 终端 UI
- nest-asyncio - 异步支持
- 各 LLM SDK (openai, anthropic, google-generativeai 等)