This guide requires JavaScript to display.
Mog: A Programming Language for AI Agents What if an AI agent could modify itself quickly, easily, and safely? Mog is a programming language designed for exactly this. Overview Mog is a statically typed, compiled, embedded language (think statically typed Lua) designed to be written by LLMs – the full spec fits in 3200 tokens. An AI agent writes a Mog program, compiles it, and dynamically loads it as a plugin, script, or hook.
The host controls exactly which functions a Mog program can call (capability-based permissions), so permissions propagate from agent to agent-written code.
Compiled to native code for low-latency plugin execution – no interpreter overhead, no JIT, no process startup cost.
The compiler is written in safe Rust so the entire toolchain can be audited for security.
Even without a full security audit, Mog is already useful for agents extending themselves with their own code.
MIT licensed, contributions welcome. https://github.com/voltropy/mog Examples Agent hook An agent hook that runs after context compaction. All I/O functions are provided by the host: import pulls in host-defined types, and optional capabilities degrade gracefully. import agent ; // Agent, Message, Role types optional log ; // silently ignored if not provided // post-compaction hook: re-inject key context that may have been lost pub fn on_post_compaction (session : agent . Session) { log .info ( "post-compaction hook: injecting reminder" ) ; session . messages .push (agent . Message { role : agent . Role . SYSTEM , content : "IMPORTANT: Always run tests before committing." , }) ; } Async HTTP with retry An async HTTP fetcher with retry logic. Mog supports async / await that suspends without blocking the host’s agent loop, match for destructuring Result values, and f-strings for expression interpolation. async fn fetch_with_retry (url : string, max_retries : int ) -> Result { attempts := 0 ; for attempts < max_retries { match await http .get (url) { ok (response) => return ok (response . body) , err (e) => { attempts = attempts + 1 ; if attempts >= max_retries { return err (f "failed after { max_retries } attempts: { e }" ) ; } println (f "attempt { attempts } failed, retrying..." ) ; await sleep ( 1000 * attempts) ; // exponential-ish backoff } , } } return err (f "all { max_retries } attempts to fetch { url } failed" ) ; } FFT on tensors Mog compiles to machine code, with native support for multi-dimensional arrays (tensors). Here is a radix-2 FFT on tensor data. To minimize foot-guns, Mog has no operator precedence, so arithmetic involving non-associative operations requires explicit parentheses. Type conversions like size as float are always explicit – no implicit coercion. // Fast Fourier Transform (Cooley-Tukey, radix-2, in-place) // Returns a 2×n tensor: row 0 = real, row 1 = imaginary. fn fft (re : tensor, im : tensor ) -> tensor { n := re . shape[ 0 ] ; r := tensor .zeros ([n]) ; im_out := tensor .zeros ([n]) ; for i in 0 .. n { r[i] = re[i] ; im_out[i] = im[i] ; } // bit-reversal permutation j := 0 ; for i := 1 to (n - 1 ) { bit := n / 2 ; while j >= bit { j = j - bit ; bit = bit / 2 ; } j = j + bit ; if i < j { tmp := r[i] ; r[i] = r[j] ; r[j] = tmp ; tmp = im_out[i] ; im_out[i] = im_out[j] ; im_out[j] = tmp ; } } // Cooley-Tukey butterfly — mixed operators require explicit parens size := 2 ; while size <= n { half := size / 2 ; step := ( 0.0 - 6.283185307 ) / (size as float ) ; // -2π/size, explicit int->float cast k := 0 ; while k < n { angle := 0.0 ; for m := 0 to (half - 1 ) { cos_a := cos (angle) as f32; // math builtins return f64; cast to match tensor sin_a := sin (angle) as f32; idx := (k + m) + half ; tr := (r[idx] * cos_a) - (im_out[idx] * sin_a) ; ti := (r[idx] * sin_a) + (im_out[idx] * cos_a) ; r[idx] = r[(k + m)] - tr ; im_out[idx] = im_out[(k + m)] - ti ; r[(k + m)] = r[(k + m)] + tr ; im_out[(k + m)] = im_out[(k + m)] + ti ; angle = angle + step ; } k = k + size ; } size = size * 2 ; } // pack real and imaginary into 2×n result result := tensor .zeros ([ 2 , n]) ; for i in 0 .. n { result[i] = r[i] ; result[n + i] = im_out[i] ; } return result ; } Why Mog? A general-purpose AI agent should be able to continuously extend and modify itself. Over time, an agent should grow into a personal server that manages tasks in all kinds of ways. To do that, the agent needs to write its own code – and that code needs to be safe. The simplest kind of program an agent writes is a one-off script to achieve some task. Examples: Converting a markdown file to PDF.
Analyzing a CSV with database results.
Sending test requests to an application’s HTTP endpoint.
Renaming all the files in a folder.
... continue reading