Truss is a programming language designed for agent-written software - finiteloop/truss

128 points•sram1337•1 day ago•97 comments•

97 comments

I'm not half as smart as most of the people on HN and I don't know much about formal verification, so maybe this is a dumb question....

My understanding of this is: You write a "contract" that defines the specification for some functionality, including inputs, outputs, preconditions, post-conditions, etc. and the contract can be formally verified by some proof checker that says it's logically consistent. Then you build the implementation and the implementation can be proven to abide by the contract (or not).

But somebody has to write the contract (either a person or AI). If the contact specifies behavior that is logically consistent as far as a proof checker is concerned, but the behavior is defined incorrectly, you could have a situation where "you built the thing right", but "you didn't build the right thing".

So someone still needs to make sure the contracts are specifying the correct behavior. Once you know you have, then I suppose the formal verification is good because everybody (people and AI) know that it guarantees its behavior.

My question then is: Assuming everything I just said isn't nonsense, aren't we still in the same place as before? Someone needs to know how to specify (and program) the right behavior?

iamwil1 day ago
It is a gap, but the spec is often declarative, on what needs to be true, rather than imperative, about all the exact steps. Hence, less prone to error. You're right that it proves the protocol, but not necessarily the implementation.

A not-quite-there way to close the gap is that you can generate traces from the spec/proof, a sequence of states and events that must hold true. and then you can use that trace to replay back in tests, and if the implementation is correct, then it should mirror the trace.

gpmabout 9 hours ago
The spec is also nice in that higher level abstractions check they're using the lower level ones according to actual specified behaviour not intended behaviour.

E.g. with a normal programming language a bug in the hash-map internals that rarely returns the wrong element is undectable. With a spec, if the spec says it can ever return the wrong element, I'm going to run head first into that when I try and prove that my pathfinding algorithm using that hashmap for memoization is correct.

finiteloopabout 17 hours ago
I am the Truss author. In Truss, the proof associated with a program explicitly proves it meets the contract. You're right the contract is declarative, and the proof is what proves the compliance of the imperative code to the contract.
dominotwabout 24 hours ago
> spec is often declarative

ppl always come with weird workarounds to put in loops and if conditions and then throw it all away to use a general purpose programming languge

cjfdabout 17 hours ago
You are not in the same place because the specification does not have to run on a computer. For instance, it could be horribly slow if it were actually executed. In the realm of optimization formal specification really shines because it is the situation where something relatively simple can be specified but the implementation is very complex. Furthermore, a specification does not in all case have to specify everything but instead can specify the essential properties that a system has. For instance, a permission system could have the property that a user who lacks a certain permission can never obtain information that he does not have the right to see but the detail of how that is implemented are not in the specifications. Also, for instance, specify that a system cannot crash or leak memory.

In situations where the specification is as complex as the program one should really wonder if one is doing the right thing.

hansvmabout 4 hours ago
Yes, but there's an implicit assumption that many parts of the contract are easier to understand than the corresponding code.

Take sorting as an example. Verifying any one instance is easy even in something like Python

  all(a<=b for a,b in zip(L,L[1:]))
Which wasn't really made for the task. If you have theorem proving as part of your contracts then that just gives you extra confidence above and beyond however else you're verifying them. Note that this is much easier to understand even if you don't know Python than a typical sorting algorithm.

I've personally never seen a contract system properly handle business rules well (the set of rules is usually about as verbose and we'll abstracted as the top-level code implementing them, and bugs are typically exactly the issue you posed, that the rules were improperly specified), so I'm skeptical of this approach.

pratzc071 day ago
The spec is far smaller than the implementation. For example take the TimSort case whose implementation in Java and Python had a bug that was there for years until someone tried to formally prove it correct. I also think many valuable properties do not need specific domain judgement like never crashes, no out of bounds access, no data races etc. A spec says "what" not the "how" you still need someone who understands the requirement but they don't have to get every single edge case right. If a model writes both the implementation and the proof, the checker doesn't care who wrote them. Human review shrinks from "read all the generated code" to "read the spec".
Joker_vD1 day ago
> The spec is far smaller than the implementation.

That heavily depends on what problem you're trying to solve. The very example from TFA is quite illustrative:

    contract ReplaceElement {
        function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64
            requires index < words.len
            ensures result == old(words[index])
                and snapshot(words) == update(old(snapshot(words)), index, value)
            terminates
            effects { read(words), write(words) }
    }

    implementation InlineReplaceElement of ReplaceElement {
        function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64 {
            let previous = words[index]
            words[index] = value
            previous
        }
    }
Or take, for instance, this spec in English prose: "given a predicate that returns true or false for each value, and a list of values, `filter` returns a new list that contains exactly the values in the original for which the predicate returned true". I guarantee you that turning this into the Truss contract would produce a significantly larger amount of code that the implementation that would consist of just the following 5 lines, modified accordingly:

    result := []{}
    for _, v := range list {
        if predicate(v) { result = append(result, v) }
    }
    return result
And of course, please note that the spec I've given is defective: it doesn't say anything about the order of the elements in the resulting list, or the presence/absence of duplicates. Also, you probably will have to insist on the predicate being a pure or at least a repeatable (reproducible?) function — I don't know how you'll spec `filter` when it's given a non-idempotent predicate.
kettlecorn1 day ago
It helps substantially because it disentangles subjective and objective programming.

Like if you want a program that sorts a list that is a subjective goal because you could just as easily choose a shuffled list, or a different sorting, or any other sort of list ordering.

Once you've established what you want fulfilling that is an objective task.

Today's programming languages entangle subjectivity and objectivity together, and better decoupling them means we can automate the objective parts which dramatically reduces the programming left over for humans.

grahamlee1 day ago
Difficulty: no existing model is trained on Truss. They have been trained on examples of design by contract in other languages (Ada, Eiffel, Java etc) and would do a better job with those and with contract-enforcement rules. Or even with grammar-constrained output and those languages.

Source: I also tried writing an agent-optimized language (for concision and adaptability, not correctness), then I measured.

spankalee1 day ago
This is not my experience at all. LLMs universal translation abilities let them pick up new languages really easily, especially if they borrow from existing languages and are consistent.

I've been building a new programming language, Zena [1], for a year and modern Claude and Gemini have absolutely no problem generating the code with about a 300-line skill: https://github.com/elematic/zena/blob/main/skills/zena/SKILL...

(I also happen to be adding contracts and formal verification for gen AI, maybe similar to Truss, but that targets Wasm for sandboxing).

[1]: https://zena-lang.dev/

ashkankianiabout 20 hours ago
They pick it up but they don't write idiomatic code. As in they write it like they write the languages they are most familiar with. Trying to teach them to use the special features of your language (the entire point of writing it) is not trivial.
burcsahinoglu1 day ago
Same experience here. I've been building LLMLL, another language no model was trained on. We built small fixtures meant to bait a subtly wrong implementation past its contract and ran them through Claude Opus, gpt-5.5 and Gemini. Across 69 attempts there were zero wrong fills.

Sounds like we overlap a lot. LLMLL has requires/ensures contracts too, and the SMT check you have planned for @verify already runs there over a decidable fragment. Anything outside that fragment is marked asserted or tested, not proven. It compiles to Haskell today, with WASM/WASI on the roadmap as the sandbox. Happy to compare notes.

brightball1 day ago
I saw a talk this year from one of the Pony Lang folks talking about this exact problem and how they essentially taught Pony to Claude.

https://carolina.codes/speakers/2026/redvers-davies

It was really interesting. Pony is also deeply underrated.

btown1 day ago
That's a great talk, and it has a resonant quote: "If you let your LLM us a general purpose language, your LLM has to solve all those hard problems instead. Good languages make the illegal impossible."

I think there's some truth here: linters and compilers for general purpose languages are only so powerful, and LLMs will always be tempted to use patterns they've seen before when they're knee-deep in a language they think they understand how to use for your problem. Restricting them to think about problems from first principles in languages with clear and enforced guidelines about data sharing, ownership, traceability, etc. can be very powerful.

Direct link to talk: https://www.youtube.com/watch?v=oU5sV1ljTzs

malloc20481 day ago
raise hand

Here someone else who tried to write a coding agent optimized programming language, but I asked it to optimize for cost. Using less tokens is an obvious one but while working on it the actual engineer (LLM) decided that saving on tokens would be marginal savings compared to being able to write the same quality code by a cheaper model. But it never found out how.

After a couple of hours seeing benchmarks in which it lost from Python on pretty much everything, it told me to give up. I did.

mikece1 day ago
Maybe the answer isn't to create a new language for AI, but add to Python the things that Claude tells me makes other languages better for some things, like type safety and a try compilation step to find errors way ahead of runtime.

(Or did I just describe something that has been done eleven times already?)

capv1 day ago
+1. You cannot teach AI a new programming language with prompts. In order to be efficient the language has to be in its "brain", i.e., AI's neural network has to be trained on large number of samples.
amterp1 day ago
> You cannot teach AI a new programming language with prompts

Incorrect. I built my own programming language [0] and agents just look up the docs and write it with great success. It helps to have static linting/analysis of course, but they always do just fine writing Rad despite it being very small.

[0] https://github.com/amterp/rad

rfgplk1 day ago
They already have been trained, on other languages that provide similar-enough constructs to translate over to the new language. Same principle as how a C++ developer can write Rust after looking at a few syntax examples.

For instance:

  contract ReplaceElement {
       function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64
           requires index < words.len
           ensures result == old(words[index])
               and snapshot(words) == update(old(snapshot(words)), index, value)
           terminates
           effects { read(words), write(words) }
   }
This is _extremely_ similar to JS/Rust/Java style syntax mixed with common forms from general ALGOL descendant languages. LLMs should have no trouble writing this whatsoever.
finiteloopabout 17 hours ago
I am the Truss author. I was worried about this, but with modern models and some specific design considerations of Truss (i.e., its syntax is not exotic), I have not found this to be a meaningful issue. The entire standard library (https://github.com/finiteloop/truss/tree/main/library) was created with GPT 6.2 Sol and it was relatively efficient, and I didn't have to baby sit it very much other than on design issues.
browningstreetabout 18 hours ago
I’m fine with the languages we have for AI programming, but what I wish we had was a more deterministic, operational plane of some kind.

I went around and around today because Claude wrote to obsidian in the wrong folder even though the obsidian vault path was in the env variables. It writes to obsidian 20 times a day and suddenly it writes to a path outside the vault path. The content never synced.

It claimed it went from recall and didn’t check the environment variables. I pointed out that each process wrote successfully to the correct path and it retorted that each effort is a new effort and had nothing to do with previous successful efforts.

These situations require more and more deterministic instructions in AGENTS.md but then it’ll find another way to escape the instructions. It’s an endless digressive evasive cycle.

ivan_gammelabout 14 hours ago
what you describe requires tooling, not instructions. CC can build a tool for scoped markdown editing in 2-3 days with a few confirmations from you, and won’t fail after that.
browningstreetabout 3 hours ago
i get that, and i have lots of scripts that partner with my LLMs for repetitive tasks.

but .. a collection of scripts, with a datastore.. starting to feel like a framework.

Great idea, but I believe AI you can't make an ML model efficient just through prompts. You must train the model with the language and vast samples of code written in that language. Even with python which is ubiquitous, something models struggle with optimization or smart algorithms it hasn't seen during training.

I guess the best way will be to improve on existing languages by adding the contracts and verification methods on top of them.

jatoraabout 23 hours ago
Well your belief is entirely wrong, because LLM's have shown time and again that they generalize to new languages easily.
abeppu1 day ago
Proofs about program correctness are great but I don't think this even really attempts to argue why a new language is needed or what this does better than other systems in the space. The only other language mentioned in this project page is Rust as "a small step", but doesn't mention F*, Dafny, Idris, Verus, CakeML etc. I think basically all of these have some greater burdens for authors which previously made them realistic for only some projects, but now that we can have agents deal with those headaches, maybe they should expect to see broader use.
finiteloopabout 17 hours ago
I am the Truss author. This is always the right and correct question for any new language, and as with most new languages, part of the rationale is "because I wanted to make it."

But more substantively, part of the thesis of Truss is composition of verification:

> When you bind Map to a provider like InlineMap, Truss uses the supplied evidence in package.proof to independently verify its conformance, a simple validation process that can be an order of magnitude faster than constructing the proof itself. > > This approach enables formal verification to scale with large code bases, pushing the majority of the work of formal verification to package authors; when you publish a package, you spend as many tokens generating proofs as you do writing the code, and the programs depending on your package don’t need to recreate your efforts.

By (1) explicitly tying the proofs to the language (as opposed to proving independent code, which can stray from what was proven), (2) making the contract claims the basis of proof composition, (3) tying this all together in the packaging system, I have a hypothesis it will make scaling verification more practical, especially in very large codebases.

gf000about 10 hours ago
So you "accept" a proof at package publish time and then go with that?

Also, aren't function composition known to be bad-behaving, and unfortunately just because you can prove something about f and something about g, f(g) may be prohibitively expensive to prove again? Do you have an idea how common it is?

miffy9001 day ago
it's interesting you mentioned Dafny, as after taking a look myself, I see the method specification syntax that Truss uses, has keywords like ensures and requires which is straight up from Dafny, which itself is a Microsoft Research language made by a person who worked on SpecSharp (basically contracts for .NET), which itself took the `ensure` and `require` keywords from Eiffel.

I couldn't find a connection between Truss's author and Microsoft, so I do wonder if he maybe got an LLM to design the syntax, which then included prior art from Microsoft etc.

trealiraabout 7 hours ago
Maybe he did, or maybe he was just inspired by prior art. Programming languages rip off each other all the time. Java and C#, for instance, ripped off a lot of C++ syntax.

Read the full thread on Hacker News →

Related stories