자동 메모리 추출 커스터마이즈

자동 메모리 추출은 추가 구성 없이 유용한 세부 정보를 캡처할 수 있습니다. 사용자정의 지침을 통해 애플리케이션은 특정 사용 사례에 맞게 기본 동작을 조정해야 하는 경우 추출 프로세스에 지침을 추가할 수 있습니다.

이 설명서에서는 사용자정의 지침을 통해 Oracle AI Agent Memory의 자동 메모리 추출을 안내하는 방법에 대해 설명합니다.

사용자 정의 지침을 통해 내구성이 뛰어난 메모리로 보존할 가치가 있는 세부 정보에 대한 도메인별 지침을 제공할 수 있습니다. 응용 프로그램에서 잠재적으로 기억에 남을 수 있는 모든 세부 정보를 동일한 방식으로 처리하는 대신 전문가의 판단, 제품 정책 또는 워크플로우별 우선 순위를 반영하기 위해 추출해야 하는 경우에 유용합니다.

주: 메모리 추출이 응용 프로그램별 지침을 따라야 하는 경우 사용자 정의 지침을 사용하십시오. 추가 지침이 필요하지 않은 경우 기본 추출이 적합합니다.

힌트: oracleagentmemory 설치 방법은 에이전트 메모리 시작하기를 참조하십시오. 이 예에 대한 로컬 Oracle AI Database가 필요한 경우 로컬에서 Oracle AI Database 실행을 따르십시오.

클라이언트 레벨 추출 지침 구성

Oracle DB 연결 또는 풀, 임베더, LLM 및 지원 중심 추출 지침을 사용하여 Oracle Agent 메모리 구성요소를 생성합니다. 이러한 지침은 스레드가 자체 추출 지침을 제공하지 않는 한 이 클라이언트를 통해 생성되거나 로드된 스레드에 적용됩니다.

import oracledb

from oracleagentmemory.core import MemoryExtractionConfig, MemoryLinkExtractionMode, SchemaPolicy
from oracleagentmemory.core.embedders.embedder import Embedder
from oracleagentmemory.core.llms.llm import Llm
from oracleagentmemory.core.oracleagentmemory import OracleAgentMemory

embedder = Embedder(model="YOUR_EMBEDDING_MODEL")
llm = Llm(model="YOUR_MEMORY_LLM")
db_pool = oracledb.SessionPool(
    user="YOUR DB USER",
    password="YOUR DB PASSWORD",
    dsn="localhost:1521/...",
)
memory_store_id = "T_MEM_EXTRACTION"

support_extraction_instructions = """
Only extract customer support facts:
- order ids
- return requests
- delivery problems
Ignore greetings, small talk, and one-off troubleshooting text.
""".strip()

memory = OracleAgentMemory(
    connection=db_pool,
    embedder=embedder,
    llm=llm,
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=support_extraction_instructions
    ),
    schema_policy=SchemaPolicy.CREATE_IF_NECESSARY,
    memory_store_id=memory_store_id,
)
API 참조: OracleAgentMemory 오라클 스레드

스레드 메시지에서 지원 메모리 추출

지원 스레드를 생성하고 사용자 및 도우미 메시지를 추가합니다. 예제에서는 memory_extraction_config=MemoryExtractionConfig(memory_extraction_frequency=1)를 설정하므로 add_messages()는 삽입된 회전에 대해 즉시 자동 추출을 실행합니다. 사용자 정의 지침은 추출된 메모리를 주문 ID, 반품 요청 및 배송 문제에 중점을 둡니다.

support_thread = memory.create_thread(
    thread_id="support_ticket_7421",
    user_id="customer_123",
    memory_extraction_config=MemoryExtractionConfig(memory_extraction_frequency=1),
)

#add_messages persists the turn and runs automated memory extraction because
#MemoryExtractionConfig(memory_extraction_frequency=1) is set for this thread.
support_thread.add_messages(
    [
        {
            "role": "user",
            "content": (
                "Hi, order 7421 arrived damaged. I need a return request "
                "and a replacement delivery."
            ),
        },
        {
            "role": "assistant",
            "content": "I can help start the return request for order 7421.",
        },
    ]
)

results = support_thread.search(
    "return request order 7421",
    max_results=5,
    record_types=["fact"],
)
for result in results:
    print(f"- [{result.record.record_type}] {result.content}")
#- [fact] Customer reported damaged order 7421 and requested a return and replacement delivery.

앞의 출력은 그림입니다. 정확한 메모리 텍스트는 구성된 추출 LLM에 따라 다르지만 추출된 메모리는 클라이언트에 제공된 사용자정의 지침을 따라야 합니다.

차이는 추출기가 보관하도록 요청하는 메모리의 종류를 비교하여 보는 것이 가장 쉽습니다.

사용자 정의 지침 포함

추출기는 튼튼한 고객 지원 사실을 유지하고 인사말과 대화 표현을 무시합니다.

- [fact] Customer reported damaged order 7421 and requested a return and replacement delivery.

사용자정의 지침 없음

추출기는 작업을 지원하기 위해 기본 추출 프롬프트의 범위가 지정되지 않으므로 더 넓은 대화 메모리를 유지할 수 있습니다.

- [memory] The user contacted support about order 7421 and discussed a damaged delivery.
API 참조: OracleThread 오라클 검색 결과

자동 메모리 연결 구성

자동 메모리 연결은 새로 추출된 메모리를 관련된 기존 메모리에 연결합니다. SDK는 제한된 후보자 메모리 세트를 검색하고 추출 LLM에 입력된 링크를 생성해야 하는지 여부를 결정하도록 요청합니다. 기본적으로 POST_EXTRACTION는 메모리가 추출된 후 추가 요청 하나로 해당 결정을 내립니다.

링크 유형은 새 메모리에서 기존 후보자와의 관계를 설명합니다. supersedes, refines 및 duplicates는 이전 메모리를 기록으로 유지하고 부적합으로 표시합니다. supports 및 contradicts는 두 메모리를 모두 적합한 상태로 유지합니다. 자동 연결은 검색된 후보자로 제한됩니다. 항상 관계를 기록해야 하는 경우 명시적 연결 API를 사용합니다.

MemoryExtractionConfig를 사용하여 자동 링크 사용자정의:

앞에서 설명한 추출 설정과 마찬가지로 이러한 필드를 클라이언트 레벨에서 제공하거나 특정 스레드에 대해 대체합니다. 다음 예에서는 지원 스레드를 업데이트하여 지원 팩트의 의미 있는 변경 사항만 연결합니다.

memory.update_thread(
    "support_ticket_7421",
    memory_extraction_config=MemoryExtractionConfig(
        memory_link_extraction_mode=MemoryLinkExtractionMode.POST_EXTRACTION,
        memory_link_extraction_custom_instructions=(
            "Only link a new support fact when it supersedes or refines "
            "an existing support fact. Do not create supports or contradicts links."
        ),
        memory_link_extraction_token_limit=8_000,
    ),
)

동일한 설정을 create_thread()로 전달하거나 클라이언트의 MemoryExtractionConfig에 포함할 수 있습니다. 링크 수동 생성 및 링크된 컨텍스트 검색에 대한 자세한 내용은 링크된 메모리 그래프 생성 및 검색을 참조하십시오.

API 참조: MemoryExtractionConfig 오라클 스레드

한 스레드에 대한 지침 재정의

한 스레드에 클라이언트 기본값보다 더 좁은 추출 정책이 필요한 경우 memory_extraction_config=MemoryExtractionConfig(memory_extraction_custom_instructions=...)를 create_thread()에 전달합니다. 스레드 레벨 값은 해당 스레드에 대해 우선하며 스레드 구성과 함께 유지됩니다.

billing_thread = memory.create_thread(
    thread_id="billing_ticket_9310",
    user_id="customer_123",
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_frequency=1,
        memory_extraction_custom_instructions=(
            "Only extract billing facts, invoice identifiers, and payment issues."
        ),
    ),
)

billing_thread.add_messages(
    [
        {
            "role": "user",
            "content": "Invoice INV-9310 was paid twice and needs a refund.",
        }
    ]
)
API 참조: OracleAgentMemory 오라클 스레드

스레드 지침 업데이트 또는 지우기

기존 스레드에 대한 지속 추출 지침을 변경하려면 update_thread()를 사용합니다. None를 전달하여 이후 스레드 핸들이 클라이언트 레벨 지침을 사용하거나 구성되지 않은 경우 SDK의 일반 추출 동작을 사용하도록 스레드 레벨 지침을 지웁니다.

memory.update_thread(
    "support_ticket_7421",
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=(
            "Only extract product defects and replacement requests."
        )
    ),
)

memory.update_thread(
    "support_ticket_7421",
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=None
    ),
)

주: get_thread(..., memory_extraction_config=MemoryExtractionConfig(memory_extraction_custom_instructions=...))는 지속 스레드 구성을 업데이트하지 않고 반환된 라이브 스레드 핸들에 지침을 적용할 수 있습니다.

API 참조: OracleAgentMemory 오라클 스레드

결론

이 설명서에서는 클라이언트 레벨 사용자 정의 추출 지침을 구성하고, 자동 메모리 연결을 구성하고, 특정 스레드에 대한 추출 지침을 대체하고, 스레드 레벨 추출 지침을 업데이트하거나 지우는 방법을 배웠습니다.

→ 자동 추출을 사용자정의하는 방법을 배웠으므로 이제 LangGraph에서 Oracle Agent Memory Short-Term API 사용을 진행할 수 있습니다.

전체 코드

뒤에 나오는 전체 코드를 복사합니다.

#Copyright © 2026 Oracle and/or its affiliates.
#This software is under the Apache License 2.0
#(LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
#(UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.

#Oracle Agent Memory Code Example - Customize Automatic Memory Extraction
#------------------------------------------------------------------------

##Configure custom memory extraction instructions

import oracledb

from oracleagentmemory.core import MemoryExtractionConfig, MemoryLinkExtractionMode, SchemaPolicy
from oracleagentmemory.core.embedders.embedder import Embedder
from oracleagentmemory.core.llms.llm import Llm
from oracleagentmemory.core.oracleagentmemory import OracleAgentMemory

embedder = Embedder(model="YOUR_EMBEDDING_MODEL")
llm = Llm(model="YOUR_MEMORY_LLM")
db_pool = oracledb.SessionPool(
    user="YOUR DB USER",
    password="YOUR DB PASSWORD",
    dsn="localhost:1521/...",
)
memory_store_id = "T_MEM_EXTRACTION"

support_extraction_instructions = """
Only extract customer support facts:
- order ids
- return requests
- delivery problems
Ignore greetings, small talk, and one-off troubleshooting text.
""".strip()

memory = OracleAgentMemory(
    connection=db_pool,
    embedder=embedder,
    llm=llm,
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=support_extraction_instructions
    ),
    schema_policy=SchemaPolicy.CREATE_IF_NECESSARY,
    memory_store_id=memory_store_id,
)

##Extract support memories from thread messages

support_thread = memory.create_thread(
    thread_id="support_ticket_7421",
    user_id="customer_123",
    memory_extraction_config=MemoryExtractionConfig(memory_extraction_frequency=1),
)

#add_messages persists the turn and runs automated memory extraction because
#MemoryExtractionConfig(memory_extraction_frequency=1) is set for this thread.
support_thread.add_messages(
    [
        {
            "role": "user",
            "content": (
                "Hi, order 7421 arrived damaged. I need a return request "
                "and a replacement delivery."
            ),
        },
        {
            "role": "assistant",
            "content": "I can help start the return request for order 7421.",
        },
    ]
)

results = support_thread.search(
    "return request order 7421",
    max_results=5,
    record_types=["fact"],
)
for result in results:
    print(f"- [{result.record.record_type}] {result.content}")
#- [fact] Customer reported damaged order 7421 and requested a return and replacement delivery.

##Configure automatic memory linking

memory.update_thread(
    "support_ticket_7421",
    memory_extraction_config=MemoryExtractionConfig(
        memory_link_extraction_mode=MemoryLinkExtractionMode.POST_EXTRACTION,
        memory_link_extraction_custom_instructions=(
            "Only link a new support fact when it supersedes or refines "
            "an existing support fact. Do not create supports or contradicts links."
        ),
        memory_link_extraction_token_limit=8_000,
    ),
)

##Override custom instructions for one thread

billing_thread = memory.create_thread(
    thread_id="billing_ticket_9310",
    user_id="customer_123",
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_frequency=1,
        memory_extraction_custom_instructions=(
            "Only extract billing facts, invoice identifiers, and payment issues."
        ),
    ),
)

billing_thread.add_messages(
    [
        {
            "role": "user",
            "content": "Invoice INV-9310 was paid twice and needs a refund.",
        }
    ]
)

##Update or clear thread custom instructions

memory.update_thread(
    "support_ticket_7421",
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=(
            "Only extract product defects and replacement requests."
        )
    ),
)

memory.update_thread(
    "support_ticket_7421",
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=None
    ),
)