google-cloud-platformdialogflow-cx

dfcx-scrapi error while trying to export agent to GCS Bucket


I've written a python script to export a dialogflow agent to GCS Bucket.

from dfcx_scrapi.core.agents import Agents

gcs_bucket = "gs://<my-bucket-name>"

print("Starting connection to Dialogflow using credentials")
agent_obj = Agents(creds_path, agent_id)
print("Beginning Agent export to Bucket")
lro_id = agent_obj.export_agent(agent_id, gcs_bucket_uri=gcs_bucket, data_format="JSON")
print("Long Running Operation ID: "+lro_id)

This script will be scheduled at regular intervals

I get this error readout when I run it

Starting connection to Dialogflow using credentials
Beginning Agent export to Bucket

Traceback (most recent call last):

File "redacted-path/my_custom_script", line redacted, in <module> 
 lro_id = agent_obj.export_agent(agent_id, gcs_bucket_uri=gcs_bucket, data_format="JSON_PACKAGE")

File "redacted-path/dfcx_scrapi/core/scrapi_base.py", line 322, in wrapper 
 return func(self, *args, **kwargs)

File "redacted-path/dfcx_scrapi/core/agents.py", line 397, in export_agent
 json_format = types.agent.ExportAgentRequest.DataFormat(4) 
 
File "/redacted-path/env/lib/python3.9/enum.py", line 384, in __call__ 
 return cls.__new__(cls, value) 

File "redacted-path/env/lib/python3.9/enum.py", line 702, in __new__
 raise ve_exc

ValueError: 4 is not a valid ExportAgentRequest.DataFormat

The SCRAPI library version I'm using is 1.8.1 and that release does support this method of exporting agents.

I tried specifying the BLOB format in lro_id = agent_obj.export_agent(agent_id, gcs_bucket_uri=gcs_bucket, data_format="JSON") and it still popped up the error above.

I went into the redacted-path/dfcx_scrapi/core/agents.py file and deleted the json_format lines and executed and it popped up a new error AttributeError: Unknown field for ExportAgentRequest: include_bigquery_export_settings. I removed that lines as well in the agents.py file and the script worked.

I need the export in JSON and not BLOB. It's a non-negotiable requirement.

References I used:

  1. dfcx-scrapi Github for Agents: https://github.com/GoogleCloudPlatform/dfcx-scrapi/blob/main/src/dfcx_scrapi/core/agents.py
  2. https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents/export
  3. https://cloud.google.com/python/docs/reference/dialogflow-cx/latest/google.cloud.dialogflowcx_v3.types.ExportAgentRequest.DataFormat

Solution

  • Found out the problem. dfcx-scrapi library was updated to 1.8.1 but the google-cloud-dialogflow-cx library was still at ver 1.16.0 and did not support the export_agent method. Updated it to latest and it works