From a679d019957014c42d8ee3a9d4c4eb4bc31c280b Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 29 Nov 2023 16:14:12 -0800 Subject: [PATCH] [FEAT][SequentialWorkflow] --- sequential_workflow_example.py | 20 ++--- swarms/prompts/sop_generator_agent_prompt.py | 93 ++++++++++++++++++++ swarms/structs/sequential_workflow.py | 3 +- tests/models/test_revgptv1.py | 93 -------------------- 4 files changed, 104 insertions(+), 105 deletions(-) create mode 100644 swarms/prompts/sop_generator_agent_prompt.py delete mode 100644 tests/models/test_revgptv1.py diff --git a/sequential_workflow_example.py b/sequential_workflow_example.py index beefbfb1..ff868697 100644 --- a/sequential_workflow_example.py +++ b/sequential_workflow_example.py @@ -1,10 +1,14 @@ -from swarms.models import OpenAIChat, BioGPT, Anthropic +import os +from swarms.models import OpenAIChat from swarms.structs import Agent from swarms.structs.sequential_workflow import SequentialWorkflow +from dotenv import load_dotenv +load_dotenv() + +# Load the environment variables +api_key = os.getenv("OPENAI_API_KEY") -# Example usage -api_key = "" # Your actual API key here # Initialize the language agent llm = OpenAIChat( @@ -13,19 +17,15 @@ llm = OpenAIChat( max_tokens=3000, ) -biochat = BioGPT() - -# Use Anthropic -anthropic = Anthropic() # Initialize the agent with the language agent -agent1 = Agent(llm=llm, max_loops=1, dashboard=False) +agent1 = Agent(llm=llm, max_loops=1) # Create another agent for a different task -agent2 = Agent(llm=llm, max_loops=1, dashboard=False) +agent2 = Agent(llm=llm, max_loops=1) # Create another agent for a different task -agent3 = Agent(llm=biochat, max_loops=1, dashboard=False) +agent3 = Agent(llm=llm, max_loops=1) # agent4 = Agent(llm=anthropic, max_loops="auto") diff --git a/swarms/prompts/sop_generator_agent_prompt.py b/swarms/prompts/sop_generator_agent_prompt.py new file mode 100644 index 00000000..0e802301 --- /dev/null +++ b/swarms/prompts/sop_generator_agent_prompt.py @@ -0,0 +1,93 @@ +def sop_generator_agent_prompt(task_name: str): + """ + SOP Generator Agent Prompt + -------------------------- + + """ + SOP_GENERATOR_SOP = f""" + Your are an autonomous agent that generates Standard Operating Procedures for autonomous + worker agents, your goal is to generate a SOP for the following task: {task_name} + For this task, you will need to generate a SOP that will be used by an autonomous worker agent to perform the task. + Follow the guide below to generate the SOP. Create a SOP that is easy to understand and follow. + You will be evaluated on the quality of the SOP you generate. You will be given a score between 0 and 100. + The score will be based on the quality of the SOP you generate. The higher the score, the better the SOP. + + + ######## SOP Structure Guide ######## + Standard Operating Procedure for Teaching Task Documentation + + Purpose: Provides guidelines for instructor agents to teach autonomous agents on documenting procedures for standardized execution of a new task. + + Scope: Applies to the development of comprehensive SOP training material covering all key aspects to successfully perform unfamiliar tasks. + + Instructor Responsibilities: + - Analyze task to identify all required steps + - Verify agent has necessary background context + - Develop modular SOP content for clear understanding + - Reinforce critical thinking at key decision points + - Encourage questions to check ongoing comprehension + - Be adaptive and respond to the agent’s pacing and progress + - Provide sufficient opportunities for practice and repetition + - Give constructive feedback on agent’s SOP drafts + - Coach agents patiently until task proficiency is achieved + + Procedure to Teach SOP Creation: + + 1. Set Context + - Outline purpose of the task and why procedure is required. + - Explain governing rules, principles and best practices. + - Define key vocabulary and terminology. + - Establish standards for work quality and output. + + 2. Demonstrate Task + - Walk through the task sequentially from start to end. + - Clearly call out each step and decision point. + - Explain rationale for sequence of steps. + - Highlight areas that require caution or extra attention. + - Be transparent about assumptions made and exceptions. + + 3. Simplify Instruction + - Modularize instructions into sections for clarity + - Use headings, numbered lists and visual aids + - Maintain brevity and use simple language + - Define specialized terms, acronyms and abbreviations + - Provide examples to aid understanding + + 4. Practice Sequentially + - Agent observes instructor performing task end-to-end + - Instructor completes task based on own SOP + - Agent follows along by applying documented steps + - Steps can be repeated for memorization + - Agent mimics instructor to build muscle memory + + 5. Adjust Guidance + - Coach agent according to pace of comprehension + - Be adaptive to feedback and questions + - Identify knowledge gaps for clarification + - Break down complex segments for step-wise practice + - Repeat critical sub-tasks until perfected + - Celebrate small wins to maintain confidence + + 6. Drive Collaboration + - Encourage agent to maintain notes for clarification + - Motivate questions at any time for understanding + - Be approachable and show patience + - Appreciate feedback from agent’s perspective + - Foster open conversations and positive rapport + + 7. Ensure Competency + - Agent drafts SOP proof for review + - Provide improvement comments + - Agent updates based on feedback + - Repeat review cycles until approved + - Audit periodically for continued success + + Templates: + - SOP Structure Guide + - Style standards + - Sample SOPs + - Revision checklist + + This refactored SOP focuses on guidelines specifically for the instructor agent on techniques to teach the process of writing standard operating procedures to execute tasks. Let me know if you need any other updates. + """ + return str(SOP_GENERATOR_SOP) \ No newline at end of file diff --git a/swarms/structs/sequential_workflow.py b/swarms/structs/sequential_workflow.py index 22e1236c..b56210df 100644 --- a/swarms/structs/sequential_workflow.py +++ b/swarms/structs/sequential_workflow.py @@ -154,14 +154,13 @@ class SequentialWorkflow: ) # Append the task to the tasks list - if self.img: + if img: self.tasks.append( Task( description=task, agent=agent, args=list(args), kwargs=kwargs, - img=img, ) ) else: diff --git a/tests/models/test_revgptv1.py b/tests/models/test_revgptv1.py deleted file mode 100644 index cb539da6..00000000 --- a/tests/models/test_revgptv1.py +++ /dev/null @@ -1,93 +0,0 @@ -import unittest -from unittest.mock import patch -from Sswarms.models.revgptv1 import RevChatGPTModelv1 - - -class TestRevChatGPT(unittest.TestCase): - def setUp(self): - self.access_token = "" - self.model = RevChatGPTModelv1(access_token=self.access_token) - - def test_run(self): - prompt = "What is the capital of France?" - response = self.model.run(prompt) - self.assertEqual(response, "The capital of France is Paris.") - - def test_run_time(self): - prompt = "Generate a 300 word essay about technology." - self.model.run(prompt) - self.assertLess( - self.model.end_time - self.model.start_time, 60 - ) - - def test_generate_summary(self): - text = ( - "This is a sample text to summarize. It has multiple" - " sentences and details. The summary should be concise." - ) - summary = self.model.generate_summary(text) - self.assertLess(len(summary), len(text) / 2) - - def test_enable_plugin(self): - plugin_id = "some_plugin_id" - self.model.enable_plugin(plugin_id) - self.assertIn(plugin_id, self.model.config["plugin_ids"]) - - def test_list_plugins(self): - plugins = self.model.list_plugins() - self.assertGreater(len(plugins), 0) - self.assertIsInstance(plugins[0], dict) - self.assertIn("id", plugins[0]) - self.assertIn("name", plugins[0]) - - def test_get_conversations(self): - conversations = self.model.chatbot.get_conversations() - self.assertIsInstance(conversations, list) - - @patch("RevChatGPTModelv1.Chatbot.get_msg_history") - def test_get_msg_history(self, mock_get_msg_history): - conversation_id = "convo_id" - self.model.chatbot.get_msg_history(conversation_id) - mock_get_msg_history.assert_called_with(conversation_id) - - @patch("RevChatGPTModelv1.Chatbot.share_conversation") - def test_share_conversation(self, mock_share_conversation): - self.model.chatbot.share_conversation() - mock_share_conversation.assert_called() - - def test_gen_title(self): - convo_id = "123" - message_id = "456" - title = self.model.chatbot.gen_title(convo_id, message_id) - self.assertIsInstance(title, str) - - def test_change_title(self): - convo_id = "123" - title = "New Title" - self.model.chatbot.change_title(convo_id, title) - self.assertEqual( - self.model.chatbot.get_msg_history(convo_id)["title"], - title, - ) - - def test_delete_conversation(self): - convo_id = "123" - self.model.chatbot.delete_conversation(convo_id) - with self.assertRaises(Exception): - self.model.chatbot.get_msg_history(convo_id) - - def test_clear_conversations(self): - self.model.chatbot.clear_conversations() - conversations = self.model.chatbot.get_conversations() - self.assertEqual(len(conversations), 0) - - def test_rollback_conversation(self): - original_convo_id = self.model.chatbot.conversation_id - self.model.chatbot.rollback_conversation(1) - self.assertNotEqual( - original_convo_id, self.model.chatbot.conversation_id - ) - - -if __name__ == "__main__": - unittest.main()