Skip navigation
One magical part of Cursor’s internal tech stack is a prompt compilation library called priompt (
0:00 / 0:23

One magical part of Cursor’s internal tech stack is a prompt compilation library called priompt (

Aman Sanger

@amanrsanger52K followers

Visit on X
695 likesDownloadOriginal post

152,112 views

One magical part of Cursor’s internal tech stack is a prompt compilation library called priompt ( Here's why works so well... (1/12)

12 Comments

Comments from the original post on X (Twitter)

  • Aman Sanger's profile picture

    @amanrsanger

    Standard prompting libraries use variants of “f-strings” with subbed-in inputs. For us, a prompt is defined as a function that maps some set of inputs X and a token budget n to some string, s: p(X, n) = s We call this operation "rendering" (2/12)

    40 likes

  • Aman Sanger's profile picture

    @amanrsanger

    For example, my inputs, X, could include conversation history, contents of the current file, chunks of documentation, and codebase context we deem relevant. This sums to 100K tokens. But the budget we are working with may just be 4000 tokens. (3/12)

    24 likes

  • Aman Sanger's profile picture

    @amanrsanger

    For some input, X_1, let's say the text around the user's cursor matters most. This is followed by the last message in the conversation history, then the first few chunks of both documentation and codebase context. (4/12)

    22 likes

  • Aman Sanger's profile picture

    @amanrsanger

    Finally, every 5 lines of text above and below the selected region matters as much as each preceding message in the conversation history. From X_1, we must render the string that contains the most useful pieces of information, with prioritization in the order described (5/12)

    20 likes

  • Aman Sanger's profile picture

    @amanrsanger

    We need a framework with enough flexibility to design these mappings, but enough abstraction that you won’t be writing a million if/else’s with tedious string manipulation. This is where priompt comes in - A JSX and priorities-based prompting library. (6/12)

    22 likes

  • Aman Sanger's profile picture

    @amanrsanger

    Prompt design has many similarities to web design ( The notable ones are: 1. Dynamic views given variable inputs (or props) 2. Re-use of rendered primitives (component re-use) 3. Adaptive rendering given size constraint (screen width/token budget) (7/12)

    44 likes

  • Aman Sanger's profile picture

    @amanrsanger

    What makes everything work are the “priorities” Each component has some priority, p, which is initially set via simple heuristics. When introducing embeddings/rerankers, components can be assigned priority equal to the deemed relevance. (8/12)

    19 likes

  • Aman Sanger's profile picture

    @amanrsanger

    The promise of the priompt renderer is that it will find the smallest global priority, p*, such that when all components with p>p* are included, the total string is under the token budget. (9/12)

    19 likes

  • Aman Sanger's profile picture

    @amanrsanger

    Consider this very simple toy prompt: It prioritizes later messages in the chat over older ones and will render as many messages as possible. Instead of cutting off the message that lies in the order, it chooses to not include it. (10/12)

    19 likes

  • Aman Sanger's profile picture

    @amanrsanger

    But it gets an order of magnitude more expressive than this. A favorite of mine is the PriorityControlledCode, which powers most of our file-views. Both component composability and priorities dramatically improve quality and DX (11/12)

    24 likes

  • Aman Sanger's profile picture

    @amanrsanger

    Combining these allows us to define expressive prompts with re-usable components with almost pixel-perfect context. This library was the brainchild of @arvid220, who had fantastic foresight into its usefulness

    29 likes

  • Aman Sanger's profile picture

    @amanrsanger

    * @ArVID220u

    12 likes