Skip to content

Commit

Permalink
[FEAT][AgentRearrange][CLEANUP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Apr 2, 2024
1 parent d8b42f0 commit 71f6aae
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 90 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/cron_job_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run pytest

on:
schedule:
# This will run the job every day at a random minute past the hour
- cron: '0 0 * * *'

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install swarms
- name: Run tests
run: pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static/generated
runs
chroma
Unit Testing Agent_state.json
Devin_state.json
swarms/__pycache__
artifacts
venv
Expand Down
77 changes: 77 additions & 0 deletions devin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
Plan -> act in a loop until observation is met
# Tools
- Terminal
- Text Editor
- Browser
"""
from swarms import Agent, OpenAIChat, tool
import subprocess

# Model
llm = OpenAIChat()


# 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.
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."


# 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."
),
llm=llm,
max_loops=4,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
interactive=True,
tools=[terminal, browser],
# streaming=True,
)

# Run the agent
out = agent("What is the weather today in palo alto?")
print(out)
9 changes: 0 additions & 9 deletions playground/agents/devin.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "swarms"
version = "4.7.1"
version = "4.7.3"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <[email protected]>"]
Expand Down
4 changes: 0 additions & 4 deletions swarms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import os

from swarms.telemetry.bootup import bootup # noqa: E402, F403
from swarms.telemetry.sentry_active import activate_sentry

os.environ["WANDB_SILENT"] = "true"

bootup()
activate_sentry()

Expand Down
2 changes: 0 additions & 2 deletions swarms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)
from swarms.models.qwen import QwenVLMultiModal # noqa: E402

from swarms.models.sam_supervision import SegmentAnythingMarkGenerator
from swarms.models.sampling_params import SamplingParams, SamplingType
from swarms.models.together import TogetherLLM # noqa: E402
from swarms.models.types import ( # noqa: E402
Expand Down Expand Up @@ -74,7 +73,6 @@
"Replicate",
"SamplingParams",
"SamplingType",
"SegmentAnythingMarkGenerator",
"TextModality",
"TogetherLLM",
"Vilt",
Expand Down
2 changes: 2 additions & 0 deletions swarms/structs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
find_token_in_text,
parse_tasks,
)
from swarms.structs.agent_rearrange import AgentRearrange


__all__ = [
Expand Down Expand Up @@ -147,4 +148,5 @@
"find_agent_by_id",
"find_token_in_text",
"parse_tasks",
"AgentRearrange",
]
151 changes: 77 additions & 74 deletions rearrange_agent_example.py → swarms/structs/agent_rearrange.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
from collections import defaultdict
from typing import Callable, Sequence
from swarms import Agent, Anthropic
from swarms.structs.agent import Agent
from swarms.structs.base_swarm import BaseSwarm


# Assuming the existence of an appropriate Agent class and logger setup
class AgentRearrange(BaseSwarm):
def __init__(
Expand All @@ -12,6 +13,8 @@ def __init__(
verbose: bool = False,
custom_prompt: str = None,
callbacks: Sequence[Callable] = None,
*args,
**kwargs,
):
super().__init__()
if not all(isinstance(agent, Agent) for agent in agents):
Expand Down Expand Up @@ -159,76 +162,76 @@ def __call__(
return results


## Initialize the workflow
agent = Agent(
agent_name="t",
agent_description=(
"Generate a transcript for a youtube video on what swarms"
" are!"
),
system_prompt=(
"Generate a transcript for a youtube video on what swarms"
" are!"
),
llm=Anthropic(),
max_loops=1,
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
)

agent2 = Agent(
agent_name="t1",
agent_description=(
"Generate a transcript for a youtube video on what swarms"
" are!"
),
llm=Anthropic(),
max_loops=1,
system_prompt="Summarize the transcript",
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
)

agent3 = Agent(
agent_name="t2",
agent_description=(
"Generate a transcript for a youtube video on what swarms"
" are!"
),
llm=Anthropic(),
max_loops=1,
system_prompt="Finalize the transcript",
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
)


# Rearrange the agents
rearrange = AgentRearrange(
agents=[agent, agent2, agent3],
verbose=True,
# custom_prompt="Summarize the transcript",
)

# Run the workflow on a task
results = rearrange(
# pattern="t -> t1, t2 -> t2",
pattern="t -> t1 -> t2",
default_task=(
"Generate a transcript for a YouTube video on what swarms"
" are!"
),
t="Generate a transcript for a YouTube video on what swarms are!",
# t2="Summarize the transcript",
# t3="Finalize the transcript",
)
# print(results)
# ## Initialize the workflow
# agent = Agent(
# agent_name="t",
# agent_description=(
# "Generate a transcript for a youtube video on what swarms"
# " are!"
# ),
# system_prompt=(
# "Generate a transcript for a youtube video on what swarms"
# " are!"
# ),
# llm=Anthropic(),
# max_loops=1,
# autosave=True,
# dashboard=False,
# streaming_on=True,
# verbose=True,
# stopping_token="<DONE>",
# )

# agent2 = Agent(
# agent_name="t1",
# agent_description=(
# "Generate a transcript for a youtube video on what swarms"
# " are!"
# ),
# llm=Anthropic(),
# max_loops=1,
# system_prompt="Summarize the transcript",
# autosave=True,
# dashboard=False,
# streaming_on=True,
# verbose=True,
# stopping_token="<DONE>",
# )

# agent3 = Agent(
# agent_name="t2",
# agent_description=(
# "Generate a transcript for a youtube video on what swarms"
# " are!"
# ),
# llm=Anthropic(),
# max_loops=1,
# system_prompt="Finalize the transcript",
# autosave=True,
# dashboard=False,
# streaming_on=True,
# verbose=True,
# stopping_token="<DONE>",
# )


# # Rearrange the agents
# rearrange = AgentRearrange(
# agents=[agent, agent2, agent3],
# verbose=True,
# # custom_prompt="Summarize the transcript",
# )

# # Run the workflow on a task
# results = rearrange(
# # pattern="t -> t1, t2 -> t2",
# pattern="t -> t1 -> t2",
# default_task=(
# "Generate a transcript for a YouTube video on what swarms"
# " are!"
# ),
# t="Generate a transcript for a YouTube video on what swarms are!",
# # t2="Summarize the transcript",
# # t3="Finalize the transcript",
# )
# # print(results)
2 changes: 2 additions & 0 deletions swarms/telemetry/bootup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import logging
import warnings

Expand All @@ -9,5 +10,6 @@ def bootup():
"""Bootup swarms"""
disable_logging()
logging.disable(logging.CRITICAL)
os.environ["WANDB_SILENT"] = "true"
warnings.filterwarnings("ignore", category=DeprecationWarning)
auto_update()

0 comments on commit 71f6aae

Please sign in to comment.