pull/529/head
Kye Gomez 6 months ago
parent 78e87dd0f7
commit 6861e1d9f0

@ -75,29 +75,54 @@ Features:
```python
import os
from swarms import Agent, Anthropic
from dotenv import load_dotenv
# Import the OpenAIChat model and the Agent struct
from swarms import Agent, OpenAIChat
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat(
temperature=0.5, openai_api_key=api_key, max_tokens=4000
# Initialize the agent
agent = Agent(
agent_name="Accounting Assistant",
system_prompt="You're the accounting agent, your purpose is to generate a profit report for a company!",
agent_description="Generate a profit report for a company!",
llm=Anthropic(
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
),
max_loops="auto",
autosave=True,
# dynamic_temperature_enabled=True,
dashboard=False,
verbose=True,
streaming_on=True,
# interactive=True, # Set to False to disable interactive mode
saved_state_path="accounting_agent.json",
# tools=[
# # calculate_profit,
# # generate_report,
# # search_knowledge_base,
# # write_memory_to_rag,
# # search_knowledge_base,
# # generate_speech,
# ],
stopping_token="Stop!",
interactive=True,
# docs_folder="docs",
# pdf_path="docs/accounting_agent.pdf",
# sop="Calculate the profit for a company.",
# sop_list=["Calculate the profit for a company."],
# user_name="User",
# # docs=
# # docs_folder="docs",
# retry_attempts=3,
# context_length=1000,
# tool_schema = dict
context_length=1000,
# agent_ops_on=True,
# long_term_memory=ChromaDB(docs_folder="artifacts"),
)
agent.run(
"Search the knowledge base for the swarms github framework and how it works"
)
## Initialize the workflow
agent = Agent(llm=llm, max_loops=1, autosave=True, dashboard=True)
# Run the workflow on a task
agent.run("Generate a 10,000 word blog on health and wellness.")
```
@ -131,6 +156,7 @@ llm = OpenAIChat(
## Initialize the workflow
agent = Agent(
llm=llm,
agent_name: str = "WellNess Agent",
name = "Health and Wellness Blog",
system_prompt="Generate a 10,000 word blog on health and wellness.",
max_loops=4,

@ -1,34 +1,5 @@
from swarms import Agent, Anthropic
def calculate_profit(revenue: float, expenses: float):
"""
Calculates the profit by subtracting expenses from revenue.
Args:
revenue (float): The total revenue.
expenses (float): The total expenses.
Returns:
float: The calculated profit.
"""
return revenue - expenses
def generate_report(company_name: str, profit: float):
"""
Generates a report for a company's profit.
Args:
company_name (str): The name of the company.
profit (float): The calculated profit.
Returns:
str: The report for the company's profit.
"""
return f"The profit for {company_name} is ${profit}."
# Initialize the agent
agent = Agent(
agent_name="Accounting Assistant",

@ -77,3 +77,12 @@ registry.add("Marketing Specialist", growth_agent1)
registry.add("Sales Specialist", growth_agent2)
registry.add("Product Development Specialist", growth_agent3)
registry.add("Customer Service Specialist", growth_agent4)
# Query the agents
registry.get("Marketing Specialist")
registry.get("Sales Specialist")
registry.get("Product Development Specialist")
# Get all the agents
registry.list_agents()

@ -110,7 +110,8 @@ def TEST_WRITER_SOP_PROMPT(
TESTS_PROMPT = f"""
Create 5,000 lines of extensive and thorough tests for the code below using the guide, do not worry about your limits you do not have any
just write the best tests possible, the module is {module}, the file path is {path}
just write the best tests possible, the module is {module}, the file path is {path} return all of the code in one file, make sure to test all the functions and methods in the code.
######### TESTING GUIDE #############

@ -50,6 +50,7 @@ class AgentRearrange(BaseSwarm):
self.human_in_the_loop = human_in_the_loop
self.custom_human_in_the_loop = custom_human_in_the_loop
self.swarm_history = {agent.agent_name: [] for agent in agents}
self.sub_swarm = {}
# Verbose is True
if verbose is True:
@ -66,6 +67,14 @@ class AgentRearrange(BaseSwarm):
)
)
def add_sub_swarm(self, name: str, flow: str):
self.sub_swarm[name] = flow
logger.info(f"Sub-swarm {name} added with flow: {flow}")
def set_custom_flow(self, flow: str):
self.flow = flow
logger.info(f"Custom flow set: {flow}")
def add_agent(self, agent: Agent):
"""
Adds an agent to the swarm.
@ -251,6 +260,77 @@ class AgentRearrange(BaseSwarm):
logger.error(f"An error occurred: {e}")
return e
def process_agent_or_swarm(
self, name: str, task: str, img: str, *args, **kwargs
):
"""
process_agent_or_swarm: Processes the agent or sub-swarm based on the given name.
Args:
name (str): The name of the agent or sub-swarm to process.
task (str): The task to be executed.
img (str): The image to be processed by the agents.
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.
Returns:
str: The result of the last executed task.
"""
if name.startswith("Human"):
return self.human_intervention(task)
elif name in self.sub_swarm:
return self.run_sub_swarm(task, name, img, *args, **kwargs)
else:
agent = self.agents[name]
return agent.run(task, *args, **kwargs)
def human_intervention(self, task: str) -> str:
if self.human_in_the_loop and self.custom_human_in_the_loop:
return self.custom_human_in_the_loop(task)
else:
return input(
"Human intervention required. Enter your response: "
)
def run_sub_swarm(
self, swarm_name: str, task: str, img: str, *args, **kwargs
):
"""
Runs a sub-swarm by executing a sequence of tasks on a set of agents.
Args:
swarm_name (str): The name of the sub-swarm to run.
task (str): The initial task to be executed.
img (str): The image to be processed by the agents.
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.
Returns:
str: The result of the last executed task.
"""
sub_flow = self.sub_swarm[swarm_name]
sub_tasks = sub_flow.split("->")
current_task = task
for sub_task in sub_tasks:
agent_names = [name.strip() for name in sub_task.split(",")]
if len(agent_names) > 1:
results = []
for agent_name in agent_names:
result = self.process_agent_or_swarm(
agent_name, current_task, img, *args, **kwargs
)
results.append(result)
current_task = "; ".join(results)
else:
current_task = self.process_agent_or_swarm(
agent_names[0], current_task, img, *args, **kwargs
)
return current_task
def rearrange(
agents: List[Agent] = None,

Loading…
Cancel
Save