Skip to content

Commit

Permalink
[CLEANUP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Apr 26, 2024
1 parent d5d9da1 commit 351b322
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 227 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ __pycache__/
.grit
swarm-worker-01_state.json
error.txt

Devin Worker 2_state.json
# C extensions
*.so
.ruff_cache
Expand Down
141 changes: 141 additions & 0 deletions playground/swarms/groupchat_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import subprocess


from swarms import (
Agent,
Anthropic,
GroupChat,
GroupChatManager,
tool,
)

# Model
llm = Anthropic(
temperature=0.1,
)


# Tools
@tool
def terminal(
code: str,
):
"""
Run code in the terminal.
Args:
code (str): The code to run in the terminal.
Returns:
str: The output of the code.
"""
out = subprocess.run(
code, shell=True, capture_output=True, text=True
).stdout
return str(out)


@tool
def browser(query: str):
"""
Search the query in the browser with the `browser` tool.
Args:
query (str): The query to search in the browser.
Returns:
str: The search results.
"""
import webbrowser

url = f"https://www.google.com/search?q={query}"
webbrowser.open(url)
return f"Searching for {query} in the browser."


@tool
def create_file(file_path: str, content: str):
"""
Create a file using the file editor tool.
Args:
file_path (str): The path to the file.
content (str): The content to write to the file.
Returns:
str: The result of the file creation operation.
"""
with open(file_path, "w") as file:
file.write(content)
return f"File {file_path} created successfully."


@tool
def file_editor(file_path: str, mode: str, content: str):
"""
Edit a file using the file editor tool.
Args:
file_path (str): The path to the file.
mode (str): The mode to open the file in.
content (str): The content to write to the file.
Returns:
str: The result of the file editing operation.
"""
with open(file_path, mode) as file:
file.write(content)
return f"File {file_path} edited successfully."


# Agent
agent = Agent(
agent_name="Devin",
system_prompt=(
"Autonomous agent that can interact with humans and other"
" agents. Be Helpful and Kind. Use the tools provided to"
" assist the user. Return all code in markdown format."
),
llm=llm,
max_loops=1,
autosave=False,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
tools=[terminal, browser, file_editor, create_file],
)

# Agent
agent_two = Agent(
agent_name="Devin Worker 2",
system_prompt=(
"Autonomous agent that can interact with humans and other"
" agents. Be Helpful and Kind. Use the tools provided to"
" assist the user. Return all code in markdown format."
),
llm=llm,
max_loops=1,
autosave=False,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
tools=[terminal, browser, file_editor, create_file],
)


# Initialize the group chat
group_chat = GroupChat(
agents=[agent, agent_two],
max_round=2,
admin_name="Supreme Commander Kye",
group_objective="Research everyone at Goldman Sachs",
)

# Initialize the group chat manager
manager = GroupChatManager(groupchat=group_chat, selector=agent)

# Run the group chat manager on a task
out = manager("Generate a 10,000 word blog on health and wellness.")
print(out)
File renamed without changes.
2 changes: 0 additions & 2 deletions swarms/structs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from swarms.structs.block_wrapper import block
from swarms.structs.concurrent_workflow import ConcurrentWorkflow
from swarms.structs.conversation import Conversation
from swarms.structs.graph_workflow import GraphWorkflow
from swarms.structs.groupchat import GroupChat, GroupChatManager
from swarms.structs.majority_voting import (
MajorityVoting,
Expand Down Expand Up @@ -99,7 +98,6 @@
"block",
"ConcurrentWorkflow",
"Conversation",
"GraphWorkflow",
"GroupChat",
"GroupChatManager",
"MajorityVoting",
Expand Down
6 changes: 6 additions & 0 deletions swarms/structs/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ def __init__(
role=self.user_name, content=tool_schema_str
)

# Name
self.name = agent_name

# Description
self.description = agent_description

def set_system_prompt(self, system_prompt: str):
"""Set the system prompt"""
self.system_prompt = system_prompt
Expand Down
3 changes: 3 additions & 0 deletions swarms/structs/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,6 @@ def truncate_memory_with_tokenizer(self):
break

self.conversation_history = truncated_history

def clear(self):
self.conversation_history = []
173 changes: 0 additions & 173 deletions swarms/structs/graph_workflow.py

This file was deleted.

Loading

0 comments on commit 351b322

Please sign in to comment.