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.
What you need
- Python 3.10+
- A free Belcore API key (5,000 calls, no card): https://belcore.xyz/developers/signup
-
pip install langchain-belcore
export BELCORE_API_KEY=sk_...
The code
ChatBelcore 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.
import json, pathlib
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
from langchain_belcore import ChatBelcore
DB = pathlib.Path("conversation.json") # stand-in for your database
llm = ChatBelcore(model="openai/gpt-4o-mini")
def load():
return json.loads(DB.read_text()) if DB.exists() else {"messages": [], "emotion": None}
def turn(text):
state = load()
state["messages"].append({"role": "user", "content": text})
history = [SystemMessage("You are a friendly assistant.")] + [
HumanMessage(m["content"]) if m["role"] == "user" else AIMessage(m["content"])
for m in state["messages"]
]
opts = {"emotion": state["emotion"]} if state["emotion"] else {}
res = llm.invoke(history, belcore=opts)
state["messages"].append({"role": "assistant", "content": res.content})
state["emotion"] = res.response_metadata["belcore"]["emotion"]
DB.write_text(json.dumps(state, indent=2))
return res.content
Three things to notice:
- You own the history. Belcore does not store conversation text from API calls. Your database is the source of truth.
- Send everything. Belcore selects the relevant turns from the full history, so you don't write your own summarizer or retrieval step.
-
Save the emotion state. It comes back in
response_metadata["belcore"]["emotion"]; pass it in on the next call.
Try it
turn("My daughter's name is Soo-ah and she starts piano lessons on Tuesdays.")
turn("Give me a tip for staying focused while working from home.")
print(turn("What day are my daughter's piano lessons?"))
# Your daughter's piano lessons are on Tuesdays.
Restart Python between the calls; the answer still works because the history lives in conversation.json, not in the process.
res.response_metadata["belcore"]["memory"] tells you what was used: "recent" means only the last messages were needed (short chats), "long-term" means context was selected by searching the whole history. In this three-turn demo you will see "recent"; the long-term path matters once the conversation is long.
Limits (v0.1)
Text only. No tool calling, no token-by-token streaming, and no temperature / max_tokens options yet. ainvoke works for async apps.
Links
- Package: https://pypi.org/project/langchain-belcore/
- All integrations (JS and Python): https://github.com/terracore-kr/belcore-integrations
- Plain Python client: https://pypi.org/project/belcore/
- Why "when it was said" matters for memory: https://dev.to/belcore/your-agent-remembered-both-messages-and-still-got-it-wrong-a-360-question-test-for-when-not-18j1
Drafted with AI assistance; code was run against the live API before publishing.
Top comments (1)
The framing is exactly right — the hard problem isn't storing history, it's deciding which old turns to send when the conversation gets long. Keeping the history in my own conversation.json and letting the model pick the relevant turns, instead of bolting on a vector DB, is a much smaller mental model for a side project.
The detail that caught my eye is that you send the full history every turn and Belcore selects from it server-side. That keeps the client at 15 lines, but the full-history payload still grows with every turn. At what conversation length does that start to hurt — is there a point where the selection should happen before the send, rather than after?
Also, the emotion state round-tripped in response_metadata is a nice touch — persisting how the user felt, not just what they said. Your 360-question test for "when" vs "what" sounds like the real proof here: at what history length did the long-term path start beating the recent-only path?