Skip to main content

A framework for hosting and scaling AI agents.

Project description

   ___                __  ____
  / _ |___ ____ ___  / /_/ __/__ _____  _____
 / __ / _ `/ -_) _ \/ __/\ \/ -_) __/ |/ / -_)
/_/ |_\_, /\__/_//_/\__/___/\__/_/  |___/\__/
     /___/

AgentServe

Discord GitHub License PyPI Version GitHub Stars Beta

AgentServe is an lightweight framework for hosting and scaling AI agents. It is designed to be easy to use and integrate with existing projects and agent / LLM frameworks. It wraps your agent in a REST API and supports optional task queuing for scalability.

Join the Discord for support and discussion.

Goals and Objectives

The goal of AgentServe is to provide the easiest way to take an local agent to production and standardize the communication layer between multiple agents, humans, and other systems.

Features

  • Standardized: AgentServe provides a standardized way to communicate with AI agents via a REST API.
  • Framework Agnostic: AgentServe supports multiple agent frameworks (OpenAI, LangChain, LlamaIndex, and Blank).
  • Task Queuing: AgentServe supports optional task queuing for scalability. Choose between local, Redis, or Celery task queues based on your needs.
  • Configurable: AgentServe is designed to be configurable via an agentserve.yaml file and overridable with environment variables.
  • Easy to Use: AgentServe aims to be easy to use and integrate with existing projects and make deployment as simple as possible.

Requirements

  • Python 3.9+

Installation

To install AgentServe, you can use pip:

pip install -U agentserve

Getting Started

AgentServe allows you to easily wrap your agent code in a FastAPI application and expose it via REST endpoints. Below are the steps to integrate AgentServe into your project.

1. Install AgentServe

First, install the agentserve package using pip:

pip install -U agentserve

Make sure your virtual environment is activated if you're using one.

2. Create or Update Your Agent

Within your entry point file (e.g. main.py) we will import agentserve and create an app instance, then decorate an agent function with @app.agent. Finally, we will call app.run() to start the server.

The agent function should take a single argument, task_data, which will be a dictionary of data prequired by your agent.

Example:

# main.py
import agentserve
from openai import OpenAI

app = agentserve.app()

@app.agent
def my_agent(task_data):
    # Your agent logic goes here
    client = OpenAI()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": task_data["prompt"]}]
    )
    return response.choices[0].message.content

if __name__ == "__main__":
    app.run()

In this example:

  • We import agentserve and create an app instance using agentserve.app().
  • We define our agent function my_agent and decorate it with @app.agent.
  • Within the agent function, we implement our agent's logic.
  • We call app.run() to start the server.

3. Run the Agent Server

To run the agent server, use the following command:

python main.py

4. Configure Task Queue (Optional)

By default, AgentServe uses a local task queue, which is suitable for development and testing. If you need more robust queue management for production, you can configure AgentServe to use Redis or Celery.

Using a Configuration File Create a file named agentserve.yaml in your project directory:

# agentserve.yaml

task_queue: celery # Options: 'local', 'redis', 'celery'

celery:
  broker_url: pyamqp://guest@localhost//

Using Environment Variables

Alternatively, you can set configuration options using environment variables:

export AGENTSERVE_TASK_QUEUE=celery
export AGENTSERVE_CELERY_BROKER_URL=pyamqp://guest@localhost//

5. Start the Worker (if using Celery or Redis)

To start the worker, use the following command:

agentserve startworker

6. Test the Agent

With the server and worker (if needed) running, you can test your agent using the available endpoints.

Synchronous Task Processing

POST /task/sync

curl -X POST http://localhost:8000/task/sync \
     -H "Content-Type: application/json" \
       -d '{"input": "Test input"}'

Asynchronously process a task

POST /task/async

curl -X POST http://localhost:8000/task/async \
     -H "Content-Type: application/json" \
       -d '{"input": "Test input"}'

Get the status of a task

GET /task/status/:task_id

curl http://localhost:8000/task/status/1234567890

Get the result of a task

GET /task/result/:task_id

curl http://localhost:8000/task/result/1234567890

Configuration Options

AgentServe allows you to configure various aspects of the application using a configuration file or environment variables.

Using agentserve.yaml

Place an agentserve.yaml file in your project directory with the desired configurations.

Example:

# agentserve.yaml

task_queue: celery # Options: 'local', 'redis', 'celery'

celery:
  broker_url: pyamqp://guest@localhost//

redis:
  host: localhost
  port: 6379

server:
  host: 0.0.0.0
  port: 8000

Using Environment Variables

Set the desired configuration options using environment variables.

You can override configurations using environment variables without modifying the configuration file.

  • AGENTSERVE_TASK_QUEUE
  • AGENTSERVE_CELERY_BROKER_URL
  • AGENTSERVE_REDIS_HOST
  • AGENTSERVE_REDIS_PORT
  • AGENTSERVE_SERVER_HOST
  • AGENTSERVE_SERVER_PORT

Example:

export AGENTSERVE_TASK_QUEUE=redis
export AGENTSERVE_REDIS_HOST=redis-server-host
export AGENTSERVE_REDIS_PORT=6379

Advanced Usage

Integrating with Existing Projects

You can integrate AgentServe into your existing projects by importing agentserve and defining your agent function.

Example:

# main.py
import agentserve

app = agentserve.app()

@app.agent
def my_custom_agent(task_data):
    # Your custom agent logic (e.g. using LangChain, LlamaIndex, etc.)
    result = perform_complex_computation(task_data)
    return {"result": result}

if __name__ == "__main__":
    app.run()

Input Validation

AgentServe allows you to validate the input to your agent function using Pydantic. Simply add an input schema to your agent function.

Example:

# main.py
import agentserve
from pydantic import BaseModel

class MyInputSchema(BaseModel):
    prompt: str

@app.agent(input_schema=MyInputSchema)
def my_custom_agent(task_data):
    # Your custom agent logic
    return {"result": "Hello, world!"}

if __name__ == "__main__":
    app.run()

Hosting

INSTRUCTIONS COMING SOON

ROADMAP

  • Add support for streaming responses
  • Add easy instructions for more hosting options (GCP, Azure, AWS, etc.)
  • Add support for external storage for task results
  • Add support for multi model agents
  • Add support for more agent frameworks

License

This project is licensed under the MIT License.

Contact

Join the Discord for support and discussion.

For any questions or issues, please contact Peter at peter@getprops.ai.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentserve-0.2.6.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentserve-0.2.6-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file agentserve-0.2.6.tar.gz.

File metadata

  • Download URL: agentserve-0.2.6.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for agentserve-0.2.6.tar.gz
Algorithm Hash digest
SHA256 dfe921fc299d4683b2bf7728054d7f157cb29fff32e9bf84ba3bf54964166a17
MD5 941f160bacad53ec6361aaf6e72348d0
BLAKE2b-256 3fa15c8cfedd819ba8f7358a114ac52f92ccbc66b6041bceb7cd780598da1218

See more details on using hashes here.

File details

Details for the file agentserve-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: agentserve-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for agentserve-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0ef799e2e93cc753af809e8256e1db9c76670633f63b1d1d3a21d408c9955a6d
MD5 2de61ef262a523afcb4616b6bb68d6f3
BLAKE2b-256 4fb0823cb0fd0cb7cfe6f45fa88121706d3b2e5ba3a8a2d25132013f98b75d9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page