[FEAT][AgentRearrange][CLEANUP]

pull/440/head
Kye 9 months ago
parent d8b42f08e7
commit 71f6aaec25

@ -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
.gitignore vendored

@ -12,6 +12,7 @@ static/generated
runs runs
chroma chroma
Unit Testing Agent_state.json Unit Testing Agent_state.json
Devin_state.json
swarms/__pycache__ swarms/__pycache__
artifacts artifacts
venv venv

@ -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)

@ -1,9 +0,0 @@
"""
Plan -> act in a loop until observation is met
# Tools
- Terminal
- Text Editor
- Browser
"""

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "4.7.1" version = "4.7.3"
description = "Swarms - Pytorch" description = "Swarms - Pytorch"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"] authors = ["Kye Gomez <kye@apac.ai>"]

@ -1,10 +1,6 @@
import os
from swarms.telemetry.bootup import bootup # noqa: E402, F403 from swarms.telemetry.bootup import bootup # noqa: E402, F403
from swarms.telemetry.sentry_active import activate_sentry from swarms.telemetry.sentry_active import activate_sentry
os.environ["WANDB_SILENT"] = "true"
bootup() bootup()
activate_sentry() activate_sentry()

@ -34,7 +34,6 @@ from swarms.models.popular_llms import (
) )
from swarms.models.qwen import QwenVLMultiModal # noqa: E402 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.sampling_params import SamplingParams, SamplingType
from swarms.models.together import TogetherLLM # noqa: E402 from swarms.models.together import TogetherLLM # noqa: E402
from swarms.models.types import ( # noqa: E402 from swarms.models.types import ( # noqa: E402
@ -74,7 +73,6 @@ __all__ = [
"Replicate", "Replicate",
"SamplingParams", "SamplingParams",
"SamplingType", "SamplingType",
"SegmentAnythingMarkGenerator",
"TextModality", "TextModality",
"TogetherLLM", "TogetherLLM",
"Vilt", "Vilt",

@ -78,6 +78,7 @@ from swarms.structs.utils import (
find_token_in_text, find_token_in_text,
parse_tasks, parse_tasks,
) )
from swarms.structs.agent_rearrange import AgentRearrange
__all__ = [ __all__ = [
@ -147,4 +148,5 @@ __all__ = [
"find_agent_by_id", "find_agent_by_id",
"find_token_in_text", "find_token_in_text",
"parse_tasks", "parse_tasks",
"AgentRearrange",
] ]

@ -1,9 +1,10 @@
import logging import logging
from collections import defaultdict from collections import defaultdict
from typing import Callable, Sequence from typing import Callable, Sequence
from swarms import Agent, Anthropic from swarms.structs.agent import Agent
from swarms.structs.base_swarm import BaseSwarm from swarms.structs.base_swarm import BaseSwarm
# Assuming the existence of an appropriate Agent class and logger setup # Assuming the existence of an appropriate Agent class and logger setup
class AgentRearrange(BaseSwarm): class AgentRearrange(BaseSwarm):
def __init__( def __init__(
@ -12,6 +13,8 @@ class AgentRearrange(BaseSwarm):
verbose: bool = False, verbose: bool = False,
custom_prompt: str = None, custom_prompt: str = None,
callbacks: Sequence[Callable] = None, callbacks: Sequence[Callable] = None,
*args,
**kwargs,
): ):
super().__init__() super().__init__()
if not all(isinstance(agent, Agent) for agent in agents): if not all(isinstance(agent, Agent) for agent in agents):
@ -159,76 +162,76 @@ class AgentRearrange(BaseSwarm):
return results return results
## Initialize the workflow # ## Initialize the workflow
agent = Agent( # agent = Agent(
agent_name="t", # agent_name="t",
agent_description=( # agent_description=(
"Generate a transcript for a youtube video on what swarms" # "Generate a transcript for a youtube video on what swarms"
" are!" # " are!"
), # ),
system_prompt=( # system_prompt=(
"Generate a transcript for a youtube video on what swarms" # "Generate a transcript for a youtube video on what swarms"
" are!" # " are!"
), # ),
llm=Anthropic(), # llm=Anthropic(),
max_loops=1, # max_loops=1,
autosave=True, # autosave=True,
dashboard=False, # dashboard=False,
streaming_on=True, # streaming_on=True,
verbose=True, # verbose=True,
stopping_token="<DONE>", # stopping_token="<DONE>",
) # )
agent2 = Agent( # agent2 = Agent(
agent_name="t1", # agent_name="t1",
agent_description=( # agent_description=(
"Generate a transcript for a youtube video on what swarms" # "Generate a transcript for a youtube video on what swarms"
" are!" # " are!"
), # ),
llm=Anthropic(), # llm=Anthropic(),
max_loops=1, # max_loops=1,
system_prompt="Summarize the transcript", # system_prompt="Summarize the transcript",
autosave=True, # autosave=True,
dashboard=False, # dashboard=False,
streaming_on=True, # streaming_on=True,
verbose=True, # verbose=True,
stopping_token="<DONE>", # stopping_token="<DONE>",
) # )
agent3 = Agent( # agent3 = Agent(
agent_name="t2", # agent_name="t2",
agent_description=( # agent_description=(
"Generate a transcript for a youtube video on what swarms" # "Generate a transcript for a youtube video on what swarms"
" are!" # " are!"
), # ),
llm=Anthropic(), # llm=Anthropic(),
max_loops=1, # max_loops=1,
system_prompt="Finalize the transcript", # system_prompt="Finalize the transcript",
autosave=True, # autosave=True,
dashboard=False, # dashboard=False,
streaming_on=True, # streaming_on=True,
verbose=True, # verbose=True,
stopping_token="<DONE>", # stopping_token="<DONE>",
) # )
# Rearrange the agents # # Rearrange the agents
rearrange = AgentRearrange( # rearrange = AgentRearrange(
agents=[agent, agent2, agent3], # agents=[agent, agent2, agent3],
verbose=True, # verbose=True,
# custom_prompt="Summarize the transcript", # # custom_prompt="Summarize the transcript",
) # )
# Run the workflow on a task # # Run the workflow on a task
results = rearrange( # results = rearrange(
# pattern="t -> t1, t2 -> t2", # # pattern="t -> t1, t2 -> t2",
pattern="t -> t1 -> t2", # pattern="t -> t1 -> t2",
default_task=( # default_task=(
"Generate a transcript for a YouTube video on what swarms" # "Generate a transcript for a YouTube video on what swarms"
" are!" # " are!"
), # ),
t="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", # # t2="Summarize the transcript",
# t3="Finalize the transcript", # # t3="Finalize the transcript",
) # )
# print(results) # # print(results)

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

Loading…
Cancel
Save