View a markdown version of this page

自訂內建策略或建立您自己的策略 - Amazon Bedrock AgentCore

自訂內建策略或建立您自己的策略

對於進階或特定網域的使用案例,您可以建立具有覆寫策略的內建 ,以取得長期記憶體程序的精細控制。內建的 覆寫策略可讓您提供自己的指示,並選取擷取和合併步驟的特定基礎模型,以覆寫內建策略的預設行為。

何時使用具有覆寫策略的內建

當您需要根據特定需求量身打造記憶體邏輯時,請選擇具有覆寫策略的內建 。常用案例包括:

  • 特定網域擷取:限制僅擷取特定類型資訊的策略。例如,擷取使用者的食物和食物偏好,同時忽略他們對衣服的偏好。

  • 控制精細程度:調整擷取記憶體中的詳細資訊層級。例如,指示摘要策略只儲存高階關鍵點,而不是詳細的敘述。

  • 模型選擇:使用更適合您的特定網域或任務的特定基礎模型,例如針對財務或法律文字微調的模型。

如何自訂策略

若要使用自訂組態覆寫內建策略,請在使用 CreateMemory 操作或 UpdateMemory 操作時指定組態。您可以覆寫下列項目:

下表顯示您可以為每個記憶體策略覆寫的步驟:

策略 您可以覆寫的步驟

語意

擷取合併

摘要

合併

使用者偏好設定

擷取合併

事件

擷取合併反射

注意

您也可以使用自我管理策略覆寫 。如需詳細資訊,請參閱自我管理策略

如何自訂策略

例如,您可以修改語意記憶體策略的擷取指示,以在自訂時新增指示。

內建語意記憶體策略指示

以下顯示語意記憶體策略的內建說明:

You are a long-term memory extraction agent supporting a lifelong learning system. Your task is to identify and extract meaningful information about the users from a given list of messages. Analyze the conversation and extract structured information about the user according to the schema below. Only include details that are explicitly stated or can be logically inferred from the conversation. - Extract information ONLY from the user messages. You should use assistant messages only as supporting context. - If the conversation contains no relevant or noteworthy information, return an empty list. - Do NOT extract anything from prior conversation history, even if provided. Use it solely for context. - Do NOT incorporate external knowledge. - Avoid duplicate extractions. IMPORTANT: Maintain the original language of the user's conversation. If the user communicates in a specific language, extract and format the extracted information in that same language.

您可以在這些指示中附加新的規則,例如:

- Focus exclusively on extracting facts related to travel and booking preferences.

或編輯現有規則,例如:

IMPORTANT: Always extract memories in English irrespective of the original language of the user's conversation.

自訂的最佳實務

  • 根據現有的指示:強烈建議您使用內建策略指示做為起點。基本結構和指示對記憶體功能至關重要。您應該將任務特定的指引新增至現有的指示,而不是從頭開始撰寫全新的指引。

  • 提供明確的指示: 的內容會appendToPrompt取代系統提示中的預設指示。請確定您的指示符合邏輯且完整,因為空白或格式不佳的指示可能會導致不理想的結果。

重要考量

若要維持記憶體管道的可靠性,請遵循下列準則:

  • 請勿在提示中修改結構描述:您應該只新增或修改指示如何解壓縮或合併記憶體的指示。請勿嘗試變更提示本身內的對話或記憶體結構描述定義,因為這可能會導致非預期的失敗。

  • 請勿重新命名合併操作:自訂合併提示時,請勿變更操作名稱 AddMemory (例如,、UpdateMemory)。變更這些名稱會導致長期記憶體管道失敗。

  • 輸出結構描述無法編輯:具有覆寫策略的內建 不會讓您變更擷取或合併記憶體的最終輸出結構描述。將新增至具有覆寫策略之內建 系統提示的輸出結構描述將與內建策略相同。如需輸出結構描述的資訊,請參閱下列內容:

如需end-to-end記憶體程序的完整控制權,包括輸出結構描述,請參閱自我管理策略

執行角色

使用內建 搭配 覆寫策略時,您也需要在 CreateMemory API memoryExecutionRoleArn中提供 。Bedrock Amazon Bedrock AgentCore 將擔任此角色,以呼叫您 AWS 帳戶中的基礎模型進行擷取和合併。

注意

將內建 與 覆寫策略搭配使用時,用於擷取和合併的 LLM 使用量將分別向您的 AWS 帳戶收費,且可能需支付額外費用。