code cleanup in auto swarm builder

pull/772/head
Kye Gomez 2 months ago
parent 982601614e
commit ed740c6585

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "7.2.6" version = "7.2.7"
description = "Swarms - TGSC" description = "Swarms - TGSC"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"] authors = ["Kye Gomez <kye@apac.ai>"]

@ -257,7 +257,6 @@ class AutoSwarmBuilder:
return agent return agent
# @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
def swarm_router( def swarm_router(
self, self,
agents: List[Agent], agents: List[Agent],
@ -292,14 +291,14 @@ class AutoSwarmBuilder:
) )
example = AutoSwarmBuilder( # example = AutoSwarmBuilder(
name="ChipDesign-Swarm", # name="ChipDesign-Swarm",
description="A swarm of specialized AI agents collaborating on chip architecture, logic design, verification, and optimization to create novel semiconductor designs", # description="A swarm of specialized AI agents collaborating on chip architecture, logic design, verification, and optimization to create novel semiconductor designs",
max_loops=1, # max_loops=1,
) # )
print( # print(
example.run( # example.run(
"Design a new AI accelerator chip optimized for transformer model inference. Consider the following aspects: 1) Overall chip architecture and block diagram 2) Memory hierarchy and interconnects 3) Processing elements and data flow 4) Power and thermal considerations 5) Physical layout recommendations -> " # "Design a new AI accelerator chip optimized for transformer model inference. Consider the following aspects: 1) Overall chip architecture and block diagram 2) Memory hierarchy and interconnects 3) Processing elements and data flow 4) Power and thermal considerations 5) Physical layout recommendations -> "
) # )
) # )

@ -1,23 +1,23 @@
from typing import Callable, Any
import psutil
import asyncio import asyncio
from dataclasses import dataclass
from datetime import datetime
from queue import Queue
from typing import Any, Callable, Dict, List, Optional
import psutil
from rich.console import Console from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.layout import Layout from rich.layout import Layout
from rich.tree import Tree from rich.live import Live
from rich.panel import Panel
from rich.progress import ( from rich.progress import (
Progress, Progress,
TimeElapsedColumn,
TextColumn,
SpinnerColumn, SpinnerColumn,
TextColumn,
TimeElapsedColumn,
) )
from rich.live import Live from rich.table import Table
from rich.text import Text from rich.text import Text
from typing import Dict, Optional, List from rich.tree import Tree
from dataclasses import dataclass
from queue import Queue
from datetime import datetime
try: try:
import pynvml import pynvml
@ -400,107 +400,107 @@ class SwarmVisualizationRich:
await asyncio.sleep(self.refresh_rate) await asyncio.sleep(self.refresh_rate)
# Example usage # # Example usage
if __name__ == "__main__": # if __name__ == "__main__":
# Create swarm metadata # # Create swarm metadata
swarm_metadata = SwarmMetadata( # swarm_metadata = SwarmMetadata(
name="Financial Advisory Swarm", # name="Financial Advisory Swarm",
description="Intelligent swarm for financial analysis and advisory", # description="Intelligent swarm for financial analysis and advisory",
version="1.0.0", # version="1.0.0",
type="hierarchical", # type="hierarchical",
created_at=datetime.now(), # created_at=datetime.now(),
author="AI Research Team", # author="AI Research Team",
# tags=["finance", "analysis", "advisory"], # # tags=["finance", "analysis", "advisory"],
primary_objective="Provide comprehensive financial analysis and recommendations", # primary_objective="Provide comprehensive financial analysis and recommendations",
secondary_objectives=[ # secondary_objectives=[
"Monitor market trends", # "Monitor market trends",
"Analyze competitor behavior", # "Analyze competitor behavior",
"Generate investment strategies", # "Generate investment strategies",
], # ],
) # )
# Create agent hierarchy with detailed parameters # # Create agent hierarchy with detailed parameters
analyst = Agent( # analyst = Agent(
name="Financial Analyst", # name="Financial Analyst",
role="Analysis", # role="Analysis",
description="Analyzes financial data and market trends", # description="Analyzes financial data and market trends",
agent_type="LLM", # agent_type="LLM",
capabilities=[ # capabilities=[
"data analysis", # "data analysis",
"trend detection", # "trend detection",
"risk assessment", # "risk assessment",
], # ],
parameters={"model": "gpt-4", "temperature": 0.7}, # parameters={"model": "gpt-4", "temperature": 0.7},
metadata={ # metadata={
"specialty": "Market Analysis", # "specialty": "Market Analysis",
"confidence_threshold": "0.85", # "confidence_threshold": "0.85",
}, # },
) # )
researcher = Agent( # researcher = Agent(
name="Market Researcher", # name="Market Researcher",
role="Research", # role="Research",
description="Conducts market research and competitor analysis", # description="Conducts market research and competitor analysis",
agent_type="Neural", # agent_type="Neural",
capabilities=[ # capabilities=[
"competitor analysis", # "competitor analysis",
"market sentiment", # "market sentiment",
"trend forecasting", # "trend forecasting",
], # ],
parameters={"batch_size": 32, "learning_rate": 0.001}, # parameters={"batch_size": 32, "learning_rate": 0.001},
metadata={ # metadata={
"data_sources": "Bloomberg, Reuters", # "data_sources": "Bloomberg, Reuters",
"update_frequency": "1h", # "update_frequency": "1h",
}, # },
) # )
advisor = Agent( # advisor = Agent(
name="Investment Advisor", # name="Investment Advisor",
role="Advisory", # role="Advisory",
description="Provides investment recommendations", # description="Provides investment recommendations",
agent_type="Hybrid", # agent_type="Hybrid",
capabilities=[ # capabilities=[
"portfolio optimization", # "portfolio optimization",
"risk management", # "risk management",
"strategy generation", # "strategy generation",
], # ],
parameters={ # parameters={
"risk_tolerance": "moderate", # "risk_tolerance": "moderate",
"time_horizon": "long", # "time_horizon": "long",
}, # },
metadata={ # metadata={
"certification": "CFA Level 3", # "certification": "CFA Level 3",
"specialization": "Equity", # "specialization": "Equity",
}, # },
children=[analyst, researcher], # children=[analyst, researcher],
) # )
# Create visualization # # Create visualization
viz = SwarmVisualizationRich( # viz = SwarmVisualizationRich(
swarm_metadata=swarm_metadata, # swarm_metadata=swarm_metadata,
root_agent=advisor, # root_agent=advisor,
refresh_rate=0.1, # refresh_rate=0.1,
) # )
# Example of streaming output simulation # # Example of streaming output simulation
async def simulate_outputs(): # async def simulate_outputs():
await viz.stream_output( # await viz.stream_output(
advisor, # advisor,
"Analyzing market conditions...\nGenerating investment advice...", # "Analyzing market conditions...\nGenerating investment advice...",
) # )
await viz.stream_output( # await viz.stream_output(
analyst, # analyst,
"Processing financial data...\nIdentifying trends...", # "Processing financial data...\nIdentifying trends...",
) # )
await viz.stream_output( # await viz.stream_output(
researcher, # researcher,
"Researching competitor movements...\nAnalyzing market share...", # "Researching competitor movements...\nAnalyzing market share...",
) # )
# Run the visualization # # Run the visualization
async def main(): # async def main():
viz_task = asyncio.create_task(viz.start()) # viz_task = asyncio.create_task(viz.start())
await simulate_outputs() # await simulate_outputs()
await viz_task # await viz_task
asyncio.run(main()) # asyncio.run(main())
Loading…
Cancel
Save