Here's something surprising. Models don't remember anything between calls. Each call starts fresh. So to have a conversation, you send the whole history every time.
First, let's prove it. We tell the model our name in one call, then ask for it in a second call. Run it. The model has no idea, because the second call didn't include the first message.
forget.pypython
from langchain.chat_models import init_chat_modelmodel = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)model.invoke("Hi, my name is Priya.")print(model.invoke("What is my name? Answer in one short sentence.").text)
Output
I don't know your name since you haven't told me yet.
Now we keep a list. We add the user's message, call the model with the whole list, and add its reply too. Then the next question goes on the end. Run it. This time, the model knows the name, because it can see the earlier messages.
history.pypython
from langchain.chat_models import init_chat_modelmodel = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)history = [{"role": "user", "content": "Hi, my name is Priya."}]history.append(model.invoke(history))history.append({"role": "user", "content": "What is my name? One short sentence."})print(model.invoke(history).text)print("messages sent:", len(history))
Models are stateless, so a conversation means sending the whole message history each time. Messages can also be simple dictionaries, with a role and content. Next, model settings.