I'm a career software developer, so naturally I'm interested in extending Home further by developing new abilities for it. Amazon Echo is known to have an extensive developer and partner program with over 5,000 skills available; so what about Home? Google Home also has a developer program, which you can find out about at Actions on Google. Note, when you are developing for Home you are really developing for the Google Assistant, something that potentially can be used in additional ways (such as on Google Pixel phones).
There are several ways to develop conversation actions for Google Home and its Conversation API. One is with the Actions SDK, which includes a NodeJS client library and a web simulator. The other is API.AI, a web-based interface. API.AI is where I'm starting, and that's what I'm writing about today.
I've just started on learning, but I've already gone through the first tutorial and added a new conversation action that I can test in the web simulator or with my actual Google Home device. I can already tell this is going to be a great deal of fun.
Getting Started Sample: Silly Name Maker
Defining an Agent in API.AIThe API.AI site has a walk-through that gives you the steps to build a simple app named Silly Name Maker - and it's really simple - all it does is ask you for a number and a color, and constructs a silly name from that information. But, it does the job of getting you on your way. If you faithfully go to the API.AI site and enter the instructions, you will soon have an agent that looks like this:
Silly Name Maker tutorial sample in API.AI
and interacts like this:
User: Hey Google, Talk to Silly Name Maker. Silly Name Maker: Hi! Welcome to Silly Name Maker! Let's get started. What is your lucky number? User: 22 Silly Name Maker: What is your favorite color? User: Blue Silly Name Maker: Alright, your silly name is Blue 22. I hope you like it! See you next time.
Yes, it's not terribly useful but it does show you the ropes of defining an agent and running it.
So what goes into making this agent? It consists of a number of intents. The first intent is named start_name_maker, and it's the first thing that happens after you invoke Silly Name Maker by asking Home to "Talk to Silly Name Maker". That's because it's tagged as a Welcome intent. All this intent does is welcome you to the agent, and prompt the user to select a number (and when the user does that, they'll be triggering the second intent). It's important for Google Home agents to clearly identify themselves to the user so they understand they're now interacting with an agent (app) and not Google.
The second intent is called make_name, and it gets triggered when the user says a number or says "My lucky number is number". The intent can recognize several patterns of input, any of which will trigger it. Note how easy it is in API.AI to define user input - you simply provide samples of what someone would say, and then you can mark parts of that as parameter values. Parameter values have types; for example, @sys.color is a color and @sys.number is a number.
Some of those "user says" patterns may provide parameter data - in this case, both patterns define the parameter $number. The intent has another parameter, named $color. Since $color is marked as a required parameter, and none of the defined "user says" patterns provide $color, Home will automatically prompt for it when this intent is triggered. That's why the example dialog above asks "What is your favorite color?" The make_name intent incorporates the parameters in its response: "Alright, your silly name is $color $number. I hope you really like it! See you next time!". Although it's not done in this case, it's possible to list multiple text responses for an intent (if more than one is present, one will be selected at random for the response).
User: Hey Google, Talk to Silly Name Maker. [Silly Name Maker agent is launched. start_make_name intent runs, and provides its response] Silly Name Maker: Hi! Welcome to Silly Name Maker! Let's get started. What is your lucky number? [start_make_name intent ends] User: 22 [make_name intent matches user input of number
, and executes] [$number parameter is from the user input] [$color parameter value has not been provided yet, so API.AI prompts for it automatically] Silly Name Maker: What is your favorite color? User: Blue [make_name intent provides its response] Silly Name Maker: Alright, your silly name is Blue 22. I hope you like it! See you next time. [make_name intent ends]
Testing and Deploying your Agent
You can run the agent in a couple of ways. There's a web simulator on the right-hand side of the API.AI site you can interact with: just click the microphone icon and say something. You'll see how that was interpreted and what the response is. Click the Play link to have the response spoken to you.
Test Console built into API.API
Even better, you can test this on your own Google Home device. If you're logged into API.AI with the same Google account that your Google Home device uses, you can deploy it and go over and talk to the Home. Click Integrations on the left-side menu. On the list of One-click Integrations, click Actions on Google.
On the Actions on Google dialog that appears, review the options (you can for example change the voice Home will use), then click Authorize at bottom right.
Actions on Google dialog with Authorize option
Actions on Google dialog with Preview option
Once you click Preview, you'll soon see confirmation that your agent has been published. Now you can walk over to your Home device and try it out. Begin with "Hey Google, Talk to Silly Name Maker."
Preview published confirmation
In my next post, I'll develop my first solo agent for Google Home.