Skip to content

Erlang Base

Experimental — Not part of v1 launch scope

This base is available for advanced use and evaluation. For production deployments, use the MCP Server or REST API.

The Erlang base provides an OTP interop bridge, enabling Erlang/Elixir applications to invoke G6Solver operations via erlport.


Overview

The Erlang base exposes G6 operations as commands callable from an Erlang Port driver. It uses erlport to serialize Erlang terms to/from Python dicts, enabling seamless integration with OTP supervision trees.

python -m mvp.erlang

Architecture

erlport is imported lazily. The module is fully importable and testable without erlport installed. Business logic helpers return plain dicts, tested directly in Python.

The bridge uses a single entry point:

from mvp.erlang.bridge import dispatch

result = dispatch("decompose_goal", {"goal": "Build API", "max_depth": 3})

Available commands

The dispatch(command, args) function routes to these handlers:

Command Parameters Description
decompose_goal goal: str, max_depth: int Goal decomposition
run_bayesian data: list, model_type: str Bayesian inference
run_automl X: list, y: list, task: str AutoML pipeline search
recommend_algo X: list, y: list, task: str Algorithm recommendation
system_status -- Service health
list_components -- List all components
invoke component: str, op: str, params: dict Invoke any component
run_pipeline steps: list[dict], initial: dict Execute a pipeline

Unknown commands return {"ok": false, "error": "Unknown command: ..."}.

Errors are caught and returned as {"ok": false, "error": "[ERLANG_BRIDGE_ERROR] ..."}.

Erlang usage

From an Erlang shell or OTP application:

%% Start the Python port
{ok, Port} = python:start(),

%% Call G6 operations
python:call(Port, 'mvp.erlang.bridge', dispatch,
            [<<"decompose_goal">>, #{<<"goal">> => <<"Build API">>}]).

%% System status
python:call(Port, 'mvp.erlang.bridge', dispatch,
            [<<"system_status">>, #{}]).

Message loop

The run_loop() function starts a stdin/stdout message loop for the erlport Port driver:

  1. Reads a 4-byte length prefix from stdin
  2. Reads the Erlang term of that length
  3. Deserializes to (command_bytes, args_dict)
  4. Dispatches to the appropriate handler
  5. Serializes the result dict as an Erlang term
  6. Writes length prefix + encoded term to stdout

This loop runs until stdin is closed (i.e., the Erlang node terminates the port).

Fault tolerance

The bridge integrates with OTP fault tolerance patterns:

  • Supervision: The Python port can be supervised by an OTP supervisor, automatically restarting on crash
  • Isolation: Each port is a separate OS process, preventing Python errors from affecting the BEAM VM
  • Message passing: All communication is asynchronous message passing via the Port protocol

Deployment

# Start the bridge (typically launched by Erlang)
python -m mvp.erlang

# Docker
docker build -f bases/mvp/erlang/Dockerfile -t g6-erlang .
docker run g6-erlang

Source files

File Purpose
bases/mvp/erlang/__init__.py Exports bridge
bases/mvp/erlang/__main__.py Entry point
bases/mvp/erlang/bridge.py dispatch(), command registry, run_loop()
bases/mvp/erlang/Dockerfile Container build

See also