docs examples

pull/805/head
Kye Gomez 3 weeks ago
parent 4bd0bae285
commit 45f78485c6

@ -253,11 +253,13 @@ nav:
- Swarms Tools: - Swarms Tools:
- Overview: "swarms_tools/overview.md" - Overview: "swarms_tools/overview.md"
- Finance: "swarms_tools/finance.md"
- Search: "swarms_tools/search.md" Vertical Tools:
- Social Media: - Finance: "swarms_tools/finance.md"
- Overview: "swarms_tools/social_media.md" - Search: "swarms_tools/search.md"
- Twitter: "swarms_tools/twitter.md" - Social Media:
- Overview: "swarms_tools/social_media.md"
- Twitter: "swarms_tools/twitter.md"
- Swarms Memory: - Swarms Memory:
- Overview: "swarms_memory/index.md" - Overview: "swarms_memory/index.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 ```bash
pip install swarms 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 ```python
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os
from swarms import Agent, GroupChat from swarms import Agent, GroupChat
```
if __name__ == "__main__": ### Configure Agents
load_dotenv()
# Get the OpenAI API key from the environment variable !!! example "Agent Configuration"
api_key = os.getenv("OPENAI_API_KEY") Here's how to set up your agents with specific roles:
# Example agents ```python
# Expense Analysis Agent
agent1 = Agent( agent1 = Agent(
agent_name="Expense-Analysis-Agent", agent_name="Expense-Analysis-Agent",
description="You are an accounting agent specializing in analyzing potential expenses.", description="You are an accounting agent specializing in analyzing potential expenses.",
@ -49,6 +59,7 @@ if __name__ == "__main__":
max_tokens=15000, max_tokens=15000,
) )
# Budget Adviser Agent
agent2 = Agent( agent2 = Agent(
agent_name="Budget-Adviser-Agent", agent_name="Budget-Adviser-Agent",
description="You are a budget adviser who provides insights on managing and optimizing expenses.", description="You are a budget adviser who provides insights on managing and optimizing expenses.",
@ -65,7 +76,14 @@ if __name__ == "__main__":
streaming_on=False, streaming_on=False,
max_tokens=15000, max_tokens=15000,
) )
```
### Initialize GroupChat
!!! example "GroupChat Setup"
Configure the GroupChat with your agents:
```python
agents = [agent1, agent2] agents = [agent1, agent2]
chat = GroupChat( chat = GroupChat(
@ -75,8 +93,117 @@ if __name__ == "__main__":
max_loops=1, max_loops=1,
output_type="all", output_type="all",
) )
```
### Run the Chat
!!! example "Execute the Chat"
Start the conversation between agents:
```python
history = chat.run( history = chat.run(
"What potential expenses should we consider for the upcoming quarter? Please collaborate to outline a comprehensive list." "What potential expenses should we consider for the upcoming quarter? Please collaborate to outline a comprehensive list."
) )
``` ```
## 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)

@ -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:
- Conigure your `SequentialWorkflow` - Python 3.7+ installed
## Install - A valid API key for your model provider
- The Swarms package installed
## Installation
```bash ```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 ```python
from swarms import Agent, SequentialWorkflow from swarms import Agent, SequentialWorkflow
```
### 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
# Core Legal Agent Definitions with enhanced system prompts - Monitor agent responses for quality and relevance
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.")
```

Loading…
Cancel
Save