💚
Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! 🚀
Chat-Based AI
Chat-based AI like ChatGPT appears to have a conversation with you. But technically, there is no persistent conversation. Each time you send a message, the entire conversation history is sent to the model as a single long input.
10 min•By Priygop Team•Updated 2026
How Chat Works Under the Hood
How Chat Works Under the Hood
# How chat-based AI maintains conversation context
# Each message in a chat is structured with a role
chat_history = [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is a programming language known for its simple, readable syntax."},
{"role": "user", "content": "Is it good for beginners?"},
# The model sees ALL of this before generating the next response
]
print("=== How Chat Conversation is Sent to the LLM ===")
print()
print("When you send the second message 'Is it good for beginners?'")
print("the AI does NOT just receive that one message.")
print("It receives the ENTIRE conversation up to that point:")
print()
total_tokens = 0
for i, message in enumerate(chat_history):
word_count = len(message["content"].split())
approx_tokens = word_count * 1.33 # rough conversion
total_tokens += approx_tokens
print(f" Message {i + 1} [{message['role']}]: '{message['content']}'")
print(f" Approx tokens: {approx_tokens:.0f}")
print()
print(f"Total input to model: approx {total_tokens:.0f} tokens")
print()
print("This is why the AI remembers what you said earlier in the conversation.")
print("It is not memory - it is the entire conversation being re-sent each time.")Diagram
Loading diagram…
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
What This Means for Users
- The AI appears to remember the conversation because the full history is included with each message
- Longer conversations use more tokens (and cost more when using APIs)
- When you start a new chat, the AI starts completely fresh with no memory of previous chats
- The system message (the first message from 'system') sets the AI's behavior for the whole conversation
- Clearing the conversation and starting fresh is useful when the conversation has drifted off track
Key Takeaways
- Chat-based AI like ChatGPT appears to have a conversation with you.
- The AI appears to remember the conversation because the full history is included with each message
- Longer conversations use more tokens (and cost more when using APIs)
- When you start a new chat, the AI starts completely fresh with no memory of previous chats