Vertex AI Agent Engine 메모리 뱅크를 사용하기 전에 환경을 설정해야 합니다. 메모리 뱅크는 Agent Engine의 일부이지만 메모리 뱅크를 사용하기 위해 코드를 Agent Engine 런타임에 배포할 필요는 없습니다.
Google Cloud 프로젝트 설정
모든 프로젝트는 프로젝트 번호 또는 프로젝트 ID의 두 가지 방법으로 식별될 수 있습니다. PROJECT_NUMBER
는 사용자가 프로젝트를 만들 때 자동으로 생성되고, PROJECT_ID
는 사용자 또는 프로젝트를 만든 사람이 지정합니다. 프로젝트를 설정하려면 다음 단계를 따르세요.
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
익스프레스 모드에서 Vertex AI를 사용하지 않는 경우 Vertex AI에 인증의 안내를 따르세요.
익스프레스 모드에서 Vertex AI를 사용하는 경우 환경에서 API 키를 설정하여 인증을 설정합니다.
os.environ["GOOGLE_API_KEY"] = "API_KEY"
PROJECT_ID
는 프로젝트 ID입니다.LOCATION
은 메모리 뱅크의 지원되는 리전 중 하나입니다.Agent Engine 인스턴스 만들기 또는 업데이트: 인스턴스를 만들거나 업데이트할 때 Agent Engine의 기본값을 재정의하여 인스턴스를 다음과 같이 수정할 수 있습니다.
- AGENT_ENGINE_NAME: 에이전트 엔진의 이름.
projects/.../locations/.../reasoningEngines/...
형식이어야 합니다. Memory Bank의 지원되는 리전을 참고하세요. 메모리 뱅크에서 추억을 생성하고 관리하는 방법을 구성합니다.
Agent Engine 런타임에 에이전트를 배포합니다.
agent_engine = client.agent_engines.create( # Optional. Set this argument if you want to deploy to Agent Engine Runtime. agent_engine=..., # Optional. Set this argument if you want to change the Memory Bank configuration. config=... )
새로 만들거나 기억을 생성하지 않으면 새 인스턴스는 비어 있습니다.
메모리를 읽거나 쓰려면 에이전트 엔진의 이름이 필요합니다.
agent_engine_name = agent_engine.api_resource.name
- AGENT_ENGINE_NAME: 에이전트 엔진의 이름.
projects/.../locations/.../reasoningEngines/...
형식이어야 합니다. Memory Bank의 지원되는 리전을 참고하세요. - 맞춤설정 구성: 소스 데이터에서 메모리를 추출하는 방법을 구성합니다.
- 유사성 검색 구성: 유사성 검색에 사용되는 임베딩 모델을 구성합니다. 기본값은
text-embedding-005
입니다. - 생성 구성: 메모리 생성에 사용되는 LLM을 구성합니다. 기본값은
gemini-2.0-flash-001
입니다. - TTL 구성: 생성되거나 업데이트된 메모리에 TTL이 자동으로 설정되는 방식을 구성합니다. 기본값은 TTL 없음입니다.
- 메모리 주제 구성: 메모리 은행에서 지속하는 것이 의미 있다고 간주해야 하는 정보의 유형을 정의합니다. 이러한 메모리 주제 중 하나에 해당하는 정보만 메모리 뱅크에 유지됩니다.
- 퓨샷 예시 제공: 메모리 추출의 예상 동작을 메모리 뱅크에 보여줍니다.
관리형 주제: 라벨과 안내는 메모리 뱅크에 의해 정의됩니다. 관리 주제의 이름만 제공하면 됩니다. 예를 들면 다음과 같습니다.
딕셔너리
memory_topic = { "managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" } }
클래스 기반
from vertexai.types import ManagedTopicEnum from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic memory_topic = MemoryTopic( managed_memory_topic=ManagedMemoryTopic( managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO ) )
Memory Bank에서 지원하는 관리 주제는 다음과 같습니다.
- 개인 정보 (
USER_PERSONAL_INFO
): 이름, 관계, 취미, 중요한 날짜 등 사용자에 관한 중요한 개인 정보입니다. 예를 들어 '나는 Google에서 일해' 또는 '내 결혼기념일은 12월 31일이야'라고 말하면 됩니다. - 사용자 선호도 (
USER_PREFERENCES
): 명시적 또는 암시적 좋아요, 싫어요, 선호하는 스타일 또는 패턴입니다. 예를 들어 '중간 좌석을 선호합니다'라고 말할 수 있습니다. - 주요 대화 이벤트 및 작업 결과 (
KEY_CONVERSATION_DETAILS
): 대화 내의 중요한 단계 또는 결론입니다. 예를 들어 'JFK와 SFO 간 왕복 항공권을 예약했어. 2025년 6월 1일에 출발하여 2025년 6월 7일에 돌아옵니다.' - 명시적 기억 / 잊기 요청 (
EXPLICIT_INSTRUCTIONS
): 사용자가 에이전트에게 기억하거나 잊도록 명시적으로 요청한 정보입니다. 예를 들어 사용자가 '주로 Python을 사용한다고 기억해 줘'라고 말하면 Memory Bank는 '주로 Python을 사용합니다'와 같은 메모리를 생성합니다.
- 개인 정보 (
맞춤 주제: 메모리 뱅크 인스턴스를 설정할 때 라벨과 안내가 정의됩니다. 이러한 정보는 메모리 뱅크의 추출 단계 프롬프트에 사용됩니다. 예를 들면 다음과 같습니다.
딕셔너리
memory_topic = { "custom_memory_topic": { "label": "business_feedback", "description": """Specific user feedback about their experience at the coffee shop. This includes opinions on drinks, food, pastries, ambiance, staff friendliness, service speed, cleanliness, and any suggestions for improvement.""" } }
클래스 기반
from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic from vertexai.types import MemoryBankCustomizationConfigMemoryTopicCustomMemoryTopic as CustomMemoryTopic memory_topic = MemoryTopic( custom_memory_topic=CustomMemoryTopic( label="business_feedback", description="""Specific user feedback about their experience at the coffee shop. This includes opinions on drinks, food, pastries, ambiance, staff friendliness, service speed, cleanliness, and any suggestions for improvement.""" ) )
맞춤 주제를 사용하는 경우 대화에서 메모리를 추출하는 방법을 보여주는 퓨샷 예시도 제공하는 것이 좋습니다.
- EMBEDDING_MODEL: 유사성 검색에 사용할 Google 텍스트 임베딩 모델입니다(
projects/{project}/locations/{location}/publishers/google/models/{model}
형식). - LLM_MODEL: 기억을 추출하고 통합하는 데 사용할 Google LLM 모델입니다(
projects/{project}/locations/{location}/publishers/google/models/{model}
형식). 기본 TTL: TTL은
UpdateMemory
,CreateMemory
,GenerateMemories
를 비롯해 메모리를 생성하거나 업데이트하는 모든 작업에 적용됩니다.딕셔너리
memory_bank_config = { "ttl_config": { "default_ttl": f"TTLs" } }
클래스 기반
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfig as TtlConfig memory_bank_config = MemoryBankConfig( ttl_config=TtlConfig( default_ttl=f"TTLs" ) )
다음을 바꿉니다.
- TTL: TTL의 기간(초)입니다. 업데이트된 추억의 경우 새로 계산된 만료 시간 (현재 + TTL)이 추억의 이전 만료 시간을 덮어씁니다.
세부적인 (작업별) TTL: TTL은 메모리를 생성하거나 업데이트한 작업을 기반으로 계산됩니다. 특정 작업에 대해 설정되지 않은 경우 작업에서 메모리의 만료 시간을 업데이트하지 않습니다.
딕셔너리
memory_bank_config = { "ttl_config": { "granular_ttl": { "create_ttl": f"CREATE_TTLs", "generate_created_ttl": f"GENERATE_CREATED_TTLs", "generate_updated_ttl": f"GENERATE_UPDATED_TTLs" } } }
클래스 기반
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfig as TtlConfig from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfigGranularTtlConfig as GranularTtlConfig memory_bank_config = MemoryBankConfig( ttl_config=TtlConfig( granular_ttl_config=GranularTtlConfig( create_ttl=f"CREATE_TTLs", generate_created_ttl=f"GENERATE_CREATED_TTLs", generate_updated_ttl=f"GENERATE_UPDATED_TTLs", ) ) )
다음을 바꿉니다.
- CREATE_TTL:
CreateMemory
을 사용하여 생성된 추억의 TTL 기간(초)입니다. - GENERATE_CREATED_TTL:
GeneratedMemories
을 사용하여 생성된 추억의 TTL 기간(초)입니다. - GENERATE_UPDATED_TTL:
GeneratedMemories
를 사용하여 업데이트된 추억의 TTL 기간(초)입니다. 새로 계산된 만료 시간 (현재 + TTL)이 메모리의 이전 만료 시간을 덮어씁니다.
- CREATE_TTL:
- STAGING_BUCKET: 에이전트 엔진 런타임을 스테이징하는 데 사용할 Cloud Storage 버킷입니다.
필요한 역할 가져오기
Vertex AI Agent Engine을 사용하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한 Vertex AI 사용자 (roles/aiplatform.user
) IAM 역할을 부여해 달라고 요청하세요.
역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.
커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.
Google Kubernetes Engine 또는 Cloud Run에 배포된 에이전트에서 메모리 뱅크에 요청하는 경우 서비스 계정에 필요한 권한이 있는지 확인하세요. Reasoning Engine 서비스 에이전트에는 이미 메모리를 읽고 쓰는 데 필요한 권한이 있으므로 Agent Engine 런타임의 아웃바운드 요청에는 메모리 은행에 액세스할 수 있는 권한이 이미 있어야 합니다.
환경 설정
이 섹션에서는 Python 개발 환경을 설정했거나 Python 개발 환경이 포함된 런타임 (예: Colab)을 사용하고 있다고 가정합니다.
라이브러리 설치
Vertex AI SDK를 설치합니다.
pip install google-cloud-aiplatform>=1.104.0
인증
인증 안내는 Vertex AI를 익스프레스 모드로 사용하고 있는지에 따라 다릅니다.
Vertex AI SDK 클라이언트 설정
다음 코드를 실행하여 Vertex AI SDK 클라이언트를 설정합니다.
import vertexai
client = vertexai.Client(
project="PROJECT_ID",
location="LOCATION",
)
각 항목의 의미는 다음과 같습니다.
메모리 뱅크용 Agent Engine 인스턴스 구성
메모리 뱅크를 시작하려면 먼저 Agent Engine 인스턴스가 필요합니다.
다음 중 하나를 실행하세요.
기존 인스턴스 사용
기존 Agent Engine 인스턴스를 수정할 필요가 없는 경우 다음을 실행하여 메모리 뱅크의 인스턴스를 구성합니다.
agent_engine = client.agent_engines.get(name="AGENT_ENGINE_NAME")
다음을 바꿉니다.
Google Kubernetes Engine, Cloud Run 등 모든 환경에서 인스턴스를 사용할 수 있습니다. 시작하려면 메모리 뱅크를 식별하는 Agent Engine 이름과 메모리 뱅크를 호출할 수 있는 충분한 권한이 필요합니다.
인스턴스 만들기 또는 업데이트
만들기
Agent Engine 인스턴스를 만들면 메모리 뱅크가 기본적으로 사용 설정됩니다. 런타임 없이 새 Agent Engine을 만드는 데는 몇 초밖에 걸리지 않습니다.
agent_engine = client.agent_engines.create()
Agent Engine 인스턴스를 만들 때 Agent Engine의 기본값을 재정의하여 다음과 같이 수정할 수도 있습니다.
업데이트
인스턴스에 저장된 메모리를 유지하면서 Agent Engine을 업데이트하려면 기존 Agent Engine 인스턴스를 업데이트하면 됩니다. 메모리 뱅크 구성 변경 또는 에이전트를 에이전트 엔진 런타임에 배포와 같은 업데이트를 할 수 있습니다.
agent_engine = client.agent_engines.update(
# If you have an existing AgentEngine, you can access the name using `agent_engine.api_resource.name`.
name="AGENT_ENGINE_NAME",
# Optional. Set this argument if you want to deploy to Agent Engine Runtime.
agent_engine=...,
# Optional. Set this argument if you want to change the Memory Bank configuration.
config=...
)
다음을 바꿉니다.
메모리 뱅크 구성 설정
메모리 뱅크를 구성하여 추억이 생성되고 관리되는 방식을 맞춤설정할 수 있습니다. 구성이 제공되지 않으면 메모리 뱅크는 각 구성 유형의 기본 설정을 사용합니다.
메모리 뱅크 구성은 에이전트 엔진 인스턴스를 만들거나 업데이트할 때 설정됩니다.
client.agent_engines.create(
...,
config={
"context_spec": {
"memory_bank_config": memory_bank_config
}
}
)
# Alternatively, update an existing Agent Engine's Memory Bank config.
agent_engine = client.agent_engines.update(
name=agent_engine.api_resource.name,
config={
"context_spec": {
"memory_bank_config": memory_bank_config
}
}
)
인스턴스에 대해 다음 설정을 구성할 수 있습니다.
맞춤설정 구성
소스 데이터에서 메모리를 추출하는 방식을 맞춤설정하려면 에이전트 엔진 인스턴스를 설정할 때 메모리 추출 동작을 구성하면 됩니다. 맞춤설정에 사용할 수 있는 두 가지 요소가 있습니다.
원하는 경우 범위 수준별로 다른 동작을 구성할 수 있습니다. 예를 들어 세션 수준 기억에 의미가 있는 주제가 여러 세션에 걸친 사용자 수준 기억에는 의미가 없을 수 있습니다. 특정 메모리 하위 집합의 동작을 구성하려면 맞춤설정 구성의 범위 키를 설정하세요. 해당 범위 키를 포함하는 GenerateMemories
요청만 해당 구성을 사용합니다. scope_key
필드를 생략하여 모든 범위 키 집합에 적용되는 기본 동작을 구성할 수도 있습니다. 이 구성은 다른 맞춤설정 구성의 범위 키와 정확히 일치하는 구성이 없는 모든 요청에 적용됩니다.
예를 들어 user_level_config
는 범위 키 user_id
를 정확하게 사용하는 GenerateMemories
요청에만 적용됩니다 (즉, 추가 키가 없는 scope={"user_id": "123"}
). default_config
가 다른 요청에 적용됩니다.
딕셔너리
user_level_config = {
"scope_keys": ["user_id"],
"memory_topics": [...],
"generate_memories_examples": [...]
}
default_config = {
"memory_topics": [...],
"generate_memories_examples": [...]
}
config = {
"customization_configs": [
user_level_config,
default_config
]
}
클래스 기반
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
user_level_config = CustomizationConfig(
scope_keys=["user_id"],
memory_topics=[...],
generate_memories_examples=[...]
)
메모리 주제 구성
'메모리 주제'는 메모리 뱅크에서 의미가 있다고 간주하여 생성된 기억으로 유지해야 하는 정보를 식별합니다. 메모리 뱅크는 두 가지 유형의 메모리 주제를 지원합니다.
맞춤설정을 사용하면 메모리 주제를 원하는 대로 조합하여 사용할 수 있습니다. 예를 들어 사용 가능한 관리 메모리 주제의 하위 집합을 사용할 수 있습니다.
딕셔너리
{
"memory_topics": [
"managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" },
"managed_memory_topic": { "managed_topic_enum": "USER_PREFERENCES" }
]
}
클래스 기반
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
from vertexai.types import ManagedTopicEnum
CustomizationConfig(
memory_topics=[
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO)
),
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PREFERENCES)
),
]
)
관리 주제와 맞춤 주제를 조합하여 사용하거나 맞춤 주제만 사용할 수도 있습니다.
딕셔너리
{
"memory_topics": [
"managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" },
"custom_memory_topic": {
"label": "Jargon",
"description": """Specific user feedback about their experience at
the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
staff friendliness, service speed, cleanliness, and any suggestions for
improvement."""
}
]
}
클래스 기반
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
from vertexai.types import MemoryBankCustomizationConfigMemoryTopicCustomMemoryTopic as CustomMemoryTopic
from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
from vertexai.types import ManagedTopicEnum
CustomizationConfig(
memory_topics=[
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO)
),
MemoryTopic(
custom_memory_topic=CustomMemoryTopic(
label="business_feedback",
description="""Specific user feedback about their experience at
the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
staff friendliness, service speed, cleanliness, and any suggestions for
improvement."""
)
)
]
)
퓨샷 예시
퓨샷 예시를 사용하면 메모리 뱅크에 예상되는 메모리 추출 동작을 보여줄 수 있습니다. 예를 들어 샘플 입력 대화와 해당 대화에서 추출될 것으로 예상되는 메모리를 제공할 수 있습니다.
메모리 뱅크가 의도한 동작을 학습할 수 있도록 항상 맞춤 주제와 함께 few-shot을 사용하는 것이 좋습니다. 관리 주제를 사용하는 경우 메모리 뱅크에서 각 주제의 예를 정의하므로 few-shot은 선택사항입니다. 빈 generated_memories
목록을 제공하여 메모리가 생성되지 않을 것으로 예상되는 대화를 보여줍니다.
예를 들어 고객 메시지에서 비즈니스에 관한 피드백을 추출하는 방법을 보여주는 퓨샷 예시를 제공할 수 있습니다.
딕셔너리
example = {
"conversationSource": {
"events": [
{
"content": {
"role": "model",
"parts": [{ "text": "Welcome back to The Daily Grind! We'd love to hear your feedback on your visit." }] }
},
{
"content": {
"role": "user",
"parts": [{ "text": "Hey. The drip coffee was a bit lukewarm today, which was a bummer. Also, the music was way too loud, I could barely hear my friend." }] }
}
]
},
"generatedMemories": [
{
"fact": "The user reported that the drip coffee was lukewarm."
},
{
"fact": "The user felt the music in the shop was too loud."
}
]
}
클래스 기반
from google.genai.types import Content, Part
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExample as GenerateMemoriesExample
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSource as ConversationSource
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSourceEvent as ConversationSourceEvent
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleGeneratedMemory as ExampleGeneratedMemory
example = GenerateMemoriesExample(
conversation_source=ConversationSource(
events=[
ConversationSourceEvent(
content=Content(
role="model",
parts=[Part(text="Welcome back to The Daily Grind! We'd love to hear your feedback on your visit.")]
)
),
ConversationSourceEvent(
content=Content(
role="user",
parts=[Part(text= "Hey. The drip coffee was a bit lukewarm today, which was a bummer. Also, the music was way too loud, I could barely hear my friend.")]
)
)
]
),
generated_memories=[
ExampleGeneratedMemory(
fact="The user reported that the drip coffee was lukewarm."
),
ExampleGeneratedMemory(
fact="The user felt the music in the shop was too loud."
)
]
)
예상 출력 (generated_memories
)에 빈 목록을 제공하여 생성된 메모리가 없어야 하는 대화의 예를 제공할 수도 있습니다.
딕셔너리
example = {
"conversationSource": {
"events": [
{
"content": {
"role": "model",
"parts": [{ "text": "Good morning! What can I get for you at The Daily Grind?" }] }
},
{
"content": {
"role": "user",
"parts": [{ "text": "Thanks for the coffee." }] }
}
]
},
"generatedMemories": []
}
클래스 기반
from google.genai.types import Content, Part
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExample as GenerateMemoriesExample
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSource as ConversationSource
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSourceEvent as ConversationSourceEvent
example = GenerateMemoriesExample(
conversation_source=ConversationSource(
events=[
ConversationSourceEvent(
content=Content(
role="model",
parts=[Part(text="Welcome back to The Daily Grind! We'd love to hear your feedback on your visit.")]
)
),
ConversationSourceEvent(
content=Content(
role="user",
parts=[Part(text= "Thanks for the coffee!")]
)
)
]
),
generated_memories=[]
)
유사성 검색 구성
유사성 검색 구성은 인스턴스에서 유사성 검색에 사용하는 임베딩 모델을 제어합니다. 유사성 검색은 통합의 후보가 되어야 하는 기억과 유사성 검색 기반 기억 검색을 식별하는 데 사용됩니다. 이 구성이 제공되지 않으면 Memory Bank는 text-embedding-005
을 기본 모델로 사용합니다.
사용자 대화가 영어 외의 언어로 진행될 것으로 예상되는 경우 gemini-embedding-001
또는 text-multilingual-embedding-002
과 같은 다국어를 지원하는 모델을 사용하여 검색 품질을 개선하세요.
딕셔너리
memory_bank_config = {
"similarity_search_config": {
"embedding_model": "EMBEDDING_MODEL",
}
}
클래스 기반
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfig as SimilaritySearchConfig
memory_bank_config = MemoryBankConfig(
similarity_search_config=SimilaritySearchConfig(
embedding_model="EMBEDDING_MODEL"
)
)
다음을 바꿉니다.
생성 구성
생성 구성은 기억을 추출하고 새 기억을 기존 기억과 통합하는 등 기억을 생성하는 데 사용되는 LLM을 제어합니다.
Memory Bank는 gemini-2.0-flash-001
을 기본 모델로 사용합니다.
딕셔너리
memory_bank_config = {
"generation_config": {
"model": "LLM_MODEL",
}
}
클래스 기반
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigGenerationConfig as GenerationConfig
memory_bank_config = MemoryBankConfig(
generation_config=GenerationConfig(
model="LLM_MODEL"
)
)
다음을 바꿉니다.
TTL (수명) 구성
TTL 구성은 메모리 뱅크가 기억의 만료 시간을 동적으로 설정하는 방법을 제어합니다. 만료 시간이 지나면 추억을 검색할 수 없으며 삭제됩니다.
구성을 제공하지 않으면 생성되거나 업데이트된 추억의 만료 시간이 동적으로 설정되지 않으므로 만료 시간이 수동으로 설정되지 않는 한 추억이 만료되지 않습니다.
TTL 구성에는 두 가지 옵션이 있습니다.
메모리가 있는 에이전트를 에이전트 엔진에 배포
메모리 뱅크는 모든 런타임에서 사용할 수 있지만, Agent Engine 런타임과 함께 사용하여 배포된 에이전트에서 기억을 읽고 쓸 수도 있습니다.
Vertex AI Agent Engine 런타임에서 메모리 뱅크를 사용하여 에이전트를 배포하려면 먼저 Agent Engine 런타임의 환경을 설정하세요. 그런 다음 메모리 통합을 사용하여 에이전트 엔진 런타임에 배포할 에이전트를 준비합니다. 배포된 에이전트는 필요에 따라 메모리를 읽고 쓰는 호출을 해야 합니다.
AdkApp
Agent Engine 에이전트 개발 키트 템플릿을 사용하는 경우 에이전트가 Agent Engine 런타임에 배포될 때 기본적으로 VertexAiMemoryBankService
를 사용합니다. 즉, ADK 메모리 도구는 메모리 뱅크에서 메모리를 읽습니다.
from google.adk.agents import Agent
from vertexai.preview.reasoning_engines import AdkApp
# Develop an agent using the ADK template.
agent = Agent(...)
adk_app = AdkApp(
agent=adk_agent,
...
)
# Deploy the agent to Agent Engine Runtime.
agent_engine = client.agent_engines.create(
agent_engine=adk_app,
config={
"staging_bucket": "STAGING_BUCKET",
"requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
# Optional.
**context_spec
}
)
# Update an existing Agent Engine to add or modify the Runtime.
agent_engine = client.agent_engines.update(
name=agent_engine.api_resource.name,
agent_engine=adk_app,
config={
"staging_bucket": "STAGING_BUCKET",
"requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
# Optional.
**context_spec
}
)
다음을 바꿉니다.
ADK로 메모리 뱅크를 사용하는 방법에 대한 자세한 내용은 에이전트 개발 키트 사용하기 빠른 시작을 참고하세요.
맞춤 에이전트
Agent Engine 런타임에 배포된 맞춤 에이전트와 함께 메모리 뱅크를 사용할 수 있습니다. 이 경우 에이전트는 메모리 뱅크에 대한 호출을 조정하여 기억 생성 및 기억 검색 호출을 트리거해야 합니다.
메모리 뱅크와 에이전트 엔진 런타임에 동일한 에이전트 엔진 인스턴스를 사용하려면 환경 변수 GOOGLE_CLOUD_PROJECT
, GOOGLE_CLOUD_LOCATION
, GOOGLE_CLOUD_AGENT_ENGINE_ID
를 읽어 환경에서 에이전트 엔진 이름을 추론하면 됩니다.
project = os.environ.get("GOOGLE_CLOUD_PROJECT")
location = os.environ.get("GOOGLE_CLOUD_LOCATION")
agent_engine_id = os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID")
agent_engine_name = f"projects/{project}/locations/{location}/reasoningEngines/{agent_engine_id}"