GoogleCloudPlatform / dfcx-scrapi

A high level scripting API for bot builders, developers, and maintainers.
Apache License 2.0
88 stars 59 forks source link

[BUG] copy_paste_agent_resources not working at all with entities and does not work with the "Default Negative Intent" #192

Closed my3sons closed 1 month ago

my3sons commented 3 months ago

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.

Steps to Reproduce

1. 2. 3. 4.

Context (Environment)

Detailed Description

Possible Implementation

kmaphoenix commented 3 months ago

@my3sons thanks for reporting these!

Re: EntityTypes.create_entity_type, feel free to create PR if you want to contribute to the repo.
Otherwise, we can also make a fix for it soon.

Re: Default Negative Intent, seems like a leftover / legacy message from when this used to be called the Default Fallback Intent. These are created by default with each new agent and you cannot "recreate" them, so the error makes sense.

We can update the code so that Default Negative Intent is always excluded.

FYI @MRyderOC

my3sons commented 2 months ago

Hello @kmaphoenix, sorry for the delayed response! I did create a PR for the above issue with copy_paste_agent_resources function: https://github.com/GoogleCloudPlatform/dfcx-scrapi/pull/205.

SeanScripts commented 2 months ago

@kmaphoenix Since we can't recreate the Default Negative Intent, it would be better to copy over the training phases into it instead of skipping over it

On Mon, Jul 15, 2024, 10:01 AM my3sons @.***> wrote:

Hello @kmaphoenix https://github.com/kmaphoenix, sorry for the delayed response! I did create a PR for the above issue with copy_paste_agent_resources function: #205 https://github.com/GoogleCloudPlatform/dfcx-scrapi/pull/205.

— Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/dfcx-scrapi/issues/192#issuecomment-2228981497, or unsubscribe https://github.com/notifications/unsubscribe-auth/APK3JMYQQGTDJMJDNAJLYIDZMP57NAVCNFSM6AAAAABJMRXERGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRYHE4DCNBZG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>