pull/584/head
Your Name 4 months ago
parent 46726f9974
commit 5d112d0358

@ -434,7 +434,9 @@ Run the agent with multiple modalities useful for various real-world tasks in ma
```python
import os
from dotenv import load_dotenv
from swarms import GPT4VisionAPI, Agent
from swarms import Agent
from swarm_models import GPT4VisionAPI
# Load the environment variables
load_dotenv()
@ -529,79 +531,6 @@ print(f"Generated data: {generated_data}")
```
### `Task`
For deeper control of your agent stack, `Task` is a simple structure for task execution with the `Agent`. Imagine zapier like LLM-based workflow automation.
✅ Task is a structure for task execution with the Agent.
✅ Tasks can have descriptions, scheduling, triggers, actions, conditions, dependencies, priority, and a history.
✅ The Task structure allows for efficient workflow automation with LLM-based agents.
```python
import os
from dotenv import load_dotenv
from swarms import Agent, OpenAIChat, Task
# Load the environment variables
load_dotenv()
# Define a function to be used as the action
def my_action():
print("Action executed")
# Define a function to be used as the condition
def my_condition():
print("Condition checked")
return True
# Create an agent
agent = Agent(
llm=OpenAIChat(openai_api_key=os.environ["OPENAI_API_KEY"]),
max_loops=1,
dashboard=False,
)
# Create a task
task = Task(
description=(
"Generate a report on the top 3 biggest expenses for small"
" businesses and how businesses can save 20%"
),
agent=agent,
)
# Set the action and condition
task.set_action(my_action)
task.set_condition(my_condition)
# Execute the task
print("Executing task...")
task.run()
# Check if the task is completed
if task.is_completed():
print("Task completed")
else:
print("Task not completed")
# Output the result of the task
print(f"Task result: {task.result}")
```
---
----
# Multi-Agent Orchestration:
Swarms was designed to facilitate the communication between many different and specialized agents from a vast array of other frameworks such as langchain, autogen, crew, and more.
@ -623,7 +552,9 @@ In traditional swarm theory, there are many types of swarms usually for very spe
Sequential Workflow enables you to sequentially execute tasks with `Agent` and then pass the output into the next agent and onwards until you have specified your max loops.
```python
from swarms import Agent, SequentialWorkflow, Anthropic
from swarms import Agent, SequentialWorkflow
from swarm_models import Anthropic
# Initialize the language model agent (e.g., GPT-3)
@ -742,7 +673,10 @@ import os
from dotenv import load_dotenv
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType
from swarm_models import OpenAIChat
load_dotenv()
@ -1059,23 +993,10 @@ The easiest way to contribute is to pick any issue with the `good first issue` t
Swarms is an open-source project, and contributions are VERY welcome. If you want to contribute, you can create new features, fix bugs, or improve the infrastructure. Please refer to the [CONTRIBUTING.md](https://github.com/kyegomez/swarms/blob/master/CONTRIBUTING.md) and our [contributing board](https://github.com/users/kyegomez/projects/1) to participate in Roadmap discussions!
<a href="https://github.com/kyegomez/swarms/graphs/contributors">
<img src="https://contrib.rocks/image?repo=kyegomez/swarms" />
</a>
----
## Swarm Newsletter 🤖 🤖 🤖 📧
Sign up to the Swarm newsletter to receive updates on the latest Autonomous agent research papers, step by step guides on creating multi-agent app, and much more Swarmie goodiness 😊
[CLICK HERE TO SIGNUP](https://docs.google.com/forms/d/e/1FAIpQLSfqxI2ktPR9jkcIwzvHL0VY6tEIuVPd-P2fOWKnd6skT9j1EQ/viewform?usp=sf_link)
## Discovery Call
Book a discovery call to learn how Swarms can lower your operating costs by 40% with swarms of autonomous agents in lightspeed. [Click here to book a time that works for you!](https://calendly.com/swarm-corp/30min?month=2023-11)
## Accelerate Backlog
Accelerate Bugs, Features, and Demos to implement by supporting us here:
@ -1095,9 +1016,6 @@ Join our growing community around the world, for real-time support, ideas, and d
---
# License
Apache License
# Citations
Please cite Swarms in your paper or your project if you found it beneficial in any way! Appreciate you.

@ -139,7 +139,10 @@ import os
from dotenv import load_dotenv
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType
from swarm_models import OpenAIChat
load_dotenv()

@ -5,7 +5,9 @@
Sequential Workflow enables you to sequentially execute tasks with `Agent` and then pass the output into the next agent and onwards until you have specified your max loops.
```python
from swarms import Agent, SequentialWorkflow, Anthropic
from swarms import Agent, SequentialWorkflow
from swarm_models import Anthropic
# Initialize the language model agent (e.g., GPT-3)
@ -123,7 +125,10 @@ import os
from dotenv import load_dotenv
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType
from swarm_models import OpenAIChat
load_dotenv()

@ -34,7 +34,9 @@ Runs the specified task through the agents in the dynamically constructed flow.
- **Usage Example:**
```python
from swarms import Agent, SequentialWorkflow, Anthropic
from swarms import Agent, SequentialWorkflow
from swarm_models import Anthropic
# Initialize the language model agent (e.g., GPT-3)

@ -1,5 +1,6 @@
from swarms import Agent, AgentRearrange, OpenAIChat
from swarms.agents.multion_wrapper import MultiOnAgent
from swarms import Agent, AgentRearrange
from swarm_models import OpenAIChatfrom swarms.agents.multion_wrapper import MultiOnAgent
model = MultiOnAgent(
url="https://tesla.com",

@ -1,6 +1,8 @@
import os
from dotenv import load_dotenv
from swarms import GPT4VisionAPI, Agent
from swarms import Agent
from swarm_models import GPT4VisionAPI
# Load the environment variables
load_dotenv()

@ -1,4 +1,6 @@
from swarms import GPT4VisionAPI, Agent
from swarms import Agent
from swarm_models import GPT4VisionAPI
llm = GPT4VisionAPI()

@ -1,5 +1,6 @@
from swarms import Agent, AgentRearrange, OpenAIChat
from swarms import Agent, AgentRearrange
from swarm_models import OpenAIChat
# Initialize the director agent

@ -1,5 +1,6 @@
from swarms import Agent, AgentRearrange, OpenAIChat
from swarms import Agent, AgentRearrange
from swarm_models import OpenAIChat
# Initialize the director agent

@ -1,4 +1,6 @@
from swarms import Agent, SequentialWorkflow, Anthropic
from swarms import Agent, SequentialWorkflow
from swarm_models import Anthropic
# Initialize the language model agent (e.g., GPT-3)

@ -434,7 +434,9 @@ Run the agent with multiple modalities useful for various real-world tasks in ma
```python
import os
from dotenv import load_dotenv
from swarms import GPT4VisionAPI, Agent
from swarms import Agent
from swarm_models import GPT4VisionAPI
# Load the environment variables
load_dotenv()
@ -623,7 +625,9 @@ In traditional swarm theory, there are many types of swarms usually for very spe
Sequential Workflow enables you to sequentially execute tasks with `Agent` and then pass the output into the next agent and onwards until you have specified your max loops.
```python
from swarms import Agent, SequentialWorkflow, Anthropic
from swarms import Agent, SequentialWorkflow
from swarm_models import Anthropic
# Initialize the language model agent (e.g., GPT-3)
@ -741,7 +745,10 @@ import os
from dotenv import load_dotenv
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType, OpenAIChat
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType
from swarm_models import OpenAIChat
load_dotenv()

@ -1,83 +1,93 @@
import os
import asyncio
from dotenv import load_dotenv
load_dotenv()
from swarms.structs import Agent
from swarm_models import Anthropic
from swarms.structs.rearrange import AgentRearrange
llm = Anthropic(anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"), streaming=True)
llm = Anthropic(
anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"), streaming=True
)
async def sequential():
agent1 = Agent(
agent_name="Blog generator",
system_prompt="Generate a blog post like stephen king",
llm=llm,
dashboard=False,
streaming_on=True
)
agent2 = Agent(
agent_name="Summarizer",
system_prompt="Summarize the blog post",
llm=llm,
dashboard=False,
streaming_on=True
)
flow = f"{agent1.name} -> {agent2.name}"
agent_rearrange = AgentRearrange(
[agent1, agent2], flow, verbose=False, logging=False
)
result = await agent_rearrange.astream(
"Generate a short blog post about Muhammad Ali."
)
# LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;)
# await agent_rearrange.run(
# "Generate a short blog post about Muhammad Ali."
# )
agent1 = Agent(
agent_name="Blog generator",
system_prompt="Generate a blog post like stephen king",
llm=llm,
dashboard=False,
streaming_on=True,
)
async def parallel():
agent2 = Agent(
agent_name="Summarizer",
system_prompt="Summarize the blog post",
llm=llm,
dashboard=False,
streaming_on=True,
)
writer1 = Agent(
agent_name="Writer 1",
system_prompt="Generate a blog post in the style of J.K. Rowling about Muhammad Ali",
llm=llm,
dashboard=False,
)
flow = f"{agent1.name} -> {agent2.name}"
writer2 = Agent(
agent_name="Writer 2",
system_prompt="Generate a blog post in the style of Stephen King about Muhammad Ali",
llm=llm,
dashboard=False
)
agent_rearrange = AgentRearrange(
[agent1, agent2], flow, verbose=False, logging=False
)
reviewer = Agent(
agent_name="Reviewer",
system_prompt="Select the writer that wrote the best story. There can only be one best story.",
llm=llm,
dashboard=False
)
result = await agent_rearrange.astream(
"Generate a short blog post about Muhammad Ali."
)
flow = f"{writer1.name}, {writer2.name} -> {reviewer.name}"
# LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;)
# await agent_rearrange.run(
# "Generate a short blog post about Muhammad Ali."
# )
agent_rearrange = AgentRearrange(
[writer1, writer2, reviewer], flow, verbose=False, logging=False
)
result = await agent_rearrange.astream("Generate a 1 sentence story about Michael Jordan.")
async def parallel():
writer1 = Agent(
agent_name="Writer 1",
system_prompt="Generate a blog post in the style of J.K. Rowling about Muhammad Ali",
llm=llm,
dashboard=False,
)
writer2 = Agent(
agent_name="Writer 2",
system_prompt="Generate a blog post in the style of Stephen King about Muhammad Ali",
llm=llm,
dashboard=False,
)
reviewer = Agent(
agent_name="Reviewer",
system_prompt="Select the writer that wrote the best story. There can only be one best story.",
llm=llm,
dashboard=False,
)
flow = f"{writer1.name}, {writer2.name} -> {reviewer.name}"
agent_rearrange = AgentRearrange(
[writer1, writer2, reviewer],
flow,
verbose=False,
logging=False,
)
result = await agent_rearrange.astream(
"Generate a 1 sentence story about Michael Jordan."
)
# LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;)
# result = agent_rearrange.run(
# "Generate a short blog post about Michael Jordan."
# )
# LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;)
# result = agent_rearrange.run(
# "Generate a short blog post about Michael Jordan."
# )
asyncio.run(sequential())
# asyncio.run(parallel())

@ -1,6 +1,8 @@
import os
from swarms import Agent, AgentRearrange, OpenAIChat
from swarms import Agent, AgentRearrange
from swarm_models import OpenAIChat
# Get the OpenAI API key from the environment variable
api_key = os.getenv("OPENAI_API_KEY")

@ -1,6 +1,6 @@
# import os
# from swarms import Agent
from swarm_models import OpenAIChat
# from typing import List
# class DepthFirstSearchSwarm:
@ -81,7 +81,6 @@ from swarm_models import OpenAIChat
# ####################
# import os
# from swarms import Agent
from swarm_models import OpenAIChat
# class DFSSwarm:
# def __init__(self, agents):

@ -226,7 +226,7 @@ class GraphWorkflow(BaseModel):
# # Example usage
# if __name__ == "__main__":
# from swarms import Agent
from swarm_models import OpenAIChat
# import os
# from dotenv import load_dotenv

@ -201,7 +201,7 @@ def average_aggregator(results: List[float]) -> float:
# import os
# from swarms import Agent
from swarm_models import OpenAIChat
# from typing import List, Union, Callable
# from collections import Counter

@ -11,8 +11,6 @@ from swarms.structs.agent import Agent
from swarms.structs.base_swarm import BaseSwarm
from swarms.structs.omni_agent_types import AgentType
from swarms.utils.loguru_logger import logger
<<<<<<< HEAD
=======
class AgentRearrangeInput(BaseModel):
@ -42,7 +40,6 @@ class AgentRearrangeOutput(BaseModel):
),
description="The time the agent was created.",
)
>>>>>>> ce359f5e ([5.6.8])
class AgentRearrange(BaseSwarm):
@ -362,7 +359,6 @@ class AgentRearrange(BaseSwarm):
logger.error(f"An error occurred: {e}")
return e
<<<<<<< HEAD
async def astream(
self,
task: str = None,
@ -392,7 +388,9 @@ class AgentRearrange(BaseSwarm):
# If custom_tasks have the agents name and tasks then combine them
if custom_tasks is not None:
c_agent_name, c_task = next(iter(custom_tasks.items()))
c_agent_name, c_task = next(
iter(custom_tasks.items())
)
# Find the position of the custom agent in the tasks list
position = tasks.index(c_agent_name)
@ -498,7 +496,9 @@ class AgentRearrange(BaseSwarm):
# print(evt) # <- useful when building/debugging
if evt["event"] == "on_llm_end":
result = evt["data"]["output"]
print(agent.name, "result", result)
print(
agent.name, "result", result
)
current_task = result
loop_count += 1
@ -529,13 +529,13 @@ class AgentRearrange(BaseSwarm):
if name.startswith("Human"):
return self.human_intervention(task)
elif name in self.sub_swarm:
return self.run_sub_swarm(task, name, img, *args, **kwargs)
return self.run_sub_swarm(
task, name, img, *args, **kwargs
)
else:
agent = self.agents[name]
return agent.run(task, img, is_last, *args, **kwargs)
=======
>>>>>>> ce359f5e ([5.6.8])
def human_intervention(self, task: str) -> str:
if self.human_in_the_loop and self.custom_human_in_the_loop:
return self.custom_human_in_the_loop(task)

Loading…
Cancel
Save