Truss: A programming language optimized for agent-written software
Truss Truss Overview Truss is a programming language optimized for agent-written software. Truss aims to make software more reliable, secure, and performant by embracing the unique strengths of AI agents. Traditional programming languages were designed for the ergonomics of human authors, effectively optimizing for the convenience of writing code. Truss, in contrast, assumes code is no longer written by hand, but instead written by AI agents. This fundamental assumption changes most of the design considerations for Truss relative to traditional programming languages: Rather than optimizing for authoring convenience, Truss requires quite a bit of reasoning at authoring time to verify a program's correctness and performance. That tradeoff is sensible for agent-written software because it is not a burden to the software engineer and the one-time token spend can produce software with enduring robustness. Popular programming languages like Rust are a small step in this direction, providing compile-time memory safety — making Rust code a bit harder to write for humans, but a fantastic language target for AI. Truss takes this idea a few steps further, formally verifying behaviors well beyond memory management. I (Bret Taylor) think we will probably rewrite most software written before AI because that software is imperfect, insecure, and slow. I would like to have software that is provably correct, verifiably secure, and incredibly fast, and I would like to be able to use agents to produce software of unparalleled scale and complexity that has those qualities. Truss is just a prototype, but I was hoping to start a conversation about the platforms we need to design to achieve that vision. How Truss Works The atomic unit of a Truss package is a contract. A contract specifies data structures and functions along with their formally verified behaviors, including what they return, what memory they can access, and what state they can change. Providers implement contracts. For example, a Map contract could have multiple providers, a HashMap and a SortedMap. Each provider must provably satisfy all the claims in the contract, and each provider provides evidence of their conformance in the form of a proof alongside the implementation source code. library/collections/map/ map.truss # The Map contract package.truss # Map dependencies inline/ inline_map.truss # InlineMap implementation of Map package.truss # InlineMap dependencies package.proof # Evidence that InlineMap satisfies Map sorted/ sorted_map.truss # SortedMap implementation of Map package.truss # SortedMap dependencies package.proof # Evidence that SortedMap satisfies Map When your program uses Map, the Truss compiler will generate a proof of its correctness by relying on the claims in the Map contract without having to independently verify each provider. 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. Truss brings verification all the way to code generation. A provider proves that it implements the contract. The compiler proves that its translation preserves the body’s observable behavior. A separate-compilation rule proves that the guarantee survives linking against conforming implementations. Example We’re going to make a package that replaces one element in a slice of UInt64 words and returns the value it overwrote. replace-element/ package.truss replace_element.truss inline/ package.truss inline_replace_element.truss package.proof Declare the Contract Declare the contract in replace_element.truss. The contract guarantees that the element at index is replaced by value, and also protects against buffer overflow: contract ReplaceElement { function replace(words: &mutable Slice
, 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) } } Define the Provider Define the provider in inline_replace_element.truss: implementation InlineReplaceElement of ReplaceElement { function replace(words: &mutable Slice
, index: UInt64, value: UInt64) -> UInt64 { let previous = words[index] words[index] = value previous } } Generate the Contract Conformance Proof Now that we’ve defined an implementation, we can generate a proof that it satisfies the ReplaceElement contract. The result of that proof lives side-by-side with the implementation so that clients of this package don’t need to reproduce the effort to prove conformance to the contract. To generate the proof, we run this command in the provider directory, which emits the package.proof file: truss proof update Use the Package To use the package in a program, you create a dependency on ReplaceElement and bind it to the provider: package "hello-world" { requires ReplaceElement from "replace-element" version "1.0.0" bind ReplaceElement to provider "replace-element/inline" version "1.0.0" } Try it Yourself Build and run your first program in the getting-started chapter. Examples in the Standard Library If you want to get a sense of what Truss contracts can guarantee, take a look at the examples in the included standard library: Sort — Sort a table by one column and every key keeps its original payload, even when keys repeat. SHA-256 — The streaming contract proves that the digest covers exactly the bytes accepted, in order, however you split them across calls. HTTP response framing — The parser finds exactly where the headers end even when the final blank line is split across reads. The bytes that follow are still available to the body reader. ZIP extraction — If extraction fails halfway through, the reported file and byte counts cover exactly the prefix whose publication was confirmed. JSON strings — The contract proves which Unicode character an escape sequence represents and exactly where the next character begins, including when two escapes encode a single character. Socket readiness — A delayed event for a closed connection cannot be accepted for a new connection that reuses the same slot. CRC-32 — A proof using the shipping checksum loop shows that any split of the same bytes, including empty chunks, gives the same checksum as one pass. Owned byte buffers — A successful append keeps every original byte and adds exactly the bytes supplied. If the append fails, the caller gets back the original allocation and contents. Using Truss Install Truss from source to write and run packages. For compiler development, see Build the toolchain. Using the Compiler The truss command supports the following operations: Documentation Truss Language Guide Truss Compiler Design Truss Standard Library Contact Information Truss is a project from Bret Taylor.