Skip to main content

AgentHive Logo

Latest Release

AgentHive

AgentHive is a Python-based framework for managing distributed task execution with a focus on scalability and ease of use. It coordinates producers (tasks) and consumers (workers) in a high-availability setup, using Redis for messaging and PostgreSQL for persistent storage. With a powerful CLI, Docker Compose integration, and a web-based monitor, AgentHive is ideal for developers building extensible task-processing systems.

AgentHive Service

Key Features

  • Task Coordination: Producers submit tasks; workers process them dynamically.
  • High Availability: Coordinators manage workers and tasks with failover support.
  • Dynamic Workers: Workers declare task-handling capabilities, loaded at runtime.
  • Real-Time Monitoring: Web interface displays worker and task statuses via coordinator APIs.
  • Dockerized: Pre-configured services for easy deployment with Docker Compose.
  • CLI-Driven: Initialize projects and manage workers with simple agenthive commands.

Installation

Install AgentHive from PyPI to use the CLI:

pip install agenthive

Quick Start

  1. Initialize a Project Create a new project with the agenthive init command:

    agenthive init my-project
    cd my-project
    
  2. Run the System Start all services (Redis, PostgreSQL, coordinators, workers, monitor) using Docker Compose:

    docker-compose -f docker/docker-compose.yml up --build
    
  3. Customize Workers Add custom workers to src/workers/ and rebuild the services:

    # Example: Add a new worker manually or extend CLI in the future
    echo "print('Custom worker loaded')" > src/workers/custom_worker.py
    docker-compose -f docker/docker-compose.yml up --build
    

Project Structure

After initialization, your project looks like this:

my-project/
├── docker/
│   ├── coordinator/
│   │   └── Dockerfile
│   ├── monitor/
│   │   └── Dockerfile
│   ├── workers/
│   │   └── Dockerfile
│   ├── docker-compose.yml
│   ├── postgres/
│   │   └── init.sql
│   └── redis/
│       └── redis.conf
└── src/
    └── workers/
        ├── example_worker.py
        └── requirements/
            └── example_worker.txt
  • docker/: Contains Dockerfiles and Compose configuration.
  • src/workers/: Directory for custom worker implementations.

Architecture

  • Coordinators: Assign tasks via Redis, track states in PostgreSQL.
  • Workers: Fetch tasks from Redis, report heartbeats, execute custom logic.
  • Redis: Message broker for tasks and status updates.
  • PostgreSQL: Persistent storage for task and worker data.
  • Monitor: Web UI querying coordinator APIs for system insights.

Usage

For End Users

  • Initialize with agenthive init <project-name> and run with Docker Compose.
  • Dockerfiles use pip install agenthive by default, requiring a PyPI-published version.

For Developers

  • Use --agenthive-project-path to test local code:
    agenthive init my-project --agenthive-project-path /path/to/agenthive
    cd my-project
    docker-compose -f docker/docker-compose.yml up --build
    
  • This copies /path/to/agenthive/src/, setup.py, and requirements/ into the project, configuring Dockerfiles to use local code instead of PyPI.

Scaling Workers

  • To increase the number of worker instances without restarting existing services, use:

    docker compose -f docker/docker-compose.yml up -d --no-recreate --scale worker=2
    
  • This command will:

    • Start additional worker instances to reach the specified total (2 in this example)
    • Run in detached mode (-d)
    • Preserve existing containers (--no-recreate)
    • Only affect the worker service, leaving other services untouched
  • Alternatively, to scale workers while only targeting the worker service:

    docker compose -f docker/docker-compose.yml up -d --scale worker=2 worker
    
  • For permanent scaling, you can modify the replicas value in the docker-compose.yml file:

    worker:
      # other configuration...
      deploy:
        mode: replicated
        replicas: 2  # Change from 1 to desired number
    

Development Setup

  1. Clone and Install Locally

    git clone https://github.com/changyy/py-AgentHive.git
    cd py-AgentHive
    python3 -m venv venv
    source venv/bin/activate
    pip install -e .
    
  2. Test CLI

    agenthive init test-project --agenthive-project-path .
    cd test-project
    docker-compose -f docker/docker-compose.yml up --build
    
  3. Run Original Development Environment Use the local docker/ for core development:

    docker-compose -f docker/docker-compose.yml up --build
    

Worker Customization

Workers are Python modules in src/workers/. The worker service scans this directory dynamically at runtime. Example worker:

# src/workers/example_worker.py
from agenthive.core.worker import Worker
from typing import Dict, Any

class ExampleWorker(Worker):
    TASK_TYPES = ["example_task"]

    async def setup(self) -> None:
        print("ExampleWorker setting up...")

    async def process_task(self, task) -> Dict[str, Any]:
        print(f"Processing task: {task.data}")
        return {"result": "Task completed", "data": task.data}

Add dependencies in src/workers/requirements/<worker_name>.txt (e.g., requests==2.32.3).

Contributing

Fork the repo, create a feature branch, and submit a pull request to github.com/changyy/py-AgentHive.

License

MIT License. See the LICENSE file for details.

Metadata

Release files for AgentHive 1.0.202504142220

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AgentHive 1.0.202504142220
File Size Uploaded Provenance
agenthive-1.0.202504142220.tar.gz 89.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for AgentHive 1.0.202504142220
File Interpreter ABI Platform
agenthive-1.0.202504142220-py3-none-any.whl Python 3 none any Details

Total release size: 197.7 kB

Release files / agenthive-1.0.202504142220.tar.gz

Download URL agenthive-1.0.202504142220.tar.gz
Size 89.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2f4069975acae0e34e9f15086afd807c72e439c200f9244d34ccb3de1c1929ec
BLAKE2b-256 checksum
How to use checksums
4ad139e48a2ea5aa2b6485dfce8b9362bb655cef61cb09352e4516de90ed3079
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 14, 2025.

Transparency log

Release files / agenthive-1.0.202504142220-py3-none-any.whl

Download URL agenthive-1.0.202504142220-py3-none-any.whl
Size 108.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2520c6b3bc2d28d3de60c27ef70a0fde2338e3a251506b322dc042eb2821a014
BLAKE2b-256 checksum
How to use checksums
5e2cf4332348674d794dc3eb10f9e5ae333b56fe1ed8540aaf777d0a97929451
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 14, 2025.

Transparency log

Security for AgentHive 1.0.202504142220

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agenthive-1.0.202504142220.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 14, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page