<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Purohit Shripriya</title>
    <description>The latest articles on DEV Community by Purohit Shripriya (@purohit_shripriya_9624a69).</description>
    <link>https://dev.to/purohit_shripriya_9624a69</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4147990%2Fff4f0921-60d5-4e70-b03d-5401e1bcc3a1.png</url>
      <title>DEV Community: Purohit Shripriya</title>
      <link>https://dev.to/purohit_shripriya_9624a69</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/purohit_shripriya_9624a69"/>
    <language>en</language>
    <item>
      <title>Building OpsSentry Backend: Integrating Long-Term AI Memory with Hindsight &amp; FastAPI</title>
      <dc:creator>Purohit Shripriya</dc:creator>
      <pubDate>Tue, 29 Sep 2026 02:44:09 +0000</pubDate>
      <link>https://dev.to/purohit_shripriya_9624a69/building-opssentry-backend-integrating-long-term-ai-memory-with-hindsight-fastapi-1f06</link>
      <guid>https://dev.to/purohit_shripriya_9624a69/building-opssentry-backend-integrating-long-term-ai-memory-with-hindsight-fastapi-1f06</guid>
      <description>&lt;h3&gt;
  
  
  Powering Long-Term Memory in OpsSentry Backend
&lt;/h3&gt;

&lt;p&gt;While building &lt;strong&gt;OpsSentry&lt;/strong&gt;, one of our primary technical challenges was ensuring that the AI agent could dynamically retain and recall user context across multiple sessions without bloating the primary prompt window. &lt;/p&gt;

&lt;p&gt;To solve this, we implemented a dual-action memory workflow in our FastAPI backend powered by &lt;strong&gt;Hindsight&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Memory Recall Before Generation
&lt;/h3&gt;

&lt;p&gt;Before generating any response with our LLM, our backend queries Hindsight using the incoming user message to retrieve relevant context from previous conversations. This gives the model access to earlier interactions without requiring us to manually paste the entire conversation into every prompt.&lt;/p&gt;

&lt;p&gt;Here is how the recall integration is implemented in our backend service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Query Hindsight memory bank for context relevant to the current query
&lt;/span&gt;&lt;span class="n"&gt;memory_context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hindsight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;recall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;bank_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;HINDSIGHT_BANK_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;user_message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Inject retrieved context directly into system prompt
&lt;/span&gt;&lt;span class="n"&gt;system_prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
You are OpsSentry, an AI assistant.
Relevant Past Context:
&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;memory_context&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

&lt;span class="c1"&gt;### 2. Retaining New Information
&lt;/span&gt;&lt;span class="n"&gt;Recall&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;useful&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt; &lt;span class="n"&gt;also&lt;/span&gt; &lt;span class="n"&gt;stores&lt;/span&gt; &lt;span class="n"&gt;useful&lt;/span&gt; &lt;span class="n"&gt;information&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;future&lt;/span&gt; &lt;span class="n"&gt;interactions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;After&lt;/span&gt; &lt;span class="n"&gt;generating&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;backend&lt;/span&gt; &lt;span class="n"&gt;retains&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;interaction&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;Hindsight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
python&lt;br&gt;
hindsight.retain(&lt;br&gt;
    bank_id=HINDSIGHT_BANK_ID,&lt;br&gt;
    content=f"User: {message} | AI: {ai_response}"&lt;br&gt;
)&lt;br&gt;
"""&lt;/p&gt;

&lt;p&gt;This creates a simple memory loop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User asks a question&lt;/li&gt;
&lt;li&gt;Backend recalls relevant memories&lt;/li&gt;
&lt;li&gt;LLM generates response with context&lt;/li&gt;
&lt;li&gt;Backend retains interaction back to Hindsight&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Takeaways &amp;amp; Architecture
&lt;/h2&gt;

&lt;p&gt;Decoupled Memory: Keeping short-term context window management handled dynamically via Hindsight keeps latency minimal and responses highly accurate.&lt;/p&gt;

&lt;p&gt;Database Sync: Metadata and chat logs are safely stored in Supabase, while vectorized long-term memory indexes live in Hindsight.&lt;/p&gt;

&lt;p&gt;Seamless API: FastAPI handles asynchronous request routing between Groq, Supabase, and Hindsight seamlessly.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>fastapi</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
