<spanid="arch-multi-turn-guide"></span><h1>Multi-Turn<a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#multi-turn"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></h1>
<codeclass="docutils literal notranslate"><spanclass="pre">follow-up</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">clarification</span></code> questions. Specifically, when users ask for changes or additions to previous responses, it requires developers to
re-write prompts using LLMs with precise prompt engineering techniques. This process is slow, manual, error prone and adds latency and token cost for
common scenarios that can be managed more efficiently.</p>
<p>Arch is highly capable of accurately detecting and processing prompts in multi-turn scenarios so that you can buil fast and accurate agents in minutes.
Below are some cnversational examples that you can build via Arch. Each example is enriched with annotations (via ** [Arch] ** ) that illustrates how Arch
processess conversational messages on your behalf.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>The following section assumes that you have some knowledge about the core concepts of Arch, such as <aclass="reference internal"href="../concepts/tech_overview/prompt.html#arch-overview-prompt-handling"><spanclass="std std-ref">prompt_targets</span></a>.
If you haven’t familizaried yourself with Arch’s concepts, we recommend you first read the <aclass="reference internal"href="../concepts/tech_overview/tech_overview.html#tech-overview"><spanclass="std std-ref">tech overview</span></a> section firtst.
Additionally, the conversation examples below assume the usage of the following <aclass="reference internal"href="#multi-turn-subsection-prompt-target"><spanclass="std std-ref">arch_config.yaml</span></a> file.</p>
</div>
<sectionid="example-1-adjusting-retrieval">
<h2>Example 1: Adjusting Retrieval<a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#example-1-adjusting-retrieval"x-intersect.margin.0%.0%.-70%.0%="activeSection ='#example-1-adjusting-retrieval'"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></h2>
<divclass="highlight-text notranslate"><divclass="highlight"><pre><span></span><code><spanid="line-1">User: What are the benefits of renewable energy?
</span><spanid="line-2">**[Arch]**: Check if there is an available <prompt_target> that can handle this user query.
</span><spanid="line-3">**[Arch]**: Found "get_info_for_energy_source" prompt_target in arch_config.yaml. Forward prompt to the endpoint configured in "get_info_for_energy_source"
</span><spanid="line-4">...
</span><spanid="line-5">Assistant: Renewable energy reduces greenhouse gas emissions, lowers air pollution, and provides sustainable power sources like solar and wind.
</span><spanid="line-6">
</span><spanid="line-7">User: Include cost considerations in the response.
</span><spanid="line-8">**[Arch]**: Follow-up detected. Forward prompt history to the "get_info_for_energy_source" prompt_target and post the following parameters consideration="cost"
</span><spanid="line-9">...
</span><spanid="line-10">Assistant: Renewable energy reduces greenhouse gas emissions, lowers air pollution, and provides sustainable power sources like solar and wind. While the initial setup costs can be high, long-term savings from reduced fuel expenses and government incentives make it cost-effective.
</span></code></pre></div>
</div>
</section>
<sectionid="example-2-switching-intent">
<h2>Example 2: Switching Intent<a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#example-2-switching-intent"x-intersect.margin.0%.0%.-70%.0%="activeSection ='#example-2-switching-intent'"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></h2>
<divclass="highlight-text notranslate"><divclass="highlight"><pre><span></span><code><spanid="line-1">User: What are the symptoms of diabetes?
</span><spanid="line-2">**[Arch]**: Check if there is an available <prompt_target> that can handle this user query.
</span><spanid="line-3">**[Arch]**: Found "diseases_symptoms" prompt_target in arch_config.yaml. Forward disease=diabeteres to "diseases_symptoms" prompt target
</span><spanid="line-4">...
</span><spanid="line-5">Assistant: Common symptoms include frequent urination, excessive thirst, fatigue, and blurry vision.
</span><spanid="line-6">
</span><spanid="line-7">User: How is it diagnosed?
</span><spanid="line-8">**[Arch]**: New intent detected.
</span><spanid="line-9">**[Arch]**: Found "disease_diagnoses" prompt_target in arch_config.yaml. Forward disease=diabeteres to "disease_diagnoses" prompt target
</span><spanid="line-10">...
</span><spanid="line-11">Assistant: Diabetes is diagnosed through blood tests like fasting blood sugar, A1C, or an oral glucose tolerance test.
</span></code></pre></div>
</div>
</section>
<sectionid="build-multi-turn-rag-apps">
<h2>Build Multi-Turn RAG Apps<a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#build-multi-turn-rag-apps"x-intersect.margin.0%.0%.-70%.0%="activeSection ='#build-multi-turn-rag-apps'"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></h2>
<p>The following section describes how you can easilly add support for multi-turn scenarios via Arch. You process and manage multi-turn prompts
just like you manage single-turn ones. Arch handles the conpleixity of detecting the correct intent based on the last user prompt and
the covnersational history, extracts relevant parameters needed by downstream APIs, and dipatches calls to any upstream LLMs to summarize the
response from your APIs.</p>
<sectionid="step-1-define-arch-config">
<spanid="multi-turn-subsection-prompt-target"></span><h3>Step 1: Define Arch Config<a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#step-1-define-arch-config"x-intersect.margin.0%.0%.-70%.0%="activeSection ='#step-1-define-arch-config'"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></h3>
<divclass="code-block-caption"><spanclass="caption-text">Arch Config</span><a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#id2"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></div>
</span><spanid="line-4"><spanclass="linenos"> 4</span><spanclass="w"></span><spanclass="nt">port</span><spanclass="p">:</span><spanclass="w"></span><spanclass="l l-Scalar l-Scalar-Plain">8080</span><spanclass="w"></span><spanclass="c1">#If you configure port 443, you'll need to update the listener with tls_certificates</span>
</span><spanid="line-7"><spanclass="linenos"> 7</span><spanclass="c1"># Centralized way to manage LLMs, manage keys, retry logic, failover and limits in a central way</span>
</span><spanid="line-17"><spanclass="linenos">17</span><spanclass="w"></span><spanclass="no">You are a helpful assistant and can offer information about energy sources. You will get a JSON object with energy_source and consideration fields. Focus on answering using those fields</span>
</span><spanid="line-21"><spanclass="linenos">21</span><spanclass="w"></span><spanclass="nt">description</span><spanclass="p">:</span><spanclass="w"></span><spanclass="l l-Scalar l-Scalar-Plain">get information about an energy source</span>
</span><spanid="line-30"><spanclass="linenos">30</span><spanclass="w"></span><spanclass="nt">description</span><spanclass="p">:</span><spanclass="w"></span><spanclass="l l-Scalar l-Scalar-Plain">a specific type of consideration for an energy source</span>
<h3>Step 2: Process Request in Flask<a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#step-2-process-request-in-flask"x-intersect.margin.0%.0%.-70%.0%="activeSection ='#step-2-process-request-in-flask'"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></h3>
<p>Once the prompt targets are configured as above, handle parameters across multi-turn as if its a single-turn request</p>
<divclass="code-block-caption"><spanclass="caption-text">Parameter handling with Flask</span><a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#id3"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></div>
</span><spanid="line-30"><spanclass="linenos">30</span><spanclass="n">considertion</span><spanclass="o">=</span><spanclass="s2">"You don't have any specific consideration. Feel free to talk in a more open ended fashion"</span>
</span><spanid="line-33"><spanclass="linenos">33</span><spanclass="n">considertion</span><spanclass="o">=</span><spanclass="sa">f</span><spanclass="s2">"Add specific focus on the following consideration when you summarize the content for the energy source: </span><spanclass="si">{</span><spanclass="n">request</span><spanclass="o">.</span><spanclass="n">consideration</span><spanclass="si">}</span><spanclass="s2">"</span>
<p><spanclass="caption-text">Example multi-turn user conversation showing adjusting retrieval</span><a@click.prevent="window.navigator.clipboard.writeText($el.href); $el.setAttribute('data-tooltip', 'Copied!'); setTimeout(() => $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)"aria-label="Copy link to this element"class="headerlink"data-tooltip="Copy link to this element"href="#id4"><svgheight="1em"viewbox="0 0 24 24"width="1em"xmlns="http://www.w3.org/2000/svg"><pathd="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></a></p>
<li><a:data-current="activeSection === '#step-2-process-request-in-flask'"class="reference internal"href="#step-2-process-request-in-flask">Step 2: Process Request in Flask</a></li>