0Pricing
AI Agents with LangChain & Autonomous Workflows · บทเรียน

เพิ่มความจำและสถานะการสนทนาให้เอเจนต์

เพิ่มความจำระยะสั้นและระยะยาวให้เอเจนต์ของ LangChain เพื่อให้จดจำบริบทข้ามแต่ละรอบการสนทนาและสร้างบทสนทนาหลายขั้นตอนที่สอดคล้องกัน

เพิ่มความจำและสถานะการสนทนาให้เอเจนต์ เป็นบทเรียน AI Agents with LangChain & Autonomous Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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.

คำถามที่พบบ่อย

บทเรียน “เพิ่มความจำและสถานะการสนทนาให้เอเจนต์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “เพิ่มความจำและสถานะการสนทนาให้เอเจนต์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Agents with LangChain & Autonomous Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Agents with LangChain & Autonomous Workflows มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “เพิ่มความจำและสถานะการสนทนาให้เอเจนต์”

เพิ่มความจำระยะสั้นและระยะยาวให้เอเจนต์ของ LangChain เพื่อให้จดจำบริบทข้ามแต่ละรอบการสนทนาและสร้างบทสนทนาหลายขั้นตอนที่สอดคล้องกัน คุณปฏิบัติ AI Agents with LangChain & Autonomous Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Agents with LangChain & Autonomous Workflows หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Agents with LangChain & Autonomous Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “เพิ่มความจำและสถานะการสนทนาให้เอเจนต์” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AI Agents with LangChain & Autonomous Workflows นี้ได้ไหม

ได้ บทเรียน AI Agents with LangChain & Autonomous Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ทำความเข้าใจเอเจนต์ปัญญาประดิษฐ์และ LLM
  2. อธิบายองค์ประกอบหลักของ LangChain
  3. การสร้างเอเจนต์อย่างง่ายตัวแรก
  4. เพิ่มความจำและสถานะการสนทนาให้เอเจนต์
← กลับไปที่ AI Agents with LangChain & Autonomous Workflows