Overview

Chains allow you to create multi-step prompts that can interact with the AI model in stages. You can pass the result of one step to the next one. This enables more complex workflows and dynamic conversations.

Using Steps in Your Prompts

  • Use the <response /> tag in your prompt to add a step. The engine will pause at that step, generate a response, and add it to the conversaion as an assistant message, before continuing with the prompt.
  • You can add custom configuration to each step by adding attributes to the <response /> tag:
        <response provider="openai" model="gpt-4o-mini" temperature={{0.1}} />
    
  • You can store the response of a step as a variable using the as attribute, followed by the variable name.
        <response as="result" />
    
        {{#if result === "correct"}}
            …
        {{/if}}
    
    This allows you to reuse the response later in your prompt and use it in conditionals or other logic. Check the logic section.

Basic Example

    ---
    provider: openai
    model: gpt-4o
    ---
    Analyze the following sentence and identify the subject, verb, and object:

    <user>
        "The curious cat chased the playful mouse."
    </user>

    <response provider="openai" model="gpt-4o-mini" />

    Now, using this information, create a new sentence by
    replacing each part of speech with a different word, but keep the same structure.

    <response />

    Finally, translate the new sentence you created into French and return just the sentence.