dfcx-scrapi
dfcx-scrapi copied to clipboard
[BUG] copy_paste_agent_resources not working at all with entities and does not work with the "Default Negative Intent"
Expected Behavior
I am attempting to copy and paste entity and intent resources from one agent to another agent. My skip_list includes webhooks and route_groups. Following the documentation, I made sure that my resources dictionary followed what was being done in the get_page_dependencies function, so I am confident that my resource dictionary is in the proper format.
I also have a general question about copy_paste_agent_resources function. I may be certainly missing something but I am wondering why this function returns an object called "resources_skip_list", which implies resources skipped, when in fact it seems to represent just the opposite, and that is resources created?
Current Behavior
For entities, when copy_util invokes the _create_entity_resources function and that function calls EntityTypes.create_entity_type funtion, the below error is thrown.
2024-06-16 07:04:31 INFO ACreating Entity geekSquadEntity...
Traceback (most recent call last):
File "/Users/a660709/PycharmProjects/gcp/scrapi.py", line 39, in <module>
cu.copy_paste_agent_resources(resources=resources_dict, source_agent=ccai_agent_id, destination_agent=ss_agent_id, skip_list=["webhooks", "route_groups"])
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/tools/copy_util.py", line 717, in copy_paste_agent_resources
resources_skip_list = self._create_entity_resources(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/tools/copy_util.py", line 450, in _create_entity_resources
self.entities.create_entity_type(destination_agent, entity)
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/core/scrapi_base.py", line 452, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/core/entity_types.py", line 344, in create_entity_type
entity_type_obj = types.EntityType(
^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/proto/message.py", line 615, in __init__
super().__setattr__("_pb", self._meta.pb(**params))
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad argument type for built-in operation
Copying of intents works fine except for the "Default Negative Intent". The below error occurs whether or not the "Default Negative Intent" exists in the destination agent. As you can see, the interesting thing is that the error is referencing the "fallback" intent, even though the intent being copied is the "negative" intent.
2024-06-16 07:17:47 INFO ACreating Entity sms_same-calling-number...
2024-06-16 07:17:51 INFO Creating Intent Default Welcome Intent...
2024-06-16 07:17:59 INFO Creating Intent Default Negative Intent...
Traceback (most recent call last):
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/google/api_core/grpc_helpers.py", line 76, in error_remapped_callable
return callable_(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/grpc/_channel.py", line 1181, in __call__
return _end_unary_response_blocking(state, call, False, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/grpc/_channel.py", line 1006, in _end_unary_response_blocking
raise _InactiveRpcError(state) # pytype: disable=not-instantiable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "com.google.apps.framework.request.BadRequestException: You cannot create fallback intent."
debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.191.202:443 {grpc_message:"com.google.apps.framework.request.BadRequestException: You cannot create fallback intent.", grpc_status:3, created_time:"2024-06-16T07:18:03.744788-05:00"}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/a660709/PycharmProjects/gcp/scrapi.py", line 39, in <module>
cu.copy_paste_agent_resources(resources=resources_dict, source_agent=ccai_agent_id, destination_agent=ss_agent_id, skip_list=["webhooks", "route_groups"])
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/tools/copy_util.py", line 722, in copy_paste_agent_resources
resources_skip_list = self._create_intent_resources(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/tools/copy_util.py", line 478, in _create_intent_resources
self.intents.create_intent(destination_agent, intent)
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/core/scrapi_base.py", line 452, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/dfcx_scrapi/core/intents.py", line 533, in create_intent
response = client.create_intent(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/google/cloud/dialogflowcx_v3beta1/services/intents/client.py", line 1043, in create_intent
response = rpc(
^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
return wrapped_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/a660709/PycharmProjects/gcp/venv/lib/python3.12/site-packages/google/api_core/grpc_helpers.py", line 78, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 com.google.apps.framework.request.BadRequestException: You cannot create fallback intent.
Possible Solution
For the entities related issue, the fix was to simply change the entity argument to a named argument on line 447 in copy_util.py so that it would not be incorrectly interpreted as display_name in the create_entity_type function.
self.entities.create_entity_type(destination_agent, obj=entity)
For the "Default Negative Intent" issue, I just removed it from the resources dictionary before calling the copy_paste_agent_resources, but I was hoping something could be done in dfcx-scrapi to deal with that more appropriately.