[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
chroma
Unit Testing Agent_state.json
Devin_state.json
swarms/__pycache__
artifacts
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]
name = "swarms"
version = "4.7.1"
version = "4.7.3"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"]

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

@ -34,7 +34,6 @@ from swarms.models.popular_llms import (
)
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
@ -74,7 +73,6 @@ __all__ = [
"Replicate",
"SamplingParams",
"SamplingType",
"SegmentAnythingMarkGenerator",
"TextModality",
"TogetherLLM",
"Vilt",

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

@ -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__(
@ -12,6 +13,8 @@ class AgentRearrange(BaseSwarm):
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):
@ -159,76 +162,76 @@ class AgentRearrange(BaseSwarm):
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)

@ -1,3 +1,4 @@
import os
import logging
import warnings
@ -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()

Loading…
Cancel
Save