[FEAT][AgentRearrange]

pull/459/merge
Kye 9 months ago
parent ed4b129b04
commit f55c140b5a

@ -0,0 +1,59 @@
from swarms import Agent, Anthropic, AgentRearrange
# Define the agents with specific tasks for financial activities
agent_risk_analysis = Agent(
agent_name="RiskAnalysis",
agent_description="Analyze the financial risks associated with the portfolio.",
system_prompt="Analyze and identify the risks in the financial data provided.",
llm=Anthropic(),
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
)
agent_compliance_check = Agent(
agent_name="ComplianceCheck",
agent_description="Ensure all financial activities adhere to regulatory standards.",
system_prompt="Review the financial data to ensure compliance with all relevant regulations.",
llm=Anthropic(),
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
)
agent_report_generation = Agent(
agent_name="ReportGeneration",
agent_description="Generate a detailed report based on the risk analysis and compliance check.",
system_prompt="Compile the findings from risk analysis and compliance checks into a comprehensive financial report.",
llm=Anthropic(),
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
)
# Initialize the AgentRearrange system
financial_workflow = AgentRearrange(
agents=[
agent_risk_analysis,
agent_compliance_check,
agent_report_generation,
],
flow="RiskAnalysis -> ComplianceCheck -> ReportGeneration",
verbose=True,
)
# Run the workflow on a task
default_task = (
"Prepare a comprehensive financial review for the fiscal quarter."
)
results = financial_workflow.run(default_task)
print("Workflow Results:", results)

@ -1,7 +1,6 @@
from swarms import Agent, AgentRearrange, rearrange, Anthropic
# Initialize the director agent
director = Agent(

@ -314,8 +314,7 @@ class Agent:
self.execute_tool = execute_tool
self.planning = planning
self.planning_prompt = planning_prompt
# Name
self.name = agent_name
self.description = agent_description
@ -457,7 +456,7 @@ class Agent:
logger.info(f"Beginning of Agent {self.agent_name} History")
logger.info(self.short_memory.return_history_as_string())
logger.info(f"End of Agent {self.agent_name} History")
# If the user inputs a list of strings for the sop then join them and set the sop
if self.sop_list:
self.sop = "\n".join(self.sop_list)
@ -466,7 +465,6 @@ class Agent:
if self.sop is not None:
self.short_memory.add(role=self.user_name, content=self.sop)
def set_system_prompt(self, system_prompt: str):
"""Set the system prompt"""
self.system_prompt = system_prompt

@ -116,30 +116,38 @@ class AgentRearrange(BaseSwarm):
Returns:
str: The final processed task.
"""
if not self.validate_flow():
return "Invalid flow configuration."
tasks = self.flow.split("->")
current_task = task
try:
if not self.validate_flow():
return "Invalid flow configuration."
tasks = self.flow.split("->")
current_task = task
for task in tasks:
agent_names = [name.strip() for name in task.split(",")]
if len(agent_names) > 1:
# Parallel processing
logger.info(
f"Running agents in parallel: {agent_names}"
)
results = []
for agent_name in agent_names:
agent = self.agents[agent_name]
result = agent.run(current_task, *args, **kwargs)
results.append(result)
current_task = "; ".join(results)
else:
# Sequential processing
logger.info(
f"Running agents sequentially: {agent_names}"
)
agent = self.agents[agent_names[0]]
current_task = agent.run(current_task, *args, **kwargs)
for task in tasks:
agent_names = [name.strip() for name in task.split(",")]
if len(agent_names) > 1:
# Parallel processing
logger.info(f"Running agents in parallel: {agent_names}")
results = []
for agent_name in agent_names:
agent = self.agents[agent_name]
result = agent.run(current_task, *args, **kwargs)
results.append(result)
current_task = "; ".join(results)
else:
# Sequential processing
logger.info(f"Running agents sequentially: {agent_names}")
agent = self.agents[agent_names[0]]
current_task = agent.run(current_task, *args, **kwargs)
return current_task
return current_task
except Exception as e:
logger.error(f"An error occurred: {e}")
return e
def rearrange(

Loading…
Cancel
Save