Exploring a more deterministic approach to AI-assisted code generation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5168

    #1

    Exploring a more deterministic approach to AI-assisted code generation

    Introduction

    AI coding agents are getting surprisingly good.


    In small projects, you can ask them to add features, fix bugs, and even write tests—and they often succeed.


    But once your project grows, things start to break down.


    In my experience, the issue is not model capability. It’s something more subtle: prompt instability.


    The Problem: Prompt Instability

    Most coding agents construct prompts dynamically using:
    • chat history
    • parts of the codebase
    • internal heuristics


    This means the final prompt is not fully under your control.


    As a result:
    • the same request can produce different outputs
    • changes can appear in unexpected parts of the codebase
    • behavior becomes harder to reason about


    In small projects, this is manageable.

    In larger systems, it becomes risky.

    A Different Approach: Treat Prompts Like Source Code

    Instead of relying on dynamically constructed prompts, I started experimenting with a different idea:


    Treat prompts like source code.


    That means:
    • prompts are explicit
    • prompts are reusable
    • prompts can be composed from other prompts
    • prompt construction is deterministic
    • prompts are the source of truth, not code


    This shifts the workflow from “chatting with an agent” to something closer to designing system architecture.

    The Tool: SVI (Structured Vibe Coding)

    To explore this idea, I built a small tool called SVI.


    SVI generates source code from structured specification files (.svi) written in a Markdown-like format.


    Key ideas:
    • Each .svi file defines how a specific source file should be generated
    • Prompts can import and reuse other prompts
    • The final prompt is constructed in a fully controlled and predictable way


    Unlike typical coding agents, SVI does not depend on chat history or implicit context.

    Example

    Here is a simple .svi file:






    # Destination File
    hello.js

    # Output
    function hello()

    # Options
    ProgrammingLanguage=Node.js
    Active=True

    # Prompt
    Create a function that prints "Hello World", and call this function








    Generate the code with:






    svi run







    The output is generated by an LLM and based on the specification.


    Why This Matters

    This approach has a few practical benefits:
    • More predictable results


    You know exactly which prompt generated which file, and get more predictable results
    • Reusability


    Prompts can be shared and composed
    • Lower model requirements


    Smaller prompts allow you to use cheaper or even free models; you can adjust the prompt size and complexity to match the LLM you’re using.


    Trade-offs

    This approach is not a silver bullet.
    • It requires more upfront structure
    • It is less flexible than free-form prompting
    • It changes the workflow from interactive to more declarative


    However, for larger projects, this trade-off might be worthwhile.


    Conclusion

    AI coding agents are powerful, but their current design makes them hard to control at scale.

    Treating prompts like source code is one way to bring back structure and predictability.

    I’m still experimenting with this approach, and I’d be interested to hear if others have explored similar ideas.


    Links

    GitHub repository: https://github.com/avrmsoft/svi




    More...
Working...