Skip to content

Commit

Permalink
router_concurrent doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
Occupying-Mars committed Nov 9, 2024
1 parent e9818db commit 5b313ec
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 20 deletions.
13 changes: 13 additions & 0 deletions docs/swarms/structs/concurrentworkflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,16 @@ except ValueError as e:
- [Pydantic Documentation](https://pydantic-docs.helpmanual.io/)
- [ThreadPoolExecutor in Python](https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor)
- [Loguru for Logging in Python](https://loguru.readthedocs.io/en/stable/)

### Agent Configuration Parameters

When initializing agents for use with ConcurrentWorkflow, the following additional parameters are available:

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `autosave` | `bool` | `True` | Whether to automatically save the agent's state |
| `dashboard` | `bool` | `False` | Whether to enable dashboard visualization |
| `verbose` | `bool` | `True` | Whether to output detailed logging information |
| `context_length` | `int` | `200000` | Maximum context length for the agent |
| `return_step_meta` | `bool` | `False` | Whether to return metadata for each step |
| `user_name` | `str` | `"swarms_corp"` | Default username for the agent |
75 changes: 55 additions & 20 deletions docs/swarms/structs/swarm_router.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@

## Overview

The `SwarmRouter` class is a flexible routing system designed to manage different types of swarms for task execution. It provides a unified interface to interact with various swarm types, including `AgentRearrange`, `MixtureOfAgents`, `SpreadSheetSwarm`, `SequentialWorkflow`, and `ConcurrentWorkflow`. We will be continously adding more and more swarm architectures here as we progress with new architectures.
The `SwarmRouter` class is a flexible routing system designed to manage different
types of swarms for task execution. It provides a unified interface to interact with
various swarm types, including `AgentRearrange`, `MixtureOfAgents`,
`SpreadSheetSwarm`, `SequentialWorkflow`, and `ConcurrentWorkflow`. We will be
continously adding more and more swarm architectures here as we progress with new
architectures.
## Types

### SwarmType
A literal type that can be one of:
```python
SwarmType = Literal[
"AgentRearrange",
"MixtureOfAgents",
"SpreadSheetSwarm",
"SequentialWorkflow",
"ConcurrentWorkflow",
]
```

## Classes

Expand All @@ -11,33 +29,50 @@ The `SwarmRouter` class is a flexible routing system designed to manage differen
A Pydantic model for capturing log entries.

#### Attributes:
- `id` (str): Unique identifier for the log entry.
- `timestamp` (datetime): Time of log creation.
- `level` (str): Log level (e.g., "info", "error").
- `message` (str): Log message content.
- `swarm_type` (SwarmType): Type of swarm associated with the log.
- `task` (str): Task being performed (optional).
- `metadata` (Dict[str, Any]): Additional metadata (optional).
- `id` (str): Unique identifier generated using UUID4
- `timestamp` (datetime): UTC timestamp of log creation
- `level` (str): Log level (e.g., "info", "error", "success")
- `message` (str): Log message content
- `swarm_type` (SwarmType): Type of swarm associated with the log
- `task` (str): Task being performed (optional, defaults to "")
- `metadata` (Dict[str, Any]): Additional metadata (optional, defaults to empty dict)

### SwarmRouter

Main class for routing tasks to different swarm types.

#### Attributes:
- `name` (str): Name of the SwarmRouter instance.
- `description` (str): Description of the SwarmRouter instance.
- `max_loops` (int): Maximum number of loops to perform.
- `agents` (List[Agent]): List of Agent objects to be used in the swarm.
- `swarm_type` (SwarmType): Type of swarm to be used.
- `swarm` (Union[AgentRearrange, MixtureOfAgents, SpreadSheetSwarm, SequentialWorkflow, ConcurrentWorkflow]): Instantiated swarm object.
#### Parameters:
- `name` (str, optional): Name of the SwarmRouter instance. Defaults to "swarm-router"
- `description` (str, optional): Description of the SwarmRouter instance. Defaults to "Routes your task to the desired swarm"
- `max_loops` (int, optional): Maximum number of loops to perform. Defaults to 1
- `agents` (List[Agent]): List of Agent objects to be used in the swarm
- `swarm_type` (SwarmType): Type of swarm to be used
- `swarm` (Union[AgentRearrange, MixtureOfAgents, SpreadSheetSwarm,
SequentialWorkflow, ConcurrentWorkflow]): Instantiated swarm object.
- `logs` (List[SwarmLog]): List of log entries captured during operations.

#### Methods:
- `__init__(self, name: str, description: str, max_loops: int, agents: List[Agent], swarm_type: SwarmType, *args, **kwargs)`: Initialize the SwarmRouter.
- `_create_swarm(self, *args, **kwargs)`: Create and return the specified swarm type.
- `_log(self, level: str, message: str, task: str, metadata: Dict[str, Any])`: Create a log entry and add it to the logs list.
- `run(self, task: str, *args, **kwargs)`: Run the specified task on the selected swarm.
- `get_logs(self)`: Retrieve all logged entries.
- `__init__`: Initialize the SwarmRouter
- `_create_swarm`: Create and return the specified swarm type
- `_log`: Create a log entry and add it to the logs list
- `run`: Run the specified task on the selected swarm
- `get_logs`: Retrieve all logged entries

### Log Levels
The SwarmRouter supports the following log levels:
- "info": General information
- "error": Error messages
- "success": Successful task completion

### Error Handling

The SwarmRouter includes several validation checks that may raise ValueError:
- If no agents are provided (`agents` is None or empty)
- If swarm type is None
- If max_loops is 0
- If an invalid swarm type is provided

Additionally, any exceptions during task execution are logged and re-raised.

## Installation

Expand Down

0 comments on commit 5b313ec

Please sign in to comment.