<?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: belcore</title>
    <description>The latest articles on DEV Community by belcore (@belcore).</description>
    <link>https://dev.to/belcore</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%2F4234291%2Fb08c59de-7fcf-4a57-bd51-376a88ed6fb3.png</url>
      <title>DEV Community: belcore</title>
      <link>https://dev.to/belcore</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/belcore"/>
    <language>en</language>
    <item>
      <title>Add long-term memory to a LangChain chatbot in Python (15 lines, no vector DB)</title>
      <dc:creator>belcore</dc:creator>
      <pubDate>Sat, 28 Nov 2026 06:34:48 +0000</pubDate>
      <link>https://dev.to/belcore/add-long-term-memory-to-a-langchain-chatbot-in-python-15-lines-no-vector-db-i3i</link>
      <guid>https://dev.to/belcore/add-long-term-memory-to-a-langchain-chatbot-in-python-15-lines-no-vector-db-i3i</guid>
      <description>&lt;p&gt;Most chat apps already store the conversation in their own database. The hard part is deciding which old messages to send to the model when the history gets long. Here is a small Python setup that keeps your history where it is and lets Belcore pick the turns that matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.10+&lt;/li&gt;
&lt;li&gt;A free Belcore API key (5,000 calls, no card): &lt;a href="https://belcore.xyz/developers/signup" rel="noopener noreferrer"&gt;https://belcore.xyz/developers/signup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pip install langchain-belcore&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BELCORE_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sk_...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ChatBelcore&lt;/code&gt; is a normal LangChain chat model. You send the full history you keep; it returns the reply plus a small emotion state you save and send back next turn.&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_core&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;AIMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HumanMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SystemMessage&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_belcore&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ChatBelcore&lt;/span&gt;

&lt;span class="no"&gt;DB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"conversation.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# stand-in for your database&lt;/span&gt;
&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ChatBelcore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"openai/gpt-4o-mini"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SystemMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"You are a friendly assistant."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nc"&gt;HumanMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nc"&gt;AIMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;belcore&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;response_metadata&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"belcore"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things to notice:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;You own the history.&lt;/strong&gt; Belcore does not store conversation text from API calls. Your database is the source of truth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Send everything.&lt;/strong&gt; Belcore selects the relevant turns from the full history, so you don't write your own summarizer or retrieval step.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save the emotion state.&lt;/strong&gt; It comes back in &lt;code&gt;response_metadata["belcore"]["emotion"]&lt;/code&gt;; pass it in on the next call.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"My daughter's name is Soo-ah and she starts piano lessons on Tuesdays."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Give me a tip for staying focused while working from home."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"What day are my daughter's piano lessons?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Your daughter's piano lessons are on Tuesdays.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart Python between the calls; the answer still works because the history lives in &lt;code&gt;conversation.json&lt;/code&gt;, not in the process.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;res.response_metadata["belcore"]["memory"]&lt;/code&gt; tells you what was used: &lt;code&gt;"recent"&lt;/code&gt; means only the last messages were needed (short chats), &lt;code&gt;"long-term"&lt;/code&gt; means context was selected by searching the whole history. In this three-turn demo you will see &lt;code&gt;"recent"&lt;/code&gt;; the long-term path matters once the conversation is long.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits (v0.1)
&lt;/h2&gt;

&lt;p&gt;Text only. No tool calling, no token-by-token streaming, and no &lt;code&gt;temperature&lt;/code&gt; / &lt;code&gt;max_tokens&lt;/code&gt; options yet. &lt;code&gt;ainvoke&lt;/code&gt; works for async apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Package: &lt;a href="https://pypi.org/project/langchain-belcore/" rel="noopener noreferrer"&gt;https://pypi.org/project/langchain-belcore/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;All integrations (JS and Python): &lt;a href="https://github.com/terracore-kr/belcore-integrations" rel="noopener noreferrer"&gt;https://github.com/terracore-kr/belcore-integrations&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Plain Python client: &lt;a href="https://pypi.org/project/belcore/" rel="noopener noreferrer"&gt;https://pypi.org/project/belcore/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Why "when it was said" matters for memory: &lt;a href="https://dev.to/belcore/your-agent-remembered-both-messages-and-still-got-it-wrong-a-360-question-test-for-when-not-18j1"&gt;https://dev.to/belcore/your-agent-remembered-both-messages-and-still-got-it-wrong-a-360-question-test-for-when-not-18j1&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance; code was run against the live API before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>langchain</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Your agent remembered both messages and still got it wrong. A 360-question test for "when", not just "what"</title>
      <dc:creator>belcore</dc:creator>
      <pubDate>Sat, 28 Nov 2026 05:25:14 +0000</pubDate>
      <link>https://dev.to/belcore/your-agent-remembered-both-messages-and-still-got-it-wrong-a-360-question-test-for-when-not-18j1</link>
      <guid>https://dev.to/belcore/your-agent-remembered-both-messages-and-still-got-it-wrong-a-360-question-test-for-when-not-18j1</guid>
      <description>&lt;p&gt;Two messages sit in your agent's memory:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Minji is your point of contact."&lt;br&gt;
"Junho takes over next month."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A user asks: &lt;em&gt;who should I contact today?&lt;/em&gt; The right answer is Minji. The message about Junho came later, but the handoff hasn't happened yet.&lt;/p&gt;

&lt;p&gt;A memory layer can retrieve both messages and still answer Junho. Most memory benchmarks check whether the right text comes back. Fewer check whether the system keeps track of &lt;strong&gt;when&lt;/strong&gt; something was said, and which fact replaced which.&lt;/p&gt;

&lt;p&gt;We built a small, open test for exactly that, and you can run it on your own memory system in a few minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the test covers
&lt;/h2&gt;

&lt;p&gt;15 synthetic customers, six dated sessions each, 360 questions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question type&lt;/th&gt;
&lt;th&gt;Example of what it checks&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Corrected facts&lt;/td&gt;
&lt;td&gt;The user changed their address. Do you return the new one?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Date said&lt;/td&gt;
&lt;td&gt;
&lt;em&gt;When&lt;/em&gt; did the user tell you X?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Which came first&lt;/td&gt;
&lt;td&gt;Of two events, which happened earlier?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Days between&lt;/td&gt;
&lt;td&gt;How many days passed between X and Y?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Counting&lt;/td&gt;
&lt;td&gt;How many trainers has the user had?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Apply a stated condition&lt;/td&gt;
&lt;td&gt;The user said they prefer aisle seats. Which seat do you book?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Someone else's fact mixed in&lt;/td&gt;
&lt;td&gt;Does a fact about another person leak in?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No answer exists&lt;/td&gt;
&lt;td&gt;Does the system say "unknown" instead of guessing?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each question is asked three times and scored by majority vote. Predictions were written down before each run, including the ones that turned out wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: check the harness (free, about a minute)
&lt;/h2&gt;

&lt;p&gt;You need Node.js 22 or newer. Nothing to install; &lt;code&gt;npx&lt;/code&gt; fetches what it needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/terracore-kr/ai-memory-date-test
&lt;span class="nb"&gt;cd&lt;/span&gt; ai-memory-date-test
npx tsx quickstart/run.mts
npx tsx quickstart/score.mts quickstart/answers-echo-*.jsonl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This uses an adapter that always answers "unknown". I ran it before writing this post. The scorer prints a table, and the only non-zero row is the one you'd expect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| No answer exists | 45/45 |
| **Overall**      | **45/360** |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So "say unknown to everything" is worth 45 points. That's your floor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: connect your memory system
&lt;/h2&gt;

&lt;p&gt;Edit one file, &lt;code&gt;quickstart/adapter.mts&lt;/code&gt;. You write three functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;MemoryAdapter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;                 &lt;span class="c1"&gt;// start empty&lt;/span&gt;
  &lt;span class="nf"&gt;ingest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// once per session, in date order&lt;/span&gt;
  &lt;span class="nf"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// plain text, or "unknown"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every session has a date, and every message carries a &lt;code&gt;timestamp&lt;/code&gt;. The first user message of each session also says "Today's date is YYYY-MM-DD." Use whichever your system supports. If it drops timestamps on the way in, that is exactly what the date questions will show.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: estimate, then run
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;ADAPTER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mine npx tsx quickstart/run.mts --dry-run
&lt;span class="nv"&gt;ADAPTER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mine npx tsx quickstart/run.mts
npx tsx quickstart/score.mts quickstart/answers-mine-*.jsonl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--dry-run&lt;/code&gt; prints the cost estimate before anything is sent. Use &lt;code&gt;--customers A,B&lt;/code&gt; to try a small subset first.&lt;/p&gt;

&lt;p&gt;For a reference point with no memory system at all, &lt;code&gt;ADAPTER=full-transcript&lt;/code&gt; sends the whole conversation with every question through any OpenAI-compatible endpoint. Its dry run estimates about $0.71 with gpt-4.1-mini.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading your score
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Corrected facts vs. date said&lt;/strong&gt; tend to split. A system can be good at "what is it now?" and bad at "when did they tell me?", because one depends on order and the other on dates surviving storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two of the three counting questions are ambiguous&lt;/strong&gt; ("counting the current one?"). The scorer prints counting per question so you can read that row with care.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One build, one answer model.&lt;/strong&gt; Scores move with the model you answer with. Compare systems with the same answer model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What this test is not
&lt;/h2&gt;

&lt;p&gt;It's not a ranking of memory products, and it's not an independent evaluation. The test was written and run by the Belcore team, and Belcore is one of the systems it has measured. A passing score is not a security or compliance result. Questions, raw answers, scoring code and preregistrations are all public, so you can check every number yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Share your result
&lt;/h2&gt;

&lt;p&gt;Open a &lt;a href="https://github.com/terracore-kr/ai-memory-date-test/issues/new?template=submit-results.yml" rel="noopener noreferrer"&gt;results issue&lt;/a&gt; with your score. Please don't rerun until you get a better number.&lt;/p&gt;

&lt;p&gt;If you'd rather not wire up the adapter yourself, we also run it for teams and send a report with every wrong answer grouped by cause: &lt;a href="https://belcore.xyz/audit" rel="noopener noreferrer"&gt;belcore.xyz/audit&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test and code: &lt;a href="https://github.com/terracore-kr/ai-memory-date-test" rel="noopener noreferrer"&gt;https://github.com/terracore-kr/ai-memory-date-test&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Paper (DOI): &lt;a href="https://doi.org/10.5281/zenodo.24500314" rel="noopener noreferrer"&gt;https://doi.org/10.5281/zenodo.24500314&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance. The free quickstart was run before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>testing</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Try Belcore's long-term memory from any MCP client (Claude Desktop, Cursor) in two minutes</title>
      <dc:creator>belcore</dc:creator>
      <pubDate>Thu, 26 Nov 2026 06:35:25 +0000</pubDate>
      <link>https://dev.to/belcore/try-belcores-long-term-memory-from-any-mcp-client-claude-desktop-cursor-in-two-minutes-2ind</link>
      <guid>https://dev.to/belcore/try-belcores-long-term-memory-from-any-mcp-client-claude-desktop-cursor-in-two-minutes-2ind</guid>
      <description>&lt;p&gt;If your tool speaks MCP, you can try Belcore's memory and emotion-state chat without writing any code. &lt;code&gt;@belcore/mcp&lt;/code&gt; is a small MCP server that exposes it as a tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Get a free API key (5,000 calls, no card): &lt;a href="https://belcore.xyz/developers/signup" rel="noopener noreferrer"&gt;https://belcore.xyz/developers/signup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Add the server to your MCP client's config:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"belcore"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"npx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"@belcore/mcp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"BELCORE_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;your-api-key&amp;gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Claude Desktop this goes in &lt;code&gt;claude_desktop_config.json&lt;/code&gt;; in Cursor, in &lt;code&gt;~/.cursor/mcp.json&lt;/code&gt;. Restart the client.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you get
&lt;/h2&gt;

&lt;p&gt;Two tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;belcore_chat&lt;/code&gt;: answers from the conversation history you send. It picks the relevant turns from the whole history and returns an updated emotion state.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;belcore_export_memory&lt;/code&gt;: exports memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How I checked it
&lt;/h2&gt;

&lt;p&gt;I ran the server directly over MCP's stdio transport against the live API and sent one call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="s"&gt;My cat is named Miso and she hates the vacuum.&lt;/span&gt;
  &lt;span class="na"&gt;assistant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Noted!&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="s"&gt;What is my cat's name?&lt;/span&gt;

&lt;span class="na"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Your cat's name is Miso!&lt;/span&gt;
&lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;recent   degraded: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Server info reported &lt;code&gt;belcore 0.1.2&lt;/code&gt;, and &lt;code&gt;tools/list&lt;/code&gt; returned the two tools above. I did not click through Claude Desktop or Cursor for this post, only the protocol itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this is (and isn't)
&lt;/h2&gt;

&lt;p&gt;Belcore does not store conversation text from API calls. You keep the history and send it with each call. With MCP that means the client (your model) has to pass the messages it wants considered, and pass the emotion state back on the next call. This is a good way to &lt;em&gt;try&lt;/em&gt; the engine and see what it returns. For a real app that keeps its own conversation database, the libraries are a better fit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript / Vercel AI SDK: &lt;code&gt;@belcore/ai-sdk&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Python / LangChain: &lt;code&gt;langchain-belcore&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;memory&lt;/code&gt; in the response is &lt;code&gt;"recent"&lt;/code&gt; for short conversations and &lt;code&gt;"long-term"&lt;/code&gt; when context was selected by searching the whole history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;MCP server: &lt;a href="https://www.npmjs.com/package/@belcore/mcp" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/@belcore/mcp&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;All integrations: &lt;a href="https://github.com/terracore-kr/belcore-integrations" rel="noopener noreferrer"&gt;https://github.com/terracore-kr/belcore-integrations&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance; the server was run against the live API before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>llm</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Add long-term memory to a LangChain chatbot in Python (no vector DB)</title>
      <dc:creator>belcore</dc:creator>
      <pubDate>Thu, 26 Nov 2026 05:57:29 +0000</pubDate>
      <link>https://dev.to/belcore/add-long-term-memory-to-a-langchain-chatbot-in-python-no-vector-db-33ba</link>
      <guid>https://dev.to/belcore/add-long-term-memory-to-a-langchain-chatbot-in-python-no-vector-db-33ba</guid>
      <description>&lt;p&gt;Most chat apps already store the conversation in their own database. The hard part is deciding which old messages to send to the model when the history gets long. Here is a small Python setup that keeps your history where it is and lets Belcore pick the turns that matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.10+&lt;/li&gt;
&lt;li&gt;A free Belcore API key (5,000 calls, no card): &lt;a href="https://belcore.xyz/developers/signup" rel="noopener noreferrer"&gt;https://belcore.xyz/developers/signup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pip install langchain-belcore&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BELCORE_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sk_...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ChatBelcore&lt;/code&gt; is a normal LangChain chat model. You send the full history you keep; it returns the reply plus a small emotion state you save and send back next turn.&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_core&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;AIMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HumanMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SystemMessage&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_belcore&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ChatBelcore&lt;/span&gt;

&lt;span class="no"&gt;DB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"conversation.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# stand-in for your database&lt;/span&gt;
&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ChatBelcore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"openai/gpt-4o-mini"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SystemMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"You are a friendly assistant."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nc"&gt;HumanMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nc"&gt;AIMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;belcore&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;response_metadata&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"belcore"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"emotion"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things to notice:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;You own the history.&lt;/strong&gt; Belcore does not store conversation text from API calls. Your database is the source of truth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Send everything.&lt;/strong&gt; Belcore selects the relevant turns from the full history, so you don't write your own summarizer or retrieval step.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save the emotion state.&lt;/strong&gt; It comes back in &lt;code&gt;response_metadata["belcore"]["emotion"]&lt;/code&gt;; pass it in on the next call.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"My daughter's name is Soo-ah and she starts piano lessons on Tuesdays."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Give me a tip for staying focused while working from home."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"What day are my daughter's piano lessons?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Your daughter's piano lessons are on Tuesdays.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart Python between the calls; the answer still works because the history lives in &lt;code&gt;conversation.json&lt;/code&gt;, not in the process.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;res.response_metadata["belcore"]["memory"]&lt;/code&gt; tells you what was used: &lt;code&gt;"recent"&lt;/code&gt; means only the last messages were needed (short chats), &lt;code&gt;"long-term"&lt;/code&gt; means context was selected by searching the whole history. In this three-turn demo you will see &lt;code&gt;"recent"&lt;/code&gt;; the long-term path matters once the conversation is long.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits (v0.1)
&lt;/h2&gt;

&lt;p&gt;Text only. No tool calling, no token-by-token streaming, and no &lt;code&gt;temperature&lt;/code&gt; / &lt;code&gt;max_tokens&lt;/code&gt; options yet. &lt;code&gt;ainvoke&lt;/code&gt; works for async apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Package: &lt;a href="https://pypi.org/project/langchain-belcore/" rel="noopener noreferrer"&gt;https://pypi.org/project/langchain-belcore/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;All integrations (JS and Python): &lt;a href="https://github.com/terracore-kr/belcore-integrations" rel="noopener noreferrer"&gt;https://github.com/terracore-kr/belcore-integrations&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Plain Python client: &lt;a href="https://pypi.org/project/belcore/" rel="noopener noreferrer"&gt;https://pypi.org/project/belcore/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance; the code was run against the live API before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>langchain</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Add long-term memory to a Next.js chatbot in 5 minutes</title>
      <dc:creator>belcore</dc:creator>
      <pubDate>Thu, 26 Nov 2026 05:18:16 +0000</pubDate>
      <link>https://dev.to/belcore/add-long-term-memory-to-a-nextjs-chatbot-in-5-minutes-10oi</link>
      <guid>https://dev.to/belcore/add-long-term-memory-to-a-nextjs-chatbot-in-5-minutes-10oi</guid>
      <description>&lt;p&gt;Most chatbots forget. You tell one about your peanut allergy on Monday, and on Friday it recommends a satay place.&lt;/p&gt;

&lt;p&gt;The usual fix is to send the whole conversation on every call. That works until the history gets long: the prompt gets expensive, and models get worse at finding the one line that matters in a wall of old messages.&lt;/p&gt;

&lt;p&gt;This tutorial adds long-term memory to a Next.js chatbot with &lt;a href="https://belcore.xyz" rel="noopener noreferrer"&gt;Belcore&lt;/a&gt; and the Vercel AI SDK. It takes about five minutes, and you can copy the whole app.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;You keep the conversation history in &lt;strong&gt;your&lt;/strong&gt; database, as you probably already do. On each turn you send the full history to Belcore. Belcore picks the turns that matter for the current question and answers from them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;your DB ──history──▶ Belcore ──reply + emotion state──▶ your DB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Belcore does not store the conversation text. Your database stays the only copy. Belcore also returns a small emotion state (a few numbers) that you save and send back next turn, so the assistant's tone stays consistent.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Get the example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx degit terracore-kr/belcore-integrations/examples/nextjs-chat my-chat
&lt;span class="nb"&gt;cd&lt;/span&gt; my-chat
npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Add a key
&lt;/h2&gt;

&lt;p&gt;Get a key at &lt;a href="https://belcore.xyz/developers/signup" rel="noopener noreferrer"&gt;belcore.xyz/developers/signup&lt;/a&gt;. Signup gives 5,000 free calls and needs no card.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cp .env.example .env.local
&lt;span class="c"&gt;# paste the key into BELCORE_API_KEY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Run it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; and try this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;"I'm allergic to peanuts and I'm planning a trip to Lisbon in May."&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Chat about something else for a while.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"What should I watch out for when I eat out on my trip?"&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now stop the server, start it again, reload the page, and ask again. It still knows, because the history lives in a file on your machine and goes out with every call.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code that matters
&lt;/h2&gt;

&lt;p&gt;The whole chat turn is one route handler. Belcore plugs into the AI SDK as a provider, so it is a normal &lt;code&gt;generateText&lt;/code&gt; call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/api/chat/route.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;generateText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"ai"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;belcore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@belcore/ai-sdk"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;loadConversation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;saveConversation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/lib/store"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// 1. Load the full history from your database and add the new message.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;conversation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;loadConversation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// 2. Send the whole history. Belcore picks the turns that matter and answers.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;providerMetadata&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;belcore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"You are a friendly assistant."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;providerOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emotion&lt;/span&gt;
      &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;belcore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;emotion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emotion&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// 3. Save the reply and the new emotion state back to your database.&lt;/span&gt;
  &lt;span class="n"&gt;conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emotion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;providerMetadata&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;belcore&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emotion&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;saveConversation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;conversation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;lib/store.ts&lt;/code&gt; is two functions that read and write a JSON file. Swap them for Postgres, Redis or whatever you already use before you deploy. Serverless file systems are temporary, so the JSON file will not survive there.&lt;/p&gt;

&lt;p&gt;The response also tells you how the reply was built: &lt;code&gt;providerMetadata.belcore.memory&lt;/code&gt; is &lt;code&gt;"long-term"&lt;/code&gt; when Belcore searched the whole history, and &lt;code&gt;"recent"&lt;/code&gt; when only the latest messages were used (a short conversation, or a fallback).&lt;/p&gt;

&lt;h2&gt;
  
  
  Not on the AI SDK?
&lt;/h2&gt;

&lt;p&gt;The same call is available elsewhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install @belcore/langchain   &lt;span class="c"&gt;# LangChain.js&lt;/span&gt;
npm install @belcore/sdk         &lt;span class="c"&gt;# plain TypeScript client&lt;/span&gt;
npx -y @belcore/mcp              &lt;span class="c"&gt;# MCP server for Claude Desktop, Cursor&lt;/span&gt;
pip install belcore              &lt;span class="c"&gt;# Python&lt;/span&gt;
pip install langchain-belcore    &lt;span class="c"&gt;# LangChain (Python)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Text only. Tool calls and file parts are dropped.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;streamText&lt;/code&gt; works, but the reply arrives as one chunk.&lt;/li&gt;
&lt;li&gt;Settings like &lt;code&gt;temperature&lt;/code&gt; are ignored for now.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source for the example and all integrations (Apache-2.0): &lt;a href="https://github.com/terracore-kr/belcore-integrations" rel="noopener noreferrer"&gt;github.com/terracore-kr/belcore-integrations&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>nextjs</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Token savings depend on what you count: three numbers from the same benchmark runs</title>
      <dc:creator>belcore</dc:creator>
      <pubDate>Mon, 09 Nov 2026 01:42:55 +0000</pubDate>
      <link>https://dev.to/belcore/token-savings-depend-on-what-you-count-three-numbers-from-the-same-benchmark-runs-2pa1</link>
      <guid>https://dev.to/belcore/token-savings-depend-on-what-you-count-three-numbers-from-the-same-benchmark-runs-2pa1</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm affiliated with Belcore, a memory and context layer for LLM apps. This is a measurement post. The numbers, their limits, and one result that did not hold up are all below.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why "tokens saved" is slippery
&lt;/h2&gt;

&lt;p&gt;Chat and agent setups usually keep context by resending history on every call, so input tokens per call grow with the session. A memory layer replaces that with a selected context. How large the saving looks depends on what you compare, so here are the same runs counted three ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Dataset: LongMemEval_S, 500 questions, about 109k tokens of prior conversation each (roughly 500 turns).&lt;/li&gt;
&lt;li&gt;Answer model: gpt-5. Fixed seed, frozen harness.&lt;/li&gt;
&lt;li&gt;Tokenizer for context counts: o200k_base.&lt;/li&gt;
&lt;li&gt;Runs: August 2026.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Three numbers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What is counted&lt;/th&gt;
&lt;th&gt;Tokens per call&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Full transcript, uncut&lt;/td&gt;
&lt;td&gt;109,079&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Assembled memory context&lt;/td&gt;
&lt;td&gt;6,671&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Billed input per call (27-question subset, includes prompt and question)&lt;/td&gt;
&lt;td&gt;9,908&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Context tokens: &lt;strong&gt;-93.9%&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Billed input on that subset: about &lt;strong&gt;-91%&lt;/strong&gt;. The subset was hand-picked, so treat this one as indicative only.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What this does not show
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Nothing here says anything about answer quality. Accuracy is a separate metric and I'm not quoting one in this post.&lt;/li&gt;
&lt;li&gt;Cost per successful task, including retries and fixes, is the number that matters for a real bill. I haven't measured it yet.&lt;/li&gt;
&lt;li&gt;LongMemEval_S is a public benchmark, not production traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A result that did not hold up
&lt;/h2&gt;

&lt;p&gt;We tried a multi-pass retrieval step that re-checks and re-retrieves before answering. On 27 questions hand-picked for missing evidence it went from 16 to 20 correct. On a random sample of 103 the attributable effect was +2, inside a ±5.2 noise bar, with one case where extra evidence turned a correct aggregation answer wrong. It also cost about 2.9x the input tokens and 2.6x the latency on the subset. We are not shipping it as an improvement.&lt;/p&gt;

&lt;p&gt;Two more limits: in the wrong answers we audited, 38% involved a gold label that was wrong or defensible either way, and n = 499 cannot resolve small effects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;There is a free measurement demo on the site: &lt;a href="https://belcore.xyz/?utm_source=devto&amp;amp;utm_campaign=token-counting" rel="noopener noreferrer"&gt;belcore.xyz&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Questions about the method are welcome, especially the ones that make the numbers look worse.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>agents</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
