You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Populates it with necessary AgentServe files tailored to the OpenAI framework.
180
185
- Sets up `requirements.txt` with necessary dependencies.
181
186
182
-
### Setup Command (for existing projects)
187
+
### Build Command
188
+
189
+
```bash
190
+
agentserve build
191
+
```
183
192
184
-
Navigate to your existing project directory and run:
193
+
### Run Command
185
194
186
195
```bash
187
-
agentserve setup
196
+
agentserve run
188
197
```
189
198
190
-
**Result:**
199
+
## Adding AgentServe to an Existing Project
200
+
201
+
This guide provides step-by-step instructions to manually integrate AgentServe into your existing Python application. By following these steps, you can add AI agent capabilities to your project without using the AgentServe CLI.
202
+
203
+
### Steps to Integrate AgentServe
204
+
205
+
#### 1. Install AgentServe
206
+
207
+
First, install the agentserve package using pip:
208
+
209
+
```bash
210
+
pip install agentserve
211
+
```
212
+
213
+
If you're using a virtual environment, make sure it is activated before running the command.
214
+
215
+
#### 2. Update Your requirements.txt
216
+
217
+
If your project uses a requirements.txt file, add agentserve to it:
218
+
219
+
```
220
+
agentserve
221
+
```
222
+
223
+
This ensures that AgentServe will be installed when setting up the project in the future.
191
224
192
-
- Adds AgentServe to the project and sets up the necessary files.
193
-
- Note this command will not run if the project already included a main.py, Dockerfile or docker-compose.yml
225
+
#### 3. Create an agents Directory
226
+
227
+
Create a new directory called agent in the root of your project. This is where your agent classes will reside.
228
+
229
+
```bash
230
+
mkdir agent
231
+
```
232
+
233
+
#### 4. Implement Your Agent Class
234
+
235
+
Inside the directory, create a new Python file for your agent. For example, my_agent.py:
236
+
237
+
```bash
238
+
touch agent/my_agent.py
239
+
```
240
+
241
+
Open agent/my_agent.py and implement your agent by subclassing Agent from agentserve:
242
+
243
+
```python
244
+
# agent/my_agent.py
245
+
from agentserve import Agent
246
+
247
+
classMyAgent(Agent):
248
+
defprocess(self, task_data):
249
+
# Implement your agent's logic here
250
+
client = OpenAI()
251
+
response = client.chat.completions.create(
252
+
model="gpt-4o-mini",
253
+
messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": task_data}]
254
+
)
255
+
return response.choices[0].message.content
256
+
```
257
+
258
+
#### 5. Create or Update Your main.py
259
+
260
+
In the root of your project, create a main.py file if it doesn't already exist:
261
+
262
+
```bash
263
+
touch main.py
264
+
```
265
+
266
+
Open main.py and set up the AgentServer:
267
+
268
+
```python
269
+
from agentserve import AgentServer
270
+
from agent.my_agent import MyAgent
271
+
272
+
agent_server = AgentServer(MyAgent)
273
+
app = agent_server.app
274
+
```
275
+
276
+
#### 6. Build and Run the Server
277
+
278
+
```bash
279
+
agentserve build
280
+
agentserve run
281
+
```
194
282
195
283
## License
196
284
197
285
This project is licensed under the MIT License.
198
286
199
287
## Contact
200
288
201
-
For any questions or issues, please contact Peter at [email protected].
289
+
For any questions or issues, please contact Peter at [email protected].
0 commit comments