Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
my3sons opened this issue Jun 16, 2024 · 3 comments · Fixed by #205
Assignees
Labels
bug Something isn't working Entity Types Entity Resources

Comments

@my3sons
Copy link
Contributor

my3sons commented Jun 16, 2024

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

Context (Environment)

Detailed Description

Possible Implementation

@my3sons my3sons added the bug Something isn't working label Jun 16, 2024
@my3sons my3sons changed the title copy_paste_agent_resources not working at all with entities and does not work with the "Default Negative Intent" [BUG] copy_paste_agent_resources not working at all with entities and does not work with the "Default Negative Intent" Jun 17, 2024
@kmaphoenix
Copy link
Member

@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

@kmaphoenix kmaphoenix self-assigned this Jun 24, 2024
@my3sons
Copy link
Contributor Author

my3sons commented Jul 15, 2024

Hello @kmaphoenix, sorry for the delayed response! I did create a PR for the above issue with copy_paste_agent_resources function: #205.

@SeanScripts
Copy link
Collaborator

SeanScripts commented Jul 15, 2024 via email

@kmaphoenix kmaphoenix linked a pull request Jul 18, 2024 that will close this issue
@kmaphoenix kmaphoenix added the Entity Types Entity Resources label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Entity Types Entity Resources
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants