设置记忆库

在使用 Vertex AI Agent Engine 记忆库之前,您必须先设置环境。请注意,虽然记忆库是 Agent Engine 的一部分,但您无需将代码部署到 Agent Engine 运行时即可使用记忆库。

设置 Google Cloud 项目

每个项目都可以通过项目编号和项目 ID 这两种方式来识别。PROJECT_NUMBER 由系统在您创建项目时自动创建,PROJECT_ID 则是由您或项目创建者创建的。如需设置项目,请执行以下操作:

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Enable the API

  8. 获取所需的角色

    如需获得使用 Vertex AI Agent Engine 所需的权限,请让您的管理员为您授予项目的 Vertex AI User (roles/aiplatform.user) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

    您也可以通过自定义角色或其他预定义角色来获取所需的权限。

    如果您要从部署在 Google Kubernetes Engine 或 Cloud Run 上的代理向 Memory Bank 发出请求,请确保您的服务账号具有必要的权限。Reasoning Engine Service Agent 已经拥有读取和写入记忆所需的权限,因此来自 Agent Engine Runtime 的出站请求应该已经拥有访问 Memory Bank 的权限。

    设置环境

    本部分假定您已设置 Python 开发环境,或者正在使用具有 Python 开发环境的运行时(例如 Colab)。

    安装库

    安装 Vertex AI SDK:

      pip install google-cloud-aiplatform>=1.104.0

    身份验证

    身份验证说明取决于您是否是在快速模式下使用 Vertex AI:

    • 如果您未使用快速模式下的 Vertex AI,请按照向 Vertex AI 进行身份验证中的说明操作。

    • 如果您使用快速模式下的 Vertex AI,请通过在环境中设置 API 密钥来设置身份验证:

        os.environ["GOOGLE_API_KEY"] = "API_KEY"
      

    设置 Vertex AI SDK 客户端

    运行以下代码以设置 Vertex AI SDK 客户端:

    import vertexai
    
    client = vertexai.Client(
        project="PROJECT_ID",
        location="LOCATION",
    )
    

    其中

    • PROJECT_ID 是项目 ID。
    • LOCATION 是 Memory Bank 的支持区域之一。

    为 Agent Engine 实例配置记忆库

    如需开始使用记忆库,您首先需要一个 Agent Engine 实例。

    您可以执行下列任一操作:

    使用现有实例

    如果您不需要修改现有的 Agent Engine 实例,请运行以下命令来为记忆库配置该实例:

    agent_engine = client.agent_engines.get(name="AGENT_ENGINE_NAME")
    

    替换以下内容:

    • AGENT_ENGINE_NAME:Agent Engine的名称。应采用 projects/.../locations/.../reasoningEngines/... 格式。如需了解 Memory Bank 支持的区域,请参阅支持的区域

    您可以在任何环境中使用该实例,包括 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 = 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,同时仍保留存储在实例中的记忆,可以更新现有的 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=...
      )
    

    替换以下内容:

    • AGENT_ENGINE_NAME:Agent Engine的名称。应采用 projects/.../locations/.../reasoningEngines/... 格式。如需了解 Memory Bank 支持的区域,请参阅支持的区域

    设置记忆库配置

    您可以配置记忆库,自定义回忆的生成和管理方式。如果未提供配置,则内存库会针对每种类型的配置使用默认设置。

    您可以在创建或更新 Agent Engine 实例时设置记忆库配置:

    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
              }
          }
    )
    

    您可以为实例配置以下设置:

    • 自定义配置:用于配置如何从源数据中提取回忆。
    • 相似度搜索配置:用于配置相似度搜索所用的嵌入模型。默认值为 text-embedding-005
    • 生成配置:配置用于生成记忆的 LLM。默认值为 gemini-2.0-flash-001
    • TTL 配置:配置如何为创建或更新的记忆自动设置 TTL。默认值为无 TTL。
    自定义配置

    如果您想自定义从源数据中提取记忆的方式,可以在设置 Agent Engine 实例时配置记忆提取行为。您可以使用以下两种方式进行自定义:

    • 配置记忆主题:定义记忆库应视为有意义并持久保存的信息类型。记忆库只会持久保存符合以下任一记忆主题的信息。
    • 提供少样本示例:演示将记忆提取到记忆库的预期行为。

    您可以选择为不同的范围级别配置不同的行为。例如,对于会话级记忆有意义的主题可能对于用户级记忆(跨多个会话)没有意义。如需为特定部分回忆配置行为,请设置自定义配置的范围键。只有包含这些范围键的 GenerateMemories 请求才会使用相应配置。您还可以省略 scope_key 字段来配置默认行为(适用于所有范围键集)。此配置将应用于所有没有配置完全匹配另一个自定义配置的范围键的请求。

    例如,user_level_config 仅适用于完全使用范围密钥 user_id(即 scope={"user_id": "123"},不含其他密钥)的 GenerateMemories 请求。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_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
          )
      )
      

      记忆库支持以下受管理的知识主题:

      • 个人信息 (USER_PERSONAL_INFO):与用户相关的重要个人信息,例如姓名、关系、爱好和重要日期。例如,“我在 Google 工作”或“我的结婚纪念日是 12 月 31 日”。
      • 用户偏好 (USER_PREFERENCES):明确或隐含的喜好、厌恶、偏好的风格或图案。例如,“我喜欢中间的座位。”
      • 关键对话事件和任务结果 (KEY_CONVERSATION_DETAILS):对话中的重要里程碑或结论。例如,“我预订了从 JFK 机场往返 SFO 机场的机票。我将于 2025 年 6 月 1 日出发,并于 2025 年 6 月 7 日返回。”
      • 明确的记忆 / 忘记指令 (EXPLICIT_INSTRUCTIONS):用户明确要求智能体记住或忘记的信息。例如,如果用户说“记住,我主要使用 Python”,记忆库会生成一条记忆,例如“我主要使用 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."""
        )
      )
      

      使用自定义主题时,建议同时提供少样本示例,以展示应如何从对话中提取记忆。

    通过自定义,您可以任意组合使用记忆主题。例如,您可以使用部分可用的受管理内存主题:

    字典

    {
      "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."""
              )
        )
      ]
    )
    
    少样本示例

    通过少样本示例,您可以向记忆库展示预期的记忆提取行为。例如,您可以提供示例输入对话,以及预期从该对话中提取的记忆。

    我们建议始终使用包含自定义主题的少样本,以便 Memory Bank 了解预期行为。使用受管理的 Topic 时,由于记忆库会为每个 Topic 定义示例,因此您可以选择不提供少量示例。通过提供空的 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-001text-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"
        )
    )
    

    替换以下内容:

    • EMBEDDING_MODEL:用于相似性搜索的 Google 文本嵌入模型,格式为 projects/{project}/locations/{location}/publishers/google/models/{model}
    生成配置

    生成配置用于控制使用哪个 LLM 来生成记忆,包括提取记忆以及将新记忆与现有记忆整合。

    记忆库使用 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"
        )
    )
    
    

    替换以下内容:

    • LLM_MODEL:用于提取和整合记忆的 Google LLM 模型,格式为 projects/{project}/locations/{location}/publishers/google/models/{model}
    存留时间 (TTL) 配置

    TTL 配置用于控制记忆库应如何动态设置记忆的过期时间。过期时间过后,回忆将无法检索,并会被删除。

    如果未提供配置,系统不会为创建或更新的回忆动态设置到期时间,因此回忆不会过期,除非手动设置了到期时间。

    您可以通过以下两种方式配置 TTL:

    • 默认 TTL:TTL 将应用于创建或更新记忆的所有操作,包括 UpdateMemoryCreateMemoryGenerateMemories

      字典

      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 的操作来计算。如果未针对给定操作设置此参数,则相应操作不会更新记忆的到期时间。

      字典

      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)将覆盖 Memory 之前的到期时间。

    将具有记忆功能的代理部署到 Agent Engine

    虽然记忆库可以在任何运行时中使用,但您也可以将记忆库与 Agent Engine 运行时搭配使用,以便从已部署的智能体中读取和写入记忆。

    如需在 Vertex AI Agent Engine 运行时中部署具有记忆库的智能体,请先为 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
          }
    )
    

    替换以下内容:

    • STAGING_BUCKET:用于暂存 Agent Engine Runtime 的 Cloud Storage 存储桶。

    如需详细了解如何将记忆库与 ADK 搭配使用,请参阅智能体开发套件快速入门

    自定义代理

    您可以将记忆库与部署在 Agent Engine 运行时的自定义代理搭配使用。在这种情况下,您的代理应编排对 Memory Bank 的调用,以触发记忆生成记忆检索调用。

    如果您想将同一 Agent Engine 实例用于记忆库和 Agent Engine 运行时,可以读取环境变量 GOOGLE_CLOUD_PROJECTGOOGLE_CLOUD_LOCATIONGOOGLE_CLOUD_AGENT_ENGINE_ID,以从环境中推断出 Agent Engine 名称:

    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}"
    

    后续步骤