
Swarms 提供全面的企业级多代理基础架构平台,旨在实现生产规模部署并与现有系统无缝集成。点击此处,了解更多关于 Swarms 功能集的信息
类别 | 特征 | 好处 |
---|---|---|
🏢企业架构 | • 生产就绪基础设施 • 高可用性系统 • 模块化微服务设计 • 全面的可观察性 • 向后兼容性 |
• 99.9%+ 正常运行时间保证 • 降低运营开销 • 无缝遗留集成 • 增强系统监控 • 无风险迁移路径 |
🤖多代理编排 | • 分层代理群 • 并行处理管道 • 顺序工作流编排 • 基于图形的代理网络 • 动态代理组合 • 代理注册管理 |
• 复杂业务流程自动化 • 可扩展任务分配 • 灵活的工作流适应 • 优化资源利用率 • 集中代理治理 • 企业级代理生命周期管理 |
🔄企业集成 | • 多模型提供商支持 • 自定义代理开发框架 • 广泛的企业工具库 • 多种内存系统 • 与 LangChain、AutoGen、CrewAI 向后兼容 • 标准化 API 接口 |
• 供应商无关架构 • 定制解决方案开发 • 扩展功能集成 • 增强知识管理 • 无缝框架迁移 • 降低集成复杂性 |
📈企业可扩展性 | • 并发多代理处理 • 智能资源管理 • 负载平衡和自动扩展 • 水平扩展功能 • 性能优化 • 容量规划工具 |
• 高吞吐量处理 • 经济高效的资源利用 • 根据需求弹性扩展 • 线性性能扩展 • 优化响应时间 • 可预测的增长规划 |
🛠️开发者体验 | • 直观的企业 API • 全面的文档 • 活跃的企业社区 • CLI 和 SDK 工具 • IDE 集成支持 • 代码生成模板 |
• 加速开发周期 • 降低学习曲线 • 专家社区支持 • 快速部署能力 • 提高开发人员生产力 • 标准化开发模式 |
$ pip3 install -U swarms
uv是一个快速的 Python 包安装程序和解析器,用 Rust 编写。
# Install uv
$ curl -LsSf https://astral.sh/uv/install.sh | sh
# Install swarms using uv
$ uv pip install swarms
# Install poetry if you haven't already
$ curl -sSL https://install.python-poetry.org | python3 -
# Add swarms to your project
$ poetry add swarms
# Clone the repository
$ git clone https://github.com/kyegomez/swarms.git
$ cd swarms
# Install with pip
$ pip install -e .
OPENAI_API_KEY=""
WORKSPACE_DIR="agent_workspace"
ANTHROPIC_API_KEY=""
GROQ_API_KEY=""
代理是集群的基本组成部分,是一个由 LLM + 工具 + 内存驱动的自主实体。点击此处了解更多信息
from swarms import Agent
# Initialize a new agent
agent = Agent(
model_name="gpt-4o-mini", # Specify the LLM
max_loops=1, # Set the number of interactions
interactive=True, # Enable interactive mode for real-time feedback
)
# Run the agent with a task
agent.run("What are the key benefits of using a multi-agent system?")
Swarm由多个协同工作的智能体组成。这个简单的示例创建了一个用于研究和撰写博客文章的双智能体工作流。了解更多关于 SequentialWorkflow 的信息
from swarms import Agent, SequentialWorkflow
# Agent 1: The Researcher
researcher = Agent(
agent_name="Researcher",
system_prompt="Your job is to research the provided topic and provide a detailed summary.",
model_name="gpt-4o-mini",
)
# Agent 2: The Writer
writer = Agent(
agent_name="Writer",
system_prompt="Your job is to take the research summary and write a beautiful, engaging blog post about it.",
model_name="gpt-4o-mini",
)
# Create a sequential workflow where the researcher's output feeds into the writer's input
workflow = SequentialWorkflow(agents=[researcher, writer])
# Run the workflow on a task
final_post = workflow.run("The history and future of artificial intelligence")
print(final_post)
它AutoSwarmBuilder
会根据您的任务描述自动生成专用代理及其工作流程。只需描述您的需求,它就会创建一个完整的多代理系统,其中包含详细的提示和最佳的代理配置。了解更多关于 AutoSwarmBuilder 的信息
from swarms.structs.auto_swarm_builder import AutoSwarmBuilder
import json
# Initialize the AutoSwarmBuilder
swarm = AutoSwarmBuilder(
name="My Swarm",
description="A swarm of agents",
verbose=True,
max_loops=1,
return_agents=True,
model_name="gpt-4o-mini",
)
# Let the builder automatically create agents and workflows
result = swarm.run(
task="Create an accounting team to analyze crypto transactions, "
"there must be 5 agents in the team with extremely extensive prompts. "
"Make the prompts extremely detailed and specific and long and comprehensive. "
"Make sure to include all the details of the task in the prompts."
)
# The result contains the generated agents and their configurations
print(json.dumps(result, indent=4))
规定AutoSwarmBuilder
:
- 自动代理生成:根据任务需求创建专门的代理
- 智能提示工程:为每个座席生成全面、详细的提示
- 最佳工作流程设计:确定最佳代理交互和工作流程结构
- 生产就绪配置:返回已配置完毕且可供部署的代理
- 灵活的架构:支持各种群体类型和代理专业化
此功能非常适合快速原型设计、复杂任务分解以及创建无需手动配置的专业代理团队。
swarms
提供多种强大的预构建多智能体架构,让您能够以各种方式编排智能体。根据您的具体问题选择合适的架构,构建高效可靠的生产系统。
建筑学 | 描述 | 最适合 |
---|---|---|
顺序工作流 | 代理以线性链的方式执行任务;一个代理的输出成为下一个代理的输入。 | 数据转换管道和报告生成等逐步的过程。 |
并发工作流 | 代理同时运行任务以实现最高效率。 | 批处理和并行数据分析等高通量任务。 |
AgentRearrange | a -> b, c 动态映射代理之间的复杂关系(例如)。 |
灵活且适应性强的工作流程、任务分配和动态路由。 |
GraphWorkflow | 将代理编排为有向无环图 (DAG) 中的节点。 | 具有复杂依赖关系的复杂项目,例如软件构建。 |
混合剂(MoA) | 并行利用多个专家代理并合成它们的输出。 | 通过协作解决复杂问题并实现最先进的性能。 |
群聊 | 代理通过对话界面进行协作并做出决策。 | 实时协作决策、谈判和头脑风暴。 |
森林群 | 为给定任务动态选择最合适的代理或代理树。 | 任务路由、专业知识优化和复杂的决策树。 |
分层蜂群 | 与主管协调代理,主管制定计划并将任务分配给专门的工作者代理。 | 复杂的项目管理、团队协调以及具有反馈回路的分层决策。 |
重型蜂群 | 实施五阶段工作流程,由专门的代理(研究、分析、替代方案、验证)进行全面的任务分析。 | 复杂的研究和分析任务、财务分析、战略规划和综合报告。 |
SwarmRouter | 通用编排器提供单一界面来运行具有动态选择的任何类型的群。 | 简化复杂的工作流程、在群体策略之间切换以及统一的多代理管理。 |
ASequentialWorkflow
按照严格的顺序执行任务,形成一个流水线,每个代理都基于前一个代理的工作进行构建。SequentialWorkflow
非常适合步骤清晰有序的流程。这确保了具有依赖关系的任务得到正确处理。
from swarms import Agent, SequentialWorkflow
# Agent 1: The Researcher
researcher = Agent(
agent_name="Researcher",
system_prompt="Your job is to research the provided topic and provide a detailed summary.",
model_name="gpt-4o-mini",
)
# Agent 2: The Writer
writer = Agent(
agent_name="Writer",
system_prompt="Your job is to take the research summary and write a beautiful, engaging blog post about it.",
model_name="gpt-4o-mini",
)
# Create a sequential workflow where the researcher's output feeds into the writer's input
workflow = SequentialWorkflow(agents=[researcher, writer])
# Run the workflow on a task
final_post = workflow.run("The history and future of artificial intelligence")
print(final_post)
AConcurrentWorkflow
同时运行多个代理,允许并行执行任务。这种架构大大缩短了可并行执行任务的执行时间,使其成为代理同时处理类似任务的高吞吐量场景的理想选择。
from swarms import Agent, ConcurrentWorkflow
# Create agents for different analysis tasks
market_analyst = Agent(
agent_name="Market-Analyst",
system_prompt="Analyze market trends and provide insights on the given topic.",
model_name="gpt-4o-mini",
max_loops=1,
)
financial_analyst = Agent(
agent_name="Financial-Analyst",
system_prompt="Provide financial analysis and recommendations on the given topic.",
model_name="gpt-4o-mini",
max_loops=1,
)
risk_analyst = Agent(
agent_name="Risk-Analyst",
system_prompt="Assess risks and provide risk management strategies for the given topic.",
model_name="gpt-4o-mini",
max_loops=1,
)
# Create concurrent workflow
concurrent_workflow = ConcurrentWorkflow(
agents=[market_analyst, financial_analyst, risk_analyst],
max_loops=1,
)
# Run all agents concurrently on the same task
results = concurrent_workflow.run(
"Analyze the potential impact of AI technology on the healthcare industry"
)
print(results)
受 启发einsum
,AgentRearrange
您可以使用简单的字符串语法定义代理之间复杂的非线性关系。了解更多。此架构非常适合编排动态工作流,其中代理可以并行、顺序或两者结合工作。
from swarms import Agent, AgentRearrange
# Define agents
researcher = Agent(agent_name="researcher", model_name="gpt-4o-mini")
writer = Agent(agent_name="writer", model_name="gpt-4o-mini")
editor = Agent(agent_name="editor", model_name="gpt-4o-mini")
# Define a flow: researcher sends work to both writer and editor simultaneously
# This is a one-to-many relationship
flow = "researcher -> writer, editor"
# Create the rearrangement system
rearrange_system = AgentRearrange(
agents=[researcher, writer, editor],
flow=flow,
)
# Run the swarm
outputs = rearrange_system.run("Analyze the impact of AI on modern cinema.")
print(outputs)
通过提供单一界面来运行任何类型的 Swarm,简化SwarmRouter
了构建复杂工作流程。您无需导入和管理不同的 Swarm 类,只需更改swarm_type
参数即可动态选择所需的 Swarm 类。阅读完整文档
这使得你的代码更简洁、更灵活,让你能够轻松地在不同的多智能体策略之间切换。这是一个完整的示例,展示了如何定义智能体,以及如何SwarmRouter
使用不同的协作策略执行相同的任务。
from swarms import Agent
from swarms.structs.swarm_router import SwarmRouter, SwarmType
# Define a few generic agents
writer = Agent(agent_name="Writer", system_prompt="You are a creative writer.", model_name="gpt-4o-mini")
editor = Agent(agent_name="Editor", system_prompt="You are an expert editor for stories.", model_name="gpt-4o-mini")
reviewer = Agent(agent_name="Reviewer", system_prompt="You are a final reviewer who gives a score.", model_name="gpt-4o-mini")
# The agents and task will be the same for all examples
agents = [writer, editor, reviewer]
task = "Write a short story about a robot who discovers music."
# --- Example 1: SequentialWorkflow ---
# Agents run one after another in a chain: Writer -> Editor -> Reviewer.
print("Running a Sequential Workflow...")
sequential_router = SwarmRouter(swarm_type=SwarmType.SequentialWorkflow, agents=agents)
sequential_output = sequential_router.run(task)
print(f"Final Sequential Output:\n{sequential_output}\n")
# --- Example 2: ConcurrentWorkflow ---
# All agents receive the same initial task and run at the same time.
print("Running a Concurrent Workflow...")
concurrent_router = SwarmRouter(swarm_type=SwarmType.ConcurrentWorkflow, agents=agents)
concurrent_outputs = concurrent_router.run(task)
# This returns a dictionary of each agent's output
for agent_name, output in concurrent_outputs.items():
print(f"Output from {agent_name}:\n{output}\n")
# --- Example 3: MixtureOfAgents ---
# All agents run in parallel, and a special 'aggregator' agent synthesizes their outputs.
print("Running a Mixture of Agents Workflow...")
aggregator = Agent(
agent_name="Aggregator",
system_prompt="Combine the story, edits, and review into a final document.",
model_name="gpt-4o-mini"
)
moa_router = SwarmRouter(
swarm_type=SwarmType.MixtureOfAgents,
agents=agents,
aggregator_agent=aggregator, # MoA requires an aggregator
)
aggregated_output = moa_router.run(task)
print(f"Final Aggregated Output:\n{aggregated_output}\n")
这SwarmRouter
是一个简化多代理编排的强大工具。它提供了一种一致且灵活的方式来部署不同的协作策略,让您能够用更少的代码构建更复杂的应用程序。
该MixtureOfAgents
架构通过将任务并行地提供给多个“专家”代理来处理。然后,聚合代理会将这些不同的输出合成一个最终的高质量结果。点击此处了解更多信息
from swarms import Agent, MixtureOfAgents
# Define expert agents
financial_analyst = Agent(agent_name="FinancialAnalyst", system_prompt="Analyze financial data.", model_name="gpt-4o-mini")
market_analyst = Agent(agent_name="MarketAnalyst", system_prompt="Analyze market trends.", model_name="gpt-4o-mini")
risk_analyst = Agent(agent_name="RiskAnalyst", system_prompt="Analyze investment risks.", model_name="gpt-4o-mini")
# Define the aggregator agent
aggregator = Agent(
agent_name="InvestmentAdvisor",
system_prompt="Synthesize the financial, market, and risk analyses to provide a final investment recommendation.",
model_name="gpt-4o-mini"
)
# Create the MoA swarm
moa_swarm = MixtureOfAgents(
agents=[financial_analyst, market_analyst, risk_analyst],
aggregator_agent=aggregator,
)
# Run the swarm
recommendation = moa_swarm.run("Should we invest in NVIDIA stock right now?")
print(recommendation)
GroupChat
创建一个对话环境,多个代理可以在此环境中互动、讨论并协作解决问题。您可以定义发言顺序,也可以动态确定。此架构非常适合需要辩论和多视角推理的任务,例如合同谈判、头脑风暴或复杂的决策。
from swarms import Agent, GroupChat
# Define agents for a debate
tech_optimist = Agent(agent_name="TechOptimist", system_prompt="Argue for the benefits of AI in society.", model_name="gpt-4o-mini")
tech_critic = Agent(agent_name="TechCritic", system_prompt="Argue against the unchecked advancement of AI.", model_name="gpt-4o-mini")
# Create the group chat
chat = GroupChat(
agents=[tech_optimist, tech_critic],
max_loops=4, # Limit the number of turns in the conversation
)
# Run the chat with an initial topic
conversation_history = chat.run(
"Let's discuss the societal impact of artificial intelligence."
)
# Print the full conversation
for message in conversation_history:
print(f"[{message['agent_name']}]: {message['content']}")
HierarchicalSwarm
实现了主管-工作者模式,其中中央主管代理负责制定综合计划,并将具体任务分配给专门的工作者代理。主管会评估结果,并在反馈循环中发出新的指令,这使得它非常适合复杂的项目管理和团队协调场景。
from swarms import Agent, HierarchicalSwarm
# Define specialized worker agents
content_strategist = Agent(
agent_name="Content-Strategist",
system_prompt="You are a senior content strategist. Develop comprehensive content strategies, editorial calendars, and content roadmaps.",
model_name="gpt-4o-mini"
)
creative_director = Agent(
agent_name="Creative-Director",
system_prompt="You are a creative director. Develop compelling advertising concepts, visual directions, and campaign creativity.",
model_name="gpt-4o-mini"
)
seo_specialist = Agent(
agent_name="SEO-Specialist",
system_prompt="You are an SEO expert. Conduct keyword research, optimize content, and develop organic growth strategies.",
model_name="gpt-4o-mini"
)
brand_strategist = Agent(
agent_name="Brand-Strategist",
system_prompt="You are a brand strategist. Develop brand positioning, identity systems, and market differentiation strategies.",
model_name="gpt-4o-mini"
)
# Create the hierarchical swarm with a director
marketing_swarm = HierarchicalSwarm(
name="Marketing-Team-Swarm",
description="A comprehensive marketing team with specialized agents coordinated by a director",
agents=[content_strategist, creative_director, seo_specialist, brand_strategist],
max_loops=2, # Allow for feedback and refinement
verbose=True
)
# Run the swarm on a complex marketing challenge
result = marketing_swarm.run(
"Develop a comprehensive marketing strategy for a new SaaS product launch. "
"The product is a project management tool targeting small to medium businesses. "
"Coordinate the team to create content strategy, creative campaigns, SEO optimization, "
"and brand positioning that work together cohesively."
)
print(result)
其HierarchicalSwarm
优点在于:
- 复杂项目管理:将大型任务分解为专门的子任务
- 团队协调:确保所有代理朝着统一的目标努力
- 质量控制:主管提供反馈和改进循环
- 可扩展的工作流程:根据需要轻松添加新的专业代理
HeavySwarm
受 X.AI Grok 重度实现的启发,实现了一套复杂的五阶段工作流程。它使用专门的代理(研究、分析、替代方案、验证),通过智能问题生成、并行执行和综合分析,提供全面的任务分析。该架构擅长处理需要深入调查和多视角的复杂研究和分析任务。
from swarms import HeavySwarm
# Initialize the HeavySwarm with configuration
swarm = HeavySwarm(
worker_model_name="gpt-4o-mini", # Model for worker agents
question_agent_model_name="gpt-4o-mini", # Model for question generation
loops_per_agent=1, # Number of loops per agent
show_dashboard=True, # Enable real-time dashboard
)
# Run complex analysis task
result = swarm.run(
"Provide 3 publicly traded biotech companies that are currently trading below their cash value. "
"For each company identified, provide available data or projections for the next 6 months, "
"including any relevant financial metrics, upcoming catalysts, or events that could impact valuation. "
"Present your findings in a clear, structured format with ticker symbols, current prices, "
"cash values, and percentage differences."
)
print(result)
规定HeavySwarm
:
-
5阶段分析:问题生成、研究、分析、替代方案和验证
-
专门代理:每个阶段使用专门的代理以获得最佳结果
-
全面报道:多角度、深入调查
-
实时仪表板:可选的分析过程可视化
-
结构化输出:组织良好且可操作的结果
该架构非常适合财务分析、战略规划、研究报告以及任何需要深度、多角度分析的任务。了解更多关于 HeavySwarm 的信息
文档位于:docs.swarms.world
探索全面的示例和教程,学习如何有效地使用 Swarms。
例子 | 描述 | 关联 |
---|---|---|
基本代理 | 简单的代理设置和使用 | 基本代理 |
带工具的代理 | 使用代理和各种工具 | 带工具的代理 |
具有结构化输出的代理 | 使用结构化数据输出 | 结构化输出 |
具有 MCP 集成的代理 | 模型上下文协议集成 | MCP 集成 |
视觉处理 | 具有图像处理能力的代理 | 视觉处理 |
多幅图像 | 处理多幅图像 | 多幅图像 |
愿景与工具 | 将视觉与工具使用相结合 | 愿景与工具 |
代理流 | 实时代理输出流 | 代理流 |
代理输出类型 | 不同的输出格式和类型 | 输出类型 |
Gradio聊天界面 | 构建交互式聊天界面 | Gradio UI |
提供者 | 描述 | 关联 |
---|---|---|
模型提供者概述 | 支持型号完整指南 | 模型提供者 |
OpenAI | OpenAI 模型集成 | OpenAI 示例 |
人择 | Claude模型集成 | 人择的例子 |
格罗克 | Groq 模型集成 | Groq 示例 |
科赫尔 | Cohere 模型集成 | 连贯的例子 |
DeepSeek | DeepSeek 模型集成 | DeepSeek 示例 |
奥拉马 | 本地 Ollama 模型集成 | Ollama 示例 |
OpenRouter | OpenRouter 模型集成 | OpenRouter 示例 |
人工智能 | XAI模型集成 | XAI示例 |
甚长线性模型 | VLLM 集成 | VLLM 示例 |
骆驼4 | Llama4 模型集成 | Llama4 示例 |
建筑学 | 描述 | 关联 |
---|---|---|
分层蜂群 | 分层代理编排 | HierarchicalSwarm 示例 |
混合层次集群群 | 高级层次模式 | HHCS 示例 |
群聊 | 多代理对话 | GroupChat 示例 |
顺序工作流 | 代理工作流程分步说明 | 顺序示例 |
SwarmRouter | 通用群体编排 | SwarmRouter 示例 |
多代理路由器 | 最小路由器示例 | MultiAgentRouter 示例 |
并发工作流 | 并行代理执行 | 并发示例 |
药剂混合物 | 专家代理协作 | 谅解备忘录示例 |
独特群体 | 专门的群体模式 | 独特群体 |
代理作为工具 | 使用代理作为工作流程中的工具 | 代理作为工具 |
汇总回复 | 组合多个代理输出 | 聚合示例 |
互动群聊 | 实时座席互动 | 互动群聊 |
应用 | 描述 | 关联 |
---|---|---|
Swarms DAO | 去中心化自治组织 | Swarms DAO |
浏览器代理 | 带代理的 Web 自动化 | 浏览器代理 |
VLLM 代理 | 高性能模型服务 | VLLM 代理 |
医学分析 | 医疗保健应用 | 医学实例 |
财务分析 | 金融应用 | 财务示例 |
资源 | 描述 | 关联 |
---|---|---|
示例概述 | 完整的示例目录 | 示例索引 |
食谱索引 | 精选示例集 | 食谱 |
纸质实现 | 研究论文实施 | 纸质实现 |
模板和应用程序 | 可重复使用的模板 | 模板 |
我们的使命是提供企业级、生产就绪的基础设施,实现数百万自主代理的无缝部署和编排,从而加速向完全自主的世界经济转型。我们正在为代理经济构建操作系统,我们需要您的帮助来实现这一目标。
Swarms 由社区构建,服务于社区。我们相信,协作开发是突破多智能体 AI 极限的关键。我们不仅欢迎您的贡献,而且您的贡献对于我们的使命至关重要。了解更多关于您为何应该为 Swarms 做出贡献的信息
加入我们,您将有机会:
-
代理前沿工作:塑造自主代理技术的未来,并帮助构建生产级开源框架。
-
加入充满活力的社区:与一群充满热情且不断壮大的代理开发人员、研究人员和人工智能爱好者合作。
-
产生切实的影响:无论您是修复错误、添加新功能还是改进文档,您的工作都将用于实际应用程序。
-
学习和成长:获得先进人工智能概念的实践经验并加强您的软件工程技能。
在我们的官方贡献者指南中详细了解我们的使命以及成为贡献者的好处。
我们简化了贡献流程。您可以通过以下方式提供帮助:
-
找到需要解决的问题:最好的开始方式是访问我们的贡献项目板。查找带有 标记的问题,
good first issue
这些是专门为新贡献者挑选的。 -
报告错误或请求功能:如果您有新想法或发现某些功能无法正常工作,我们很乐意听取您的意见。请在我们的 GitHub 问题页面提交错误报告或功能请求。
-
了解我们的工作流程和标准:在提交您的工作之前,请查看我们完整的贡献指南。为了帮助维护代码质量,我们也建议您阅读我们的代码清洁度指南。
-
加入讨论:要参与路线图讨论并与其他开发人员联系,请加入我们的Discord社区。
感谢您对 Swarm 的贡献。我们非常欣赏和认可您的工作。

加入我们的代理工程师和研究人员社区,获得技术支持、前沿更新以及世界一流的代理工程见解的独家访问权!
平台 | 描述 | 关联 |
---|---|---|
📚 文档 | 官方文档和指南 | docs.swarms.world |
📝 博客 | 最新更新和技术文章 | 中等的 |
💬 Discord | 实时聊天和社区支持 | 加入 Discord |
🐦推特 | 最新新闻和公告 | @swarms_corp |
专业网络和更新 | Swarm 公司 | |
📺YouTube | 教程和演示 | 蜂群通道 |
🎫 活动 | 加入我们的社区活动 | 在此注册 |
🚀 入职培训 | 与 Swarms 的创建者和首席维护者 Kye Gomez 一起加入 | 预订会议 |
如果您在研究中使用群体,请通过引用CITATION.cff中的元数据来引用该项目。
@misc{SWARMS_2022,
author = {Gomez, Kye and Pliny and More, Harshal and Swarms Community},
title = {{Swarms: Production-Grade Multi-Agent Infrastructure Platform}},
year = {2022},
howpublished = {\url{https://github.com/kyegomez/swarms}},
note = {Documentation available at \url{https://docs.swarms.world}},
version = {latest}
}
Swarms 采用 Apache 2.0 许可证。点击此处了解更多信息
数据统计
相关导航


langgpt_git

ZeroTier

FastGPT

酒馆

LibreChat

crewAI
