AgentSlangASL
← All posts

Keeping 3B Local Models Parse-Clean: Why Explicit S-Expressions Beat Significant Whitespace

These notes were written in September 2026, before the C host was removed, and describe designs as well as shipped behaviour. Where a post says asl-host check or asl-host test, the command today is asl check or asl test; ERR_READ_UNBALANCED is now ERR_UNBALANCED; and the current checker does not reject an unmarked effect (ERR_EFFECT_UNMARKED). Figures are the ones measured on the date each post gives. Current docs

AgentSlang (ASL) uses explicit prefix S-expressions so that even a small, quantized local model can generate and edit code without losing track of block scope. Every form opens with ( and a head symbol and closes with ), which means delimiter balance can be enforced token-by-token during decoding and checked in milliseconds by asl check before a test ever runs.

1. Where Small Models Trip on Indentation

Picture an autonomous coding loop running entirely on a laptop: a 3B-parameter coder model served locally on Apple Silicon. It is fast, private and free per token—provided its edits survive the first parse. Look at what happens when that model edits a nested Python loop:

The task: take an event loop, add an error accumulator, and keep the priority dispatch. The model writes Python:

def process_events(event_queue, max_errors=3):
    errors = []
    for event in event_queue:
        try:
            if not validate_checksum(event):
                raise ChecksumError("bad event payload")
            record_metric("event_inbound", 1)
        except ChecksumError as e:
            errors.append(e)
            if len(errors) >= max_errors:
                return Failure(errors)
        elif event.is_priority:
            dispatch_priority(event)

The elif was meant to pair with an if that the model never wrote at that indentation; it now sits directly after an except block. The harness runs python3 -m py_compile module.py (Python 3.13 here):

  File "module.py", line 12
    elif event.is_priority:
    ^^^^
SyntaxError: invalid syntax

The error goes back into the context window, the model re-emits the function, and the familiar loop begins: each repair costs prompt tokens, and a small context window fills up with failed attempts rather than with the task. This is an illustration of a failure mode, not a measured run; section 4 says what we have and have not measured.

2. Why Grammar Shape Matters

Why would a model that can reason through a state machine stumble on indentation and closing brackets?

Python's block structure follows Peter Landin's 1966 "off-side rule": scope is decided by column position, and a block ends without any closing token. To know whether the next line belongs to the inner if, the try or the for, the model has to track indentation depth implicitly, across many tokens, and emit the right amount of whitespace at the right moment. Nothing in the output marks the intent "this block is now closed".

Rust and TypeScript fail differently: brackets are explicit, but validity depends on non-local constraints. Rust's borrow checker decides whether a reference taken early in a function is still live at a later use, a whole-function analysis that a left-to-right generator cannot look ahead to satisfy.

Our hypothesis is that for small models the shape of the grammar matters as much as the parameter count: a grammar that closes every construct with an explicit, local token asks less bookkeeping of the model. It is a hypothesis; section 4 is how we intend to test it.

3. The AgentSlang Approach

In AgentSlang (ASL) every form is delimited by balanced parentheses, operators are prefix, and the text is a direct serialization of the syntax tree. Here is the same accumulator, written as a fold over a closed Event type:

(module engine/events :x [processEvents runTests])

enum Event (event id: Int64 valid: Bool)

enum Tally (tally good: Int64 bad: Int64)

fn step acc: Tally ev: Event -> Tally
  (match acc
    ((tally good bad)
      (match ev
        ((event id valid) (if valid (tally (+ good 1) bad) (tally good (+ bad 1)))))))

fn processEvents queue: (List Event) maxErrors: Int64 -> (Result Int64 Str)
  (match (fold step (tally 0 0) queue)
    ((tally good bad) (if (>= bad maxErrors) (err "checksum error threshold exceeded") (ok good))))

fn runTests -> Bool
  (do
    (assert (= (processEvents (list (event 1 true) (event 2 false) (event 3 true)) 3) (ok 2)) "under threshold")
    (assert (= (processEvents (list (event 1 false) (event 2 false)) 2) (err "checksum error threshold exceeded")) "threshold")
    true)

asl test on this file reports 2 assertions executed, 2 passed. While drafting it we closed one parenthesis too many; the checker answered ERR_READ_UNBALANCED unmatched ')' with the position, before running anything. That is the property this post is about: a structural mistake is caught by counting delimiters, and the error points at one specific character rather than at a line whose meaning depends on the lines around it.

What the language gives a small model, concretely:

  1. Explicit closure. Every ( is closed by its own ). Ending a block is a token the model emits, not a whitespace decision.
  2. No precedence table. (+ good 1) and (>= bad maxErrors) say their evaluation order outright.
  3. A checked, closed set of names. The checker rejects unbound names, wrong arity, non-exhaustive matches over an enum and unmarked effects before running a program, so a hallucinated helper is a load error, not a runtime surprise.
  4. No nil, no exceptions. Absence is (none), failure is (err e), and both are taken apart with match.

There is also a path to constraining generation itself. The asl-slm package contains a grammar token-mask engine (computeTokenMaskBitset, isTokenAllowed) that, given a grammar state and a vocabulary, computes which tokens may come next; its two test suites pass (149 checks). It is a library today: it is not wired into llama.cpp or any other inference server.

4. What We Have Measured, and What We Have Not

We have not run a recorded comparison of a 3B model writing Python against the same model writing ASL. There is no pass-rate, token or latency figure in the repository for that experiment, so this post quotes none.

The experiment we intend to run is straightforward: the same task specifications, the same quantized model and the same local server, in Python and in ASL, counting first-pass parse success, first-run test success and repair turns to green, with each language's strict checker (python3 -m py_compile plus the task's tests on one side, asl check and asl test on the other) as the gate. When it is done, the method and raw results will be in the repository before a number appears here.

5. Trying It Locally

You can check and run ASL with the asl CLI from a checkout of the repository. The project is pre-release and ships no binaries, so the CLI comes from that checkout:

git clone https://github.com/GenSEAM/asl.git
cd asl
asl check events.asl   # names, arity, enums, effects
asl test events.asl    # runs runTests, prints the assertion count

To point a local model at ASL, give it llms.txt as the language reference and use asl check as the gate in your loop: exit code 0 and an executed assertion count are the evidence.

6. Resources