AI Hints
Home›LangChain Tutorial›Models and Messages
LangChain · Lesson 6 of 120

Conversations

A list of messages.

⏱ 2 min read▶ Video at 5:14🎓 Free
Watch this lesson in the LangChain courseWatch on YouTube ↗Full LangChain course

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.

Conversations
From the video: Conversations
  • Models don't remember
  • Each call starts fresh
  • Send the history

Forgetting by default

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_model

model = 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.

Sending the history

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_model

model = 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))
Output
Your name is Priya.
messages sent: 3

Summary

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.

Key takeaways
  • Models forget
  • Keep a history list
  • Send it every call
Next up: Model Settings — temperature and limits