µNorman

µNorman v0.2.0

A small language for AI agents

Typed model calls, budgets in money and time, tools, and concurrency.

Background

Different studies and previous works inspired the idea for µNorman. They all identified shortcomings and existing problems with current agentic work:

ProblemWhat µNorman does
Unreliable answersevery ask names the type of answer it wants
Decisionsanswers can be choices that the program branches on
Cost and deadlinesmoney and time are built in, and the budget is never overspent
Latencyeach budget has one shared clock with deadlines
Failed stepsfailures are values, and retry wraps a single step
Tool accesstools are capabilities that a model can never create

Note that most of these are enforced when the program runs. See Status.

An overview of the main capabilities of µNorman:

1. Ask

You give ask a model and the context it should see. You also name the type of answer you want. If the reply fits that type, you get a real value back. If it doesn’t, the ask fails. The context is just a list you build yourself. Nothing gets added to it without you knowing.

typed-ask.nrm
(grant claude (model [in 3] [out 15] [ceiling 8000]))

(datatype Verdict
  [Buy  (reason (Text 400))]
  [Hold (reason (Text 400))]
  [Sell (reason (Text 400))])

(define analyst-ctx (filing)
  (list (Message [role System] [content "You are an equity analyst."])
        (Message [role User]   [content filing])))

;; A script: what the model says, how big the reply is, how long it takes.
(script sell
  [analyst (reply "{\"tag\":\"Sell\",\"reason\":\"Margins are compressing.\"}")
           (out 20) (latency 2s)])

(under ([script sell] [cost $1.00] [time 1min])
  (check-expect (ask claude Verdict (analyst-ctx "FY2025 10-K") 'analyst)
                (Sell "Margins are compressing."))
  ;; the same call, measured: at most a cent and two seconds
  (check-within (ask claude Verdict (analyst-ctx "FY2025 10-K") 'analyst)
                ([cost $0.01] [time 2s])))

2. Handling Failure

Agents fail a lot. The reply might not fit the type. The provider might be down. You might run out of money or time. In each case ask gives back a failure instead of crashing. There are six kinds: Invalid, ToolError, Refused, OverBudget, PastDeadline and Raised. You can catch any of them and decide what to do next.

failure.nrm
(grant claude (model [in 3] [out 15] [ceiling 8000]))

(datatype Verdict
  [Buy  (reason (Text 400))]
  [Hold (reason (Text 400))]
  [Sell (reason (Text 400))])

(define ctx () (list (Message [role User] [content "FY2025 10-K"])))

(define analyst (model)
  (catch (ask model Verdict (ctx) 'analyst)
         err
         (Hold "analysis unavailable")))

;; The model replies with prose where a Verdict was required.
(script garbled
  [analyst (reply "I think you should sell.") (out 8) (latency 1s)])

(under ([script garbled] [cost $1.00] [time 1min])
  (check-fail   (ask claude Verdict (ctx) 'analyst) (Invalid _))
  (check-expect (analyst claude) (Hold "analysis unavailable")))

3. The budget can never be overspent

Before it calls the model, ask reserves the worst case. That means the full prompt plus the longest answer the type allows. If that doesn’t fit in the budget, the model is never called and you pay nothing. This is why types have size limits. Leave the limit off and the same question gets turned away.

budget.nrm
(grant claude (model [in 3] [out 15] [ceiling 8000]))

(datatype Verdict [Sell (reason (Text 400))])   ; bounded: reserves about $0.007
(datatype Loose   [LSell (reason Text)])        ; unbounded: reserves about $0.12

(define ctx () (list (Message [role User] [content "FY2025 10-K"])))

(script both
  [tight (reply "{\"tag\":\"Sell\",\"reason\":\"Margins fell.\"}")  (out 20) (latency 2s)]
  [loose (reply "{\"tag\":\"LSell\",\"reason\":\"Margins fell.\"}") (out 20) (latency 2s)])

(under ([script both] [cost $0.05] [time 1min])
  (check-expect (ask claude Verdict (ctx) 'tight) (Sell "Margins fell."))

  ;; The same question with an unbounded answer type will not fit $0.05.
  (check-fail (ask claude Loose (ctx) 'loose) OverBudget)

  ;; And refusing costs nothing at all: no money, no time, no call.
  (check-within (catch (ask claude Loose (ctx) 'loose) e 0)
                ([cost $0] [time 0s])))

4. Agent Loop

This is the CP-Agent design. The model picks the next step. If it writes code, we run it and show it the output. When it says it’s done, we stop. The answer is a choice, so the loop is a plain case. The budget around it makes sure it always ends.

react.nrm
(grant claude (model [in 3] [out 15] [ceiling 8000]))
(grant py     (kernel))                   ; a stateful tool, from the host

(datatype Step
  [Exec (code (Text 4000))]               ; "run this and show me the output"
  [Done (code (Text 4000))])              ; "this is my final answer"

;; A tool error becomes an observation the model can read. Nothing else does.
(define observe (py code)
  (catch (call py exec code) e
    (case e [(ToolError m) m] [_ (fail e)])))

(define react (model py ctx)
  (case (ask model Step ctx 'react)
    [(Exec code)
       (react model py
              (append ctx (list (Message [role Assistant] [content code])
                                (Message [role Tool]      [content (observe py code)]))))]
    [(Done code) code]))

(define cp-agent (model py task)
  (budget ([cost $0.50] [time 10min])
    (react model py (list (Message [role User] [content task])))))

(script cp
  [react   (reply "{\"tag\":\"Exec\",\"code\":\"x = 6 * 7\"}")   (out 12) (latency 3s)
           (reply "{\"tag\":\"Done\",\"code\":\"print(42)\"}")   (out 16) (latency 3s)]
  [py/exec (result "") (latency 1s)])

(under ([script cp] [cost $1.00] [time 5min])
  (check-expect (cp-agent claude py "Compute 6 * 7.") "print(42)")
  ;; two asks at 3s and one tool call at 1s
  (check-within (cp-agent claude py "Compute 6 * 7.") ([cost $0.05] [time 7s])))

5. Concurrency

A workflow is a set of named steps. A step waits only on the steps it mentions by name. As soon as its inputs are ready, it runs. In the example below, four model calls take 40 seconds this way. Forcing them into “run two, wait, run two” takes 60 seconds. Both cost the same. Running things at once saves time, not money.

workflow.nrm
(grant claude (model [in 3] [out 15] [ceiling 8000]))

(define step-ctx (name)
  (list (Message [role User] [content (string-append "Do step " name)])))

;; c needs a and b; d needs only a. Mentioning a name creates the edge.
(define n-graph (m)
  (workflow ([a (ask m (Text 20) (step-ctx "a") 'a)]
             [b (ask m (Text 20) (step-ctx "b") 'b)]
             [c (begin a b (ask m (Text 20) (step-ctx "c") 'c))]
             [d (begin a   (ask m (Text 20) (step-ctx "d") 'd))])
    (list a b c d)))

;; The same work, forced into two phases.
(define n-graph-par (m)
  (let* ([ab (par (ask m (Text 20) (step-ctx "a") 'a)
                  (ask m (Text 20) (step-ctx "b") 'b))]
         [cd (par (ask m (Text 20) (step-ctx "c") 'c)
                  (ask m (Text 20) (step-ctx "d") 'd))])
    (list (. ab fst) (. ab snd) (. cd fst) (. cd snd))))

;; `elapsed` is six lines of µNorman, built on the (remaining) observer.
(define elapsed (thunk)
  (let* ([t0 (. (remaining) time)] [_ (thunk)] [t1 (. (remaining) time)])
    (- t0 t1)))

(script dag
  [a (reply "\"A\"") (out 2) (latency 10s)]
  [b (reply "\"B\"") (out 2) (latency 30s)]
  [c (reply "\"C\"") (out 2) (latency 10s)]
  [d (reply "\"D\"") (out 2) (latency 30s)])

(under ([script dag] [cost $1.00] [time 5min])
  (check-expect (n-graph claude) (list "A" "B" "C" "D"))
  (check-expect (elapsed (lambda () (n-graph claude)))     40s)   ; critical path
  (check-expect (elapsed (lambda () (n-graph-par claude))) 60s))  ; fork and join

6. Laws

Every construct comes with algebraic laws. They tell you which rewrites are safe. The non-laws matter just as much. A compiler might merge two identical asks into one. That would change the result, since the same question can get a different answer each time. So µNorman never caches a model’s answer on its own.

laws.nrm
(grant claude (model [in 3] [out 15] [ceiling 8000]))

(datatype Verdict
  [Buy  (reason (Text 400))]
  [Sell (reason (Text 400))])

(define ask-v ()
  (ask claude Verdict (list (Message [role User] [content "FY2025 10-K"])) 'analyst))

(script two-answers
  [analyst (reply "{\"tag\":\"Buy\",\"reason\":\"One.\"}")  (out 10) (latency 2s)
           (reply "{\"tag\":\"Sell\",\"reason\":\"Two.\"}") (out 10) (latency 2s)])

(under ([script two-answers] [cost $1.00] [time 1min])

  ;; NOT a law: common-subexpression elimination. Two asks, two answers.
  ;; An optimizer that rewrote this to (Pair [fst a] [snd a]) would be wrong.
  (check-expect (let* ([a (ask-v)] [b (ask-v)]) (Pair [fst a] [snd b]))
                (Pair [fst (Buy "One.")] [snd (Sell "Two.")]))

  ;; A law that does hold: catching a failure only to re-raise it changes
  ;; nothing at all -- not the value, not the money, not the clock, not the trace.
  (check-equiv (catch (ask-v) x (fail x)) (ask-v) 'exact))

What µNorman guarantees

  1. The budget is never overspent, even with many steps running at once. The interpreter checks this invariant in every state it reaches.
  2. A model can’t hand your program a tool. Authority comes only from the host.
  3. No answer is accepted after the deadline.
  4. Concurrency doesn’t change answers. A workflow gives the same result as running its steps one at a time, when no budget or deadline binds and no step reads its own remaining budget.
  5. Every model call and tool call is recorded in a trace. That is what makes testing, replay and cost profiling possible.

Status

µNorman is a research prototype, designed in the style of Norman Ramsey’s Programming Languages: Build, Prove, and Compare and his Seven Lessons in Program Design.

What works

The language, its semantics, its laws, and an interpreter that runs them. 187 unit tests written in µNorman, 13 laws checked on 150 random scripts each, and a suite of deliberately wrong tests that must fail.

It runs!

CP-Agent solves problems against Claude Sonnet 5 with a Python kernel. The traces are here, including the budget refusing to start a run it couldn’t afford.

No static checking yet

The guarantees above are enforced when a program runs. A type and effect system is designed but not built; it is what would move the checks to compile time.

A small standard library

show writes any value as text that reads back, and there are substrings, so a program can build real prompts. It is still small: no sorting, no maps, no regular expressions.

Performance is a hypothesis

µNorman makes an agent’s behaviour knowable and bounded. It does not make the model better, and nothing here has been measured against a baseline.

One Important Finding

The answer’s type is sent with every ask as a JSON schema, which accounts for a significant portion of the input tokens. A type costs money twice: bounding an answer shrinks the reservation, but adding a constructor or a field makes every ask dearer on input, for as long as the program runs. That falsified one of the algebraic laws, which had priced an ask without its schema.

This is cool, what can I look at next?