Integrate LLMCouncil into SwarmRouter

pull/1182/head^2
Kye Gomez 3 days ago
parent f703f2525b
commit f73b4f6b07

@ -42,6 +42,7 @@ Main class for routing tasks to different swarm types.
| `verbose` | bool | Flag to enable/disable verbose logging (default: False) | | `verbose` | bool | Flag to enable/disable verbose logging (default: False) |
| `worker_tools` | List[Callable] | List of tools available to worker agents | | `worker_tools` | List[Callable] | List of tools available to worker agents |
| `aggregation_strategy` | str | Aggregation strategy for HeavySwarm (default: "synthesis") | | `aggregation_strategy` | str | Aggregation strategy for HeavySwarm (default: "synthesis") |
| `chairman_model` | str | Model name for the Chairman in LLMCouncil (default: "gpt-5.1") |
### Methods ### Methods
@ -123,6 +124,7 @@ The `SwarmRouter` supports many various multi-agent architectures for various ap
| `InteractiveGroupChat` | Interactive group chat with user participation | | `InteractiveGroupChat` | Interactive group chat with user participation |
| `HeavySwarm` | Heavy swarm architecture with question and worker agents | | `HeavySwarm` | Heavy swarm architecture with question and worker agents |
| `BatchedGridWorkflow` | Batched grid workflow for parallel task processing | | `BatchedGridWorkflow` | Batched grid workflow for parallel task processing |
| `LLMCouncil` | Council of specialized LLM agents with peer review and synthesis |
| `auto` | Automatically selects best swarm type via embedding search | | `auto` | Automatically selects best swarm type via embedding search |
## Basic Usage ## Basic Usage
@ -456,6 +458,30 @@ result = batched_grid_router.run(tasks=["Task 1", "Task 2", "Task 3"])
BatchedGridWorkflow is designed for efficiently processing multiple tasks in parallel batches, optimizing resource utilization. BatchedGridWorkflow is designed for efficiently processing multiple tasks in parallel batches, optimizing resource utilization.
### LLMCouncil
Use Case: Collaborative analysis with multiple specialized LLM agents that evaluate each other's responses and synthesize a final answer.
```python
llm_council_router = SwarmRouter(
name="LLMCouncil",
description="Collaborative council of LLM agents with peer review",
swarm_type="LLMCouncil",
chairman_model="gpt-5.1", # Model for the Chairman agent
output_type="dict", # Output format: "dict", "list", "string", "json", "yaml", "final", etc.
verbose=True # Show progress and intermediate results
)
result = llm_council_router.run("What are the top five best energy stocks across nuclear, solar, gas, and other energy sources?")
```
LLMCouncil creates a council of specialized agents (GPT-5.1, Gemini, Claude, Grok by default) that:
1. Each independently responds to the query
2. Evaluates and ranks each other's anonymized responses
3. A Chairman synthesizes all responses and evaluations into a final comprehensive answer
The council automatically tracks all messages in a conversation object and supports flexible output formats. Note: LLMCouncil uses default council members and doesn't require the `agents` parameter.
## Advanced Features ## Advanced Features
### Processing Documents ### Processing Documents

@ -502,3 +502,15 @@ class LLMCouncil:
return history_output_formatter( return history_output_formatter(
conversation=self.conversation, type=self.output_type conversation=self.conversation, type=self.output_type
) )
def batched_run(self, tasks: List[str]):
"""
Run the LLM Council workflow for a batch of tasks.
Args:
tasks: List of tasks to process
Returns:
List of formatted outputs based on output_type
"""
return [self.run(task) for task in tasks]

@ -37,6 +37,7 @@ from swarms.telemetry.log_executions import log_execution
from swarms.utils.generate_keys import generate_api_key from swarms.utils.generate_keys import generate_api_key
from swarms.utils.loguru_logger import initialize_logger from swarms.utils.loguru_logger import initialize_logger
from swarms.utils.output_types import OutputType from swarms.utils.output_types import OutputType
from swarms.structs.llm_council import LLMCouncil
logger = initialize_logger(log_folder="swarm_router") logger = initialize_logger(log_folder="swarm_router")
@ -56,6 +57,7 @@ SwarmType = Literal[
"InteractiveGroupChat", "InteractiveGroupChat",
"HeavySwarm", "HeavySwarm",
"BatchedGridWorkflow", "BatchedGridWorkflow",
"LLMCouncil",
] ]
@ -210,6 +212,7 @@ class SwarmRouter:
verbose: bool = False, verbose: bool = False,
worker_tools: List[Callable] = None, worker_tools: List[Callable] = None,
aggregation_strategy: str = "synthesis", aggregation_strategy: str = "synthesis",
chairman_model: str = "gpt-5.1",
*args, *args,
**kwargs, **kwargs,
): ):
@ -252,6 +255,7 @@ class SwarmRouter:
self.heavy_swarm_swarm_show_output = ( self.heavy_swarm_swarm_show_output = (
heavy_swarm_swarm_show_output heavy_swarm_swarm_show_output
) )
self.chairman_model = chairman_model
# Initialize swarm factory for O(1) lookup performance # Initialize swarm factory for O(1) lookup performance
self._swarm_factory = self._initialize_swarm_factory() self._swarm_factory = self._initialize_swarm_factory()
@ -425,6 +429,7 @@ class SwarmRouter:
"SequentialWorkflow": self._create_sequential_workflow, "SequentialWorkflow": self._create_sequential_workflow,
"ConcurrentWorkflow": self._create_concurrent_workflow, "ConcurrentWorkflow": self._create_concurrent_workflow,
"BatchedGridWorkflow": self._create_batched_grid_workflow, "BatchedGridWorkflow": self._create_batched_grid_workflow,
"LLMCouncil": self._create_llm_council,
} }
def _create_heavy_swarm(self, *args, **kwargs): def _create_heavy_swarm(self, *args, **kwargs):
@ -442,6 +447,16 @@ class SwarmRouter:
show_dashboard=False, show_dashboard=False,
) )
def _create_llm_council(self, *args, **kwargs):
"""Factory function for LLMCouncil."""
return LLMCouncil(
name=self.name,
description=self.description,
output_type=self.output_type,
verbose=self.verbose,
chairman_model=self.chairman_model,
)
def _create_agent_rearrange(self, *args, **kwargs): def _create_agent_rearrange(self, *args, **kwargs):
"""Factory function for AgentRearrange.""" """Factory function for AgentRearrange."""
return AgentRearrange( return AgentRearrange(

Loading…
Cancel
Save