Skip to content

Commit d18c647

Browse files
Merge pull request #477 from MervinPraison/develop
multi agents deploy
2 parents eb94124 + c7eae10 commit d18c647

18 files changed

Lines changed: 284 additions & 48 deletions

File tree

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.11-slim
22
WORKDIR /app
33
COPY . .
4-
RUN pip install flask praisonai==2.1.4 gunicorn markdown
4+
RUN pip install flask praisonai==2.1.5 gunicorn markdown
55
EXPOSE 8080
66
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]

docker/Dockerfile.chat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1313
RUN pip install --no-cache-dir \
1414
praisonaiagents>=0.0.4 \
1515
praisonai_tools \
16-
"praisonai==2.1.4" \
16+
"praisonai==2.1.5" \
1717
"praisonai[chat]" \
1818
"embedchain[github,youtube]"
1919

docker/Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1515
RUN pip install --no-cache-dir \
1616
praisonaiagents>=0.0.4 \
1717
praisonai_tools \
18-
"praisonai==2.1.4" \
18+
"praisonai==2.1.5" \
1919
"praisonai[ui]" \
2020
"praisonai[chat]" \
2121
"praisonai[realtime]" \

docker/Dockerfile.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1313
RUN pip install --no-cache-dir \
1414
praisonaiagents>=0.0.4 \
1515
praisonai_tools \
16-
"praisonai==2.1.4" \
16+
"praisonai==2.1.5" \
1717
"praisonai[ui]" \
1818
"praisonai[crewai]"
1919

docs/api/praisonai/deploy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2 id="raises">Raises</h2>
110110
file.write(&#34;FROM python:3.11-slim\n&#34;)
111111
file.write(&#34;WORKDIR /app\n&#34;)
112112
file.write(&#34;COPY . .\n&#34;)
113-
file.write(&#34;RUN pip install flask praisonai==2.1.4 gunicorn markdown\n&#34;)
113+
file.write(&#34;RUN pip install flask praisonai==2.1.5 gunicorn markdown\n&#34;)
114114
file.write(&#34;EXPOSE 8080\n&#34;)
115115
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)
116116

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
---
2+
title: "Deploying Multi-Agent Systems as APIs"
3+
sidebarTitle: "Multi-Agent Deployment"
4+
description: "Learn how to deploy PraisonAI multi-agent systems as RESTful APIs for production environments"
5+
icon: "network-wired"
6+
---
7+
8+
# Deploying Multi-Agent Systems as APIs
9+
10+
PraisonAI 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.
11+
12+
## Quick Start
13+
14+
<Steps>
15+
<Step title="Install Dependencies">
16+
Make sure you have the required packages installed:
17+
```bash
18+
pip install "praisonaiagents[api]>=0.0.81"
19+
```
20+
</Step>
21+
<Step title="Set API Key">
22+
```bash
23+
export OPENAI_API_KEY="your_api_key"
24+
```
25+
</Step>
26+
<Step title="Deploy a Multi-Agent System">
27+
Create a file named `multi-agents-api.py` with the following code:
28+
```python
29+
from praisonaiagents import Agent, Agents, Tools
30+
31+
research_agent = Agent(name="Research", instructions="You are a research agent to search internet about AI 2024", tools=[Tools.internet_search])
32+
summarise_agent = Agent(name="Summarise", instructions="You are a summarize agent to summarise in points")
33+
agents = Agents(agents=[research_agent, summarise_agent])
34+
agents.launch(path="/agents", port=3030)
35+
```
36+
</Step>
37+
<Step title="Run the API Server">
38+
```bash
39+
python multi-agents-api.py
40+
```
41+
42+
Your multi-agent API will be available at `http://localhost:3030/agents`
43+
</Step>
44+
</Steps>
45+
46+
## Making API Requests
47+
48+
Once your multi-agent system is deployed, you can make POST requests to interact with it:
49+
50+
```bash
51+
curl -X POST http://localhost:3030/agents \
52+
-H "Content-Type: application/json" \
53+
-d '{"message": "What are the latest developments in AI in 2024?"}'
54+
```
55+
56+
The response will include the collaborative output from both the research and summarization agents:
57+
58+
```json
59+
{
60+
"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"
61+
}
62+
```
63+
64+
## Multiple Agent Groups
65+
66+
You can deploy multiple agent groups on the same server, each with its own endpoint:
67+
68+
```python
69+
from praisonaiagents import Agent, Agents, Tools
70+
71+
research_agent = Agent(name="Research", instructions="You are a research agent to search internet about AI 2024", tools=[Tools.internet_search])
72+
summarise_agent = Agent(name="Summarise", instructions="You are a summarize agent to summarise in points")
73+
agents = Agents(agents=[research_agent, summarise_agent])
74+
agents2 = Agents(agents=[research_agent])
75+
agents.launch(path="/agents", port=3030)
76+
agents2.launch(path="/agents2", port=3030)
77+
```
78+
79+
With this setup, you can access:
80+
- The full agent group at `http://localhost:3030/agents`
81+
- Just the research agent at `http://localhost:3030/agents2`
82+
83+
## Independent Multi-Agent Deployment
84+
85+
You can also deploy multiple independent agents on the same server:
86+
87+
```python
88+
from praisonaiagents import Agent
89+
90+
weather_agent = Agent(
91+
instructions="""You are a weather agent that can provide weather information for a given city.""",
92+
llm="gpt-4o-mini"
93+
)
94+
95+
stock_agent = Agent(
96+
instructions="""You are a stock market agent that can provide information about stock prices and market trends.""",
97+
llm="gpt-4o-mini"
98+
)
99+
100+
travel_agent = Agent(
101+
instructions="""You are a travel agent that can provide recommendations for destinations, hotels, and activities.""",
102+
llm="gpt-4o-mini"
103+
)
104+
105+
weather_agent.launch(path="/weather", port=3030)
106+
stock_agent.launch(path="/stock", port=3030)
107+
travel_agent.launch(path="/travel", port=3030)
108+
```
109+
110+
## Production Deployment Options
111+
112+
For production environments, consider the following deployment options:
113+
114+
### Docker Deployment
115+
116+
<Steps>
117+
<Step title="Create a Dockerfile">
118+
```dockerfile
119+
FROM python:3.11-slim
120+
121+
WORKDIR /app
122+
123+
COPY requirements.txt .
124+
RUN pip install --no-cache-dir -r requirements.txt
125+
126+
COPY . .
127+
128+
EXPOSE 3030
129+
130+
CMD ["python", "multi-agents-api.py"]
131+
```
132+
</Step>
133+
<Step title="Create requirements.txt">
134+
```
135+
praisonaiagents[api]>=0.0.81
136+
```
137+
</Step>
138+
<Step title="Build and Run Docker Container">
139+
```bash
140+
docker build -t praisonai-multi-agent .
141+
docker run -p 3030:3030 -e OPENAI_API_KEY=your_api_key praisonai-multi-agent
142+
```
143+
</Step>
144+
</Steps>
145+
146+
### Cloud Deployment
147+
148+
For detailed cloud deployment instructions, refer to:
149+
- [AWS Deployment Guide](/deploy/aws)
150+
- [Google Cloud Deployment Guide](/deploy/googlecloud)
151+
152+
## Scaling Multi-Agent Systems
153+
154+
When deploying multi-agent systems to production, consider these scaling strategies:
155+
156+
1. **Horizontal Scaling**: Deploy multiple instances behind a load balancer
157+
2. **Vertical Scaling**: Allocate more CPU and memory resources for complex agent interactions
158+
3. **Caching**: Implement response caching for frequently asked questions
159+
4. **Asynchronous Processing**: Use message queues for handling long-running agent tasks
160+
161+
## API Configuration Options
162+
163+
When launching your multi-agent system as an API, you can customize various parameters:
164+
165+
```python
166+
agents.launch(
167+
path="/custom-endpoint", # API endpoint path
168+
port=8080, # Port number
169+
host="0.0.0.0", # Host address (0.0.0.0 for external access)
170+
debug=True, # Enable debug mode
171+
cors_origins=["*"], # CORS configuration
172+
api_key="your-api-key" # Optional API key for authentication
173+
)
174+
```
175+
176+
## Securing Your Multi-Agent API
177+
178+
For production deployments, consider implementing:
179+
180+
1. **API Key Authentication**: Require API keys for all requests
181+
2. **Rate Limiting**: Limit the number of requests per client
182+
3. **HTTPS**: Use SSL/TLS certificates for encrypted communication
183+
4. **Input Validation**: Validate all input data before processing
184+
5. **Output Filtering**: Implement content filtering for agent responses
185+
186+
## Monitoring and Logging
187+
188+
For production environments, consider:
189+
190+
1. **Centralized Logging**: Collect logs from all agents in a central location
191+
2. **Performance Metrics**: Track response times and resource usage
192+
3. **Error Tracking**: Monitor and alert on agent failures
193+
4. **Usage Analytics**: Track which agents are used most frequently
194+
195+
## Features
196+
197+
<CardGroup cols={2}>
198+
<Card title="Collaborative Agents" icon="users-gear">
199+
Deploy agent systems that collaborate to solve complex problems.
200+
</Card>
201+
<Card title="Specialized Endpoints" icon="sitemap">
202+
Create dedicated endpoints for different agent groups or individual agents.
203+
</Card>
204+
<Card title="Tool Integration" icon="screwdriver-wrench">
205+
Deploy agents with specialized tools like web search capabilities.
206+
</Card>
207+
<Card title="Scalable Architecture" icon="server">
208+
Scale your multi-agent systems to handle production workloads.
209+
</Card>
210+
</CardGroup>

docs/developers/local-development.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ WORKDIR /app
2727

2828
COPY . .
2929

30-
RUN pip install flask praisonai==2.1.4 watchdog
30+
RUN pip install flask praisonai==2.1.5 watchdog
3131

3232
EXPOSE 5555
3333

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
"group": "Deploy",
377377
"pages": [
378378
"deploy/deploy",
379+
"deploy/multi-agents-deploy",
379380
"deploy/aws",
380381
"deploy/googlecloud"
381382
]

docs/ui/chat.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ To facilitate local development with live reload, you can use Docker. Follow the
155155

156156
COPY . .
157157

158-
RUN pip install flask praisonai==2.1.4 watchdog
158+
RUN pip install flask praisonai==2.1.5 watchdog
159159

160160
EXPOSE 5555
161161

docs/ui/code.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ To facilitate local development with live reload, you can use Docker. Follow the
208208

209209
COPY . .
210210

211-
RUN pip install flask praisonai==2.1.4 watchdog
211+
RUN pip install flask praisonai==2.1.5 watchdog
212212

213213
EXPOSE 5555
214214

0 commit comments

Comments
 (0)