[MixtureOfAgents.reference_agents -> agents]

pull/643/head
Your Name 2 months ago
parent c1c98a85af
commit b6ca99b513

@ -1201,7 +1201,7 @@ Your final report should be well-structured, easy to understand, and provide a h
# Create the Mixture of Agents class # Create the Mixture of Agents class
moa = MixtureOfAgents( moa = MixtureOfAgents(
reference_agents=[agent1, agent2, agent3], agents=[agent1, agent2, agent3],
aggregator_agent=aggregator_agent, 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. 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.

@ -0,0 +1,71 @@
import os
import asyncio
import threading
from swarms import Agent
from swarm_models import OpenAIChat
import time
import psutil
from swarms.prompts.finance_agent_sys_prompt import (
FINANCIAL_AGENT_SYS_PROMPT,
)
from dotenv import load_dotenv
load_dotenv()
# Get the OpenAI API key from the environment variable
api_key = os.getenv("OPENAI_API_KEY")
# Create an instance of the OpenAIChat class
model = OpenAIChat(
openai_api_key=api_key, model_name="gpt-4o-mini", temperature=0.1
)
# Initialize the agent
agent = Agent(
agent_name="Financial-Analysis-Agent",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
llm=model,
max_loops=1,
autosave=True,
dashboard=False,
verbose=True,
dynamic_temperature_enabled=True,
saved_state_path="finance_agent.json",
user_name="swarms_corp",
retry_attempts=1,
context_length=200000,
return_step_meta=False,
output_type="string",
streaming_on=False,
)
# Function to measure time and memory usage
def measure_time_and_memory(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
memory_usage = psutil.Process().memory_info().rss / 1024 ** 2
print(f"Time taken: {end_time - start_time} seconds")
print(f"Memory used: {memory_usage} MB")
return result
return wrapper
# Function to run the agent asynchronously
@measure_time_and_memory
async def run_agent_async():
await asyncio.gather(
agent.run(
"How can I establish a ROTH IRA to buy stocks and get a tax break? What are the criteria"
)
)
# Function to run the agent on another thread
@measure_time_and_memory
def run_agent_thread():
asyncio.run(run_agent_async())
# Run the agent asynchronously and on another thread to test the speed
asyncio.run(run_agent_async())
run_agent_thread()

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "6.2.8" version = "6.2.9"
description = "Swarms - Pytorch" description = "Swarms - Pytorch"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"] authors = ["Kye Gomez <kye@apac.ai>"]

@ -20,7 +20,7 @@ class MixtureOfAgentsInput(BaseModel):
description: str = ( description: str = (
"A class to run a mixture of agents and aggregate their responses." "A class to run a mixture of agents and aggregate their responses."
) )
reference_agents: List[Dict[str, Any]] agents: List[Dict[str, Any]]
aggregator_agent: Any = Field( aggregator_agent: Any = Field(
..., ...,
description="An aggregator agent to be used in the mixture.", description="An aggregator agent to be used in the mixture.",
@ -60,7 +60,7 @@ class MixtureOfAgents:
self, self,
name: str = "MixtureOfAgents", name: str = "MixtureOfAgents",
description: str = "A class to run a mixture of agents and aggregate their responses.", description: str = "A class to run a mixture of agents and aggregate their responses.",
reference_agents: List[Agent] = [], agents: List[Agent] = [],
aggregator_agent: Agent = None, aggregator_agent: Agent = None,
aggregator_system_prompt: str = "", aggregator_system_prompt: str = "",
layers: int = 3, layers: int = 3,
@ -71,14 +71,14 @@ class MixtureOfAgents:
Args: Args:
name (str, optional): The name of the mixture of agents. Defaults to "MixtureOfAgents". name (str, optional): The name of the mixture of agents. Defaults to "MixtureOfAgents".
description (str, optional): A description of the mixture of agents. Defaults to "A class to run a mixture of agents and aggregate their responses.". description (str, optional): A description of the mixture of agents. Defaults to "A class to run a mixture of agents and aggregate their responses.".
reference_agents (List[Agent], optional): A list of reference agents to be used in the mixture. Defaults to []. agents (List[Agent], optional): A list of reference agents to be used in the mixture. Defaults to [].
aggregator_agent (Agent, optional): The aggregator agent to be used in the mixture. Defaults to None. aggregator_agent (Agent, optional): The aggregator agent to be used in the mixture. Defaults to None.
aggregator_system_prompt (str, optional): The system prompt for the aggregator agent. Defaults to "". aggregator_system_prompt (str, optional): The system prompt for the aggregator agent. Defaults to "".
layers (int, optional): The number of layers to process in the mixture. Defaults to 3. layers (int, optional): The number of layers to process in the mixture. Defaults to 3.
""" """
self.name = name self.name = name
self.description = description self.description = description
self.reference_agents: List[Agent] = reference_agents self.agents: List[Agent] = agents
self.aggregator_agent: Agent = aggregator_agent self.aggregator_agent: Agent = aggregator_agent
self.aggregator_system_prompt: str = aggregator_system_prompt self.aggregator_system_prompt: str = aggregator_system_prompt
self.layers: int = layers self.layers: int = layers
@ -86,8 +86,8 @@ class MixtureOfAgents:
self.input_schema = MixtureOfAgentsInput( self.input_schema = MixtureOfAgentsInput(
name=name, name=name,
description=description, description=description,
reference_agents=[ agents=[
agent.to_dict() for agent in self.reference_agents agent.to_dict() for agent in self.agents
], ],
aggregator_agent=aggregator_agent.to_dict(), aggregator_agent=aggregator_agent.to_dict(),
aggregator_system_prompt=self.aggregator_system_prompt, aggregator_system_prompt=self.aggregator_system_prompt,
@ -113,7 +113,7 @@ class MixtureOfAgents:
"Checking the reliability of the Mixture of Agents class." "Checking the reliability of the Mixture of Agents class."
) )
if not self.reference_agents: if not self.agents:
raise ValueError("No reference agents provided.") raise ValueError("No reference agents provided.")
if not self.aggregator_agent: if not self.aggregator_agent:
@ -205,7 +205,7 @@ class MixtureOfAgents:
results: List[str] = await asyncio.gather( results: List[str] = await asyncio.gather(
*[ *[
self._run_agent_async(agent, task) self._run_agent_async(agent, task)
for agent in self.reference_agents for agent in self.agents
] ]
) )
@ -216,7 +216,7 @@ class MixtureOfAgents:
self._run_agent_async( self._run_agent_async(
agent, task, prev_responses=results agent, task, prev_responses=results
) )
for agent in self.reference_agents for agent in self.agents
] ]
) )

@ -295,7 +295,7 @@ class SwarmRouter:
return MixtureOfAgents( return MixtureOfAgents(
name=self.name, name=self.name,
description=self.description, description=self.description,
reference_agents=self.agents, agents=self.agents,
aggregator_system_prompt=aggregator_system_prompt.get_prompt(), aggregator_system_prompt=aggregator_system_prompt.get_prompt(),
aggregator_agent=self.agents[-1], aggregator_agent=self.agents[-1],
layers=self.max_loops, layers=self.max_loops,

Loading…
Cancel
Save