-
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import asyncio | ||
import json | ||
import secrets | ||
import time | ||
from concurrent.futures import ThreadPoolExecutor, TimeoutError | ||
from contextlib import contextmanager | ||
|
@@ -11,15 +10,10 @@ | |
from cryptography.fernet import Fernet | ||
from loguru import logger | ||
from prometheus_client import Counter, Histogram, start_http_server | ||
from pydantic import BaseModel, Field, validator | ||
from pydantic import BaseModel, Field | ||
from pydantic.v1 import validator | ||
from tenacity import retry, stop_after_attempt, wait_exponential | ||
|
||
from swarms.prompts.finance_agent_sys_prompt import ( | ||
FINANCIAL_AGENT_SYS_PROMPT, | ||
) | ||
from swarms.structs.agent import Agent | ||
|
||
|
||
# Enhanced metrics | ||
TASK_COUNTER = Counter( | ||
"swarm_tasks_total", "Total number of tasks processed" | ||
|
@@ -409,67 +403,67 @@ def __exit__(self, exc_type, exc_val, exc_tb): | |
logger.error(f"Error during cleanup: {str(e)}") | ||
|
||
|
||
if __name__ == "__main__": | ||
# Example usage with security configuration | ||
security_config = SecurityConfig( | ||
encryption_key=secrets.token_urlsafe(32), | ||
tls_cert_path="/path/to/cert.pem", | ||
tls_key_path="/path/to/key.pem", | ||
auth_token="your-auth-token", | ||
max_message_size=1048576, | ||
rate_limit=100, | ||
) | ||
|
||
# Agent factory function | ||
def create_financial_agent() -> Agent: | ||
"""Factory function to create a financial analysis agent.""" | ||
return Agent( | ||
agent_name="Financial-Analysis-Agent", | ||
system_prompt=FINANCIAL_AGENT_SYS_PROMPT, | ||
model_name="gpt-4o-mini", | ||
max_loops=1, | ||
autosave=True, | ||
dashboard=False, | ||
verbose=True, | ||
dynamic_temperature_enabled=True, | ||
saved_state_path="finance_agent.json", | ||
user_name="swarms_corp", | ||
retry_attempts=1, | ||
context_length=200000, | ||
return_step_meta=False, | ||
output_type="string", | ||
streaming_on=False, | ||
) | ||
|
||
# Initialize agents (implementation not shown) | ||
agents = [create_financial_agent() for _ in range(3)] | ||
|
||
# Initialize the secure swarm | ||
with SecurePulsarSwarm( | ||
name="Secure Financial Swarm", | ||
description="Production-grade financial analysis swarm", | ||
agents=agents, | ||
pulsar_url="pulsar+ssl://localhost:6651", | ||
subscription_name="secure_financial_subscription", | ||
topic_name="secure_financial_tasks", | ||
security_config=security_config, | ||
max_workers=5, | ||
retry_attempts=3, | ||
task_timeout=300, | ||
metrics_port=8000, | ||
) as swarm: | ||
# Example task | ||
task = Task( | ||
task_id=secrets.token_urlsafe(16), | ||
description="Analyze Q4 financial reports", | ||
output_type="json", | ||
priority="high", | ||
metadata={ | ||
"department": "finance", | ||
"requester": "[email protected]", | ||
}, | ||
) | ||
|
||
# Run the swarm | ||
swarm.publish_task(task) | ||
asyncio.run(swarm.consume_tasks()) | ||
# if __name__ == "__main__": | ||
# # Example usage with security configuration | ||
# security_config = SecurityConfig( | ||
# encryption_key=secrets.token_urlsafe(32), | ||
# tls_cert_path="/path/to/cert.pem", | ||
# tls_key_path="/path/to/key.pem", | ||
# auth_token="your-auth-token", | ||
# max_message_size=1048576, | ||
# rate_limit=100, | ||
# ) | ||
|
||
# # Agent factory function | ||
# def create_financial_agent() -> Agent: | ||
# """Factory function to create a financial analysis agent.""" | ||
# return Agent( | ||
# agent_name="Financial-Analysis-Agent", | ||
# system_prompt=FINANCIAL_AGENT_SYS_PROMPT, | ||
# model_name="gpt-4o-mini", | ||
# max_loops=1, | ||
# autosave=True, | ||
# dashboard=False, | ||
# verbose=True, | ||
# dynamic_temperature_enabled=True, | ||
# saved_state_path="finance_agent.json", | ||
# user_name="swarms_corp", | ||
# retry_attempts=1, | ||
# context_length=200000, | ||
# return_step_meta=False, | ||
# output_type="string", | ||
# streaming_on=False, | ||
# ) | ||
|
||
# # Initialize agents (implementation not shown) | ||
# agents = [create_financial_agent() for _ in range(3)] | ||
|
||
# # Initialize the secure swarm | ||
# with SecurePulsarSwarm( | ||
# name="Secure Financial Swarm", | ||
# description="Production-grade financial analysis swarm", | ||
# agents=agents, | ||
# pulsar_url="pulsar+ssl://localhost:6651", | ||
# subscription_name="secure_financial_subscription", | ||
# topic_name="secure_financial_tasks", | ||
# security_config=security_config, | ||
# max_workers=5, | ||
# retry_attempts=3, | ||
# task_timeout=300, | ||
# metrics_port=8000, | ||
# ) as swarm: | ||
# # Example task | ||
# task = Task( | ||
# task_id=secrets.token_urlsafe(16), | ||
# description="Analyze Q4 financial reports", | ||
# output_type="json", | ||
# priority="high", | ||
# metadata={ | ||
# "department": "finance", | ||
# "requester": "[email protected]", | ||
# }, | ||
# ) | ||
|
||
# # Run the swarm | ||
# swarm.publish_task(task) | ||
# asyncio.run(swarm.consume_tasks()) |