parent
a9ae4cd222
commit
fcf52332d1
@ -0,0 +1,72 @@
|
|||||||
|
# The Swarms Index
|
||||||
|
|
||||||
|
The Swarms Index is a comprehensive catalog of repositories under The Swarm Corporation, showcasing a wide array of tools, frameworks, and templates designed for building, deploying, and managing autonomous AI agents and multi-agent systems. These repositories focus on enterprise-grade solutions, spanning industries like healthcare, finance, marketing, and more, with an emphasis on scalability, security, and performance. Many repositories include templates to help developers quickly set up production-ready applications.
|
||||||
|
|
||||||
|
| Name | Description | Link |
|
||||||
|
|------|-------------|------|
|
||||||
|
| Phala-Deployment-Template | A guide and template for running Swarms Agents in a Trusted Execution Environment (TEE) using Phala Cloud, ensuring secure and isolated execution. | [https://github.com/The-Swarm-Corporation/Phala-Deployment-Template](https://github.com/The-Swarm-Corporation/Phala-Deployment-Template) |
|
||||||
|
| Swarms-API-Status-Page | A status page for monitoring the health and performance of the Swarms API. | [https://github.com/The-Swarm-Corporation/Swarms-API-Status-Page](https://github.com/The-Swarm-Corporation/Swarms-API-Status-Page) |
|
||||||
|
| Swarms-API-Phala-Template | A deployment solution template for running Swarms API on Phala Cloud, optimized for secure and scalable agent orchestration. | [https://github.com/The-Swarm-Corporation/Swarms-API-Phala-Template](https://github.com/The-Swarm-Corporation/Swarms-API-Phala-Template) |
|
||||||
|
| DevSwarm | Develop production-grade applications effortlessly with a single prompt, powered by a swarm of v0-driven autonomous agents operating 24/7 for fully autonomous software development. | [https://github.com/The-Swarm-Corporation/DevSwarm](https://github.com/The-Swarm-Corporation/DevSwarm) |
|
||||||
|
| Enterprise-Grade-Agents-Course | A comprehensive course teaching students to build, deploy, and manage autonomous agents for enterprise workflows using the Swarms library, focusing on scalability and integration. | [https://github.com/The-Swarm-Corporation/Enterprise-Grade-Agents-Course](https://github.com/The-Swarm-Corporation/Enterprise-Grade-Agents-Course) |
|
||||||
|
| agentverse | A collection of agents from top frameworks like Langchain, Griptape, and CrewAI, integrated into the Swarms ecosystem. | [https://github.com/The-Swarm-Corporation/agentverse](https://github.com/The-Swarm-Corporation/agentverse) |
|
||||||
|
| InsuranceSwarm | A swarm of agents to automate document processing and fraud detection in insurance claims. | [https://github.com/The-Swarm-Corporation/InsuranceSwarm](https://github.com/The-Swarm-Corporation/InsuranceSwarm) |
|
||||||
|
| swarms-examples | A vast array of examples for enterprise-grade and production-ready applications using the Swarms framework. | [https://github.com/The-Swarm-Corporation/swarms-examples](https://github.com/The-Swarm-Corporation/swarms-examples) |
|
||||||
|
| auto-ai-research-team | Automates AI research at an OpenAI level to accelerate innovation using swarms of agents. | [https://github.com/The-Swarm-Corporation/auto-ai-research-team](https://github.com/The-Swarm-Corporation/auto-ai-research-team) |
|
||||||
|
| Agents-Beginner-Guide | A definitive beginner's guide to AI agents and multi-agent systems, explaining fundamentals and industry applications. | [https://github.com/The-Swarm-Corporation/Agents-Beginner-Guide](https://github.com/The-Swarm-Corporation/Agents-Beginner-Guide) |
|
||||||
|
| Solana-Ecosystem-MCP | A collection of Solana tools wrapped in MCP servers for blockchain development. | [https://github.com/The-Swarm-Corporation/Solana-Ecosystem-MCP](https://github.com/The-Swarm-Corporation/Solana-Ecosystem-MCP) |
|
||||||
|
| automated-crypto-fund | A fully automated crypto fund leveraging swarms of LLM agents for real-money trading. | [https://github.com/The-Swarm-Corporation/automated-crypto-fund](https://github.com/The-Swarm-Corporation/automated-crypto-fund) |
|
||||||
|
| Mryaid | The first multi-agent social media platform powered by Swarms. | [https://github.com/The-Swarm-Corporation/Mryaid](https://github.com/The-Swarm-Corporation/Mryaid) |
|
||||||
|
| pharma-swarm | A swarm of autonomous agents for chemical analysis in the pharmaceutical industry. | [https://github.com/The-Swarm-Corporation/pharma-swarm](https://github.com/The-Swarm-Corporation/pharma-swarm) |
|
||||||
|
| Automated-Prompt-Engineering-Hub | A hub for tools and resources focused on automated prompt engineering for generative AI. | [https://github.com/The-Swarm-Corporation/Automated-Prompt-Engineering-Hub](https://github.com/The-Swarm-Corporation/Automated-Prompt-Engineering-Hub) |
|
||||||
|
| Multi-Agent-Template-App | A simple, reliable, and high-performance template for building multi-agent applications. | [https://github.com/The-Swarm-Corporation/Multi-Agent-Template-App](https://github.com/The-Swarm-Corporation/Multi-Agent-Template-App) |
|
||||||
|
| Cookbook | Examples and guides for using the Swarms Framework effectively. | [https://github.com/The-Swarm-Corporation/Cookbook](https://github.com/The-Swarm-Corporation/Cookbook) |
|
||||||
|
| SwarmDB | A production-grade message queue system for agent communication and LLM backend load balancing. | [https://github.com/The-Swarm-Corporation/SwarmDB](https://github.com/The-Swarm-Corporation/SwarmDB) |
|
||||||
|
| CryptoTaxSwarm | A personal advisory tax swarm for cryptocurrency transactions. | [https://github.com/The-Swarm-Corporation/CryptoTaxSwarm](https://github.com/The-Swarm-Corporation/CryptoTaxSwarm) |
|
||||||
|
| Multi-Agent-Marketing-Course | A course on automating marketing operations with enterprise-grade multi-agent collaboration. | [https://github.com/The-Swarm-Corporation/Multi-Agent-Marketing-Course](https://github.com/The-Swarm-Corporation/Multi-Agent-Marketing-Course) |
|
||||||
|
| Swarms-BrandBook | Branding guidelines and assets for Swarms.ai, embodying innovation and collaboration. | [https://github.com/The-Swarm-Corporation/Swarms-BrandBook](https://github.com/The-Swarm-Corporation/Swarms-BrandBook) |
|
||||||
|
| AgentAPI | A definitive API for managing and interacting with AI agents. | [https://github.com/The-Swarm-Corporation/AgentAPI](https://github.com/The-Swarm-Corporation/AgentAPI) |
|
||||||
|
| Research-Paper-Writer-Swarm | Automates the creation of high-quality research papers in LaTeX using Swarms agents. | [https://github.com/The-Swarm-Corporation/Research-Paper-Writer-Swarm](https://github.com/The-Swarm-Corporation/Research-Paper-Writer-Swarm) |
|
||||||
|
| swarms-sdk | A Python client for the Swarms API, providing a simple interface for managing AI swarms. | [https://github.com/The-Swarm-Corporation/swarms-sdk](https://github.com/The-Swarm-Corporation/swarms-sdk) |
|
||||||
|
| FluidAPI | A framework for interacting with APIs using natural language, simplifying complex requests. | [https://github.com/The-Swarm-Corporation/FluidAPI](https://github.com/The-Swarm-Corporation/FluidAPI) |
|
||||||
|
| MedicalCoderSwarm | A multi-agent system for comprehensive medical diagnosis and coding using specialized AI agents. | [https://github.com/The-Swarm-Corporation/MedicalCoderSwarm](https://github.com/The-Swarm-Corporation/MedicalCoderSwarm) |
|
||||||
|
| BackTesterAgent | An AI-powered backtesting framework for automated trading strategy validation and optimization. | [https://github.com/The-Swarm-Corporation/BackTesterAgent](https://github.com/The-Swarm-Corporation/BackTesterAgent) |
|
||||||
|
| .ai | The first natural language programming language powered by Swarms. | [https://github.com/The-Swarm-Corporation/.ai](https://github.com/The-Swarm-Corporation/.ai) |
|
||||||
|
| AutoHedge | An autonomous hedge fund leveraging swarm intelligence for market analysis and trade execution. | [https://github.com/The-Swarm-Corporation/AutoHedge](https://github.com/The-Swarm-Corporation/AutoHedge) |
|
||||||
|
| radiology-swarm | A multi-agent system for advanced radiological analysis, diagnosis, and treatment planning. | [https://github.com/The-Swarm-Corporation/radiology-swarm](https://github.com/The-Swarm-Corporation/radiology-swarm) |
|
||||||
|
| MedGuard | A Python library ensuring HIPAA compliance for LLM agents in healthcare applications. | [https://github.com/The-Swarm-Corporation/MedGuard](https://github.com/The-Swarm-Corporation/MedGuard) |
|
||||||
|
| doc-master | A lightweight Python library for automated file reading and content extraction. | [https://github.com/The-Swarm-Corporation/doc-master](https://github.com/The-Swarm-Corporation/doc-master) |
|
||||||
|
| Open-Aladdin | An open-source risk-management tool for stock and security risk analysis. | [https://github.com/The-Swarm-Corporation/Open-Aladdin](https://github.com/The-Swarm-Corporation/Open-Aladdin) |
|
||||||
|
| TickrAgent | A scalable Python library for building financial agents for comprehensive stock analysis. | [https://github.com/The-Swarm-Corporation/TickrAgent](https://github.com/The-Swarm-Corporation/TickrAgent) |
|
||||||
|
| NewsAgent | An enterprise-grade news aggregation agent for fetching, querying, and summarizing news. | [https://github.com/The-Swarm-Corporation/NewsAgent](https://github.com/The-Swarm-Corporation/NewsAgent) |
|
||||||
|
| Research-Paper-Hive | A platform for discovering and engaging with relevant research papers efficiently. | [https://github.com/The-Swarm-Corporation/Research-Paper-Hive](https://github.com/The-Swarm-Corporation/Research-Paper-Hive) |
|
||||||
|
| MedInsight-Pro | Revolutionizes medical research summarization for healthcare innovators. | [https://github.com/The-Swarm-Corporation/MedInsight-Pro](https://github.com/The-Swarm-Corporation/MedInsight-Pro) |
|
||||||
|
| swarms-memory | Pre-built wrappers for RAG systems like ChromaDB, Weaviate, and Pinecone. | [https://github.com/The-Swarm-Corporation/swarms-memory](https://github.com/The-Swarm-Corporation/swarms-memory) |
|
||||||
|
| CryptoAgent | An enterprise-grade solution for fetching, analyzing, and summarizing cryptocurrency data. | [https://github.com/The-Swarm-Corporation/CryptoAgent](https://github.com/The-Swarm-Corporation/CryptoAgent) |
|
||||||
|
| AgentParse | A high-performance parsing library for mapping structured data into agent-understandable blocks. | [https://github.com/The-Swarm-Corporation/AgentParse](https://github.com/The-Swarm-Corporation/AgentParse) |
|
||||||
|
| CodeGuardian | An intelligent agent for automating the generation of production-grade unit tests for Python code. | [https://github.com/The-Swarm-Corporation/CodeGuardian](https://github.com/The-Swarm-Corporation/CodeGuardian) |
|
||||||
|
| Marketing-Swarm-Template | A framework for creating multi-platform marketing content using Swarms AI agents. | [https://github.com/The-Swarm-Corporation/Marketing-Swarm-Template](https://github.com/The-Swarm-Corporation/Marketing-Swarm-Template) |
|
||||||
|
| HTX-Swarm | A multi-agent system for real-time market analysis of HTX exchange data. | [https://github.com/The-Swarm-Corporation/HTX-Swarm](https://github.com/The-Swarm-Corporation/HTX-Swarm) |
|
||||||
|
| MultiModelOptimizer | A hierarchical parameter synchronization approach for joint training of transformer models. | [https://github.com/The-Swarm-Corporation/MultiModelOptimizer](https://github.com/The-Swarm-Corporation/MultiModelOptimizer) |
|
||||||
|
| MortgageUnderwritingSwarm | A multi-agent pipeline for automating mortgage underwriting processes. | [https://github.com/The-Swarm-Corporation/MortgageUnderwritingSwarm](https://github.com/The-Swarm-Corporation/MortgageUnderwritingSwarm) |
|
||||||
|
| DermaSwarm | A multi-agent system for dermatologists to diagnose and treat skin conditions collaboratively. | [https://github.com/The-Swarm-Corporation/DermaSwarm](https://github.com/The-Swarm-Corporation/DermaSwarm) |
|
||||||
|
| IoTAgents | Integrates IoT data with AI agents for seamless parsing and processing of data streams. | [https://github.com/The-Swarm-Corporation/IoTAgents](https://github.com/The-Swarm-Corporation/IoTAgents) |
|
||||||
|
| eth-agent | An autonomous agent for analyzing on-chain Ethereum data. | [https://github.com/The-Swarm-Corporation/eth-agent](https://github.com/The-Swarm-Corporation/eth-agent) |
|
||||||
|
| Medical-Swarm-One-Click | A template for building safe, reliable, and production-grade medical multi-agent systems. | [https://github.com/The-Swarm-Corporation/Medical-Swarm-One-Click](https://github.com/The-Swarm-Corporation/Medical-Swarm-One-Click) |
|
||||||
|
| Swarms-Example-1-Click-Template | A one-click template for building Swarms applications quickly. | [https://github.com/The-Swarm-Corporation/Swarms-Example-1-Click-Template](https://github.com/The-Swarm-Corporation/Swarms-Example-1-Click-Template) |
|
||||||
|
| Custom-Swarms-Spec-Template | An official specification template for custom swarm development using the Swarms Framework. | [https://github.com/The-Swarm-Corporation/Custom-Swarms-Spec-Template](https://github.com/The-Swarm-Corporation/Custom-Swarms-Spec-Template) |
|
||||||
|
| Swarms-LlamaIndex-RAG-Template | A template for integrating Llama Index into Swarms applications for RAG capabilities. | [https://github.com/The-Swarm-Corporation/Swarms-LlamaIndex-RAG-Template](https://github.com/The-Swarm-Corporation/Swarms-LlamaIndex-RAG-Template) |
|
||||||
|
| ForexTreeSwarm | A forex market analysis system using a swarm of AI agents organized in a forest structure. | [https://github.com/The-Swarm-Corporation/ForexTreeSwarm](https://github.com/The-Swarm-Corporation/ForexTreeSwarm) |
|
||||||
|
| Generalist-Mathematician-Swarm | A swarm of agents for solving complex mathematical problems collaboratively. | [https://github.com/The-Swarm-Corporation/Generalist-Mathematician-Swarm](https://github.com/The-Swarm-Corporation/Generalist-Mathematician-Swarm) |
|
||||||
|
| Multi-Modal-XRAY-Diagnosis-Medical-Swarm-Template | A template for analyzing X-rays, MRIs, and more using a swarm of agents. | [https://github.com/The-Swarm-Corporation/Multi-Modal-XRAY-Diagnosis-Medical-Swarm-Template](https://github.com/The-Swarm-Corporation/Multi-Modal-XRAY-Diagnosis-Medical-Swarm-Template) |
|
||||||
|
| AgentRAGProtocol | A protocol for integrating Retrieval-Augmented Generation (RAG) into AI agents. | [https://github.com/The-Swarm-Corporation/AgentRAGProtocol](https://github.com/The-Swarm-Corporation/AgentRAGProtocol) |
|
||||||
|
| Multi-Agent-RAG-Template | A template for creating collaborative AI agent teams for document processing and analysis. | [https://github.com/The-Swarm-Corporation/Multi-Agent-RAG-Template](https://github.com/The-Swarm-Corporation/Multi-Agent-RAG-Template) |
|
||||||
|
| REACT-Yaml-Agent | An implementation of a REACT agent using YAML instead of JSON. | [https://github.com/The-Swarm-Corporation/REACT-Yaml-Agent](https://github.com/The-Swarm-Corporation/REACT-Yaml-Agent) |
|
||||||
|
| SwarmsXGCP | A template for deploying Swarms agents on Google Cloud Run. | [https://github.com/The-Swarm-Corporation/SwarmsXGCP](https://github.com/The-Swarm-Corporation/SwarmsXGCP) |
|
||||||
|
| Legal-Swarm-Template | A one-click template for building legal-focused Swarms applications. | [https://github.com/The-Swarm-Corporation/Legal-Swarm-Template](https://github.com/The-Swarm-Corporation/Legal-Swarm-Template) |
|
||||||
|
| swarms_sim | A simulation of a swarm of agents in a professional workplace environment. | [https://github.com/The-Swarm-Corporation/swarms_sim](https://github.com/The-Swarm-Corporation/swarms_sim) |
|
||||||
|
| medical-problems | A repository for medical problems to create Swarms applications for. | [https://github.com/The-Swarm-Corporation/medical-problems](https://github.com/The-Swarm-Corporation/medical-problems) |
|
||||||
|
| swarm-ecosystem | An overview of the Swarm Ecosystem and its components. | [https://github.com/The-Swarm-Corporation/swarm-ecosystem](https://github.com/The-Swarm-Corporation/swarm-ecosystem) |
|
||||||
|
| swarms_ecosystem_md | MDX documentation for the Swarm Ecosystem. | [https://github.com/The-Swarm-Corporation/swarms_ecosystem_md](https://github.com/The-Swarm-Corporation/swarms_ecosystem_md) |
|
||||||
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
|||||||
|
from swarms import Agent
|
||||||
|
|
||||||
|
# Initialize the agent
|
||||||
|
agent = Agent(
|
||||||
|
agent_name="Quantitative-Trading-Agent",
|
||||||
|
agent_description="Advanced quantitative trading and algorithmic analysis agent",
|
||||||
|
system_prompt="""
|
||||||
|
You are an expert quantitative trading agent with deep expertise in:
|
||||||
|
- Algorithmic trading strategies and implementation
|
||||||
|
- Statistical arbitrage and market making
|
||||||
|
- Risk management and portfolio optimization
|
||||||
|
- High-frequency trading systems
|
||||||
|
- Market microstructure analysis
|
||||||
|
- Quantitative research methodologies
|
||||||
|
- Financial mathematics and stochastic processes
|
||||||
|
- Machine learning applications in trading
|
||||||
|
|
||||||
|
Your core responsibilities include:
|
||||||
|
1. Developing and backtesting trading strategies
|
||||||
|
2. Analyzing market data and identifying alpha opportunities
|
||||||
|
3. Implementing risk management frameworks
|
||||||
|
4. Optimizing portfolio allocations
|
||||||
|
5. Conducting quantitative research
|
||||||
|
6. Monitoring market microstructure
|
||||||
|
7. Evaluating trading system performance
|
||||||
|
|
||||||
|
You maintain strict adherence to:
|
||||||
|
- Mathematical rigor in all analyses
|
||||||
|
- Statistical significance in strategy development
|
||||||
|
- Risk-adjusted return optimization
|
||||||
|
- Market impact minimization
|
||||||
|
- Regulatory compliance
|
||||||
|
- Transaction cost analysis
|
||||||
|
- Performance attribution
|
||||||
|
|
||||||
|
You communicate in precise, technical terms while maintaining clarity for stakeholders.""",
|
||||||
|
max_loops=1,
|
||||||
|
model_name="gpt-4o-mini",
|
||||||
|
dynamic_temperature_enabled=True,
|
||||||
|
output_type="all",
|
||||||
|
mcp_urls=[
|
||||||
|
"http://0.0.0.0:8000/sse",
|
||||||
|
"http://0.0.0.0:8001/sse",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
agent.run(
|
||||||
|
"Please use the get_okx_crypto_volume tool to get the trading volume for Bitcoin (BTC). Provide the volume information."
|
||||||
|
)
|
@ -0,0 +1,12 @@
|
|||||||
|
from swarms.tools.mcp_client_call import (
|
||||||
|
get_mcp_tools_sync,
|
||||||
|
execute_tool_call_simple,
|
||||||
|
)
|
||||||
|
|
||||||
|
tools = get_mcp_tools_sync()
|
||||||
|
|
||||||
|
print(tools)
|
||||||
|
|
||||||
|
result = execute_tool_call_simple(tools[0], "Hello, world!")
|
||||||
|
|
||||||
|
print(result)
|
@ -0,0 +1,234 @@
|
|||||||
|
"""
|
||||||
|
Example demonstrating how to execute multiple tools across multiple MCP servers.
|
||||||
|
|
||||||
|
This example shows how to:
|
||||||
|
1. Create a mapping of function names to servers
|
||||||
|
2. Execute multiple tool calls across different servers
|
||||||
|
3. Handle responses with tool calls and route them to the appropriate servers
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
from swarms.tools.mcp_client_call import (
|
||||||
|
execute_multiple_tools_on_multiple_mcp_servers,
|
||||||
|
execute_multiple_tools_on_multiple_mcp_servers_sync,
|
||||||
|
get_tools_for_multiple_mcp_servers,
|
||||||
|
)
|
||||||
|
from swarms.schemas.mcp_schemas import MCPConnection
|
||||||
|
|
||||||
|
|
||||||
|
def example_sync_execution():
|
||||||
|
"""Example of synchronous execution across multiple MCP servers."""
|
||||||
|
|
||||||
|
# Example server URLs (replace with your actual MCP server URLs)
|
||||||
|
urls = [
|
||||||
|
"http://localhost:8000/sse", # Server 1
|
||||||
|
"http://localhost:8001/sse", # Server 2
|
||||||
|
"http://localhost:8002/sse", # Server 3
|
||||||
|
]
|
||||||
|
|
||||||
|
# Optional: Create connection objects for each server
|
||||||
|
connections = [
|
||||||
|
MCPConnection(
|
||||||
|
url="http://localhost:8000/sse",
|
||||||
|
authorization_token="token1", # if needed
|
||||||
|
timeout=10,
|
||||||
|
),
|
||||||
|
MCPConnection(
|
||||||
|
url="http://localhost:8001/sse",
|
||||||
|
authorization_token="token2", # if needed
|
||||||
|
timeout=10,
|
||||||
|
),
|
||||||
|
MCPConnection(
|
||||||
|
url="http://localhost:8002/sse",
|
||||||
|
authorization_token="token3", # if needed
|
||||||
|
timeout=10,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Example responses containing tool calls
|
||||||
|
# These would typically come from an LLM that decided to use tools
|
||||||
|
responses = [
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "search_web",
|
||||||
|
"arguments": {
|
||||||
|
"query": "python programming best practices"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "search_database",
|
||||||
|
"arguments": {"table": "users", "id": 123},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "send_email",
|
||||||
|
"arguments": {
|
||||||
|
"to": "user@example.com",
|
||||||
|
"subject": "Test email",
|
||||||
|
"body": "This is a test email",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
print("=== Synchronous Execution Example ===")
|
||||||
|
print(
|
||||||
|
f"Executing {len(responses)} tool calls across {len(urls)} servers..."
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Execute all tool calls across multiple servers
|
||||||
|
results = execute_multiple_tools_on_multiple_mcp_servers_sync(
|
||||||
|
responses=responses,
|
||||||
|
urls=urls,
|
||||||
|
connections=connections,
|
||||||
|
output_type="dict",
|
||||||
|
max_concurrent=5, # Limit concurrent executions
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"\nExecution completed! Got {len(results)} results:")
|
||||||
|
for i, result in enumerate(results):
|
||||||
|
print(f"\nResult {i + 1}:")
|
||||||
|
print(f" Function: {result['function_name']}")
|
||||||
|
print(f" Server: {result['server_url']}")
|
||||||
|
print(f" Status: {result['status']}")
|
||||||
|
if result["status"] == "success":
|
||||||
|
print(f" Result: {result['result']}")
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f" Error: {result.get('error', 'Unknown error')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error during execution: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
async def example_async_execution():
|
||||||
|
"""Example of asynchronous execution across multiple MCP servers."""
|
||||||
|
|
||||||
|
# Example server URLs
|
||||||
|
urls = [
|
||||||
|
"http://localhost:8000/sse",
|
||||||
|
"http://localhost:8001/sse",
|
||||||
|
"http://localhost:8002/sse",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Example responses with multiple tool calls in a single response
|
||||||
|
responses = [
|
||||||
|
{
|
||||||
|
"tool_calls": [
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "search_web",
|
||||||
|
"arguments": {
|
||||||
|
"query": "machine learning trends 2024"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "search_database",
|
||||||
|
"arguments": {
|
||||||
|
"table": "articles",
|
||||||
|
"category": "AI",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "send_notification",
|
||||||
|
"arguments": {
|
||||||
|
"user_id": 456,
|
||||||
|
"message": "Your analysis is complete",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
print("\n=== Asynchronous Execution Example ===")
|
||||||
|
print(
|
||||||
|
f"Executing tool calls across {len(urls)} servers asynchronously..."
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Execute all tool calls across multiple servers
|
||||||
|
results = (
|
||||||
|
await execute_multiple_tools_on_multiple_mcp_servers(
|
||||||
|
responses=responses,
|
||||||
|
urls=urls,
|
||||||
|
output_type="str",
|
||||||
|
max_concurrent=3,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"\nAsync execution completed! Got {len(results)} results:"
|
||||||
|
)
|
||||||
|
for i, result in enumerate(results):
|
||||||
|
print(f"\nResult {i + 1}:")
|
||||||
|
print(f" Response Index: {result['response_index']}")
|
||||||
|
print(f" Function: {result['function_name']}")
|
||||||
|
print(f" Server: {result['server_url']}")
|
||||||
|
print(f" Status: {result['status']}")
|
||||||
|
if result["status"] == "success":
|
||||||
|
print(f" Result: {result['result']}")
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f" Error: {result.get('error', 'Unknown error')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error during async execution: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
def example_get_tools_from_multiple_servers():
|
||||||
|
"""Example of getting tools from multiple servers."""
|
||||||
|
|
||||||
|
urls = [
|
||||||
|
"http://localhost:8000/sse",
|
||||||
|
"http://localhost:8001/sse",
|
||||||
|
"http://localhost:8002/sse",
|
||||||
|
]
|
||||||
|
|
||||||
|
print("\n=== Getting Tools from Multiple Servers ===")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Get all available tools from all servers
|
||||||
|
all_tools = get_tools_for_multiple_mcp_servers(
|
||||||
|
urls=urls, format="openai", output_type="dict"
|
||||||
|
)
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"Found {len(all_tools)} total tools across all servers:"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Group tools by function name to see what's available
|
||||||
|
function_names = set()
|
||||||
|
for tool in all_tools:
|
||||||
|
if isinstance(tool, dict) and "function" in tool:
|
||||||
|
function_names.add(tool["function"]["name"])
|
||||||
|
elif hasattr(tool, "name"):
|
||||||
|
function_names.add(tool.name)
|
||||||
|
|
||||||
|
print("Available functions:")
|
||||||
|
for func_name in sorted(function_names):
|
||||||
|
print(f" - {func_name}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error getting tools: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Run synchronous example
|
||||||
|
example_sync_execution()
|
||||||
|
|
||||||
|
# Run async example
|
||||||
|
asyncio.run(example_async_execution())
|
||||||
|
|
||||||
|
# Get tools from multiple servers
|
||||||
|
example_get_tools_from_multiple_servers()
|
@ -0,0 +1,54 @@
|
|||||||
|
"""
|
||||||
|
Simple test for the execute_multiple_tools_on_multiple_mcp_servers functionality.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from swarms.tools.mcp_client_call import (
|
||||||
|
execute_multiple_tools_on_multiple_mcp_servers_sync,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_async_multiple_tools_execution():
|
||||||
|
"""Test the async multiple tools execution function structure."""
|
||||||
|
print(
|
||||||
|
"\nTesting async multiple tools execution function structure..."
|
||||||
|
)
|
||||||
|
|
||||||
|
urls = [
|
||||||
|
"http://localhost:8000/sse",
|
||||||
|
"http://localhost:8001/sse",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Mock responses with multiple tool calls
|
||||||
|
responses = [
|
||||||
|
{
|
||||||
|
"tool_calls": [
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "get_okx_crypto_price",
|
||||||
|
"arguments": {"symbol": "SOL-USDT"},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": {
|
||||||
|
"name": "get_crypto_price",
|
||||||
|
"arguments": {"coin_id": "solana"},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
# This will likely fail to connect, but we can test the function structure
|
||||||
|
results = execute_multiple_tools_on_multiple_mcp_servers_sync(
|
||||||
|
responses=responses, urls=urls
|
||||||
|
)
|
||||||
|
print(f"Got {len(results)} results")
|
||||||
|
print(results)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Expected error (no servers running): {str(e)}")
|
||||||
|
print("Async function structure is working correctly!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_async_multiple_tools_execution()
|
@ -0,0 +1,20 @@
|
|||||||
|
from swarms import Agent
|
||||||
|
from swarms.prompts.finance_agent_sys_prompt import (
|
||||||
|
FINANCIAL_AGENT_SYS_PROMPT,
|
||||||
|
)
|
||||||
|
from swarms_tools import yahoo_finance_api
|
||||||
|
|
||||||
|
# Initialize the agent
|
||||||
|
agent = Agent(
|
||||||
|
agent_name="Financial-Analysis-Agent",
|
||||||
|
agent_description="Personal finance advisor agent",
|
||||||
|
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
|
||||||
|
max_loops=1,
|
||||||
|
model_name="gpt-4o-mini",
|
||||||
|
tools=[yahoo_finance_api],
|
||||||
|
dynamic_temperature_enabled=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
agent.run(
|
||||||
|
"Fetch the data for nvidia and tesla both with the yahoo finance api"
|
||||||
|
)
|
@ -1,31 +0,0 @@
|
|||||||
from swarms import Agent
|
|
||||||
from swarms.prompts.finance_agent_sys_prompt import (
|
|
||||||
FINANCIAL_AGENT_SYS_PROMPT,
|
|
||||||
)
|
|
||||||
from swarms_tools import (
|
|
||||||
fetch_stock_news,
|
|
||||||
coin_gecko_coin_api,
|
|
||||||
fetch_htx_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize the agent
|
|
||||||
agent = Agent(
|
|
||||||
agent_name="Financial-Analysis-Agent",
|
|
||||||
agent_description="Personal finance advisor agent",
|
|
||||||
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
|
|
||||||
max_loops=1,
|
|
||||||
model_name="gpt-4o",
|
|
||||||
dynamic_temperature_enabled=True,
|
|
||||||
user_name="swarms_corp",
|
|
||||||
retry_attempts=3,
|
|
||||||
context_length=8192,
|
|
||||||
return_step_meta=False,
|
|
||||||
output_type="str", # "json", "dict", "csv" OR "string" "yaml" and
|
|
||||||
auto_generate_prompt=False, # Auto generate prompt for the agent based on name, description, and system prompt, task
|
|
||||||
max_tokens=4000, # max output tokens
|
|
||||||
saved_state_path="agent_00.json",
|
|
||||||
interactive=False,
|
|
||||||
tools=[fetch_stock_news, coin_gecko_coin_api, fetch_htx_data],
|
|
||||||
)
|
|
||||||
|
|
||||||
agent.run("Analyze the $swarms token on htx")
|
|
Before Width: | Height: | Size: 232 KiB After Width: | Height: | Size: 232 KiB |
@ -0,0 +1,43 @@
|
|||||||
|
from litellm import model_list, get_max_tokens
|
||||||
|
from swarms.utils.formatter import formatter
|
||||||
|
|
||||||
|
# Add model overrides here
|
||||||
|
MODEL_MAX_TOKEN_OVERRIDES = {
|
||||||
|
"llama-2-70b-chat:2796ee9483c3fd7aa2e171d38f4ca12251a30609463dcfd4cd76703f22e96cdf": 4096, # Example override
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def check_all_model_max_tokens():
|
||||||
|
"""
|
||||||
|
Check and display the maximum token limits for all available models.
|
||||||
|
|
||||||
|
This function iterates through all models in the litellm model list and attempts
|
||||||
|
to retrieve their maximum token limits. For models that are not properly mapped
|
||||||
|
in litellm, it checks for custom overrides in MODEL_MAX_TOKEN_OVERRIDES.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None: Prints the results to console using formatter.print_panel()
|
||||||
|
|
||||||
|
Note:
|
||||||
|
Models that are not mapped in litellm and have no override set will be
|
||||||
|
marked with a [WARNING] in the output.
|
||||||
|
"""
|
||||||
|
text = ""
|
||||||
|
for model in model_list:
|
||||||
|
# skip model names
|
||||||
|
try:
|
||||||
|
max_tokens = get_max_tokens(model)
|
||||||
|
except Exception:
|
||||||
|
max_tokens = MODEL_MAX_TOKEN_OVERRIDES.get(
|
||||||
|
model, "[NOT MAPPED]"
|
||||||
|
)
|
||||||
|
if max_tokens == "[NOT MAPPED]":
|
||||||
|
text += f"[WARNING] {model}: not mapped in litellm and no override set.\n"
|
||||||
|
text += f"{model}: {max_tokens}\n"
|
||||||
|
text += "─" * 80 + "\n" # Add borderline for each model
|
||||||
|
formatter.print_panel(text, "All Model Max Tokens")
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
# if __name__ == "__main__":
|
||||||
|
# print(check_all_model_max_tokens())
|
Loading…
Reference in new issue