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 Parametersshop
demonstrates how to use Intent Relations to control the conversation flowrestaurant
shows how to define Custom Entitiestravels
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
Agent fundamentals: Smalltalk¶
These intents demonstrate the fundamentals of a Conversation: Intents and Entities.
-
class
Hello
[source]¶ - User: HelloAgent: Greetings, Human :)
The simplest possible intent: a greetings exchange with no parameters.
-
class
UserNameGive
(user_name)[source]¶ - User: My name is GuidoAgent: Hi Guido
This demonstrates the use of a system entity that is recognized in the User utterance. Check
example_agent.restaurant
for custom entities.- Parameters
user_name (
Person
) – User said this is his name
-
class
AgentNameGive
(agent_name)[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.
- Parameters
agent_name (
Person
) – Agent claims this is its name
-
class
UserLikesMusic
(music_genre="Rock 'n' Roll")[source]¶ - User: I like musicAgent: I love Rock ‘n’ Roll!User: I like Reggae musicAgent: 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.
- Parameters
music_genre (
MusicGenre
) – User said he likes this genre, defaults to “Rock ‘n’ Roll”
-
class
GreetFriends
(friend_names)[source]¶ - User: Say hi to my friends Al, John and JackAgent: 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.
- Parameters
friend_names (
List
[Person
]) – A list of friends to greet
-
class
UserAsksDay
(date)[source]¶ - User: What day is it?Agent: When?User: todayAgent: That would be 2021-06-19
This is equivalent to
GreetFriends
; 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 fromdatetime.date
):>>> predicted = connector.predict("What day will be tomorrow?") >>> predicted.intent.date Sys.Date(2021, 6, 20)
- Parameters
date (
Date
) – The date User wants to check
Intent Relations: Shop¶
This module demonstrates the use of intent relations to create complex conversation flows.
Note
Intent relations are under definition, they will be extended in next releases.
Let’s break down a complex interaction involving shop
intents.
U: I want a fish A: What sort of fish do you want?
Standard Intent
OrderFish
starts the conversation.U: A kipper A: Kipper, good choice. Adding 1 to cart
Intent
OrderFishAnswerKipper
followsOrderFish
. This means that the first can’t be predicted if the latter wasn’t predicted recently; this makes sense because an utterance like “a kipper” would sound really weird without context. Note thatOrderFishAnswerKipper
is a subclass ofOrderKipper
, and therefore inherits itsOrderKipper.fulfill()
method.Check out the source code of the intents below to see how the follow relation is implemented.
U: Actually I want more A: How many would you like?
ChangeAmount
followsOrderKipper
. SinceOrderFishAnswerKipper
is a subclass ofOrderKipper
, our agent can predictChangeAmount
at this point of the conversation. However, this intent defines a required parameterChangeAmount.amount
. Since amount can’t be tagged in the user utterance, the Agent will respond with one of the slot filling prompts for parameter “amount” (seeintents.language
).-
class
ChangeAmount
(amount, parent_order_kipper=None)[source]¶ - (“…adding one kipper to cart”)U: actually, make it 2A: Sure, 2 kippers for you
- Parameters
amount (
Integer
) – The new amount of kipper. Note that this overwrites all the other values for parameter “amount” in context, even if they come from other intentsparent_order_kipper (
Optional
[OrderKipper
]) – The OrderKipper intent from context
-
class
U: 3 please A: Alright, I changed the amount to 3
User fills the slot, and
ChangeAmount
can finally be predicted.
Custom Entities: Restaurant¶
This Intents demonstrate the use of Custom Entities, which are used to recognize simple food orders.
Rich Responses: Travels¶
The travels module demonstrates the use of rich responses, such as images, cards and quick replies.
-
class
UserWantsTravel
[source]¶ - User: I want to travelAgent: How can I help? + -quick replies-
Check out example_agent/language/en/travels.UserWantsTravel.yaml for language data.
-
class
UserAskHotelRecommendation
[source]¶ - User: Recommend me a hotelAgent: -hotel card-
Check out example_agent/language/en/travels.UserAskHotelRecommendation.yaml for language data.