A simple tool to deploy OpenAI Agents as FastAPI web services.
Project description
AgentServe
A simple and efficient tool to deploy OpenAI Agents as FastAPI web services.
Overview
AgentServe is a lightweight wrapper that allows you to easily serve OpenAI Agents as web services. It provides a simple API for interacting with agents, supporting both synchronous and streaming responses.
Installation
pip install openai-agentserve
Or with Poetry:
poetry add openai-agentserve
Requirements
- Python 3.8+
- FastAPI
- Uvicorn
- OpenAI Agents SDK
Quick Start
from agents import Agent
from agentserve import serve
# Initialize your agent
my_agent = Agent(name="Assistant", instructions="You are a helpful assistant")
# Serve the agent on port 8000
serve(agent=my_agent, port=8000)
Usage Examples
Invoking the API
The API supports both streaming and non-streaming responses.
Streaming Response
import requests
url = "http://localhost:8000/invoke"
response = requests.post(url, json={
"input": "please tell me a about the history of the world",
"stream": True
}, stream=True)
for i, line in enumerate(response.iter_lines()):
if line:
decoded_line = line.decode('utf-8').strip()
print(decoded_line)
Non-Streaming Response
import requests
url = "http://localhost:8000/invoke"
response = requests.post(url, json={
"input": "please tell me about the history of the world",
"stream": False
})
result = response.json()
print(result)
API Documentation
AgentServe provides interactive API documentation through two interfaces:
ReDoc Documentation
Access the ReDoc documentation at /redoc when your server is running:
http://localhost:8000/redoc
ReDoc provides a clean, organized interface with:
- Detailed endpoint descriptions
- Request/response examples
- Interactive API testing
- Schema documentation
- Endpoint grouping by tags
Swagger UI Documentation
Access the Swagger UI documentation at /docs:
http://localhost:8000/docs
Swagger UI provides:
- Interactive API testing
- Request/response visualization
- Schema exploration
- Try-it-out functionality
OpenAPI Schema
The OpenAPI schema is available at /openapi.json:
http://localhost:8000/openapi.json
This can be used with any OpenAPI-compatible tools or documentation generators.
Development
For information about CI/CD pipelines and GitHub Actions workflows, see .github/workflows/README.md.
Development Workflow
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes
- Run local checks:
poetry install poetry run pytest poetry run black . poetry run isort . poetry run flake8
- Commit your changes:
git add . git commit -m "feat: your feature description"
- Push to your fork:
git push origin feature/your-feature-name
- Create a Pull Request
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openai_agentserve-0.0.1.tar.gz.
File metadata
- Download URL: openai_agentserve-0.0.1.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.12.7 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78137184ab199b8b909b162ab1c18200acb24ae33e7e5bc3729b1d4726b00b7a
|
|
| MD5 |
905b99dde64a3d9fb83629653f3d807e
|
|
| BLAKE2b-256 |
a2afd8a7143649ae0ee3e6f1e30593634ed5b93f7f32326c495ad073ef6cf540
|
File details
Details for the file openai_agentserve-0.0.1-py3-none-any.whl.
File metadata
- Download URL: openai_agentserve-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.12.7 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5164538f70e40406cf13dba59dba6ab6d5a3476a3c60c605461b82befacca732
|
|
| MD5 |
1bc231d010f06835a0b9b59e529c96a4
|
|
| BLAKE2b-256 |
c5fa95c3f065ca253d59db6c74ef20f8380307bcf88adb95e634c1db08e6a7f3
|