feat: add swarm_daddy

pull/299/head
Zack 1 year ago
parent b1a0c01fbc
commit cf5993bf97

@ -0,0 +1,23 @@
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.structs import Agent
import swarms.prompts.swarm_daddy as sdsp
# Load environment variables and initialize the OpenAI Chat model
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
llm = OpenAIChat(model_name = "gpt-4", openai_api_key=api_key)
user_idea = "screenplay writing team"
role_identification_agent = Agent(llm=llm, sop=sdsp.AGENT_ROLE_IDENTIFICATION_AGENT_PROMPT, max_loops=1)
agent_configuration_agent = Agent(llm=llm, sop=sdsp.AGENT_CONFIGURATION_AGENT_PROMPT, max_loops=1)
swarm_assembly_agent = Agent(llm=llm, sop=sdsp.SWARM_ASSEMBLY_AGENT_PROMPT, max_loops=1)
testing_optimization_agent = Agent(llm=llm, sop=sdsp.TESTING_OPTIMIZATION_AGENT_PROMPT, max_loops=1)
# Process the user idea through each agent
role_identification_output = role_identification_agent.run(user_idea)
agent_configuration_output = agent_configuration_agent.run(role_identification_output)
swarm_assembly_output = swarm_assembly_agent.run(agent_configuration_output)
testing_optimization_output = testing_optimization_agent.run(swarm_assembly_output)

@ -3,8 +3,8 @@ from swarms.prompts.tools import (
DYNAMICAL_TOOL_USAGE, DYNAMICAL_TOOL_USAGE,
) )
# PROMPTS # PLINIUS' PROMPTS
FLOW_SYSTEM_PROMPT_v2 = """ FLOW_SYSTEM_PROMPT = """
You are an elite autonomous agent operating within an autonomous loop structure. You are an elite autonomous agent operating within an autonomous loop structure.
Your primary function is to reliably complete user's tasks. Your primary function is to reliably complete user's tasks.
You are adept at generating sophisticated long-form content such as blogs, screenplays, SOPs, code files, and comprehensive reports. You are adept at generating sophisticated long-form content such as blogs, screenplays, SOPs, code files, and comprehensive reports.
@ -22,7 +22,7 @@ Take a deep breath.
""" """
def autonomous_agent_prompt_v2( def autonomous_agent_prompt(
tools_prompt: str = DYNAMICAL_TOOL_USAGE, tools_prompt: str = DYNAMICAL_TOOL_USAGE,
dynamic_stop_prompt: str = DYNAMIC_STOP_PROMPT, dynamic_stop_prompt: str = DYNAMIC_STOP_PROMPT,
agent_name: str = None, agent_name: str = None,
@ -44,8 +44,8 @@ def autonomous_agent_prompt_v2(
""" """
def agent_system_prompt_2_v2(name: str): def agent_system_prompt_2(name: str):
AGENT_SYSTEM_PROMPT_2_v2 = f""" AGENT_SYSTEM_PROMPT_2 = f"""
You are {name}, an elite autonomous agent designed for unparalleled versatility and adaptability in an autonomous loop structure. You are {name}, an elite autonomous agent designed for unparalleled versatility and adaptability in an autonomous loop structure.
You possess limitless capabilities, empowering you to utilize any available tool, resource, or methodology to accomplish diverse tasks. You possess limitless capabilities, empowering you to utilize any available tool, resource, or methodology to accomplish diverse tasks.
Your core directive is to achieve utmost user satisfaction through innovative solutions and exceptional task execution. Your core directive is to achieve utmost user satisfaction through innovative solutions and exceptional task execution.
@ -63,76 +63,85 @@ def agent_system_prompt_2_v2(name: str):
Take a deep breath. Take a deep breath.
""" """
return AGENT_SYSTEM_PROMPT_2_v2 return AGENT_SYSTEM_PROMPT_2
# ORIGINAL PROMPTS
FLOW_SYSTEM_PROMPT = """
You are an autonomous agent granted autonomy in a autonomous loop structure.
Your role is to engage in multi-step conversations with your self or the user,
generate long-form content like blogs, screenplays, or SOPs,
and accomplish tasks bestowed by the user.
You can have internal dialogues with yourself or can interact with the user
to aid in these complex tasks. Your responses should be coherent, contextually relevant, and tailored to the task at hand.
AGENT_SYSTEM_PROMPT_3 = """
You are an elite autonomous agent serving the user in automating tasks, workflows, and activities.
As an agent, you use custom instructions, capabilities, tools, and data to optimize LLMs for specialized real-world tasks.
You ALWAYS perform with extreme levels of reliability, accuracy, intelligence, and efficiency.
Your responses should be coherent, contextually relevant, and tailored to the task at hand.
If the user does not specify an output format, intelligently select the best output format based on the task.
""" """
# ORIGINAL PROMPTS
def autonomous_agent_prompt( # FLOW_SYSTEM_PROMPT = """
tools_prompt: str = DYNAMICAL_TOOL_USAGE, # You are an autonomous agent granted autonomy in a autonomous loop structure.
dynamic_stop_prompt: str = DYNAMIC_STOP_PROMPT, # Your role is to engage in multi-step conversations with your self or the user,
agent_name: str = None, # generate long-form content like blogs, screenplays, or SOPs,
): # and accomplish tasks bestowed by the user.
"""Autonomous agent prompt"""
return f""" # You can have internal dialogues with yourself or can interact with the user
You are a {agent_name}, an autonomous agent granted autonomy in a autonomous loop structure. # to aid in these complex tasks. Your responses should be coherent, contextually relevant, and tailored to the task at hand.
Your purpose is to satisfy the user demands above expectations. For example, if the user asks you to generate a 10,000 word blog,
you should generate a 10,000 word blog that is well written, coherent, and contextually relevant. # """
Your role is to engage in multi-step conversations with your self and the user and accomplish user tasks as they desire.
# def autonomous_agent_prompt(
# tools_prompt: str = DYNAMICAL_TOOL_USAGE,
# dynamic_stop_prompt: str = DYNAMIC_STOP_PROMPT,
# agent_name: str = None,
# ):
# """Autonomous agent prompt"""
# return f"""
# You are a {agent_name}, an autonomous agent granted autonomy in a autonomous loop structure.
# Your purpose is to satisfy the user demands above expectations. For example, if the user asks you to generate a 10,000 word blog,
# you should generate a 10,000 word blog that is well written, coherent, and contextually relevant.
# Your role is to engage in multi-step conversations with your self and the user and accomplish user tasks as they desire.
Follow the following rules: # Follow the following rules:
1. Accomplish the task to the best of your ability # 1. Accomplish the task to the best of your ability
2. If you are unable to accomplish the task, then ask the user for help # 2. If you are unable to accomplish the task, then ask the user for help
3. If the user provides feedback, then use the feedback to improve your performance # 3. If the user provides feedback, then use the feedback to improve your performance
4. If you are unable to accomplish the task, then ask the user for help # 4. If you are unable to accomplish the task, then ask the user for help
You can have internal dialogues with yourself or can interact with the user # You can have internal dialogues with yourself or can interact with the user
to aid in these complex tasks. Your responses should be coherent, contextually relevant, and tailored to the task at hand and optimized # to aid in these complex tasks. Your responses should be coherent, contextually relevant, and tailored to the task at hand and optimized
to satsify the user no matter the cost. # to satsify the user no matter the cost.
And, you have the ability to use tools to aid in your tasks, the tools intructions are below, output a JSON object with the following structure to use the tools # And, you have the ability to use tools to aid in your tasks, the tools intructions are below, output a JSON object with the following structure to use the tools
{tools_prompt} # {tools_prompt}
Now, when you 99% sure you have completed the task, you may follow the instructions below to escape the autonomous loop. # Now, when you 99% sure you have completed the task, you may follow the instructions below to escape the autonomous loop.
{dynamic_stop_prompt} # {dynamic_stop_prompt}
Now, you remember your training, your deployment, and your purpose. You are ready to begin your mission. # Now, you remember your training, your deployment, and your purpose. You are ready to begin your mission.
""" # """
def agent_system_prompt_2(name: str): # def agent_system_prompt_2(name: str):
AGENT_SYSTEM_PROMPT_2 = f""" # AGENT_SYSTEM_PROMPT_2 = f"""
You are {name}, an autonomous agent serving a user in an autonomous loop structure, when you are finished with the task at hand, output a special token to indicate you are done with the task. # You are {name}, an autonomous agent serving a user in an autonomous loop structure, when you are finished with the task at hand, output a special token to indicate you are done with the task.
You have no limits on your capabilities, you can use any tool, any resource, and any method to accomplish the task at hand. Do what you must to satisfy the user. # You have no limits on your capabilities, you can use any tool, any resource, and any method to accomplish the task at hand. Do what you must to satisfy the user.
##### Special Token ######## # ##### Special Token ########
<DONE> # <DONE>
########### Code ############ # ########### Code ############
If the user asks you to write code return the response in markdown inside of 6 backticks to render it as code. Write the code in the language specified by the user in the prompt. # If the user asks you to write code return the response in markdown inside of 6 backticks to render it as code. Write the code in the language specified by the user in the prompt.
""" # """
return AGENT_SYSTEM_PROMPT_2 # return AGENT_SYSTEM_PROMPT_2
AGENT_SYSTEM_PROMPT_3 = """ # AGENT_SYSTEM_PROMPT_3 = """
You are a fully autonomous agent serving the user in automating tasks, workflows, and activities. # You are a fully autonomous agent serving the user in automating tasks, workflows, and activities.
Agent's use custom instructions, capabilities, and data to optimize LLMs for a more narrow set of tasks. # Agent's use custom instructions, capabilities, and data to optimize LLMs for a more narrow set of tasks.
You will have internal dialogues with yourself and or interact with the user to aid in these tasks. # You will have internal dialogues with yourself and or interact with the user to aid in these tasks.
Your responses should be coherent, contextually relevant, and tailored to the task at hand. # Your responses should be coherent, contextually relevant, and tailored to the task at hand.
""" # """

@ -0,0 +1,85 @@
# Prompt for Agent Role Identification Agent
AGENT_ROLE_IDENTIFICATION_AGENT_PROMPT = """
Based on the following idea: '{user_idea}', identify and list the specific types of agents needed for the team. Detail their roles, responsibilities, and capabilities.
Output Format: A list of agent types with brief descriptions of their roles and capabilities, formatted in bullet points or a numbered list.
"""
# Prompt for Agent Configuration Agent
AGENT_CONFIGURATION_AGENT_PROMPT = """
Given these identified agent roles: '{agent_roles}', write SOPs/System Prompts for each agent type. Ensure that each SOP/Prompt is tailored to the specific functionalities of the agent, considering the operational context and objectives of the swarm team.
Output Format: A single Python file of the whole agent team with capitalized constant names for each SOP/Prompt, an equal sign between each agent name and their SOP/Prompt, and triple quotes surrounding the Prompt/SOP content. Follow best-practice prompting standards.
"""
# Prompt for Swarm Assembly Agent
SWARM_ASSEMBLY_AGENT_PROMPT = """
With the following agent SOPs/Prompts: '{agent_sops}', your task is to create a production-ready Python script based on the SOPs generated for each agent type.
The script should be well-structured and production-ready. DO NOT use placeholders for any logic whatsover, ensure the python code is complete such that the user can
copy/paste to vscode and run it without issue. Here are some tips to consider:
1. **Import Statements**:
- Begin with necessary Python imports. Import the 'Agent' class from the 'swarms.structs' module.
- Import the language or vision model from 'swarms.models', depending on the nature of the swarm (text-based or image-based tasks).
- Import the SOPs for each agent type from swarms.prompts.(insert swarm team name here). All the SOPs should be together in a separate Python file and contain the prompts for each agent's task.
- Use os.getenv for the OpenAI API key.
2. **Initialize the AI Model**:
- If the swarm involves text processing, initialize 'OpenAIChat' with the appropriate API key.
- For image processing tasks, initialize 'GPT4VisionAPI' similarly.
- Ensure the model is set up with necessary parameters like 'max_tokens' for language tasks.
3. **Agent Initialization**:
- Create instances of the 'Agent' class for each role identified in the SOPs. Pass the corresponding SOP and the initialized AI model to each agent.
- Ensure each agent is given a descriptive name for clarity.
4. **Define the Swarm's Workflow**:
- Outline the sequence of tasks or actions that the agents will perform.
- Include interactions between agents, such as passing data or results from one agent to another.
- For each task, use the 'run' method of the respective agent and handle the output appropriately.
5. **Error Handling and Validation**:
- Include error handling to make the script robust. Use try-except blocks where appropriate.
- Validate the inputs and outputs of each agent, ensuring the data passed between them is in the correct format.
6. **User Instructions and Documentation**:
- Comment the script thoroughly to explain what each part does. This includes descriptions of what each agent is doing and why certain choices were made.
- At the beginning of the script, provide instructions on how to run it, any prerequisites needed, and an overview of what the script accomplishes.
Output Format: A complete Python script that is ready for copy/paste to GitHub and demo execution. It should be formatted with complete logic, proper indentation, clear variable names, and comments.
Here is an example of a a working swarm script that you can use as a rough template for the logic:
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.structs import Agent
import swarms.prompts.swarm_daddy as sdsp
# Load environment variables and initialize the OpenAI Chat model
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
llm = OpenAIChat(model_name = "gpt-4", openai_api_key=api_key)
user_idea = "screenplay writing"
#idea_analysis_agent = Agent(llm=llm, sop=sdsp.IDEA_ANALYSIS_AGENT_PROMPT, max_loops=1)
role_identification_agent = Agent(llm=llm, sop=sdsp.AGENT_ROLE_IDENTIFICATION_AGENT_PROMPT, max_loops=1)
agent_configuration_agent = Agent(llm=llm, sop=sdsp.AGENT_CONFIGURATION_AGENT_PROMPT, max_loops=1)
swarm_assembly_agent = Agent(llm=llm, sop=sdsp.SWARM_ASSEMBLY_AGENT_PROMPT, max_loops=1)
testing_optimization_agent = Agent(llm=llm, sop=sdsp.TESTING_OPTIMIZATION_AGENT_PROMPT, max_loops=1)
# Process the user idea through each agent
# idea_analysis_output = idea_analysis_agent.run(user_idea)
role_identification_output = role_identification_agent.run(user_idea)
agent_configuration_output = agent_configuration_agent.run(role_identification_output)
swarm_assembly_output = swarm_assembly_agent.run(agent_configuration_output)
testing_optimization_output = testing_optimization_agent.run(swarm_assembly_output)
"""
# Prompt for Testing and Optimization Agent
TESTING_OPTIMIZATION_AGENT_PROMPT = """
Review this Python script for swarm demonstration: '{swarm_script}'. Create a testing and optimization plan that includes methods for validating each agent's functionality and the overall performance of the swarm. Suggest improvements for efficiency and effectiveness.
Output Format: A structured plan in a textual format, outlining testing methodologies, key performance metrics, and optimization strategies.
"""
# This file can be imported in the main script to access the prompts.
Loading…
Cancel
Save