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

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

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

사용자 정의 지침은 메모리 추출을 위한 추가 응용 프로그램별 지침을 제공합니다. 도메인 지식, 제품 정책 또는 대화별 우선 순위를 반영하기 위해 애플리케이션이 추출해야 하는 경우에 유용합니다.

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

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

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

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

import oracledb

from oracleagentmemory.core import MemoryExtractionConfig
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")
memory_llm = Llm(model="YOUR_MEMORY_LLM")
db_pool = oracledb.SessionPool(
    user="YOUR DB USER",
    password="YOUR DB PASSWORD",
    dsn="YOUR DB CONNECT STRING",
)

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=memory_llm,
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=support_extraction_instructions
    ),
)
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 오라클 검색 결과

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

한 스레드에 클라이언트 기본값보다 더 좁은 추출 정책이 필요한 경우 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에서 에이전트 메모리 단기 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
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")
memory_llm = Llm(model="YOUR_MEMORY_LLM")
db_pool = oracledb.SessionPool(
    user="YOUR DB USER",
    password="YOUR DB PASSWORD",
    dsn="YOUR DB CONNECT STRING",
)

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=memory_llm,
    memory_extraction_config=MemoryExtractionConfig(
        memory_extraction_custom_instructions=support_extraction_instructions
    ),
)



##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.



##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
    ),
)