pull/707/head
Kye Gomez 4 months ago
parent 75b196862f
commit 17e2933b29

@ -29,8 +29,6 @@ from pydantic import BaseModel, Field
from swarms.structs.agent import Agent from swarms.structs.agent import Agent
# Original API, drafting OpenTelemetry Integrations in this directory
# Load environment variables # Load environment variables
load_dotenv() load_dotenv()

@ -1,3 +1,5 @@
name: agentapi
service: service:
readiness_probe: readiness_probe:
path: /docs path: /docs
@ -11,14 +13,19 @@ service:
upscale_delay_seconds: 180 upscale_delay_seconds: 180
downscale_delay_seconds: 600 downscale_delay_seconds: 600
envs:
WORKSPACE_DIR: "agent_workspace"
OPENAI_API_KEY: ""
resources: resources:
ports: 8000 # FastAPI default port ports: 8000 # FastAPI default port
cpus: 16 cpus: 16
memory: 64 memory: 64
disk_size: 100 disk_size: 50
use_spot: true use_spot: true
workdir: /app workdir: .
setup: | setup: |
git clone https://github.com/kyegomez/swarms.git git clone https://github.com/kyegomez/swarms.git
@ -27,7 +34,6 @@ setup: |
pip install swarms pip install swarms
run: | run: |
cd swarms/api
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4 uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4
# env: # env:

@ -1,12 +1,11 @@
import asyncio import asyncio
import json import json
import uuid import os
from datetime import datetime
import aiohttp
import sys import sys
from typing import Dict, Any, Optional from typing import Any, Dict
import aiohttp
from loguru import logger from loguru import logger
import os
# Configure loguru # Configure loguru
LOG_PATH = "api_tests.log" LOG_PATH = "api_tests.log"
@ -17,7 +16,7 @@ logger.add(LOG_PATH,
level="DEBUG" level="DEBUG"
) )
BASE_URL = "https://dev.api.swarms.ai/v1" # Change this to match your server URL BASE_URL = "https://api.swarms.ai/v1" # Change this to match your server URL
async def log_request_details(method: str, url: str, headers: dict, data: Any = None): async def log_request_details(method: str, url: str, headers: dict, data: Any = None):
"""Log request details before sending.""" """Log request details before sending."""
@ -249,7 +248,7 @@ def main():
asyncio.run(run_tests()) asyncio.run(run_tests())
except KeyboardInterrupt: except KeyboardInterrupt:
logger.warning("Test execution interrupted by user.") logger.warning("Test execution interrupted by user.")
except Exception as e: except Exception:
logger.exception("Fatal error in test execution:") logger.exception("Fatal error in test execution:")
finally: finally:
logger.info("Test suite shutdown complete.") logger.info("Test suite shutdown complete.")

@ -29,7 +29,7 @@ A production-grade multi-agent system enabling sophisticated group conversations
| description | str | "" | Purpose description | | description | str | "" | Purpose description |
| agents | List[Agent] | [] | Participating agents | | agents | List[Agent] | [] | Participating agents |
| speaker_fn | Callable | round_robin | Speaker selection function | | speaker_fn | Callable | round_robin | Speaker selection function |
| max_turns | int | 10 | Maximum conversation turns | | max_loops | int | 10 | Maximum conversation turns |
## Table of Contents ## Table of Contents
@ -272,7 +272,7 @@ analysis_team = GroupChat(
description="Comprehensive market analysis group", description="Comprehensive market analysis group",
agents=[data_analyst, market_expert, strategy_advisor], agents=[data_analyst, market_expert, strategy_advisor],
speaker_fn=expertise_based, speaker_fn=expertise_based,
max_turns=15 max_loops=15
) )
# Run complex analysis # Run complex analysis

@ -111,6 +111,9 @@ class ExecutionContext:
history: List[Dict[str, Any]] = field(default_factory=list) history: List[Dict[str, Any]] = field(default_factory=list)
def func():
pass
hints = get_type_hints(func) hints = get_type_hints(func)

@ -63,7 +63,7 @@ class SpeakerMessage(BaseModel):
class GroupChatConfig(BaseModel): class GroupChatConfig(BaseModel):
max_turns: int = 10 max_loops: int = 10
timeout_per_turn: float = 30.0 timeout_per_turn: float = 30.0
require_all_speakers: bool = False require_all_speakers: bool = False
allow_concurrent: bool = True allow_concurrent: bool = True
@ -309,7 +309,7 @@ class AsyncWorkflow(BaseWorkflow):
messages: List[SpeakerMessage] = [] messages: List[SpeakerMessage] = []
current_turn = 0 current_turn = 0
while current_turn < self.group_chat_config.max_turns: while current_turn < self.group_chat_config.max_loops:
turn_context = { turn_context = {
"turn": current_turn, "turn": current_turn,
"history": messages, "history": messages,
@ -627,7 +627,7 @@ def create_default_workflow(
verbose=True, verbose=True,
enable_group_chat=enable_group_chat, enable_group_chat=enable_group_chat,
group_chat_config=GroupChatConfig( group_chat_config=GroupChatConfig(
max_turns=5, max_loops=5,
allow_concurrent=True, allow_concurrent=True,
require_all_speakers=False, require_all_speakers=False,
), ),

@ -123,7 +123,7 @@ class GroupChat:
description: str = "A group chat for multiple agents", description: str = "A group chat for multiple agents",
agents: List[Agent] = [], agents: List[Agent] = [],
speaker_fn: SpeakerFunction = round_robin, speaker_fn: SpeakerFunction = round_robin,
max_turns: int = 10, max_loops: int = 10,
): ):
""" """
Initialize the GroupChat. Initialize the GroupChat.
@ -133,13 +133,13 @@ class GroupChat:
description (str): Description of the purpose of the group chat. description (str): Description of the purpose of the group chat.
agents (List[Agent]): A list of agents participating in the chat. agents (List[Agent]): A list of agents participating in the chat.
speaker_fn (SpeakerFunction): The function to determine which agent should speak next. speaker_fn (SpeakerFunction): The function to determine which agent should speak next.
max_turns (int): Maximum number of turns in the chat. max_loops (int): Maximum number of turns in the chat.
""" """
self.name = name self.name = name
self.description = description self.description = description
self.agents = agents self.agents = agents
self.speaker_fn = speaker_fn self.speaker_fn = speaker_fn
self.max_turns = max_turns self.max_loops = max_loops
self.chat_history = ChatHistory( self.chat_history = ChatHistory(
turns=[], turns=[],
total_messages=0, total_messages=0,
@ -237,7 +237,7 @@ class GroupChat:
f"Starting chat '{self.name}' with task: {task}" f"Starting chat '{self.name}' with task: {task}"
) )
for turn in range(self.max_turns): for turn in range(self.max_loops):
current_turn = ChatTurn( current_turn = ChatTurn(
turn_number=turn, responses=[], task=task turn_number=turn, responses=[], task=task
) )

@ -63,12 +63,12 @@ def test_expertise_based_speaking():
assert first_response.agent_name == agent.agent_name assert first_response.agent_name == agent.agent_name
def test_max_turns_limit(): def test_max_loops_limit():
max_turns = 3 max_loops = 3
chat = GroupChat(agents=setup_test_agents(), max_turns=max_turns) chat = GroupChat(agents=setup_test_agents(), max_loops=max_loops)
history = chat.run("Test message") history = chat.run("Test message")
assert len(history.turns) == max_turns assert len(history.turns) == max_loops
def test_error_handling(): def test_error_handling():
@ -106,7 +106,7 @@ def test_large_agent_group():
def test_long_conversations(): def test_long_conversations():
chat = GroupChat(agents=setup_test_agents(), max_turns=50) chat = GroupChat(agents=setup_test_agents(), max_loops=50)
history = chat.run("Long conversation test") history = chat.run("Long conversation test")
assert len(history.turns) == 50 assert len(history.turns) == 50
@ -130,7 +130,7 @@ if __name__ == "__main__":
test_round_robin_speaking, test_round_robin_speaking,
test_concurrent_processing, test_concurrent_processing,
test_expertise_based_speaking, test_expertise_based_speaking,
test_max_turns_limit, test_max_loops_limit,
test_error_handling, test_error_handling,
test_conversation_context, test_conversation_context,
test_large_agent_group, test_large_agent_group,

Loading…
Cancel
Save