에이전트에 메모리와 대화 상태 부여하기
LangChain 에이전트에 단기 및 장기 메모리를 추가하여 대화 차례가 바뀌어도 맥락을 기억하고 일관된 다단계 대화를 생성하도록 합니다.
에이전트에 메모리와 대화 상태 부여하기은(는) CoddyKit의 무료 AI Agents with LangChain & Autonomous Workflows 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 AI Agents with LangChain & Autonomous Workflows 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. AI Agents with LangChain & Autonomous Workflows 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Agents Need Memory
LLMs are stateless: each call knows nothing about the last unless you tell it. Without memory, an agent forgets your name the instant you say it.
The Context Window
Memory ultimately means stuffing prior info into the context window. That window is finite, so the real challenge is deciding what to keep and what to drop.
Buffer Memory
Buffer memory stores the whole conversation and replays it every turn. Accurate, but it grows without bound and eventually overflows the context window.
from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory()
memory.save_context({'input': 'Hi, I am Lena'}, {'output': 'Hello Lena!'})Windowed Memory
Windowed memory keeps only the last N exchanges. It bounds size and forgets older context — perfect when only recent turns matter.
from langchain.memory import ConversationBufferWindowMemory
memory = ConversationBufferWindowMemory(k=4)Summary Memory
Summary memory periodically condenses older turns with the LLM, keeping the gist plus recent messages — preserving meaning in a small footprint.
from langchain.memory import ConversationSummaryMemory
memory = ConversationSummaryMemory(llm=llm)Short-Term vs Long-Term
Two flavors serve different needs: short-term memory holds the current chat in the prompt, while long-term persists facts across sessions in a store.
Long-Term Memory with Vectors
For knowledge that must survive sessions, store messages as embeddings in a vector store and retrieve the most relevant ones by similarity instead of replaying everything.
from langchain.memory import VectorStoreRetrieverMemory
memory = VectorStoreRetrieverMemory(retriever=vectorstore.as_retriever())Wiring Memory into a Chain
Wire memory into a conversation chain. Each call loads prior context, runs the model, and saves the new exchange automatically.
from langchain.chains import ConversationChain
chain = ConversationChain(llm=llm, memory=memory)
print(chain.predict(input='What is my name?'))Session and User Scoping
Real apps serve many users at once. Scope memory by session or user id so separate conversations never leak into each other.
store = {}
def get_memory(session_id):
if session_id not in store:
store[session_id] = ConversationBufferMemory()
return store[session_id]Cost and Privacy Tradeoffs
More memory means more tokens — higher cost and latency. Long-term stores may hold sensitive data, so mind retention limits and what you're allowed to keep.
Choosing a Memory Strategy
Choosing a strategy: buffer or window for short chats, summary for long ones, vector for cross-session facts — always scoped per user and mindful of cost.
Quick Check
You've met several memory types — which fits when? Time to put it to the test.
Recap
Recap: memory feeds prior context into a finite window. Buffer, window, and summary trade accuracy for size, vector stores enable long-term recall — always scope and watch cost.
자주 묻는 질문
“에이전트에 메모리와 대화 상태 부여하기” 강의는 무료인가요?
네 — “에이전트에 메모리와 대화 상태 부여하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 AI Agents with LangChain & Autonomous Workflows 강의 전체를 잠금 해제할 수 있습니다. AI Agents with LangChain & Autonomous Workflows 강의에는 총 4개의 강의가 포함되어 있습니다.
“에이전트에 메모리와 대화 상태 부여하기”에서 뭘 배우나요?
LangChain 에이전트에 단기 및 장기 메모리를 추가하여 대화 차례가 바뀌어도 맥락을 기억하고 일관된 다단계 대화를 생성하도록 합니다. 브라우저에서 직접 실행하는 실습 코드로 AI Agents with LangChain & Autonomous Workflows을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
AI Agents with LangChain & Autonomous Workflows을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 AI Agents with LangChain & Autonomous Workflows은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“에이전트에 메모리와 대화 상태 부여하기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 AI Agents with LangChain & Autonomous Workflows 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 AI Agents with LangChain & Autonomous Workflows 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 인공지능 에이전트와 LLM 이해하기
- LangChain 핵심 구성 요소 해설
- 첫 번째 간단한 에이전트 구축
- 에이전트에 메모리와 대화 상태 부여하기