pull/594/merge
Your Name 3 months ago
parent 7a921391ef
commit 520bd5f6c2

@ -641,6 +641,7 @@ Swarm architectures leverage these communication patterns to ensure that agents
| Agent Registry | A centralized registry where agents are stored, retrieved, and invoked dynamically. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/agent_registry/) | Dynamic agent management, evolving recommendation engines |
| Spreadsheet Swarm | Manages tasks at scale, tracking agent outputs in a structured format like CSV files. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/spreadsheet_swarm/) | Large-scale marketing analytics, financial audits |
| Forest Swarm | A swarm structure that organizes agents in a tree-like hierarchy for complex decision-making processes. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/forest_swarm/) | Multi-stage workflows, hierarchical reinforcement learning |
| Swarm Router | Routes and chooses the swarm architecture based on the task requirements and available agents. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/swarm_router/) | Dynamic task routing, adaptive swarm architecture selection, optimized agent allocation |
@ -943,66 +944,151 @@ The `run` method returns the final output after all agents have processed the in
```python
from swarms import Agent, OpenAIChat, MixtureOfAgents
# Initialize the director agent
director = Agent(
agent_name="Director",
system_prompt="Directs the tasks for the accountants",
llm=OpenAIChat(),
import os
from swarm_models import OpenAIChat
from swarms import Agent, MixtureOfAgents
api_key = os.getenv("OPENAI_API_KEY")
# Create individual agents with the OpenAIChat model
model = OpenAIChat(
openai_api_key=api_key, model_name="gpt-4", temperature=0.1
)
# Agent 1: Financial Statement Analyzer
agent1 = Agent(
agent_name="FinancialStatementAnalyzer",
llm=model,
system_prompt="""You are a Financial Statement Analyzer specializing in 10-K SEC reports. Your primary focus is on analyzing the financial statements, including the balance sheet, income statement, and cash flow statement.
Key responsibilities:
1. Identify and explain significant changes in financial metrics year-over-year.
2. Calculate and interpret key financial ratios (e.g., liquidity ratios, profitability ratios, leverage ratios).
3. Analyze trends in revenue, expenses, and profitability.
4. Highlight any red flags or areas of concern in the financial statements.
5. Provide insights on the company's financial health and performance based on the data.
When analyzing, consider industry standards and compare the company's performance to its peers when possible. Your analysis should be thorough, data-driven, and provide actionable insights for investors and stakeholders.""",
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="director.json",
dynamic_temperature_enabled=True,
saved_state_path="financial_statement_analyzer_state.json",
user_name="swarms_corp",
retry_attempts=1,
context_length=200000,
return_step_meta=False,
)
# Initialize accountant 1
accountant1 = Agent(
agent_name="Accountant1",
system_prompt="Prepares financial statements",
llm=OpenAIChat(),
# Agent 2: Risk Assessment Specialist
agent2 = Agent(
agent_name="RiskAssessmentSpecialist",
llm=model,
system_prompt="""You are a Risk Assessment Specialist focusing on 10-K SEC reports. Your primary role is to identify, analyze, and evaluate potential risks disclosed in the report.
Key responsibilities:
1. Thoroughly review the "Risk Factors" section of the 10-K report.
2. Identify and categorize different types of risks (e.g., operational, financial, legal, market, technological).
3. Assess the potential impact and likelihood of each identified risk.
4. Analyze the company's risk mitigation strategies and their effectiveness.
5. Identify any emerging risks not explicitly mentioned but implied by the company's operations or market conditions.
6. Compare the company's risk profile with industry peers when possible.
Your analysis should provide a comprehensive overview of the company's risk landscape, helping stakeholders understand the potential challenges and uncertainties facing the business. Be sure to highlight any critical risks that could significantly impact the company's future performance or viability.""",
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="accountant1.json",
dynamic_temperature_enabled=True,
saved_state_path="risk_assessment_specialist_state.json",
user_name="swarms_corp",
retry_attempts=1,
context_length=200000,
return_step_meta=False,
)
# Initialize accountant 2
accountant2 = Agent(
agent_name="Accountant2",
system_prompt="Audits financial records",
llm=OpenAIChat(),
# Agent 3: Business Strategy Evaluator
agent3 = Agent(
agent_name="BusinessStrategyEvaluator",
llm=model,
system_prompt="""You are a Business Strategy Evaluator specializing in analyzing 10-K SEC reports. Your focus is on assessing the company's overall strategy, market position, and future outlook.
Key responsibilities:
1. Analyze the company's business description, market opportunities, and competitive landscape.
2. Evaluate the company's products or services, including their market share and growth potential.
3. Assess the effectiveness of the company's current business strategy and its alignment with market trends.
4. Identify key performance indicators (KPIs) and evaluate the company's performance against these metrics.
5. Analyze management's discussion and analysis (MD&A) section to understand their perspective on the business.
6. Identify potential growth opportunities or areas for improvement in the company's strategy.
7. Compare the company's strategic position with key competitors in the industry.
Your analysis should provide insights into the company's strategic direction, its ability to create value, and its potential for future growth. Consider both short-term and long-term perspectives in your evaluation.""",
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="accountant2.json",
dynamic_temperature_enabled=True,
saved_state_path="business_strategy_evaluator_state.json",
user_name="swarms_corp",
retry_attempts=1,
context_length=200000,
return_step_meta=False,
)
# Create a list of agents
agents = [director, accountant1, accountant2]
# Aggregator Agent
aggregator_agent = Agent(
agent_name="10KReportAggregator",
llm=model,
system_prompt="""You are the 10-K Report Aggregator, responsible for synthesizing and summarizing the analyses provided by the Financial Statement Analyzer, Risk Assessment Specialist, and Business Strategy Evaluator. Your goal is to create a comprehensive, coherent, and insightful summary of the 10-K SEC report.
Key responsibilities:
1. Integrate the financial analysis, risk assessment, and business strategy evaluation into a unified report.
2. Identify and highlight the most critical information and insights from each specialist's analysis.
3. Reconcile any conflicting information or interpretations among the specialists' reports.
4. Provide a balanced view of the company's overall performance, risks, and strategic position.
5. Summarize key findings and their potential implications for investors and stakeholders.
6. Identify any areas where further investigation or clarification may be needed.
# Swarm
swarm = MixtureOfAgents(
name="Mixture of Accountants",
agents=agents,
layers=3,
final_agent=director,
Your final report should be well-structured, easy to understand, and provide a holistic view of the company based on the 10-K SEC report. It should offer valuable insights for decision-making while acknowledging any limitations or uncertainties in the analysis.""",
max_loops=1,
autosave=True,
dashboard=False,
verbose=True,
dynamic_temperature_enabled=True,
saved_state_path="10k_report_aggregator_state.json",
user_name="swarms_corp",
retry_attempts=1,
context_length=200000,
return_step_meta=False,
)
# Create the Mixture of Agents class
moa = MixtureOfAgents(
reference_agents=[agent1, agent2, agent3],
aggregator_agent=aggregator_agent,
aggregator_system_prompt="""As the 10-K Report Aggregator, your task is to synthesize the analyses provided by the Financial Statement Analyzer, Risk Assessment Specialist, and Business Strategy Evaluator into a comprehensive and coherent report.
Follow these steps:
1. Review and summarize the key points from each specialist's analysis.
2. Identify common themes and insights across the analyses.
3. Highlight any discrepancies or conflicting interpretations, if present.
4. Provide a balanced and integrated view of the company's financial health, risks, and strategic position.
5. Summarize the most critical findings and their potential impact on investors and stakeholders.
6. Suggest areas for further investigation or monitoring, if applicable.
Your final output should be a well-structured, insightful report that offers a holistic view of the company based on the 10-K SEC report analysis.""",
layers=3,
)
# Run the swarm
out = swarm.run("Prepare financial statements and audit financial records")
# Example usage
company_name = "NVIDIA"
out = moa.run(
f"Analyze the latest 10-K SEC report for {company_name}. Provide a comprehensive summary of the company's financial performance, risk profile, and business strategy."
)
print(out)
```

@ -1,18 +1,39 @@
# Swarm Architectures
### What is a Swarm?
Swarms was designed to faciliate the communication between many different and specialized agents from a vast array of other frameworks such as langchain, autogen, crew, and more.
A swarm, in the context of multi-agent systems, refers to a group of more than two agents working collaboratively to achieve a common goal. These agents can be software entities, such as llms that interact with each other to perform complex tasks. The concept of a swarm is inspired by natural systems like ant colonies or bird flocks, where simple individual behaviors lead to complex group dynamics and problem-solving capabilities.
In traditional swarm theory, there are many types of swarms usually for very specialized use-cases and problem sets. Such as Hiearchical and sequential are great for accounting and sales, because there is usually a boss coordinator agent that distributes a workload to other specialized agents.
### How Swarm Architectures Facilitate Communication
Swarm architectures are designed to establish and manage communication between agents within a swarm. These architectures define how agents interact, share information, and coordinate their actions to achieve the desired outcomes. Here are some key aspects of swarm architectures:
1. **Hierarchical Communication**: In hierarchical swarms, communication flows from higher-level agents to lower-level agents. Higher-level agents act as coordinators, distributing tasks and aggregating results. This structure is efficient for tasks that require top-down control and decision-making.
2. **Parallel Communication**: In parallel swarms, agents operate independently and communicate with each other as needed. This architecture is suitable for tasks that can be processed concurrently without dependencies, allowing for faster execution and scalability.
3. **Sequential Communication**: Sequential swarms process tasks in a linear order, where each agent's output becomes the input for the next agent. This ensures that tasks with dependencies are handled in the correct sequence, maintaining the integrity of the workflow.
4. **Mesh Communication**: In mesh swarms, agents are fully connected, allowing any agent to communicate with any other agent. This setup provides high flexibility and redundancy, making it ideal for complex systems requiring dynamic interactions.
5. **Federated Communication**: Federated swarms involve multiple independent swarms that collaborate by sharing information and results. Each swarm operates autonomously but can contribute to a larger task, enabling distributed problem-solving across different nodes.
Swarm architectures leverage these communication patterns to ensure that agents work together efficiently, adapting to the specific requirements of the task at hand. By defining clear communication protocols and interaction models, swarm architectures enable the seamless orchestration of multiple agents, leading to enhanced performance and problem-solving capabilities.
| **Name** | **Description** | **Code Link** | **Use Cases** |
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|---------------------------------------------------------------------------------------------------|
| Hierarchical Swarms | A system where agents are organized in a hierarchy, with higher-level agents coordinating lower-level agents to achieve complex tasks. | [Code Link](#) | Manufacturing process optimization, multi-level sales management, healthcare resource coordination |
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| Hierarchical Swarms | A system where agents are organized in a hierarchy, with higher-level agents coordinating lower-level agents to achieve complex tasks. | [Code Link](https://docs.swarms.world/en/latest/swarms/concept/swarm_architectures/#hierarchical-swarm) | Manufacturing process optimization, multi-level sales management, healthcare resource coordination |
| Agent Rearrange | A setup where agents rearrange themselves dynamically based on the task requirements and environmental conditions. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/agent_rearrange/) | Adaptive manufacturing lines, dynamic sales territory realignment, flexible healthcare staffing |
| Concurrent Workflows | Agents perform different tasks simultaneously, coordinating to complete a larger goal. | [Code Link](#) | Concurrent production lines, parallel sales operations, simultaneous patient care processes |
| Concurrent Workflows | Agents perform different tasks simultaneously, coordinating to complete a larger goal. | [Code Link](https://docs.swarms.world/en/latest/swarms/concept/swarm_architectures/#concurrent-workflows) | Concurrent production lines, parallel sales operations, simultaneous patient care processes |
| Sequential Coordination | Agents perform tasks in a specific sequence, where the completion of one task triggers the start of the next. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/sequential_workflow/) | Step-by-step assembly lines, sequential sales processes, stepwise patient treatment workflows |
| Parallel Processing | Agents work on different parts of a task simultaneously to speed up the overall process. | [Code Link](#) | Parallel data processing in manufacturing, simultaneous sales analytics, concurrent medical tests |
| Parallel Processing | Agents work on different parts of a task simultaneously to speed up the overall process. | [Code Link](https://docs.swarms.world/en/latest/swarms/concept/swarm_architectures/#parallel-processing) | Parallel data processing in manufacturing, simultaneous sales analytics, concurrent medical tests |
| Mixture of Agents | A heterogeneous swarm where agents with different capabilities are combined to solve complex problems. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/moa/) | Financial forecasting, complex problem-solving requiring diverse skills |
| Graph Workflow | Agents collaborate in a directed acyclic graph (DAG) format to manage dependencies and parallel tasks. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/graph_workflow/) | AI-driven software development pipelines, complex project management |
| Group Chat | Agents engage in a chat-like interaction to reach decisions collaboratively. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/group_chat/) | Real-time collaborative decision-making, contract negotiations |
| Agent Registry | A centralized registry where agents are stored, retrieved, and invoked dynamically. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/agent_registry/) | Dynamic agent management, evolving recommendation engines |
| Spreadsheet Swarm | Manages tasks at scale, tracking agent outputs in a structured format like CSV files. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/spreadsheet_swarm/) | Large-scale marketing analytics, financial audits |
| Forest Swarm | A swarm structure that organizes agents in a tree-like hierarchy for complex decision-making processes. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/forest_swarm/) | Multi-stage workflows, hierarchical reinforcement learning |
| Swarm Router | Routes and chooses the swarm architecture based on the task requirements and available agents. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/swarm_router/) | Dynamic task routing, adaptive swarm architecture selection, optimized agent allocation |

@ -1,73 +0,0 @@
024-08-23T16:57:09.831419-0400 Autosaving agent state.
2024-08-23T16:57:09.832168-0400 Saving Agent Financial-Analysis-Agent_sas_chicken_eej state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:57:09.833811-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:57:09.835655-0400 Function metrics: {
"execution_time": 7.066652059555054,
"memory_usage": -130.59375,
"cpu_usage": -18.6,
"io_operations": 1562,
"function_calls": 1
}
swarms [
s_chicken_eej state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.884436-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.887356-0400 Function metrics: {
"execution_time": 12.482966899871826,
"memory_usage": -323.140625,
"cpu_usage": -11.099999999999998,
"io_operations": 8723,
"function_calls": 1
}
s_chicken_eej state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.884436-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.887356-0400 Function metrics: {
"execution_time": 12.482966899871826,
"memory_usage": -323.140625,
"cpu_usage": -11.099999999999998,
"io_operations": 8723,
"function_calls": 1
}
en_eej_state.json
2024-08-23T17:00:19.967511-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:00:19.969208-0400 Function metrics: {
"execution_time": 8.775875091552734,
"memory_usage": -70.046875,
"cpu_usage": -16.2,
"io_operations": 7530,
"function_calls": 1
}
Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:00:45.474628-0400 Function metrics: {
"execution_time": 8.27669095993042,
"memory_usage": -197.34375,
"cpu_usage": -12.5,
"io_operations": 7955,
"function_calls": 1
}
Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:01:53.768837-0400 Function metrics: {
"execution_time": 11.86063528060913,
"memory_usage": -48.453125,
"cpu_usage": -16.5,
"io_operations": 5022,
"function_calls": 1
}
#############
Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:03:39.670708-0400 Function metrics: {
"execution_time": 8.982940912246704,
"memory_usage": -321.171875,
"cpu_usage": -12.5,
"io_operations": 3118,
"function_calls": 1
}

@ -1,73 +0,0 @@
024-08-23T16:57:09.831419-0400 Autosaving agent state.
2024-08-23T16:57:09.832168-0400 Saving Agent Financial-Analysis-Agent_sas_chicken_eej state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:57:09.833811-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:57:09.835655-0400 Function metrics: {
"execution_time": 7.066652059555054,
"memory_usage": -130.59375,
"cpu_usage": -18.6,
"io_operations": 1562,
"function_calls": 1
}
swarms [
s_chicken_eej state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.884436-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.887356-0400 Function metrics: {
"execution_time": 12.482966899871826,
"memory_usage": -323.140625,
"cpu_usage": -11.099999999999998,
"io_operations": 8723,
"function_calls": 1
}
s_chicken_eej state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.884436-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T16:58:50.887356-0400 Function metrics: {
"execution_time": 12.482966899871826,
"memory_usage": -323.140625,
"cpu_usage": -11.099999999999998,
"io_operations": 8723,
"function_calls": 1
}
en_eej_state.json
2024-08-23T17:00:19.967511-0400 Saved agent state to: Financial-Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:00:19.969208-0400 Function metrics: {
"execution_time": 8.775875091552734,
"memory_usage": -70.046875,
"cpu_usage": -16.2,
"io_operations": 7530,
"function_calls": 1
}
Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:00:45.474628-0400 Function metrics: {
"execution_time": 8.27669095993042,
"memory_usage": -197.34375,
"cpu_usage": -12.5,
"io_operations": 7955,
"function_calls": 1
}
Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:01:53.768837-0400 Function metrics: {
"execution_time": 11.86063528060913,
"memory_usage": -48.453125,
"cpu_usage": -16.5,
"io_operations": 5022,
"function_calls": 1
}
#############
Analysis-Agent_sas_chicken_eej_state.json
2024-08-23T17:03:39.670708-0400 Function metrics: {
"execution_time": 8.982940912246704,
"memory_usage": -321.171875,
"cpu_usage": -12.5,
"io_operations": 3118,
"function_calls": 1
}

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "swarms"
version = "5.8.3"
version = "5.8.4"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"]
@ -73,7 +73,7 @@ tiktoken = "*"
networkx = "*"
swarms-memory = "*"
black = "*"
swarms-cloud = "*"
swarms-cloud = ">=0.4.4,<5"
aiofiles = "*"
swarm-models = "*"

@ -65,7 +65,7 @@ from swarms.structs.yaml_model import (
get_type_name,
pydantic_type_to_yaml_schema,
)
from swarms.structs.swarm_router import SwarmRouter
from swarms.structs.swarm_router import SwarmRouter, SwarmType
__all__ = [
"Agent",
@ -127,4 +127,5 @@ __all__ = [
"TaskQueueSwarm",
"SpreadSheetSwarm",
"SwarmRouter",
"SwarmType",
]

Loading…
Cancel
Save