恢复含数据存储的Dialogflow CX Agent报错,求程序化关联Vertex AI应用方法
解决Dialogflow CX Agent克隆时的Vertex AI Search关联问题
一、核心前提
要恢复关联了数据存储的Dialogflow CX Agent,必须先让新Agent完成两个操作:关联Vertex AI Search and Conversation app,再添加对应的数据存储,之后才能执行恢复操作。
二、程序化关联Vertex AI Search and Conversation app(Python实现)
1. 创建/获取Vertex AI Search app
如果已有现成的app,直接获取其资源名称;若需新建,使用Vertex AI Search SDK:
from google.cloud import discoveryengine_v1 as discoveryengine client = discoveryengine.SearchEngineServiceClient() parent = f"projects/{你的项目ID}/locations/global" # 新建app app = discoveryengine.App( display_name="自定义app名称", solution_type=discoveryengine.App.SolutionType.SOLUTION_TYPE_CONVERSATION ) response = client.create_app(parent=parent, app=app) app_name = response.name # 保存该资源名称,后续关联Agent要用
2. 关联Dialogflow CX Agent到该app
使用Dialogflow CX的AgentsClient更新Agent配置:
from google.cloud import dialogflowcx_v3 as dialogflowcx client = dialogflowcx.AgentsClient() agent_name = f"projects/{你的项目ID}/locations/{你的区域}/agents/{新AgentID}" # 构建关联配置 update_mask = {"paths": ["vertex_ai_search_config"]} agent = dialogflowcx.Agent( name=agent_name, vertex_ai_search_config=dialogflowcx.Agent.VertexAISearchConfig( app=app_name ) ) # 执行关联 response = client.update_agent(agent=agent, update_mask=update_mask)
三、为新Agent添加数据存储关联
关联完app后,添加原Agent使用的数据存储:
# 数据存储资源名称格式:projects/{项目ID}/locations/global/collections/default_collection/dataStores/{数据存储ID} data_store_name = "你的数据存储资源名称" update_mask = {"paths": ["data_store_configs"]} agent = dialogflowcx.Agent( name=agent_name, data_store_configs=[ dialogflowcx.Agent.DataStoreConfig( data_store=data_store_name, data_store_type=dialogflowcx.Agent.DataStoreConfig.DataStoreType.CLOUD_SEARCH ) ] ) response = client.update_agent(agent=agent, update_mask=update_mask)
四、执行Agent恢复
完成上述步骤后,调用restore_agent函数:
from google.cloud import dialogflowcx_v3 as dialogflowcx client = dialogflowcx.AgentsClient() gcs_uri = "gs://你的存储桶路径/agent-export.json" # 导出的Agent包GCS路径 restore_request = dialogflowcx.RestoreAgentRequest( parent=f"projects/{你的项目ID}/locations/{你的区域}", agent_uri=gcs_uri, agent_id=新AgentID ) response = client.restore_agent(request=restore_request)
五、验证关联(可选)
可在Dialogflow CX控制台进入新Agent,查看Manage > Vertex AI Search页面,确认已关联目标app和数据存储。
内容的提问来源于stack exchange,提问作者perojas3
相关产品推荐
相关产品推荐

