0Pricing
AI Agents with LangChain & Autonomous Workflows · Lektion

Agents mit Gedächtnis und Konversationszustand ausstatten

Fügen Sie LangChain-Agents ein Kurzzeit- und Langzeitgedächtnis hinzu, damit sie Kontext über mehrere Gesprächsrunden hinweg behalten und kohärente mehrstufige Gespräche führen.

Agents mit Gedächtnis und Konversationszustand ausstatten ist eine kostenlose AI Agents with LangChain & Autonomous Workflows-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des AI Agents with LangChain & Autonomous Workflows-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der AI Agents with LangChain & Autonomous Workflows-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Agents mit Gedächtnis und Konversationszustand ausstatten“ kostenlos?

Ja — der vollständige Text von „Agents mit Gedächtnis und Konversationszustand ausstatten“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des AI Agents with LangChain & Autonomous Workflows-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der AI Agents with LangChain & Autonomous Workflows-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Agents mit Gedächtnis und Konversationszustand ausstatten“?

Fügen Sie LangChain-Agents ein Kurzzeit- und Langzeitgedächtnis hinzu, damit sie Kontext über mehrere Gesprächsrunden hinweg behalten und kohärente mehrstufige Gespräche führen. Du übst AI Agents with LangChain & Autonomous Workflows mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um AI Agents with LangChain & Autonomous Workflows zu starten?

Keine Vorkenntnisse erforderlich. AI Agents with LangChain & Autonomous Workflows auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Agents mit Gedächtnis und Konversationszustand ausstatten“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser AI Agents with LangChain & Autonomous Workflows-Lektion Code schreiben und ausführen?

Ja. Jede AI Agents with LangChain & Autonomous Workflows-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. KI-Agenten und LLMs verstehen
  2. Die Kernkomponenten von LangChain erklärt
  3. Ihren ersten einfachen Agenten erstellen
  4. Agents mit Gedächtnis und Konversationszustand ausstatten
← Zurück zu AI Agents with LangChain & Autonomous Workflows