Orchestrator to spin up Minecraft servers, run Minecraft agents, save buildings, and prepare for evaluation.
Please join our Discord to follow discussions, help plan the roadmap and hear about next steps.
- Docker
- Python 3.7+
- Docker Compose
- Redis
- Node.js 12+ and npm (for mineflayer)
- Clone the repository:
git clone <repository-url>
cd orchestrator
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows use: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Ensure Redis is running:
redis-server
- Run the build service:
python build_service.py
The orchestrator consists of several key components:
build_service.py
: The main service that listens to a Redis queue for build jobs.server_manager.py
: Manages Minecraft server instances using Docker.mineflayer.py
: Handles the Minecraft bot actions for building structures.test.py
: A test script to submit build jobs and monitor their progress.
This is the core of the orchestrator. It:
- Initializes a connection to Redis
- Continuously polls a specified Redis queue for new build jobs
- When a job is received, it:
- Creates a new Minecraft server instance
- Waits for the server to be ready
- Prepares the building area
- Executes the build function using mineflayer
- Saves the resulting structure
- Cleans up the server
- Handles multiple jobs concurrently (configurable batch size)
- Implements error handling and logging
The job object in build_service.py
contains:
id
: A unique identifier for the jobfunction_definition
: The Python code defining the build functionmetadata
: Additional information about the build (e.g., name, author, description)
This component manages the lifecycle of Minecraft servers:
- Creates Docker containers for Minecraft servers on-demand
- Manages server configurations (ports, RCON passwords, etc.)
- Provides methods to start, stop, and interact with servers
- Handles server readiness checks
- Prepares the building area within the Minecraft world
This script interfaces with the Minecraft server to perform building actions:
- Connects a bot to the Minecraft server
- Provides functions for placing blocks and filling areas
- Manages a command queue to prevent overwhelming the server
- Tracks coordinates of placed blocks
- Handles structure saving
In mineflayer.py
, the build task is executed through the build_structure
function, which takes:
function_definition
: The Python code to execute for buildingmetadata
: Additional information about the build
A utility script for testing the orchestrator:
- Submits a sample build job to the Redis queue
- Monitors the progress of the job
- Displays the results of the build
The test.py
script creates a sample build job with:
function_definition
: A Python function that builds a simple housemetadata
: Information about the build (name, author, version, description, tags, creation time)
The orchestrator listens to a Redis queue for build jobs. Each job contains a function definition and metadata for building a structure in Minecraft.
-
Submit a job: Use
test.py
to submit a build job to the Redis queue.python test.py
This will:
- Connect to Redis
- Submit a predefined build job (a simple house)
- Monitor the job's progress
- Display the result
-
Process jobs: The
build_service.py
script continuously listens for jobs in the queue and processes them:- Spins up a Minecraft server using
server_manager.py
- Executes the build function using
mineflayer.py
- Saves the resulting structure
- Cleans up the server
- Spins up a Minecraft server using
-
View results: The saved structures can be evaluated in the frontend (not included in this repository).
- Redis URL: Set the
REDIS_URL
environment variable (default:redis://localhost:6379/0
) - Redis Queue: Set the
REDIS_QUEUE
environment variable (default:minecraft_builder
) - Batch Size: Set the
BUILD_BATCH_SIZE
environment variable (default:1
)
To view the building process in Minecraft:
- Open Minecraft Java Edition
- Go to Multiplayer
- Add Server
- Enter
localhost:<port>
as the server address (check logs for the assigned port) - Connect to the server
Note: Servers are automatically created and destroyed for each job, so connections are temporary.
All components use Python's logging module. Check the console output and log files for detailed information about the orchestrator's operations.
When developing or extending the orchestrator:
server_manager.py
: Modify to change how Minecraft servers are managed (e.g., different Docker configurations, server settings)mineflayer.py
: Extend to add new building capabilities or optimize existing onesbuild_service.py
: Adjust job processing logic, error handling, or add new features to the main servicetest.py
: Create new test scenarios or modify the existing one to test different aspects of the system
Refer to individual files for more detailed documentation on their functionalities and how they interact with each other.
- A build job is submitted to the Redis queue (e.g., via
test.py
) build_service.py
picks up the job from the queuebuild_service.py
usesserver_manager.py
to create a new Minecraft server- Once the server is ready,
build_service.py
calls functions inmineflayer.py
to execute the build mineflayer.py
connects a bot to the server and performs the building operations- After building, the structure is saved, and the server is cleaned up
- Results are logged and can be retrieved for evaluation
This cycle repeats for each job in the queue, allowing for scalable and automated Minecraft structure generation.