AgentScript is a new proposal that seamlessly bridges AI-generated code and human-readable syntax. Its mission is to serve as the ultimate "pseudo-code–but-real-language" that is both succinct and transpilable to TypeScript. Designed from the ground up to be AI-friendly, AgentScript enforces strong best practices from contract programming, functional programming, concurrency, and beyond—ensuring that generated code is thoroughly tested and future-proof.
- Introduction
- Why AgentScript?
- Core Concepts
- Embedded Testing and Contract Programming
- Functional and Concurrency Primitives
- Transpilation Flow
- Compared to Other Languages
- Practical AI-Driven Benefits
- Implementation Workflow
- Long-Term Vision
Modern software development is dominated by AI-driven code generation. Tools like Cursor, WindSurf, Cline, and other coding agents can spin up new features in seconds, but they often struggle with maintainability, testing, and clarity. Existing languages—TypeScript included—remain too verbose, lacking a concise “intermediate” syntax that is:
- Immediately clear to both humans and AI.
- Equipped with robust best practices (like contract programming).
- Easily transpilable to stable languages (like TypeScript).
AgentScript was conceived as a direct response to these realities. By blending functional programming, test enforcement, and advanced concurrency constructs into a succinct code structure, AgentScript drastically increases the reliability of AI-generated output. The result: developers (human or AI) spend less time on boilerplate, produce fewer bugs, and achieve higher confidence in their code.
- AI-First Design: Encourages minimal token usage, making code generation more cost-effective.
- Declarative Contracts: Integrates heavyweight constructs from contract programming to catch errors early.
- Embedded Testing: Bundles success, performance, concurrency, and smoke tests within the same file.
- Functional + Concurrency: Adopts functional paradigms and concurrency checks.
- Human-Readable: Emphasizes short syntax that is easy to parse for developers reading or diffing code.
- Transpilable: Produced code can go straight into TypeScript or modern JavaScript with minimal overhead.
AgentScript focuses on being an "intermediate pseudo-code language," bridging the gap between purely natural language specifications and production-ready TypeScript.
- Minimal Syntax: Think of TypeScript stripped to its essentials, with added meta blocks for tests and context.
- Intent & Context: Every function uses short metadata blocks for AI clarity and forward-compatibility.
- Error Tags: Predefined in each function or module, ensuring clarity and easier debugging.
- State Machines: For advanced workflows, you can embed state machines directly, making concurrency and transitions explicit.
- Functional Patterns: Pipeline operators and pattern matching are front and center for succinct expression of complex logic.
function fetchTodosByUser(userId: ID): TodoList
goal: "Fetch a list of TODO items for a given user"
backstory: "Used by the main dashboard to show tasks"
requires:
userId >= 0: "User ID cannot be negative"
return: fetchFromDatabase("todos", userId)
errors:
UserNotFound: "No user found with the given ID"
tests:
success:
1 -> [ { id: 1, task: "Buy milk" }, ... ]
performance:
execution: expect < 3ms
memory: expect < 5mbHere, the function includes an actual implementation for the return statement, ensuring it is more than just pseudo-code. AI agents or human developers can update it easily while preserving the constraints and embedded tests.
AgentScript can be configured to enforce purity in function definitions, prohibiting side effects and mutable state. This ensures functional correctness and makes concurrency patterns more predictable. By default, functions may mutate local state, but stricter lint or compiler settings allow you to mark everything as immutable and side-effect-free.
Under this strict mode:
- Functions must avoid global or shared mutable state.
- Any attempts to reassign function parameters or mutate objects in place will produce warnings or errors.
- Return types must avoid “any” and be explicitly defined, preventing silent type failures.
Biome is an advanced code analysis and transformation tool that can be configured in its strictest setting to enforce:
- No use of “any” or “unknown” types without explicit justifications.
- No hidden side effects or ambiguous type declarations.
- Automatic refactoring suggestions to maintain “pure function” hygiene.
By integrating Biome into the AgentScript toolchain, teams (human or AI) can ensure that lazy or incorrect type usage is caught early, vastly improving code reliability and maintainability.
AgentScript introduces requires clauses that define input constraints, reminiscent of contract programming. These constraints compile directly into runtime checks in the TypeScript output, guaranteeing that your code will fail fast if an invalid argument is passed.
function processPayment(amount: number, currency: string)
requires:
amount > 0: "Amount must be positive"
currency != "XYZ": "Unsupported currency format"
...Tests are written inline to ensure code correctness, with categories:
- success: Traditional unit tests.
- performance: Enforces execution time or memory usage constraints.
- smoke: Simple checks for edge cases.
- concurrency: Stress tests and race condition detection.
These blocks compile to Vitest or k6-friendly test suites, reducing friction when verifying code reliability.
- Pipe Operator (
|>)
Promote a functional style that is easy for LLMs to read, and ensures transformations are explicit.data |> parseJSON |> validate |> transformData
- Pattern Matching (inspired by EcmaScript proposals and functional languages)
match (user.role) { case "admin" -> handleAdmin(user) case "guest" -> handleGuest(user) }
- Concurrency
- machine blocks for embedded state machines (like XState).
- parallel test configurations for concurrency stress tests.
- Built-in concurrency patterns (e.g., spool, watchers, supervisors) to manage parallel tasks more safely.
- AgentScript Source: Minimal syntax, embedded tests, contract requirements, and concurrency hints.
- Parser & Transpiler: A specialized parser reads AgentScript, verifying the embedded metadata.
- Output:
- TypeScript for main logic.
- Vitest test suites for unit and integration tests.
- k6 scripts for performance and concurrency testing.
- Optional advanced concurrency semantics mapped to XState or other libraries.
| Feature | TypeScript | Rust | AgentScript | Reason to Pick AgentScript |
|---|---|---|---|---|
| Concurrency | ✅ Effect-based concurrency | Easier concurrency setup and management | ||
| Parallelism | ✅ Promise.all | ✅ Rayon | ✅ Native parallel constructs | Simplified parallel testing and operations |
| State Machines | ✅ Native integration | More explicit checks with state machines | ||
| Type Safety | ✅ | ✅ High (built-in checks) | AI can rely on stable types inside code & tests | |
| Null Safety | ✅ Strict null checks | ✅ Option types | ✅ High (checked) | Minimizes runtime exceptions due to null references |
| Error Safety | ❌ Manual or throw-based | ✅ | ✅ Built-in requires constraints |
Early error detection with clear constraints |
| Pipes | ❌ | ❌ | ✅ Pipeline operator | More expressive transformations |
| Pattern Matching | ❌ | ✅ Full (match blocks) | More expressive branching (inspired by functional languages) | |
| AI-Friendliness | ✅ High | Designed for minimal token usage | ||
| Testing | ✅ Inline, enforced | Ensures AI maintains full test coverage | ||
| Contract Programming | ✅ Built-in through requires |
Early error detection with clear constraints |
- Less Token Overhead: Succinct syntax means large language models can parse, generate, and correct code with minimal token usage.
- Autonomous Updates: AI agents can automatically update or refactor code while preserving embedded tests and constraints.
- Reduced Boilerplate: Built-in best practices mean fewer lines of scaffolding or repeated patterns.
- Transparent Intent: The
intentandcontextfields let the AI keep track of the function’s purpose, preventing accidental misuse.
-
Define Requirements
- Outline each function’s
intent,context, andrequiresfor clarity.
- Outline each function’s
-
Write Skeleton
- Create initial AgentScript code with embedded tests and concurrency hints.
-
Transpile to TypeScript
- Use the AgentScript transpiler to produce TypeScript with test and concurrency scaffolding.
-
Run Tests
- Let Vitest and k6 run the inline tests to catch errors.
-
Refine & Iterate
- Tweak the AgentScript code or let an AI agent further refine constraints and concurrency patterns.
We see AgentScript as the new baseline for how AI-driven development can produce stable, maintainable code at scale. By standardizing on robust patterns, embedded testing, concurrency checks, and contract programming, we aim to:
- Elevate AI Productivity: Provide a structured yet flexible environment that suits LLM generation.
- Set Industry Standards: Expand best practices for concurrency, functional patterns, and contract definitions.
- Spark Evolution: Inspire TypeScript and other languages to adopt more explicit, embedded contracts and tests.
AgentScript is more than a language; it’s a commitment to pushing AI-driven software to new levels of reliability, readability, and efficiency.
TypeScript is among the most popular programming languages worldwide, enjoying rapid growth in community support and language evolution. Its type system provides strong guarantees while remaining flexible enough for nearly any environment or runtime—browsers, servers, serverless platforms, mobile apps, and even Infrastructure as Code (IaC). By transpiling AgentScript to TypeScript:
- You benefit from TypeScript’s thriving ecosystem of libraries and tooling.
- Deployment becomes considerably simpler, since the same TypeScript output can run on Node.js, Cloudflare, React Native, or the browser.
- The language updates regularly, which means AgentScript’s emitted TypeScript can stay current with evolving JavaScript and type system features.
Targeting TypeScript ensures you can deploy AgentScript-based code anywhere, with minimal overhead and maximum future compatibility.