router_concurrent doc update

pull/624/head
Occupying-Mars 5 months ago
parent e9818dbbe0
commit 5b313ecbfa

@ -294,3 +294,16 @@ except ValueError as e:
- [Pydantic Documentation](https://pydantic-docs.helpmanual.io/) - [Pydantic Documentation](https://pydantic-docs.helpmanual.io/)
- [ThreadPoolExecutor in Python](https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor) - [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/) - [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 |

@ -2,7 +2,25 @@
## Overview ## 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 ## Classes
@ -11,33 +29,50 @@ The `SwarmRouter` class is a flexible routing system designed to manage differen
A Pydantic model for capturing log entries. A Pydantic model for capturing log entries.
#### Attributes: #### Attributes:
- `id` (str): Unique identifier for the log entry. - `id` (str): Unique identifier generated using UUID4
- `timestamp` (datetime): Time of log creation. - `timestamp` (datetime): UTC timestamp of log creation
- `level` (str): Log level (e.g., "info", "error"). - `level` (str): Log level (e.g., "info", "error", "success")
- `message` (str): Log message content. - `message` (str): Log message content
- `swarm_type` (SwarmType): Type of swarm associated with the log. - `swarm_type` (SwarmType): Type of swarm associated with the log
- `task` (str): Task being performed (optional). - `task` (str): Task being performed (optional, defaults to "")
- `metadata` (Dict[str, Any]): Additional metadata (optional). - `metadata` (Dict[str, Any]): Additional metadata (optional, defaults to empty dict)
### SwarmRouter ### SwarmRouter
Main class for routing tasks to different swarm types. Main class for routing tasks to different swarm types.
#### Attributes: #### Parameters:
- `name` (str): Name of the SwarmRouter instance. - `name` (str, optional): Name of the SwarmRouter instance. Defaults to "swarm-router"
- `description` (str): Description of the SwarmRouter instance. - `description` (str, optional): Description of the SwarmRouter instance. Defaults to "Routes your task to the desired swarm"
- `max_loops` (int): Maximum number of loops to perform. - `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. - `agents` (List[Agent]): List of Agent objects to be used in the swarm
- `swarm_type` (SwarmType): Type of swarm to be used. - `swarm_type` (SwarmType): Type of swarm to be used
- `swarm` (Union[AgentRearrange, MixtureOfAgents, SpreadSheetSwarm, SequentialWorkflow, ConcurrentWorkflow]): Instantiated swarm object. - `swarm` (Union[AgentRearrange, MixtureOfAgents, SpreadSheetSwarm,
SequentialWorkflow, ConcurrentWorkflow]): Instantiated swarm object.
- `logs` (List[SwarmLog]): List of log entries captured during operations. - `logs` (List[SwarmLog]): List of log entries captured during operations.
#### Methods: #### Methods:
- `__init__(self, name: str, description: str, max_loops: int, agents: List[Agent], swarm_type: SwarmType, *args, **kwargs)`: Initialize the SwarmRouter. - `__init__`: Initialize the SwarmRouter
- `_create_swarm(self, *args, **kwargs)`: Create and return the specified swarm type. - `_create_swarm`: 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. - `_log`: 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. - `run`: Run the specified task on the selected swarm
- `get_logs(self)`: Retrieve all logged entries. - `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 ## Installation

Loading…
Cancel
Save