0Pricing
AI Agents with LangChain & Autonomous Workflows · Lekcja

Dodawanie agentom pamięci i stanu rozmowy

Dodaj agentom LangChain pamięć krótko- i długoterminową, aby pamiętały kontekst między kolejnymi turami i tworzyły spójne, wieloetapowe rozmowy.

Dodawanie agentom pamięci i stanu rozmowy to bezpłatna lekcja AI Agents with LangChain & Autonomous Workflows na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej AI Agents with LangChain & Autonomous Workflows, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs AI Agents with LangChain & Autonomous Workflows zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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.

Często zadawane pytania

Czy lekcja „Dodawanie agentom pamięci i stanu rozmowy” jest bezpłatna?

Tak — pełny tekst „Dodawanie agentom pamięci i stanu rozmowy” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu AI Agents with LangChain & Autonomous Workflows, przejdź na CoddyKit PRO. Kurs AI Agents with LangChain & Autonomous Workflows zawiera 4 lekcji w sumie.

Co nauczysz się w „Dodawanie agentom pamięci i stanu rozmowy”?

Dodaj agentom LangChain pamięć krótko- i długoterminową, aby pamiętały kontekst między kolejnymi turami i tworzyły spójne, wieloetapowe rozmowy. Ćwiczysz AI Agents with LangChain & Autonomous Workflows z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć AI Agents with LangChain & Autonomous Workflows?

Nie wymagamy żadnego doświadczenia. AI Agents with LangChain & Autonomous Workflows w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Dodawanie agentom pamięci i stanu rozmowy”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji AI Agents with LangChain & Autonomous Workflows?

Tak. Każda lekcja AI Agents with LangChain & Autonomous Workflows zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Poznawanie agentów AI i LLM-ów
  2. Wyjaśnienie podstawowych komponentów LangChain
  3. Budowanie pierwszego prostego agenta
  4. Dodawanie agentom pamięci i stanu rozmowy
← Powrót do AI Agents with LangChain & Autonomous Workflows