Example Agent

This is an example Agent that has a number of Intent categories. Each category demonstrates a specific set of features of the Intents library, and particularly:

  • smalltalk shows the fundamentals of Intents and their Parameters

  • rickroll demonstrates how to use Context to restrict intent predictions

  • restaurant shows how to define Custom Entities

  • travels demonstrates the use of rich responses, such as Images, Cards and Quick Replies

Tip

Most of the interesting stuff about the Example Agent comes from its source code and may not be shown in documentation pages. Hit the [source] link (or browse the full code at https://github.com/dariowho/intents/tree/master/example_agent/) to know more about your topic of interest

class example_agent.agent.ExampleAgent[source]

An example agent that greets its users, and not much more…

Agent fundamentals: Smalltalk

These intents demonstrate the fundamentals of a Conversation: Intents, Entities and Events.

class example_agent.smalltalk.WelcomeEvent[source]

This models an external event that is meant to be sent directly to the Agent. It could be a frontend component signaling that the User has just opened the chat.

class example_agent.smalltalk.agent_name_give(agent_name: intents.model.entity.Sys.Person)[source]
Agent: Howdy Human, my name is $agent_name

Note that this is Agent sending an unsolicided message to User, rather than predicting a response. The language file of the Intent will have no Example Utterances, meaning that the Intent can be triggered, but will never be predicted.

class example_agent.smalltalk.agent_welcomes_user(user_name: intents.model.entity.Sys.Person)[source]

This is an intent that is triggered by a custom event. It covers the (rare) case in which an external component wants to trigger this Intent by sending a WELCOMEEVENT Event trigger directly to Dialogflow.

class example_agent.smalltalk.greet_friends(friend_names: List[intents.model.entity.Sys.Person])[source]
User: Say hi to my friends Al, John and Jack
Agent: Hello Al, John and Jack

This intent demonstrates the use of List parameters. In the example above, the friend_names parameter will be valued [“Al”, “John”, “Jack”].

Also, friend_names is a required parameter. When User doesn’t specify names, we want to ask her to do so in a slot filling manner. This is done by defining slot_filling_prompts in the Intent language file.

class example_agent.smalltalk.hello[source]
User: Hello
Agent: Greetings, Human :)

The simplest possible intent: a greetings exchange with no parameters.

class example_agent.smalltalk.user_asks_day(date: intents.model.entity.Sys.Date)[source]
User: What day is it?
Agent: When?
User: today
Agent: That would be 2021-06-19

This is equivalent to greet_friends; they are both intents with a required parameter that is prompted to User when missing in the original utterance.

One peculiarity of this one is the use of Sys.Date: prediction services are able to turn spoken time references (“today”, “last week”, “in a month”, …) into absolute values.

The date parameter is automatically casted to a python datetime.date object when this Intent is predicted (Sys.Date inherits from datetime.date):

>>> predicted = connector.predict("What day will be tomorrow?")
>>> predicted.date
Sys.Date(2021, 6, 20)
class example_agent.smalltalk.user_likes_music(music_genre: intents.model.entity.Sys.MusicGenre = "Rock 'n' Roll")[source]
User: I like music
Agent: I love Rock ‘n’ Roll!
User: I like Reggae music
Agent: I love Reggae!

This intent demonstrates the use of default parameter values: when User doesn’t specify a genre, Agent will assume it’s Rock ‘n’ Roll.

class example_agent.smalltalk.user_name_give(user_name: intents.model.entity.Sys.Person)[source]
User: My name is Guido
Agent: Hi Guido

This demonstrates the use of a system entity that is recognized in the User utterance. Check restaurant for custom entities.

Input/Output Contexts: Rickroll

This module demonstrates the use of Contexts, to condition Agent understanding on previous conversation history.

class example_agent.rickroll.c_rickroll_started(lifespan)[source]

This is spawned when User starts a rickroll with user_start

class example_agent.rickroll.user_continue[source]
User: “Never gonna”
Agent: “Let you down 🕺”

Note that this Intent can only be predicted if c_rickroll_started is active. Therefore, it can only be predicted after user_start.

class example_agent.rickroll.user_start[source]
User: “Never gonna”
Agent: “Give you up”

This intent has no input context, but activates c_rickroll_started with a lifespan of 2 turns.

Custom Entities: Restaurant

This Intents demonstrate the use of Custom Entities, which are used to recognize simple food orders.

class example_agent.restaurant.PizzaType[source]

This entity represents different types of pizza, such as Margherita, Diavola, etc.

class example_agent.restaurant.order_pizza(pizza_type: example_agent.restaurant.PizzaType, amount: intents.model.entity.Sys.Integer = 1)[source]

User is ordering a pizza, like “I want two Margherita please”

Rich Responses: Travels

The travels module demonstrates the use of rich responses, such as images, cards and quick replies.

class example_agent.travels.user_ask_holiday_picture[source]
User: Send me a holiday picture
Agent: -picture-
class example_agent.travels.user_ask_hotel_recommendation[source]
User: Recommend me a hotel
Agent: -hotel card-
class example_agent.travels.user_ask_train_station[source]
User: Where is the train station?
Agent: Address + -custom payload (location)-
class example_agent.travels.user_wants_travel[source]
User: I want to travel
Agent: How can I help? + -quick replies-