Praison Labs allows you to deploy sophisticated multi-agent
systems as RESTful APIs, enabling seamless integration with
various applications and services. This guide covers different
approaches to deploying multi-agent systems.
Make sure you have the required packages installed:
Copy
pip install "praisonaiagents[api]>=0.0.81"
2
Set API Key
Copy
export OPENAI_API_KEY="your_api_key"
3
Deploy a Multi-Agent System
Create a file named
multi-agents-api.py with the following
code:
Copy
from praisonaiagents import Agent, Agents, Toolsresearch_agent = Agent(name="Research", instructions="You are a research agent to search internet about AI 2024", tools=[Tools.internet_search])summarise_agent = Agent(name="Summarise", instructions="You are a summarize agent to summarise in points")agents = Agents(agents=[research_agent, summarise_agent])agents.launch(path="/agents", port=3030)
4
Run the API Server
Copy
python multi-agents-api.py
Your multi-agent API will be available at
http://localhost:3030/agents
Once your multi-agent system is deployed, you can make POST
requests to interact with it:
Copy
curl -X POST http://localhost:3030/agents \ -H "Content-Type: application/json" \ -d '{"message": "What are the latest developments in AI in 2024?"}'
The response will include the collaborative output from both
the research and summarization agents:
Copy
{ "response": "# Latest AI Developments in 2024\n\n- Multimodal AI models have become mainstream, combining text, image, audio, and video understanding\n- Significant advancements in AI reasoning capabilities with models like GPT-4o and Claude 3\n- Increased focus on AI alignment and safety research\n- Emergence of specialized AI agents for specific domains\n- Growth in open-source AI models and frameworks\n- Regulatory frameworks for AI being established globally"}
You can deploy multiple agent groups on the same server, each
with its own endpoint:
Copy
from praisonaiagents import Agent, Agents, Toolsresearch_agent = Agent(name="Research", instructions="You are a research agent to search internet about AI 2024", tools=[Tools.internet_search])summarise_agent = Agent(name="Summarise", instructions="You are a summarize agent to summarise in points")agents = Agents(agents=[research_agent, summarise_agent])agents2 = Agents(agents=[research_agent])agents.launch(path="/agents", port=3030)agents2.launch(path="/agents2", port=3030)
With this setup, you can access:
The full agent group at
http://localhost:3030/agents
Just the research agent at
http://localhost:3030/agents2
You can also deploy multiple independent agents on the same
server:
Copy
from praisonaiagents import Agentweather_agent = Agent( instructions="""You are a weather agent that can provide weather information for a given city.""", llm="gpt-4o-mini")stock_agent = Agent( instructions="""You are a stock market agent that can provide information about stock prices and market trends.""", llm="gpt-4o-mini")travel_agent = Agent( instructions="""You are a travel agent that can provide recommendations for destinations, hotels, and activities.""", llm="gpt-4o-mini")weather_agent.launch(path="/weather", port=3030)stock_agent.launch(path="/stock", port=3030)travel_agent.launch(path="/travel", port=3030)
When launching your multi-agent system as an API, you can
customize various parameters:
Copy
agents.launch( path="/custom-endpoint", # API endpoint path port=8080, # Port number host="0.0.0.0", # Host address (0.0.0.0 for external access) debug=True, # Enable debug mode cors_origins=["*"], # CORS configuration api_key="your-api-key" # Optional API key for authentication)