From cc9ea26aaffaab522042818f9aa274fbe3b352dc Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Sun, 30 Mar 2025 19:58:12 -0700 Subject: [PATCH] docs examples groupchat and also swarms of browser use agents --- docs/mkdocs.yml | 8 +- docs/swarms/examples/groupchat_example.md | 82 +++++++++++++++++++ .../examples/swarms_of_browser_agents.md | 65 +++++++++++++++ groupchat_example.py | 3 - 4 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 docs/swarms/examples/groupchat_example.md create mode 100644 docs/swarms/examples/swarms_of_browser_agents.md diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 7b64a7ea..fa5d9f1f 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -254,12 +254,11 @@ nav: - Examples: - Overview: "swarms/examples/unique_swarms.md" - - Swarms API Examples: - Medical Swarm: "swarms/examples/swarms_api_medical.md" - Finance Swarm: "swarms/examples/swarms_api_finance.md" - ML Model Code Generation Swarm: "swarms/examples/swarms_api_ml_model.md" - - Various Model Providers: + - Individal LLM Examples: - OpenAI: "swarms/examples/openai_example.md" - Anthropic: "swarms/examples/claude.md" - Groq: "swarms/examples/groq.md" @@ -278,10 +277,13 @@ nav: - Quant Crypto Agent: "swarms/examples/quant_crypto_agent.md" - Meme Agents: - Bob The Builder: "swarms/examples/bob_the_builder.md" - - Meme Agent Builder: "swarms/examples/meme_agents.md" - Multi-Agent Collaboration: - Swarms DAO: "swarms/examples/swarms_dao.md" - Hybrid Hierarchical-Cluster Swarm Example: "swarms/examples/hhcs_examples.md" + - Group Chat Example: "swarms/examples/groupchat_example.md" + - Meme Agent Builder: "swarms/examples/meme_agents.md" + - External Agents: + - Swarms of Browser Agents: "swarms/examples/swarms_of_browser_agents.md" - Swarms UI: - Overview: "swarms/ui/main.md" diff --git a/docs/swarms/examples/groupchat_example.md b/docs/swarms/examples/groupchat_example.md new file mode 100644 index 00000000..d368478f --- /dev/null +++ b/docs/swarms/examples/groupchat_example.md @@ -0,0 +1,82 @@ +# Groupchat Example + +- Import required modules + +- Configure your agents first + +- Set your api keys for your model provider in the `.env` file such as `OPENAI_API_KEY="sk-"` + +- Conigure `GroupChat` with it's various settings + + +## Install +```bash +pip install swarms +``` + +--------- + +## Main Code + +```python +from dotenv import load_dotenv +import os + +from swarms import Agent, GroupChat + +if __name__ == "__main__": + + load_dotenv() + + # Get the OpenAI API key from the environment variable + api_key = os.getenv("OPENAI_API_KEY") + + # Example agents + agent1 = Agent( + agent_name="Expense-Analysis-Agent", + description="You are an accounting agent specializing in analyzing potential expenses.", + model_name="gpt-4o-mini", + max_loops=1, + autosave=False, + dashboard=False, + verbose=True, + dynamic_temperature_enabled=True, + user_name="swarms_corp", + retry_attempts=1, + context_length=200000, + output_type="string", + streaming_on=False, + max_tokens=15000, + ) + + agent2 = Agent( + agent_name="Budget-Adviser-Agent", + description="You are a budget adviser who provides insights on managing and optimizing expenses.", + model_name="gpt-4o-mini", + max_loops=1, + autosave=False, + dashboard=False, + verbose=True, + dynamic_temperature_enabled=True, + user_name="swarms_corp", + retry_attempts=1, + context_length=200000, + output_type="string", + streaming_on=False, + max_tokens=15000, + ) + + agents = [agent1, agent2] + + chat = GroupChat( + name="Expense Advisory", + description="Accounting group focused on discussing potential expenses", + agents=agents, + max_loops=1, + output_type="all", + ) + + history = chat.run( + "What potential expenses should we consider for the upcoming quarter? Please collaborate to outline a comprehensive list." + ) +``` \ No newline at end of file diff --git a/docs/swarms/examples/swarms_of_browser_agents.md b/docs/swarms/examples/swarms_of_browser_agents.md new file mode 100644 index 00000000..6ef35e97 --- /dev/null +++ b/docs/swarms/examples/swarms_of_browser_agents.md @@ -0,0 +1,65 @@ +# Swarms x Browser Use + +- Import required modules + +- Configure your agent first by making a new class + +- Set your api keys for your model provider in the `.env` file such as `OPENAI_API_KEY="sk-"` + +- Conigure your `ConcurrentWorkflow` + +## Install + +```bash +pip install swarms browser-use langchain-openai +``` +-------- + + +## Main +```python +import asyncio + +from browser_use import Agent +from dotenv import load_dotenv +from langchain_openai import ChatOpenAI + +from swarms import ConcurrentWorkflow + +load_dotenv() + + +class BrowserAgent: + def __init__(self, agent_name: str = "BrowserAgent"): + self.agent_name = agent_name + + async def browser_agent_test(self, task: str): + agent = Agent( + task=task, + llm=ChatOpenAI(model="gpt-4o"), + ) + result = await agent.run() + return result + + def run(self, task: str): + return asyncio.run(self.browser_agent_test(task)) + + +swarm = ConcurrentWorkflow( + agents=[BrowserAgent() for _ in range(3)], +) + +swarm.run( + """ + Go to pump.fun. + + 2. Make an account: use email: "test@test.com" and password: "test1234" + + 3. Make a coin called and give it a cool description and etc. Fill in the form + + 4. Sit back and watch the coin grow in value. + + """ +) + +``` \ No newline at end of file diff --git a/groupchat_example.py b/groupchat_example.py index 1c38c806..6f72d1f4 100644 --- a/groupchat_example.py +++ b/groupchat_example.py @@ -3,9 +3,6 @@ import os from swarms.structs.agent import Agent from swarms.structs.groupchat import GroupChat -from swarms.prompts.multi_agent_collab_prompt import ( - MULTI_AGENT_COLLAB_PROMPT_TWO, -) if __name__ == "__main__":