diff --git a/README.md b/README.md index 86534352..b8a47a84 100644 --- a/README.md +++ b/README.md @@ -434,7 +434,9 @@ Run the agent with multiple modalities useful for various real-world tasks in ma ```python import os from dotenv import load_dotenv -from swarms import GPT4VisionAPI, Agent +from swarms import Agent + +from swarm_models import GPT4VisionAPI # Load the environment variables load_dotenv() @@ -529,79 +531,6 @@ print(f"Generated data: {generated_data}") ``` -### `Task` -For deeper control of your agent stack, `Task` is a simple structure for task execution with the `Agent`. Imagine zapier like LLM-based workflow automation. - -✅ Task is a structure for task execution with the Agent. - -✅ Tasks can have descriptions, scheduling, triggers, actions, conditions, dependencies, priority, and a history. - -✅ The Task structure allows for efficient workflow automation with LLM-based agents. - -```python -import os - -from dotenv import load_dotenv - -from swarms import Agent, OpenAIChat, Task - -# Load the environment variables -load_dotenv() - - -# Define a function to be used as the action -def my_action(): - print("Action executed") - - -# Define a function to be used as the condition -def my_condition(): - print("Condition checked") - return True - - -# Create an agent -agent = Agent( - llm=OpenAIChat(openai_api_key=os.environ["OPENAI_API_KEY"]), - max_loops=1, - dashboard=False, -) - -# Create a task -task = Task( - description=( - "Generate a report on the top 3 biggest expenses for small" - " businesses and how businesses can save 20%" - ), - agent=agent, -) - -# Set the action and condition -task.set_action(my_action) -task.set_condition(my_condition) - -# Execute the task -print("Executing task...") -task.run() - -# Check if the task is completed -if task.is_completed(): - print("Task completed") -else: - print("Task not completed") - -# Output the result of the task -print(f"Task result: {task.result}") -``` - ---- - - - - - ----- - # Multi-Agent Orchestration: Swarms was designed to facilitate the communication between many different and specialized agents from a vast array of other frameworks such as langchain, autogen, crew, and more. @@ -623,7 +552,9 @@ In traditional swarm theory, there are many types of swarms usually for very spe Sequential Workflow enables you to sequentially execute tasks with `Agent` and then pass the output into the next agent and onwards until you have specified your max loops. ```python -from swarms import Agent, SequentialWorkflow, Anthropic +from swarms import Agent, SequentialWorkflow + +from swarm_models import Anthropic # Initialize the language model agent (e.g., GPT-3) @@ -742,7 +673,10 @@ import os from dotenv import load_dotenv -from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat + +from swarms import Agent, Edge, GraphWorkflow, Node, NodeType + +from swarm_models import OpenAIChat load_dotenv() @@ -1059,23 +993,10 @@ The easiest way to contribute is to pick any issue with the `good first issue` t Swarms is an open-source project, and contributions are VERY welcome. If you want to contribute, you can create new features, fix bugs, or improve the infrastructure. Please refer to the [CONTRIBUTING.md](https://github.com/kyegomez/swarms/blob/master/CONTRIBUTING.md) and our [contributing board](https://github.com/users/kyegomez/projects/1) to participate in Roadmap discussions! - - - - ---- -## Swarm Newsletter 🤖 🤖 🤖 📧 -Sign up to the Swarm newsletter to receive updates on the latest Autonomous agent research papers, step by step guides on creating multi-agent app, and much more Swarmie goodiness 😊 - -[CLICK HERE TO SIGNUP](https://docs.google.com/forms/d/e/1FAIpQLSfqxI2ktPR9jkcIwzvHL0VY6tEIuVPd-P2fOWKnd6skT9j1EQ/viewform?usp=sf_link) - -## Discovery Call -Book a discovery call to learn how Swarms can lower your operating costs by 40% with swarms of autonomous agents in lightspeed. [Click here to book a time that works for you!](https://calendly.com/swarm-corp/30min?month=2023-11) - - ## Accelerate Backlog Accelerate Bugs, Features, and Demos to implement by supporting us here: @@ -1095,9 +1016,6 @@ Join our growing community around the world, for real-time support, ideas, and d --- -# License -Apache License - # Citations Please cite Swarms in your paper or your project if you found it beneficial in any way! Appreciate you. diff --git a/docs/swarms/structs/graph_workflow.md b/docs/swarms/structs/graph_workflow.md index 4316bd04..cfa70f81 100644 --- a/docs/swarms/structs/graph_workflow.md +++ b/docs/swarms/structs/graph_workflow.md @@ -139,7 +139,10 @@ import os from dotenv import load_dotenv -from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat + +from swarms import Agent, Edge, GraphWorkflow, Node, NodeType + +from swarm_models import OpenAIChat load_dotenv() diff --git a/docs/swarms/structs/multi_agent_collaboration_examples.md b/docs/swarms/structs/multi_agent_collaboration_examples.md index 03640709..b2dd811c 100644 --- a/docs/swarms/structs/multi_agent_collaboration_examples.md +++ b/docs/swarms/structs/multi_agent_collaboration_examples.md @@ -5,7 +5,9 @@ Sequential Workflow enables you to sequentially execute tasks with `Agent` and then pass the output into the next agent and onwards until you have specified your max loops. ```python -from swarms import Agent, SequentialWorkflow, Anthropic +from swarms import Agent, SequentialWorkflow + +from swarm_models import Anthropic # Initialize the language model agent (e.g., GPT-3) @@ -123,7 +125,10 @@ import os from dotenv import load_dotenv -from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat + +from swarms import Agent, Edge, GraphWorkflow, Node, NodeType + +from swarm_models import OpenAIChat load_dotenv() diff --git a/docs/swarms/structs/sequential_workflow.md b/docs/swarms/structs/sequential_workflow.md index 05b047b6..e4301ccf 100644 --- a/docs/swarms/structs/sequential_workflow.md +++ b/docs/swarms/structs/sequential_workflow.md @@ -34,7 +34,9 @@ Runs the specified task through the agents in the dynamically constructed flow. - **Usage Example:** ```python - from swarms import Agent, SequentialWorkflow, Anthropic + from swarms import Agent, SequentialWorkflow + +from swarm_models import Anthropic # Initialize the language model agent (e.g., GPT-3) diff --git a/examples/agents/use_cases/browser/multion_examples/buy_abunch_of_cybertrucks.py b/examples/agents/use_cases/browser/multion_examples/buy_abunch_of_cybertrucks.py index c8238726..bbe4a6f4 100644 --- a/examples/agents/use_cases/browser/multion_examples/buy_abunch_of_cybertrucks.py +++ b/examples/agents/use_cases/browser/multion_examples/buy_abunch_of_cybertrucks.py @@ -1,5 +1,6 @@ -from swarms import Agent, AgentRearrange, OpenAIChat -from swarms.agents.multion_wrapper import MultiOnAgent +from swarms import Agent, AgentRearrange + +from swarm_models import OpenAIChatfrom swarms.agents.multion_wrapper import MultiOnAgent model = MultiOnAgent( url="https://tesla.com", diff --git a/examples/agents/use_cases/multi_modal/multi_modal_example.py b/examples/agents/use_cases/multi_modal/multi_modal_example.py index 1235e7ac..bc546552 100644 --- a/examples/agents/use_cases/multi_modal/multi_modal_example.py +++ b/examples/agents/use_cases/multi_modal/multi_modal_example.py @@ -1,6 +1,8 @@ import os from dotenv import load_dotenv -from swarms import GPT4VisionAPI, Agent +from swarms import Agent + +from swarm_models import GPT4VisionAPI # Load the environment variables load_dotenv() diff --git a/examples/agents/use_cases/multi_modal/multi_modal_flow_example.py b/examples/agents/use_cases/multi_modal/multi_modal_flow_example.py index 51acad26..08bf867d 100644 --- a/examples/agents/use_cases/multi_modal/multi_modal_flow_example.py +++ b/examples/agents/use_cases/multi_modal/multi_modal_flow_example.py @@ -1,4 +1,6 @@ -from swarms import GPT4VisionAPI, Agent +from swarms import Agent + +from swarm_models import GPT4VisionAPI llm = GPT4VisionAPI() diff --git a/examples/structs/swarms/multi_agent_collaboration/agent_rearrange.py b/examples/structs/swarms/multi_agent_collaboration/agent_rearrange.py index 8dc75fbf..495136af 100644 --- a/examples/structs/swarms/multi_agent_collaboration/agent_rearrange.py +++ b/examples/structs/swarms/multi_agent_collaboration/agent_rearrange.py @@ -1,5 +1,6 @@ -from swarms import Agent, AgentRearrange, OpenAIChat +from swarms import Agent, AgentRearrange +from swarm_models import OpenAIChat # Initialize the director agent diff --git a/examples/structs/swarms/multi_agent_collaboration/agent_rearrange_human_in_loop.py b/examples/structs/swarms/multi_agent_collaboration/agent_rearrange_human_in_loop.py index 0cc59880..d743f024 100644 --- a/examples/structs/swarms/multi_agent_collaboration/agent_rearrange_human_in_loop.py +++ b/examples/structs/swarms/multi_agent_collaboration/agent_rearrange_human_in_loop.py @@ -1,5 +1,6 @@ -from swarms import Agent, AgentRearrange, OpenAIChat +from swarms import Agent, AgentRearrange +from swarm_models import OpenAIChat # Initialize the director agent diff --git a/examples/structs/swarms/multi_agent_collaboration/sequential_workflow_new.py b/examples/structs/swarms/multi_agent_collaboration/sequential_workflow_new.py index 81ea3074..bc120e5b 100644 --- a/examples/structs/swarms/multi_agent_collaboration/sequential_workflow_new.py +++ b/examples/structs/swarms/multi_agent_collaboration/sequential_workflow_new.py @@ -1,4 +1,6 @@ -from swarms import Agent, SequentialWorkflow, Anthropic +from swarms import Agent, SequentialWorkflow + +from swarm_models import Anthropic # Initialize the language model agent (e.g., GPT-3) diff --git a/examples/structs/swarms/spreadsheet_swarm/spreadsheet_swarm_examples/csvs/README.md b/examples/structs/swarms/spreadsheet_swarm/spreadsheet_swarm_examples/csvs/README.md index ff0e1638..b7328e0e 100644 --- a/examples/structs/swarms/spreadsheet_swarm/spreadsheet_swarm_examples/csvs/README.md +++ b/examples/structs/swarms/spreadsheet_swarm/spreadsheet_swarm_examples/csvs/README.md @@ -434,7 +434,9 @@ Run the agent with multiple modalities useful for various real-world tasks in ma ```python import os from dotenv import load_dotenv -from swarms import GPT4VisionAPI, Agent +from swarms import Agent + +from swarm_models import GPT4VisionAPI # Load the environment variables load_dotenv() @@ -623,7 +625,9 @@ In traditional swarm theory, there are many types of swarms usually for very spe Sequential Workflow enables you to sequentially execute tasks with `Agent` and then pass the output into the next agent and onwards until you have specified your max loops. ```python -from swarms import Agent, SequentialWorkflow, Anthropic +from swarms import Agent, SequentialWorkflow + +from swarm_models import Anthropic # Initialize the language model agent (e.g., GPT-3) @@ -741,7 +745,10 @@ import os from dotenv import load_dotenv -from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat + +from swarms import Agent, Edge, GraphWorkflow, Node, NodeType + +from swarm_models import OpenAIChat load_dotenv() diff --git a/examples/swarms/rearrange/example.py b/examples/swarms/rearrange/example.py index 15c6a688..80a63837 100644 --- a/examples/swarms/rearrange/example.py +++ b/examples/swarms/rearrange/example.py @@ -1,83 +1,93 @@ import os import asyncio from dotenv import load_dotenv + load_dotenv() from swarms.structs import Agent from swarm_models import Anthropic from swarms.structs.rearrange import AgentRearrange -llm = Anthropic(anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"), streaming=True) +llm = Anthropic( + anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"), streaming=True +) + async def sequential(): - agent1 = Agent( - agent_name="Blog generator", - system_prompt="Generate a blog post like stephen king", - llm=llm, - dashboard=False, - streaming_on=True - ) - - agent2 = Agent( - agent_name="Summarizer", - system_prompt="Summarize the blog post", - llm=llm, - dashboard=False, - streaming_on=True - ) - - flow = f"{agent1.name} -> {agent2.name}" - - agent_rearrange = AgentRearrange( - [agent1, agent2], flow, verbose=False, logging=False - ) - - result = await agent_rearrange.astream( - "Generate a short blog post about Muhammad Ali." - ) - - # LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;) - # await agent_rearrange.run( - # "Generate a short blog post about Muhammad Ali." - # ) + agent1 = Agent( + agent_name="Blog generator", + system_prompt="Generate a blog post like stephen king", + llm=llm, + dashboard=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Summarizer", + system_prompt="Summarize the blog post", + llm=llm, + dashboard=False, + streaming_on=True, + ) + + flow = f"{agent1.name} -> {agent2.name}" + + agent_rearrange = AgentRearrange( + [agent1, agent2], flow, verbose=False, logging=False + ) + + result = await agent_rearrange.astream( + "Generate a short blog post about Muhammad Ali." + ) + + # LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;) + # await agent_rearrange.run( + # "Generate a short blog post about Muhammad Ali." + # ) + async def parallel(): - writer1 = Agent( - agent_name="Writer 1", - system_prompt="Generate a blog post in the style of J.K. Rowling about Muhammad Ali", - llm=llm, - dashboard=False, - ) - - writer2 = Agent( - agent_name="Writer 2", - system_prompt="Generate a blog post in the style of Stephen King about Muhammad Ali", - llm=llm, - dashboard=False - ) - - reviewer = Agent( - agent_name="Reviewer", - system_prompt="Select the writer that wrote the best story. There can only be one best story.", - llm=llm, - dashboard=False - ) - - flow = f"{writer1.name}, {writer2.name} -> {reviewer.name}" - - agent_rearrange = AgentRearrange( - [writer1, writer2, reviewer], flow, verbose=False, logging=False - ) - - result = await agent_rearrange.astream("Generate a 1 sentence story about Michael Jordan.") - - # LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;) - # result = agent_rearrange.run( - # "Generate a short blog post about Michael Jordan." - # ) + writer1 = Agent( + agent_name="Writer 1", + system_prompt="Generate a blog post in the style of J.K. Rowling about Muhammad Ali", + llm=llm, + dashboard=False, + ) + + writer2 = Agent( + agent_name="Writer 2", + system_prompt="Generate a blog post in the style of Stephen King about Muhammad Ali", + llm=llm, + dashboard=False, + ) + + reviewer = Agent( + agent_name="Reviewer", + system_prompt="Select the writer that wrote the best story. There can only be one best story.", + llm=llm, + dashboard=False, + ) + + flow = f"{writer1.name}, {writer2.name} -> {reviewer.name}" + + agent_rearrange = AgentRearrange( + [writer1, writer2, reviewer], + flow, + verbose=False, + logging=False, + ) + + result = await agent_rearrange.astream( + "Generate a 1 sentence story about Michael Jordan." + ) + + # LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;) + # result = agent_rearrange.run( + # "Generate a short blog post about Michael Jordan." + # ) + asyncio.run(sequential()) # asyncio.run(parallel()) - diff --git a/sample_rearrange.py b/sample_rearrange.py index 5829c79e..eaefe52f 100644 --- a/sample_rearrange.py +++ b/sample_rearrange.py @@ -1,6 +1,8 @@ import os -from swarms import Agent, AgentRearrange, OpenAIChat +from swarms import Agent, AgentRearrange + +from swarm_models import OpenAIChat # Get the OpenAI API key from the environment variable api_key = os.getenv("OPENAI_API_KEY") diff --git a/swarms/structs/dfs_search_swarm.py b/swarms/structs/dfs_search_swarm.py index a47dca3e..55afa03f 100644 --- a/swarms/structs/dfs_search_swarm.py +++ b/swarms/structs/dfs_search_swarm.py @@ -1,6 +1,6 @@ # import os # from swarms import Agent -from swarm_models import OpenAIChat + # from typing import List # class DepthFirstSearchSwarm: @@ -81,7 +81,6 @@ from swarm_models import OpenAIChat # #################### # import os # from swarms import Agent -from swarm_models import OpenAIChat # class DFSSwarm: # def __init__(self, agents): diff --git a/swarms/structs/graph_workflow.py b/swarms/structs/graph_workflow.py index 66cbaf63..989175b7 100644 --- a/swarms/structs/graph_workflow.py +++ b/swarms/structs/graph_workflow.py @@ -226,7 +226,7 @@ class GraphWorkflow(BaseModel): # # Example usage # if __name__ == "__main__": # from swarms import Agent -from swarm_models import OpenAIChat + # import os # from dotenv import load_dotenv diff --git a/swarms/structs/monte_carlo_swarm.py b/swarms/structs/monte_carlo_swarm.py index a2b558ba..fa2f2cb2 100644 --- a/swarms/structs/monte_carlo_swarm.py +++ b/swarms/structs/monte_carlo_swarm.py @@ -201,7 +201,7 @@ def average_aggregator(results: List[float]) -> float: # import os # from swarms import Agent -from swarm_models import OpenAIChat + # from typing import List, Union, Callable # from collections import Counter diff --git a/swarms/structs/rearrange.py b/swarms/structs/rearrange.py index 7f13a1b5..225eeb98 100644 --- a/swarms/structs/rearrange.py +++ b/swarms/structs/rearrange.py @@ -11,8 +11,6 @@ from swarms.structs.agent import Agent from swarms.structs.base_swarm import BaseSwarm from swarms.structs.omni_agent_types import AgentType from swarms.utils.loguru_logger import logger -<<<<<<< HEAD -======= class AgentRearrangeInput(BaseModel): @@ -42,7 +40,6 @@ class AgentRearrangeOutput(BaseModel): ), description="The time the agent was created.", ) ->>>>>>> ce359f5e ([5.6.8]) class AgentRearrange(BaseSwarm): @@ -362,7 +359,6 @@ class AgentRearrange(BaseSwarm): logger.error(f"An error occurred: {e}") return e -<<<<<<< HEAD async def astream( self, task: str = None, @@ -392,7 +388,9 @@ class AgentRearrange(BaseSwarm): # If custom_tasks have the agents name and tasks then combine them if custom_tasks is not None: - c_agent_name, c_task = next(iter(custom_tasks.items())) + c_agent_name, c_task = next( + iter(custom_tasks.items()) + ) # Find the position of the custom agent in the tasks list position = tasks.index(c_agent_name) @@ -498,7 +496,9 @@ class AgentRearrange(BaseSwarm): # print(evt) # <- useful when building/debugging if evt["event"] == "on_llm_end": result = evt["data"]["output"] - print(agent.name, "result", result) + print( + agent.name, "result", result + ) current_task = result loop_count += 1 @@ -529,13 +529,13 @@ class AgentRearrange(BaseSwarm): 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) + return self.run_sub_swarm( + task, name, img, *args, **kwargs + ) else: agent = self.agents[name] return agent.run(task, img, is_last, *args, **kwargs) -======= ->>>>>>> ce359f5e ([5.6.8]) 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) diff --git a/swarms/tools/prebuilt/code_executor.py b/swarms/tools/prebuilt/code_executor.py index 4ea7597e..730b1935 100644 --- a/swarms/tools/prebuilt/code_executor.py +++ b/swarms/tools/prebuilt/code_executor.py @@ -28,7 +28,7 @@ class CodeExecutor: self.max_output_length = max_output_length self.artifacts_dir = artifacts_directory self.language = language - + os.makedirs(self.artifacts_dir, exist_ok=True) self.setup_logging() self.tokenizer = TikTokenizer()