Memory for agents (conceptual video)

LangChain www.youtube.com

간략한 요약

이 비디오에서는 LangChain에서 메모리를 다루는 방식에 대해 설명합니다. 핵심은 메모리가 애플리케이션에 특화되어야 하며, LangChain은 이를 위해 필요한 로우 레벨 컴포넌트를 제공한다는 것입니다. 메모리는 크게 단기 메모리와 장기 메모리로 나뉘며, 각각 체크포인트와 스토어라는 추상화를 통해 구현됩니다.

  • 메모리는 애플리케이션에 특화되어야 함
  • 단기 메모리는 체크포인트를 통해 관리
  • 장기 메모리는 스토어를 통해 관리

메모리 소개

LangChain은 에이전트 분야에서 메모리가 매우 중요하다고 생각하며, L 그래프에 메모리 기능을 추가하여 메모리를 활용한 애플리케이션을 구축할 수 있도록 지원합니다. 일반적인 메모리 추상화나 서비스보다는, 사용자가 직접 메모리를 구현할 수 있도록 로우 레벨 컴포넌트를 제공하고, LangChain의 접근 방식을 공유하여 최적의 메모리 구현을 돕는 것을 목표로 합니다.

단기 메모리

메모리는 크게 단기 메모리와 장기 메모리로 나뉩니다. 단기 메모리는 주로 대화 메모리와 관련되며, LangChain의 체크포인트는 특정 스레드(대화)의 메모리를 유지하는 데 사용됩니다. 체크포인트는 링그래프에서 단기 메모리를 구현하는 방법입니다.

단기 메모리 기술

단기 메모리를 위한 일반적인 기술로는 메시지 필터링이 있습니다. AI와의 상호 작용이 많아질수록 메시지 목록이 길어지므로, 메시지를 필터링하는 것이 중요합니다. 기본적인 필터링 외에도 토큰 수나 메시지 유형에 따라 필터링할 수 있습니다. 또한, 메시지 요약을 통해 이전 메시지를 요약하고, 이를 그래프 상태의 속성으로 저장할 수도 있습니다.

장기 메모리

장기 메모리를 애플리케이션에 통합하는 방법은 크게 두 가지입니다. 첫째, 핫 패스(hot path)에서 애플리케이션 로직 자체가 메모리를 업데이트하는 방식입니다. 둘째, 백그라운드에서 별도의 프로세스가 메모리를 업데이트하는 방식입니다. 핫 패스는 메모리 업데이트가 투명하고 실시간으로 반영되지만, 지연 시간을 추가하고 애플리케이션 로직을 복잡하게 만들 수 있습니다. 백그라운드 방식은 지연 시간이 없고 로직 분리가 가능하지만, 사용자에게 업데이트를 알리기 어렵고 업데이트 시점을 결정해야 합니다.

장기 메모리 형태

장기 메모리의 형태로는 크게 세 가지가 있습니다. 첫째, 시스템 프롬프트의 일부로 삽입되는 지침(instructions)입니다. 둘째, 키-값 쌍의 딕셔너리 형태인 프로필(profile)입니다. 셋째, 객체 목록입니다. 지침은 사용자 피드백에 따라 업데이트될 수 있으며, 프로필은 사용자 대화를 기반으로 추출된 정보를 저장하고 업데이트합니다. 객체 목록은 좋아하는 식당 목록과 같이 여러 항목을 기억해야 할 때 유용합니다.

결론

LangChain은 메모리가 개인화되고 차별화된 애플리케이션을 구축하는 데 핵심적인 역할을 한다고 생각합니다. 메모리는 애플리케이션에 맞게 커스터마이징되어야 하며, LangChain은 이를 위한 다양한 도구를 제공하고자 합니다.

유튜브 영상을 몇 초 만에 요약하세요

무료 Summ 앱으로 어떤 영상이든 이런 요약을 원하는 언어로 받아보세요.

App Store에서 다운로드
Google Play에서 다운로드

스크립트

“Memory for agents (conceptual video)”의 전체 스크립트입니다. 타임스탬프를 클릭하면 해당 장면부터 영상이 열려요. 다른 영상이 필요하다면 유튜브 스크립트 추출기를 이용하세요.

0:00 today I want to talk about memory memory is one of the most exciting things that we think is happening in the agent world and we're adding a bunch of functionality into L graph to help you build applications that have memory this video will be more of a conceptual overview we won't go over any code rather we're going to talk through a few memory Concepts that we think are critical to understanding memory and understanding how we're thinking and tackling memory here at linkchain one of the main things that we think about memory is that it needs to be really application specific it needs to be specific to what you're trying to do and what things you might want to remember because that's what's going to make your application better so we're not very bullish on the idea of a general memory abstraction or service rather we're

0:46 going to give you low-level components so that you can Implement memory for yourself and we're also going to tell you how we're thinking about it so that hopefully that can help you implement the best memory for your application at a high level we think there are two types of memory one is short-term memory and this primarily relates to conversation memory if you've used Ling graph before then you're probably familiar with the idea of a checkpoint checkpoints maintain memory for a specific thread a thread is equivalent to a conversation and so this is what we call short-term memory and checkpoints are the lingraph implementation for implementing that long-term memory is a New Concept that we've recently started to think about and talk about and we've added a new abstraction called store to help with

1:31 this in Lang graph so in L graph checkpoints keep the memory within a thread store is used to keep memory across threads so it can be updated with information that it's gleaned from multiple different threads and then can pull that in and can use that when processing a new thread let's talk about some short-term memory things first and then we'll dive into more detail on long-term memory one of the common techniques we see for short-term memory is just filtering messages as you have more and more back and force with an AI the message list will grow in length and so being able to filter them is really important there's some basic filtering stuff like just keep the last 10 messages but then there's also Things

2:16 based on token counts and based on the types of messages as well perhaps it's more important to keep the human and AI messages rather than the tools for example if you're not satisfied with just filtering m mesages you can also summarize previous messages and pass in a summary this is typically done by calling an llm and storing that is some attribute on your graph State now let's talk about long-term memory at a high level we see two different ways that people are putting long-term memory into their application one is what we call in the hot path and so this is where the application logic itself updates memory the other is when it happens in the background and so here you have the application running and there's a separate process that in the background

3:02 runs and updates memory and this can happen real time or this can happen 30 minutes later an hour later whatever you decide there's some pros and cons to each of these so in the hot path it's very transparent when you're updating memory you can show this to the user so they know what's going on it's also real time so if they go start a separate conversation right away they have that updated memory the downsides are that because it's in the hot path it can add some latency and it also makes your application logic a little bit more convoluted because now you have to have your core application logic in there as well as the logic for how to update the memory when it happens in the background the pros and cons are flipped so there's no latency that's added because it's happening in the background in a

3:48 separate process you can also cleanly separate the logic for your application versus the logic for updating memory however there are some cons because this has happened in the background you can't easily surface that to the user and separately depending on how you set it up this memory may not be updated when you go to start a new conversation in fact a key part of when you're running memory in the background is figuring out when exactly to trigger that background run and that adds some additional logic that you have to think about for long-term memory it's really important to think about what's the exact shape of the memory that's your storing and there's a few different options that we see people doing one common type of

4:33 memory is instructions these are instructions that can be inserted as part of a system prompt that system prompt then controls how the application performs these instructions are often updated based on user interactions or user feedback so for example if you have a tweet writer application and you go back and forth with the user and they refine their tweet and you see that they're removing emojis you can use an llm to synthesize those interactions and update the part of the system prompt to say don't use emojis a second type of memory that we see people storing is what we call Profile instructions are typically a string but profiles are now a dictionary of key value pairs so for a chatbot that's concerned with being a companion for a user you

5:20 might have things like name age friends that you want to remember about the user the memory process here would extract that information based on user conversations and then update any previous information that had existed to create a new updated profile this profile can then be inserted as part of the system message in future conversations and this can be included when responding to the user A Step Above This profile is a list of these objects this is useful when you want to remember a list of things for example a list of my favorite restaurants and you want to remember the location and the name and the type of all of them there's some extra complexity here the llm now has to prompt to not only add a new item to the list but also update or delete previous

6:07 ones and so there's a bit of prompt engineering you need to do here again we're really excited about memory at linkchain we think it's a key part of building personalized and differentiated applications but we also think that there's no Silver Bullet single answer fits-all solution for memory we think that it has to be custom to your application and so we hope to give you a lot of the tools to help you build application specific memory yourself so I know this just covered the concepts but I'd encourage you to go check out the how-to guides and the tutorials that we have out for building this type of personalized memory thanks for watching and let me know if you have any questions

Share

다른 영상 요약