diff --git a/example.py b/example.py index ee0461d2..1887ce63 100644 --- a/example.py +++ b/example.py @@ -1,5 +1,4 @@ -from swarms import Agent -from swarms.models.llama3_hosted import llama3Hosted +from swarms import Agent, OpenAIChat # Initialize the agent @@ -8,7 +7,7 @@ agent = Agent( agent_description=( "Generate a transcript for a youtube video on what swarms" " are!" ), - llm=llama3Hosted(), + llm=OpenAIChat(), max_loops="auto", autosave=True, dashboard=False, diff --git a/pyproject.toml b/pyproject.toml index ef849dab..0d0e32a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "5.0.9" +version = "5.1.3" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/scripts/cleanup/json_log_cleanup.py b/scripts/cleanup/json_log_cleanup.py index a22c1ef3..7ae07511 100644 --- a/scripts/cleanup/json_log_cleanup.py +++ b/scripts/cleanup/json_log_cleanup.py @@ -18,7 +18,7 @@ def cleanup_json_logs(name: str = None): if ( filename.endswith(".json") or filename.endswith(".log") - or filename.endswith(".txt") + # or filename.endswith(".txt") ): # Construct the full file paths file_path = os.path.join(dirpath, filename) diff --git a/swarms/models/popular_llms.py b/swarms/models/popular_llms.py index a574b0da..abf7df11 100644 --- a/swarms/models/popular_llms.py +++ b/swarms/models/popular_llms.py @@ -65,10 +65,12 @@ class OpenAIChatLLM(OpenAIChat): super().__init__(*args, **kwargs) def __call__(self, *args, **kwargs): - return self.invoke(*args, **kwargs) + out = self.invoke(*args, **kwargs) + return out.content.strip() def run(self, *args, **kwargs): - return self.invoke(*args, **kwargs) + out = self.invoke(*args, **kwargs) + return out.content.strip() class OctoAIChat(OctoAIEndpoint): diff --git a/swarms/structs/scp.py b/swarms/structs/scp.py new file mode 100644 index 00000000..2cefdd20 --- /dev/null +++ b/swarms/structs/scp.py @@ -0,0 +1,91 @@ +""" +Swarm Communication Protocol +- RAG as a communication protocol +- Each Agent is connected to a database so they can see each others +memories, actions, and experiences + +""" + +import json +from swarms.structs.omni_agent_types import AgentType +from swarms.structs.base_structure import BaseStructure +from typing import List +from swarms.memory.base_vectordb import BaseVectorDatabase +import time +from swarms.utils.loguru_logger import logger +from pydantic import BaseModel, Field + + +class SwarmCommunicationProtocol(BaseModel): + agent_name: str = Field( + None, title="Agent Name", description="The name of the agent" + ) + message: str = Field( + None, title="Message", description="The message to be sent" + ) + timestamp: float = Field( + None, + title="Timestamp", + description="The time the message was sent", + ) + + +class SCP(BaseStructure): + def __init__( + self, + agents: List[AgentType], + memory_system: BaseVectorDatabase = None, + *args, + **kwargs, + ): + super().__init__() + self.agents = agents + self.memory_system = memory_system + + # Memory system + if memory_system is not None: + for agent in self.agents.values(): + agent.long_term_memory = memory_system + + logger.info( + "AgentRearrange initialized with agents: {}".format( + list(self.agents.keys()) + ) + ) + + def message_log( + self, agent: AgentType, task: str = None, message: str = None + ): + log = { + "agent_name": agent.agent_name, + "task": task, + "response": message, + "timestamp": time.time(), + } + + # Transform the log into a string + log_output = json.dumps(log) + + # Add the log to the memory system + self.memory_system.add(log) + + return log_output + + def run_single_agent( + self, agent: AgentType, task: str, *args, **kwargs + ): + # Send the message to the agent + output = agent.run(task) + + # log the message + self.message_log( + agent=agent, + task=task, + message=output, + ) + + # Log the output + return output + + def send_message(self, agent: AgentType, message: str): + agent.receieve_mesage(self.message_log(agent, message))