From 45f78485c643e90f4576b5d7ad5f31b99302907d Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Mon, 31 Mar 2025 01:28:15 -0700 Subject: [PATCH] docs examples --- docs/mkdocs.yml | 12 +- docs/swarms/examples/groupchat_example.md | 161 +++++++++++++++-- docs/swarms/examples/sequential_example.md | 195 ++++++++++++++++----- txt.txt | 0 4 files changed, 304 insertions(+), 64 deletions(-) create mode 100644 txt.txt diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index da841ece..842ba366 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -253,11 +253,13 @@ nav: - Swarms Tools: - Overview: "swarms_tools/overview.md" - - Finance: "swarms_tools/finance.md" - - Search: "swarms_tools/search.md" - - Social Media: - - Overview: "swarms_tools/social_media.md" - - Twitter: "swarms_tools/twitter.md" + + Vertical Tools: + - Finance: "swarms_tools/finance.md" + - Search: "swarms_tools/search.md" + - Social Media: + - Overview: "swarms_tools/social_media.md" + - Twitter: "swarms_tools/twitter.md" - Swarms Memory: - Overview: "swarms_memory/index.md" diff --git a/docs/swarms/examples/groupchat_example.md b/docs/swarms/examples/groupchat_example.md index d368478f..45c8f8be 100644 --- a/docs/swarms/examples/groupchat_example.md +++ b/docs/swarms/examples/groupchat_example.md @@ -1,37 +1,47 @@ -# Groupchat Example +# GroupChat Example -- Import required modules +!!! abstract "Overview" + Learn how to create and configure a group chat with multiple AI agents using the Swarms framework. This example demonstrates how to set up agents for expense analysis and budget advising. -- Configure your agents first +## Prerequisites -- Set your api keys for your model provider in the `.env` file such as `OPENAI_API_KEY="sk-"` +!!! info "Before You Begin" + Make sure you have: + - Python 3.7+ installed + - A valid API key for your model provider + - The Swarms package installed -- Conigure `GroupChat` with it's various settings +## Installation - -## Install ```bash pip install swarms ``` ---------- +## Environment Setup + +!!! tip "API Key Configuration" + Set your API key in the `.env` file: + ```bash + OPENAI_API_KEY="your-api-key-here" + ``` + +## Code Implementation -## Main Code +### Import Required Modules ```python from dotenv import load_dotenv import os - from swarms import Agent, GroupChat +``` -if __name__ == "__main__": - - load_dotenv() +### Configure Agents - # Get the OpenAI API key from the environment variable - api_key = os.getenv("OPENAI_API_KEY") +!!! example "Agent Configuration" + Here's how to set up your agents with specific roles: - # Example agents + ```python + # Expense Analysis Agent agent1 = Agent( agent_name="Expense-Analysis-Agent", description="You are an accounting agent specializing in analyzing potential expenses.", @@ -49,6 +59,7 @@ if __name__ == "__main__": max_tokens=15000, ) + # Budget Adviser Agent agent2 = Agent( agent_name="Budget-Adviser-Agent", description="You are a budget adviser who provides insights on managing and optimizing expenses.", @@ -65,7 +76,14 @@ if __name__ == "__main__": streaming_on=False, max_tokens=15000, ) + ``` + +### Initialize GroupChat + +!!! example "GroupChat Setup" + Configure the GroupChat with your agents: + ```python agents = [agent1, agent2] chat = GroupChat( @@ -75,8 +93,117 @@ if __name__ == "__main__": max_loops=1, output_type="all", ) + ``` + +### Run the Chat + +!!! example "Execute the Chat" + Start the conversation between agents: + ```python 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 + ``` + +## Complete Example + +!!! success "Full Implementation" + Here's the complete code combined: + + ```python + from dotenv import load_dotenv + import os + from swarms import Agent, GroupChat + + if __name__ == "__main__": + # Load environment variables + load_dotenv() + api_key = os.getenv("OPENAI_API_KEY") + + # Configure 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, + ) + + # Initialize GroupChat + agents = [agent1, agent2] + chat = GroupChat( + name="Expense Advisory", + description="Accounting group focused on discussing potential expenses", + agents=agents, + max_loops=1, + output_type="all", + ) + + # Run the chat + history = chat.run( + "What potential expenses should we consider for the upcoming quarter? Please collaborate to outline a comprehensive list." + ) + ``` + +## Configuration Options + +!!! info "Key Parameters" + | Parameter | Description | Default | + |-----------|-------------|---------| + | `max_loops` | Maximum number of conversation loops | 1 | + | `autosave` | Enable automatic saving of chat history | False | + | `dashboard` | Enable dashboard visualization | False | + | `verbose` | Enable detailed logging | True | + | `dynamic_temperature_enabled` | Enable dynamic temperature adjustment | True | + | `retry_attempts` | Number of retry attempts for failed operations | 1 | + | `context_length` | Maximum context length for the model | 200000 | + | `max_tokens` | Maximum tokens for model output | 15000 | + +## Next Steps + +!!! tip "What to Try Next" + 1. Experiment with different agent roles and descriptions + 2. Adjust the `max_loops` parameter to allow for longer conversations + 3. Enable the dashboard to visualize agent interactions + 4. Try different model configurations and parameters + +## Troubleshooting + +!!! warning "Common Issues" + - Ensure your API key is correctly set in the `.env` file + - Check that all required dependencies are installed + - Verify that your model provider's API is accessible + - Monitor the `verbose` output for detailed error messages + +## Additional Resources + +- [Swarms Documentation](https://docs.swarms.world) +- [API Reference](https://docs.swarms.world/api) +- [Examples Gallery](https://docs.swarms.world/examples) \ No newline at end of file diff --git a/docs/swarms/examples/sequential_example.md b/docs/swarms/examples/sequential_example.md index a4ba993d..e6fb1138 100644 --- a/docs/swarms/examples/sequential_example.md +++ b/docs/swarms/examples/sequential_example.md @@ -1,57 +1,168 @@ -# Swarms x Browser Use +# Sequential Workflow Example -- Import required modules like `Agent` `SequentialWorkflow` +!!! abstract "Overview" + Learn how to create a sequential workflow with multiple specialized AI agents using the Swarms framework. This example demonstrates how to set up a legal practice workflow with different types of legal agents working in sequence. -- Configure your agents first with their model provider, name, description, role, and more! +## Prerequisites -- Set your api keys for your model provider in the `.env` file such as `OPENAI_API_KEY="sk-"` etc +!!! info "Before You Begin" + Make sure you have: + + - Python 3.7+ installed + + - A valid API key for your model provider + + - The Swarms package installed -- Conigure your `SequentialWorkflow` - -## Install +## Installation ```bash -pip3 install -U swarms +pip3 install -U swarms ``` --------- +## Environment Setup +!!! tip "API Key Configuration" + Set your API key in the `.env` file: + ```bash + OPENAI_API_KEY="your-api-key-here" + ``` -## Main Code +## Code Implementation +### Import Required Modules ```python from swarms import Agent, SequentialWorkflow +``` - -# Core Legal Agent Definitions with enhanced system prompts -litigation_agent = Agent( - agent_name="Alex Johnson", # Human name for the Litigator Agent - system_prompt="As a Litigator, you specialize in navigating the complexities of lawsuits. Your role involves analyzing intricate facts, constructing compelling arguments, and devising effective case strategies to achieve favorable outcomes for your clients.", - model_name="gpt-4o-mini", - max_loops=1, -) - -corporate_agent = Agent( - agent_name="Emily Carter", # Human name for the Corporate Attorney Agent - system_prompt="As a Corporate Attorney, you provide expert legal advice on business law matters. You guide clients on corporate structure, governance, compliance, and transactions, ensuring their business operations align with legal requirements.", - model_name="gpt-4o-mini", - max_loops=1, -) - -ip_agent = Agent( - agent_name="Michael Smith", # Human name for the IP Attorney Agent - system_prompt="As an IP Attorney, your expertise lies in protecting intellectual property rights. You handle various aspects of IP law, including patents, trademarks, copyrights, and trade secrets, helping clients safeguard their innovations.", - model_name="gpt-4o-mini", - max_loops=1, -) - - -swarm = SequentialWorkflow( - agents=[litigation_agent, corporate_agent, ip_agent], - name="litigation-practice", - description="Handle all aspects of litigation with a focus on thorough legal analysis and effective case management.", -) - -swarm.run("Create a report on how to patent an all-new AI invention and what platforms to use and more.") -``` \ No newline at end of file +### Configure Agents + +!!! example "Legal Agent Configuration" + Here's how to set up your specialized legal agents: + + ```python + # Litigation Agent + litigation_agent = Agent( + agent_name="Alex Johnson", + system_prompt="As a Litigator, you specialize in navigating the complexities of lawsuits. Your role involves analyzing intricate facts, constructing compelling arguments, and devising effective case strategies to achieve favorable outcomes for your clients.", + model_name="gpt-4o-mini", + max_loops=1, + ) + + # Corporate Attorney Agent + corporate_agent = Agent( + agent_name="Emily Carter", + system_prompt="As a Corporate Attorney, you provide expert legal advice on business law matters. You guide clients on corporate structure, governance, compliance, and transactions, ensuring their business operations align with legal requirements.", + model_name="gpt-4o-mini", + max_loops=1, + ) + + # IP Attorney Agent + ip_agent = Agent( + agent_name="Michael Smith", + system_prompt="As an IP Attorney, your expertise lies in protecting intellectual property rights. You handle various aspects of IP law, including patents, trademarks, copyrights, and trade secrets, helping clients safeguard their innovations.", + model_name="gpt-4o-mini", + max_loops=1, + ) + ``` + +### Initialize Sequential Workflow + +!!! example "Workflow Setup" + Configure the SequentialWorkflow with your agents: + + ```python + swarm = SequentialWorkflow( + agents=[litigation_agent, corporate_agent, ip_agent], + name="litigation-practice", + description="Handle all aspects of litigation with a focus on thorough legal analysis and effective case management.", + ) + ``` + +### Run the Workflow + +!!! example "Execute the Workflow" + Start the sequential workflow: + + ```python + swarm.run("Create a report on how to patent an all-new AI invention and what platforms to use and more.") + ``` + +## Complete Example + +!!! success "Full Implementation" + Here's the complete code combined: + + ```python + from swarms import Agent, SequentialWorkflow + + # Core Legal Agent Definitions with enhanced system prompts + litigation_agent = Agent( + agent_name="Alex Johnson", + system_prompt="As a Litigator, you specialize in navigating the complexities of lawsuits. Your role involves analyzing intricate facts, constructing compelling arguments, and devising effective case strategies to achieve favorable outcomes for your clients.", + model_name="gpt-4o-mini", + max_loops=1, + ) + + corporate_agent = Agent( + agent_name="Emily Carter", + system_prompt="As a Corporate Attorney, you provide expert legal advice on business law matters. You guide clients on corporate structure, governance, compliance, and transactions, ensuring their business operations align with legal requirements.", + model_name="gpt-4o-mini", + max_loops=1, + ) + + ip_agent = Agent( + agent_name="Michael Smith", + system_prompt="As an IP Attorney, your expertise lies in protecting intellectual property rights. You handle various aspects of IP law, including patents, trademarks, copyrights, and trade secrets, helping clients safeguard their innovations.", + model_name="gpt-4o-mini", + max_loops=1, + ) + + # Initialize and run the workflow + swarm = SequentialWorkflow( + agents=[litigation_agent, corporate_agent, ip_agent], + name="litigation-practice", + description="Handle all aspects of litigation with a focus on thorough legal analysis and effective case management.", + ) + + swarm.run("Create a report on how to patent an all-new AI invention and what platforms to use and more.") + ``` + +## Agent Roles + +!!! info "Specialized Legal Agents" + | Agent | Role | Expertise | + |-------|------|-----------| + | Alex Johnson | Litigator | Lawsuit navigation, case strategy | + | Emily Carter | Corporate Attorney | Business law, compliance | + | Michael Smith | IP Attorney | Patents, trademarks, copyrights | + +## Configuration Options + +!!! info "Key Parameters" + | Parameter | Description | Default | + |-----------|-------------|---------| + | `agent_name` | Human-readable name for the agent | Required | + | `system_prompt` | Detailed role description and expertise | Required | + | `model_name` | LLM model to use | "gpt-4o-mini" | + | `max_loops` | Maximum number of processing loops | 1 | + +## Next Steps + +!!! tip "What to Try Next" + 1. Experiment with different agent roles and specializations + 2. Modify the system prompts to create different expertise areas + 3. Add more agents to the workflow for complex tasks + 4. Try different model configurations + +## Troubleshooting + +!!! warning "Common Issues" + - Ensure your API key is correctly set in the `.env` file + + - Check that all required dependencies are installed + + - Verify that your model provider's API is accessible + + - Monitor agent responses for quality and relevance diff --git a/txt.txt b/txt.txt new file mode 100644 index 00000000..e69de29b