Merge branch 'kyegomez:master' into feat/921-stream

pull/935/head
harshalmore31 4 weeks ago committed by GitHub
commit e44c614b2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -38,11 +38,6 @@ plugins:
# token: !ENV ["GITHUB_TOKEN"]
- git-revision-date-localized:
enable_creation_date: true
# - mkdocs-jupyter:
# kernel_name: python3
# execute: false
# include_source: True
# include_requirejs: true
extra_css:
- assets/css/extra.css
@ -85,6 +80,7 @@ theme:
- content.code.annotate
- navigation.tabs
- navigation.sections
# - navigation.expand
- navigation.top
- announce.dismiss
font:
@ -140,7 +136,8 @@ markdown_extensions:
case: lower
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.tilde
- pymdownx.inlinehilite
nav:
- Home:
- Overview: "index.md"
@ -149,13 +146,9 @@ nav:
- Environment Configuration: "swarms/install/env.md"
- Quickstart: "swarms/install/quickstart.md"
- Feature Set: "swarms/features.md"
# - Swarms CLI: "swarms/cli/main.md"
# - Swarms Framework Architecture: "swarms/concept/framework_architecture.md"
# - Swarm Ecosystem: "swarms/concept/swarm_ecosystem.md"
# - Swarms Products: "swarms/products.md"
# - Swarms Vision: "swarms/concept/vision.md"
- Agents:
# - Overview: "swarms/structs/index.md"
- Overview: "swarms/agents/index.md"
- Concepts:
# - Managing Prompts in Production: "swarms/prompts/main.md"
- Introduction into The Agent Architecture: "swarms/framework/agents_explained.md"
@ -198,39 +191,46 @@ nav:
- Multi-Agent Architectures Documentation:
- Overview: "swarms/structs/overview.md"
- MajorityVoting: "swarms/structs/majorityvoting.md"
- AgentRearrange: "swarms/structs/agent_rearrange.md"
- RoundRobin: "swarms/structs/round_robin_swarm.md"
- Mixture of Agents: "swarms/structs/moa.md"
- GroupChat: "swarms/structs/group_chat.md"
- AgentRegistry: "swarms/structs/agent_registry.md"
- SpreadSheetSwarm: "swarms/structs/spreadsheet_swarm.md"
- ForestSwarm: "swarms/structs/forest_swarm.md"
- SwarmRouter: "swarms/structs/swarm_router.md"
# - TaskQueueSwarm: "swarms/structs/taskqueue_swarm.md"
- SwarmRearrange: "swarms/structs/swarm_rearrange.md"
- MultiAgentRouter: "swarms/structs/multi_agent_router.md"
# - MatrixSwarm: "swarms/structs/matrix_swarm.md"
- ModelRouter: "swarms/structs/model_router.md"
- MALT: "swarms/structs/malt.md"
- Interactive Group Chat: "swarms/structs/interactive_groupchat.md"
- Various Execution Methods: "swarms/structs/various_execution_methods.md"
- Deep Research Swarm: "swarms/structs/deep_research_swarm.md"
- Swarm Matcher: "swarms/structs/swarm_matcher.md"
- Council of Judges: "swarms/structs/council_of_judges.md"
- Hiearchical Architectures:
- Auto Agent Builder: "swarms/structs/auto_agent_builder.md"
- Hybrid Hierarchical-Cluster Swarm: "swarms/structs/hhcs.md"
- Auto Swarm Builder: "swarms/structs/auto_swarm_builder.md"
- Swarm Matcher: "swarms/structs/swarm_matcher.md"
- Multi-Agent Multi-Modal Structures:
- ImageAgentBatchProcessor: "swarms/structs/image_batch_agent.md"
- Storage:
- AgentRegistry: "swarms/structs/agent_registry.md"
- Routers:
- SwarmRouter: "swarms/structs/swarm_router.md"
- MultiAgentRouter: "swarms/structs/multi_agent_router.md"
- ModelRouter: "swarms/structs/model_router.md"
- Rearrangers:
- SwarmRearrange: "swarms/structs/swarm_rearrange.md"
- AgentRearrange: "swarms/structs/agent_rearrange.md"
- GroupChats:
- GroupChat: "swarms/structs/group_chat.md"
- Interactive Group Chat: "swarms/structs/interactive_groupchat.md"
- Workflows:
- ConcurrentWorkflow: "swarms/structs/concurrentworkflow.md"
- SequentialWorkflow: "swarms/structs/sequential_workflow.md"
- GraphWorkflow: "swarms/structs/graph_workflow.md"
- Communication Structure: "swarms/structs/conversation.md"
- Tools:
@ -254,36 +254,40 @@ nav:
- Deployment Solutions:
- Deploy your agents on Google Cloud Run: "swarms_cloud/cloud_run.md"
- Deploy your agents on Phala: "swarms_cloud/phala_deploy.md"
- Deploy your agents on FastAPI:
# - Deploy your agents on FastAPI:
- Examples:
- Overview: "examples/index.md"
- CookBook Index: "examples/cookbook_index.md"
# - PreBuilt Templates: "examples/templates_index.md"
- Customizing Agents:
- Basic Agent: "swarms/examples/basic_agent.md"
- Agent with Streaming: "examples/agent_stream.md"
- Agents with Callable Tools: "swarms/examples/agent_with_tools.md"
# - Agent With MCP Integration: "swarms/examples/agent_with_mcp.md"
- Agent Output Types: "swarms/examples/agent_output_types.md"
- Agent with Structured Outputs: "swarms/examples/agent_structured_outputs.md"
- Agents with Vision: "swarms/examples/vision_processing.md"
- Agent with Multiple Images: "swarms/examples/multiple_images.md"
- Agents with Vision and Tool Usage: "swarms/examples/vision_tools.md"
- Gradio Chat Interface: "swarms/ui/main.md"
- Model Providers:
- Overview: "swarms/examples/model_providers.md"
- OpenAI: "swarms/examples/openai_example.md"
- Anthropic: "swarms/examples/claude.md"
- Groq: "swarms/examples/groq.md"
- Cohere: "swarms/examples/cohere.md"
- DeepSeek: "swarms/examples/deepseek.md"
- Ollama: "swarms/examples/ollama.md"
- OpenRouter: "swarms/examples/openrouter.md"
- XAI: "swarms/examples/xai.md"
- VLLM: "swarms/examples/vllm_integration.md"
- Llama4: "swarms/examples/llama4.md"
- Basic Examples:
- Individual Agents:
- Basic Agent: "swarms/examples/basic_agent.md"
- Tool Usage:
- Agents with Vision and Tool Usage: "swarms/examples/vision_tools.md"
- Agents with Callable Tools: "swarms/examples/agent_with_tools.md"
- Agent with Structured Outputs: "swarms/examples/agent_structured_outputs.md"
- Agent With MCP Integration: "swarms/examples/agent_with_mcp.md"
- Vision:
- Agents with Vision: "swarms/examples/vision_processing.md"
- Agent with Multiple Images: "swarms/examples/multiple_images.md"
- Utils:
- Agent with Streaming: "examples/agent_stream.md"
- Agent Output Types: "swarms/examples/agent_output_types.md"
- Gradio Chat Interface: "swarms/ui/main.md"
- LLM Providers:
- Overview: "swarms/examples/model_providers.md"
- OpenAI: "swarms/examples/openai_example.md"
- Anthropic: "swarms/examples/claude.md"
- Groq: "swarms/examples/groq.md"
- Cohere: "swarms/examples/cohere.md"
- DeepSeek: "swarms/examples/deepseek.md"
- Ollama: "swarms/examples/ollama.md"
- OpenRouter: "swarms/examples/openrouter.md"
- XAI: "swarms/examples/xai.md"
- VLLM: "swarms/examples/vllm_integration.md"
- Llama4: "swarms/examples/llama4.md"
@ -296,29 +300,30 @@ nav:
# - Lumo: "swarms/examples/lumo.md"
# - Quant Crypto Agent: "swarms/examples/quant_crypto_agent.md"
- Multi-Agent Collaboration:
- Hybrid Hierarchical-Cluster Swarm Example: "swarms/examples/hhcs_examples.md"
- Group Chat Example: "swarms/examples/groupchat_example.md"
- Sequential Workflow Example: "swarms/examples/sequential_example.md"
- SwarmRouter Example: "swarms/examples/swarm_router.md"
- MultiAgentRouter Minimal Example: "swarms/examples/multi_agent_router_minimal.md"
- ConcurrentWorkflow Example: "swarms/examples/concurrent_workflow.md"
# - MixtureOfAgents Example: "swarms/examples/mixture_of_agents.md"
- Mixture of Agents Example: "swarms/examples/moa_example.md"
- Unique Swarms: "swarms/examples/unique_swarms.md"
- Agents as Tools: "swarms/examples/agents_as_tools.md"
- Aggregate Multi-Agent Responses: "swarms/examples/aggregate.md"
- Interactive GroupChat Example: "swarms/examples/interactive_groupchat_example.md"
- Applications:
- Swarms DAO: "swarms/examples/swarms_dao.md"
- Swarms of Browser Agents: "swarms/examples/swarms_of_browser_agents.md"
- ConcurrentWorkflow with VLLM Agents: "swarms/examples/vllm.md"
- Advanced Examples:
- Multi-Agent Architectures:
- Hybrid Hierarchical-Cluster Swarm Example: "swarms/examples/hhcs_examples.md"
- Group Chat Example: "swarms/examples/groupchat_example.md"
- Sequential Workflow Example: "swarms/examples/sequential_example.md"
- SwarmRouter Example: "swarms/examples/swarm_router.md"
- MultiAgentRouter Minimal Example: "swarms/examples/multi_agent_router_minimal.md"
- ConcurrentWorkflow Example: "swarms/examples/concurrent_workflow.md"
# - MixtureOfAgents Example: "swarms/examples/mixture_of_agents.md"
- Mixture of Agents Example: "swarms/examples/moa_example.md"
- Unique Swarms: "swarms/examples/unique_swarms.md"
- Agents as Tools: "swarms/examples/agents_as_tools.md"
- Aggregate Multi-Agent Responses: "swarms/examples/aggregate.md"
- Interactive GroupChat Example: "swarms/examples/igc_example.md"
- Applications:
- Swarms DAO: "swarms/examples/swarms_dao.md"
- Swarms of Browser Agents: "swarms/examples/swarms_of_browser_agents.md"
- ConcurrentWorkflow with VLLM Agents: "swarms/examples/vllm.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"
# - ML Model Code Generation Swarm: "swarms/examples/swarms_api_ml_model.md"
# - Swarm Models:
# - Overview: "swarms/models/index.md"
@ -345,7 +350,6 @@ nav:
- Swarms API Tools: "swarms_cloud/swarms_api_tools.md"
- Individual Agent Completions: "swarms_cloud/agent_api.md"
- Clients:
- Swarms API Python Client: "swarms_cloud/python_client.md"
- Swarms API Rust Client: "swarms_cloud/rust_client.md"
@ -395,32 +399,4 @@ nav:
- Changelog:
- Swarms 5.6.8: "swarms/changelog/5_6_8.md"
- Swarms 5.8.1: "swarms/changelog/5_8_1.md"
- Swarms 5.9.2: "swarms/changelog/changelog_new.md"
# - Tokenomics: "web3/token.md"
# - Prompts API:
# - Add Prompts: "swarms_platform/prompts/add_prompt.md"
# - Edit Prompts: "swarms_platform/prompts/edit_prompt.md"
# - Query Prompts: "swarms_platform/prompts/fetch_prompts.md"
# - Agents API:
# - Add Agents: "swarms_platform/agents/agents_api.md"
# - Query Agents: "swarms_platform/agents/fetch_agents.md"
# - Edit Agents: "swarms_platform/agents/edit_agent.md"
# - Telemetry API:
# - PUT: "swarms_platform/telemetry/index.md"
# - Swarms Wallet API:
# - Overview: "swarms/wallet/api.md"
# - Tools API:
# - Overview: "swarms_platform/tools_api.md"
# - Add Tools: "swarms_platform/fetch_tools.md"
# - Corporate:
# - Culture: "corporate/culture.md"
# - Hiring: "corporate/hiring.md"
# - Swarms Goals & Milestone Tracking; A Vision for 2024 and Beyond: "corporate/2024_2025_goals.md"
# - Web3:
# # - Overview: "finance/index.md"
# - Swarms Wallet: "finance/wallet.md"
# - Swarms Subscription: "finance/subscription.md"
- Swarms 5.9.2: "swarms/changelog/changelog_new.md"

@ -13,43 +13,11 @@ pip3 install -U swarms
## Environment Variables
```txt
WORKSPACE_DIR=""
OPENAI_API_KEY=""
ANTHROPIC_API_KEY=""
```
## Function Parameters
### `workers: List[Callable]` (Required)
A list of Agent instances that will work on the task concurrently. Each agent should be a callable object (typically an Agent instance).
### `task: str` (Required)
The task or question that all agents will work on simultaneously. This should be a clear, specific prompt that allows for diverse perspectives.
### `type: HistoryOutputType` (Optional, Default: "all")
Controls the format of the returned conversation history. Available options:
| Type | Description |
|------|-------------|
| **"all"** | Returns the complete conversation including all agent responses and the final aggregation |
| **"list"** | Returns the conversation as a list format |
| **"dict"** or **"dictionary"** | Returns the conversation as a dictionary format |
| **"string"** or **"str"** | Returns only the final aggregated response as a string |
| **"final"** or **"last"** | Returns only the final aggregated response |
| **"json"** | Returns the conversation in JSON format |
| **"yaml"** | Returns the conversation in YAML format |
| **"xml"** | Returns the conversation in XML format |
| **"dict-all-except-first"** | Returns dictionary format excluding the first message |
| **"str-all-except-first"** | Returns string format excluding the first message |
| **"basemodel"** | Returns the conversation as a base model object |
| **"dict-final"** | Returns dictionary format with only the final response |
### `aggregator_model_name: str` (Optional, Default: "anthropic/claude-3-sonnet-20240229")
The model to use for the aggregator agent that synthesizes all the individual agent responses. This should be a model capable of understanding and summarizing complex multi-agent conversations.
## How It Works
1. **Concurrent Execution**: All agents in the `workers` list run the same task simultaneously
@ -102,35 +70,3 @@ result = aggregate(
print(result)
```
## Code Example
## Use Cases
| Use Case | Description |
|----------|-------------|
| **Investment Analysis** | Get multiple financial perspectives on investment decisions |
| **Research Synthesis** | Combine insights from different research agents |
| **Problem Solving** | Gather diverse approaches to complex problems |
| **Content Creation** | Generate comprehensive content from multiple specialized agents |
| **Decision Making** | Get balanced recommendations from different expert perspectives |
## Error Handling
The function includes validation for:
- Required parameters (`task` and `workers`)
- Proper data types (workers must be a list of callable objects)
- Agent compatibility
## Performance Considerations
- All agents run concurrently, so total execution time is limited by the slowest agent
- The aggregator agent processes all responses, so consider response length and complexity
- Memory usage scales with the number of agents and their response sizes

@ -0,0 +1,135 @@
## Interactive Groupchat Examples
The Interactive GroupChat is a powerful multi-agent architecture that enables dynamic collaboration between multiple AI agents. This architecture allows agents to communicate with each other, respond to mentions using `@agent_name` syntax, and work together to solve complex tasks through structured conversation flows.
### Architecture Description
The Interactive GroupChat implements a **collaborative swarm architecture** where multiple specialized agents work together in a coordinated manner. Key features include:
- **Mention-based Communication**: Agents can be directed to specific tasks using `@agent_name` syntax
- **Flexible Speaker Functions**: Multiple speaking order strategies (round robin, random, priority-based)
- **Enhanced Collaboration**: Agents build upon each other's responses and avoid redundancy
- **Interactive Sessions**: Support for both automated and interactive conversation modes
- **Context Awareness**: Agents maintain conversation history and context
For comprehensive documentation on Interactive GroupChat, visit: [Interactive GroupChat Documentation](https://docs.swarms.world/en/latest/swarms/structs/interactive_groupchat/)
### Step-by-Step Showcase
* **Agent Creation**: Define specialized agents with unique expertise and system prompts
* **GroupChat Initialization**: Create the InteractiveGroupChat structure with desired speaker function
* **Task Definition**: Formulate tasks using `@agent_name` mentions to direct specific agents
* **Execution**: Run the group chat to generate collaborative responses
* **Response Processing**: Handle the coordinated output from multiple agents
* **Iteration**: Chain multiple tasks for complex workflows
## Installation
Install the swarms package using pip:
```bash
pip install -U swarms
```
## Basic Setup
1. First, set up your environment variables:
```python
WORKSPACE_DIR="agent_workspace"
OPENAI_API_KEY=""
```
## Code
```python
"""
InteractiveGroupChat Speaker Function Examples
This example demonstrates how to use different speaker functions in the InteractiveGroupChat:
- Round Robin: Agents speak in a fixed order, cycling through the list
- Random: Agents speak in random order
- Priority: Agents speak based on priority weights
- Custom: User-defined speaker functions
The example also shows how agents can mention each other using @agent_name syntax.
"""
from swarms import Agent
from swarms.structs.interactive_groupchat import (
InteractiveGroupChat,
random_speaker,
)
def create_example_agents():
"""Create example agents for demonstration."""
# Create agents with different expertise
analyst = Agent(
agent_name="analyst",
system_prompt="You are a data analyst. You excel at analyzing data, creating charts, and providing insights.",
model_name="gpt-4.1",
streaming_on=True,
print_on=True,
)
researcher = Agent(
agent_name="researcher",
system_prompt="You are a research specialist. You are great at gathering information, fact-checking, and providing detailed research.",
model_name="gpt-4.1",
streaming_on=True,
print_on=True,
)
writer = Agent(
agent_name="writer",
system_prompt="You are a content writer. You excel at writing clear, engaging content and summarizing information.",
model_name="gpt-4.1",
streaming_on=True,
print_on=True,
)
return [analyst, researcher, writer]
def example_random():
agents = create_example_agents()
# Create group chat with random speaker function
group_chat = InteractiveGroupChat(
name="Random Team",
description="A team that speaks in random order",
agents=agents,
speaker_function=random_speaker,
interactive=False,
)
# Test the random behavior
task = "Let's create a marketing strategy. @analyst @researcher @writer please contribute."
response = group_chat.run(task)
print(f"Response:\n{response}\n")
if __name__ == "__main__":
# example_round_robin()
example_random()
```
## Connect With Us
Join our community of agent engineers and researchers for technical support, cutting-edge updates, and exclusive access to world-class agent engineering insights!
| Platform | Description | Link |
|----------|-------------|------|
| 📚 Documentation | Official documentation and guides | [docs.swarms.world](https://docs.swarms.world) |
| 📝 Blog | Latest updates and technical articles | [Medium](https://medium.com/@kyeg) |
| 💬 Discord | Live chat and community support | [Join Discord](https://discord.gg/jM3Z6M9uMq) |
| 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) |
| 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) |
| 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) |
| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) |
| 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) |

@ -1,13 +0,0 @@
from swarms import Agent
# Initialize a new agent
agent = Agent(
model_name="gpt-4o-mini", # Specify the LLM
max_loops=1, # Set the number of interactions
interactive=True, # Enable interactive mode for real-time feedback
streaming_on=True,
print_on=False,
)
# Run the agent with a task
agent.run("What are the key benefits of using a multi-agent system?")
Loading…
Cancel
Save