3

I'm having a bit of trouble conceptualizing the relationship between 'intents' and 'actions' in a Dialogflow agent.

I get that intents map the user's spoken request to a particular feature of my fulfillment service, optionally carrying parameters as input variables. This is how intents are defined in the official documentation:

"An intent represents a mapping between what a user says and what action should be taken by your software."

But what then are actions? Their definition reads almost exactly the same:

"An action corresponds to the step your application will take when a specific intent has been triggered by a user’s input."

Actions are defined within the context of intents, which means there can only be one action per intent and an action can't be attached to multiple intents. An action doesn't seem to be more than its name, which is also entirely optional as the intent works the same whether I specify an action name or not.

So what is their purpose? Why would I have my service react to actions instead of intents?

gmolau
  • 2,815
  • 1
  • 22
  • 45

1 Answers1

3

You have one slight misstatement in your question, but it illustrates the difference between a Dialogflow Intent and Action. The statement

an action can't be attached to multiple intents

isn't true. You can use the same Action name for multiple Intent names. In this case, it means that you can use the Action as a map to a function in the fulfillment without having to list each Intent that maps in your code.

In Dialogflow, the Intent does more than just match a particular user phrase - it also is used to match conversations that are in a particular state (determined by Contexts that are set) or for particular non-phrase events. Since you may wish to map several of these to the same action on the back-end (for example, if you have two different Incoming Contexts that you need matched with different user phrases), you can set the same Action for them but use different Intent names to identify them.

Some libraries, such as actions-on-google v2 and multivocal let you work with either, whichever makes the most sense.

When I name Intents, I will generally start all of them that do roughly the same thing with the same name I use for the Action, but add a suffix indicating why the Intents are different. (With the name of the context, or event, or parameters that are different.)

Update to clarify a few things

I generally use the Action name as the one that triggers my functions, however there are a few cases where I might still group things by action (because it makes sense to organize them that way), but carve out an exception for one of the Intents. Think of this as subclassing in an OO model. Rule of thumb would be to use the Action name but don't hold this rigidly if there is a good reason not to. (An example of this is using multivocal, the library defines an "unknown" Action that covers both misunderstood input and no input. Sometimes I want to handle one of these differently, however, so I'll define a handler that works on just the Intent.)

The Action name should be available in the JSON that Dialogflow sends your fulfillment in queryResult.action. I'm not sure why the documentation omits this at the moment.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Thanks! What I would take away from that is that I should actually consider actions as the primary interface between the Dialogflow agent and my service, not intents. The data flow between the user and me would than be user -> intent -> action -> fulfillment, with the option of reusing the same action across multiple intents with different input states. The only thing I don't understand is that the Dialogflow Webhook V2 API seems to have actually removed the 'action' parameter from fulfillment requests (https://dialogflow.com/docs/fulfillment), or am I missing something here? – gmolau Apr 30 '18 at 12:56
  • You're not missing anything - the documentation is. I've added an update to my answer that I hope clarifies things a bit, but generally you're on track. – Prisoner Apr 30 '18 at 13:13
  • Thanks, I've asked about the documentation on the Dialogflow Forum: https://productforums.google.com/forum/#!topic/dialogflow/NnyL4tnTCOA;context-place=forum/dialogflow – gmolau Apr 30 '18 at 13:58
  • @Prisoner I am facing some issue that is closely related to this discussion. To cut it short, is it possible to use actions name to trigger intent? (So, I have this carusel that when user clicks on the carousel item then name would be recognized as a text to trigger intent related to that answer. (Carousel item name "Payment" -> after clicking on it "Payment" intent is triggered)) – Gray_Rhino Dec 16 '19 at 06:20
  • 1
    @Gray_Rhino - Carousels are very different creatures in Actions on Google. I suggest you post this as a new question with details so we can go over the differences and explore possible solutions. – Prisoner Dec 16 '19 at 09:31