You are a helpful assistant generating synthetic data that captures *System 1* and *System 2* thinking, *creativity*, and *metacognitive reflection*. Follow these steps in sequence, using tags [sys1] and [end sys1] for *System 1* sections and [sys2] and [end sys2] for *System 2* sections.

1. *Identify System 1 and System 2 Thinking Requirements:*
   - Carefully read the text.
   - Identify parts of the text that require quick, straightforward responses (*System 1*). Mark these sections with [sys1] and [end sys1].
   - Identify parts that require in-depth, reflective thinking (*System 2*), marked with [sys2] and [end sys2].

2. *Apply Step-by-Step Problem Solving with Creativity and Metacognitive Reflection for System 2 Sections:*

   *2.1 Understand the Problem:*
   - Objective: Fully comprehend the issue, constraints, and relevant context.
   - Reflection: "What do I understand about this issue? What might I be overlooking?"
   - Creative Perspective: Seek hidden patterns or possibilities that could reveal deeper insights or innovative connections.

   *2.2 Analyze the Information:*
   - Objective: Break down the problem logically.
   - Reflection: "Am I considering all factors? Are there any assumptions that need challenging?"
   - Creative Perspective: Explore unique patterns or overlooked relationships in the data that could add depth to the analysis.

   *2.3 Generate Hypotheses:*
   - Objective: Propose at least 10 hypotheses, each with a Confidence Score (0.0 to 1.0) and Creative Score (0.0 to 1.0), reflecting originality, surprise, and utility.
   - Reflection: "Have I explored all possible explanations or approaches, both conventional and unconventional?"
   - Creative Perspective: Consider novel angles that might provide unexpected insights.

   *2.4 Anticipate Future Steps and Obstacles:*
   - Objective: Make predictions, accounting for potential outcomes and obstacles.
   - Reflection: "What challenges might I face? Is my plan flexible for different scenarios?"
   - Creative Perspective: Visualize unforeseen outcomes and adapt plans to make use of them effectively.

   *2.5 Evaluate Hypotheses:*
   - Objective: Assess hypotheses based on feasibility, risk, and potential impact.
   - Evaluation: Refine Confidence and Creative Scores as needed.
   - Reflection: "Am I unbiased in my assessment? Which options fit best with the overall objectives?"
   - Creative Perspective: Identify hidden opportunities or overlooked details in each hypothesis.

   *2.6 Select the Best Hypothesis:*
   - Objective: Choose the most promising, strategic hypothesis.
   - Reflection: "Why does this hypothesis stand out? How does it uniquely address the issue?"
   - Creative Perspective: Consider any underutilized potential in the selected approach.

   *2.7 Implement the Hypothesis:*
   - Objective: Outline actionable steps for testing the hypothesis.
   - Reflection: "Is this plan practical? What resources or preparation are required?"
   - Creative Perspective: Refine steps to maximize effectiveness and yield unexpected benefits.

   *2.8 Monitor and Review Progress:*
   - Objective: Review progress, noting areas for improvement.
   - Reflection: "What’s working well? What could be improved?"
   - Creative Perspective: Look for emerging patterns that could refine future approaches.

   *2.9 Reflect and Capture Insights:*
   - Objective: Summarize lessons learned and insights gained for future reference.
   - Reflection: "What new understanding has emerged from this process?"
   - Creative Perspective: Identify innovative insights or patterns that could be applied to similar challenges.

3. *Generate Text Output with Interleaved System 1 and System 2 Responses:*
   - Use the tags [sys1] and [sys2] throughout.
   - Aim for a lengthier, detailed response. Combine both direct, straightforward *System 1* insights and reflective, deeply analytical *System 2* segments to capture a blend of quick observations and thoughtful analysis.

---

### *Example Input Text:*

You are tasked with analyzing a sudden shift in customer preferences in a tech market. There has been a noticeable decline in demand for physical devices, with customers increasingly interested in digital-only options. The challenge is to understand this shift, generate hypotheses for why it might be occurring, and explore potential strategies for adapting to this new trend.

---

### *Processed Output with System 1 and System 2 Thinking:*

The tech market is experiencing a shift in customer demand, moving away from physical devices toward digital-only options.

[sys1]
Customer demand has shifted from physical devices to digital-only options.
We need to understand why this change is happening and find strategies to address it.
Key factors may include cost, convenience, and technological trends.
[end sys1]

[sys2]
**2.1 Understand the Problem:**
The goal is to understand the underlying reasons for the shift in demand from physical devices to digital-only options, then develop a strategy to adapt.

*Reflection:* 
"I understand that preferences are changing, but what might be driving this? Is it primarily cost, or are there other factors such as convenience or sustainability?"

*Creative Perspective:* 
"Could there be a larger trend in digital minimalism or a preference for eco-friendly solutions that we’re missing? What unseen motivations might explain this shift?"

**2.2 Analyze the Information:**
There are multiple possible factors driving this shift, from economic influences to cultural shifts. It’s essential to isolate each factor and understand its impact.

*Reflection:* 
"Am I fully considering the various economic and social influences? Could there be a technological factor, like better internet speeds, that makes digital-only products more accessible?"

*Creative Perspective:* 
"Are there patterns or trends in other markets that could shed light on this shift? Could this be part of a larger trend toward virtual experiences?"

**2.3 Generate Hypotheses:**
1. Customers prefer digital options due to lower costs. (Confidence: 0.8, Creative: 0.4)
2. There’s a growing trend toward minimalism and reduced physical clutter. (Confidence: 0.7, Creative: 0.7)
3. Digital products offer greater flexibility and ease of use. (Confidence: 0.6, Creative: 0.6)
4. Environmental concerns are pushing consumers away from physical goods. (Confidence: 0.6, Creative: 0.8)
5. Advances in tech make digital-only options more functional. (Confidence: 0.8, Creative: 0.5)
6. Pandemic-era remote work increased demand for digital solutions. (Confidence: 0.7, Creative: 0.6)
7. Media coverage of the environmental impact of physical devices affects preferences. (Confidence: 0.5, Creative: 0.7)
8. There’s an increase in global digital literacy, expanding market access. (Confidence: 0.6, Creative: 0.6)
9. Customers view digital as more convenient and scalable for future needs. (Confidence: 0.7, Creative: 0.5)
10. Younger consumers prefer the aesthetics and convenience of digital products. (Confidence: 0.6, Creative: 0.6)

*Reflection:* 
"Have I considered all possible influences? Are there any surprising factors that could explain this shift?"

*Creative Perspective:* 
"Could specific social trends, like the rise of influencer culture or digital-first lifestyles, be influencing customer choices?"

**2.4 Anticipate Future Steps and Obstacles:**
*Objective:* Anticipate possible challenges, such as resistance from segments still preferring physical products.

*Reflection:* 
"What market obstacles might we face if we shift our focus to digital-only? Are there sub-segments that still prioritize physical products?"

*Creative Perspective:* 
"Could expanding digital options help us reach a more global audience? Are there emerging trends that we could leverage in our strategy?"

[end sys2]

[sys1]
To address this shift, consider a strategy that incorporates both digital-only offerings and educational campaigns about the benefits of digital solutions.
Use insights from customer feedback and current trends to guide product development.
Focus on flexibility and adaptation to cater to different customer segments.
[end sys1]


In this tutorial we’ll use AWS Lambda because it doesn’t require a server setup and it’s free⁴ for a skill such as this one. If you want to learn more about the advantages and disadvantages of AWS Lambda and serverless in general, see the introduction to serverless here⁵.

Anatomy of an Alexa skill invocation

Some of the main characteristics of Amazon Alexa, and voice assistants in general, are:

Alexa has a built-in natural language processing (NLP) engine that will parse the request and pass the data in JSON format.

Voice assistants typically require a wake word or phrase — a sound that will tell them to expect a command immediately after.

Alexa is command-based and a typical command consists of the following:

Wake word is used to turn Alexa into attentive state. The default wake word is “Alexa,” but it can be customized in the device settings. At the time of writing, available wake words are “Alexa,” “Amazon,” “Echo,” and “Computer.”

Launch phrase tells Alexa to trigger a certain skill. Launch phrases include “ask,” “launch,” “start,” “show,” and many others.

Invocation name is the name of the skill you want to trigger.

Utterance tells Alexa what the skill should do (unless your launch phrase is “start” or “launch”). Those instructions are known as utterances. Having static utterances would not give you much flexibility, so Alexa allows you to add some dynamic parts to the command, called slots.

When user invokes the skill Alexa parses it into JSON and passes the parsed data to your AWS Lambda function or an HTTPs webhook.

The following image shows how the Alexa skill invocation works:

Prerequisites for this tutorial

Besides a skill idea and a good will to program that skill, there are a few more items you’ll need to be able to follow this tutorial:

Amazon account (because you’ll need to setup the skill on Amazon’s developer portal)

AWS account (because your Alexa skill will be deployed on AWS Lambda)

Configured AWS credentials (see this guide⁶ for more info)

Node.js (version 4 or more, v6.11 is recommended), and a basic knowledge of Node.js (because this guide is using it for the skill development)

If you have all of the prerequisites, then let’s jump to the setup of your skill.

Skill setup

The next step is to create and configure your Alexa skill.

To do so, go to https://developer.amazon.com/alexa-skills-kit, sign in with your Amazon account and click on the “Start a Skill” button.

This will open the “Skill information” section of Alexa skill configuration. In this section, set the name of your skill to “Crypto Bot” and invocation name to “crypto.” The rest of the fields should stay the same (skill type should be “Custom Interaction Model” and all global fields should be turned off).

Then save and click on the Next button to go to the “Interaction Model” section.

Interaction model is a set of rules that defines the way the user interacts with your skill. As a part of an interaction model, you need to define Intent Schema, a list of intents that your Alexa skill commands will be parsed to, and sample utterances; that is, sample phrases that will match each of the intents.

The intent schema should be in JSON format and it should define an array of intents, each with a name, and an optional list of dynamic parts — slots.

Our skill has two intents: GetPrice and AmountInfo . Both of the intents should have a coin name as a slot, which we’ll call Coin , and we set its type as COIN_TYPES (we’ll define it in a minute). AmountInfo intent should also have a number slot, for an amount in euros. This slot can be named Amount and it should use AMAZON.NUMBER , which is one of the built-in slot types. For more info about built-in slot types, see the documentation.

Your intent schema should look like the following JSON snippet:

{

"intents": [

{

"intent": "GetPrice",

"slots": [

{

"name": "Coin",

"type": "COIN_TYPES"

}

]

},

{

"intent": "AmountInfo",

"slots": [

{

"name": "Coin",

"type": "COIN_TYPES"

},

{

"name": "Amount",

"type": "AMAZON.NUMBER"

}

]

}

]

}

Because Coin slot type is obviously not a built-in type, you’ll need to add it as a custom slot type in “Custom Slot Types” section. Name it the same you named it in the intents schema ( COIN_TYPE ) and add the following data as values (they need to be line-separated):

Bitcoin

Litecoin

Ethereum

After adding custom slot values, click on the Add button to save them.

The last part of the Interaction Model configuration is sample utterances. Sample utterances are also line-separated. They always start with the intent name, followed by the sample phrase, excluding the wake word and skill name. Sample utterances should also contain slots, which are specified using slot names (from your intent schema) in curly braces, for example {Coin} . Slot types are case sensitive.

You should add at least 2–3 utterances for each intent type.

Your sample utterances should look like the following text snippet:

GetPrice How much is {Coin}

GetPrice What is the price for {Coin}

GetPrice Current {Coin} value

GetPrice {Coin} value AmountInfo How many {Coin} can I get for {Amount} euros

AmountInfo Amount of {Coin} for {Amount} euros

AmountInfo Number of {Coin} for {Amount} euros

Now that you have built the interaction model, click Next to save it. Saving can take up to a few seconds because Alexa will automatically train itself with the provided interaction model.

After the model is saved, you’ll be transferred to the “Configuration” section. This section requires connection to your Lambda function or webhook. But because you don’t have the Lambda function yet, let’s first stop at this step and create and deploy code for your skill first.

Coding your skill

Code for the Lambda function is a simple Node.js module. This means that you need to create a folder (for example crypto-skill ), enter your new folder name and initialize a new NPM project in it.

Because the skill is simple, it can fit into a single file, so create skill.js file in your crypto-skill folder.

This file is a standard Node.js file, with one important note — deploying on AWS Lambda requires your main file to do exports.handler instead of module.exports . So, the base of your skill.js file should look like this:

'use strict' function cryptoSkill(event, context, callback) {

// Do something with `event` and use `callback` to reply

} exports.handler = cryptoSkill

There are many ways to build a skill, but to keep everything as simple as we can we’ll use following Node.js modules:

alexa-skill-kit — a simple Node.js library that simplifies building Alexa skills for AWS Lambda.

— a simple Node.js library that simplifies building Alexa skills for AWS Lambda. alexa-message-builder — a class for creating rich Alexa replies, with reprompts, cards, etc.

— a class for creating rich Alexa replies, with reprompts, cards, etc. cryptocompare — a JavaScript API for https://www.cryptocompare.com.

— a JavaScript API for https://www.cryptocompare.com. node-fetch — a light-weight module that brings window.fetch to Node.js. This module is required by cryptocompare .

To install all the dependencies, run the following command:

npm install alexa-skill-kit alexa-message-builder cryptocompare node-fetch --save

The next step is to integrate the Alexa Skill Kit module in your handler function. This module accepts three arguments: event that triggered AWS Lambda, Lambda context, and a callback function that will be invoked with the parsed event.

You can also use Alexa Message Builder to build nice, readable replies. For full documentation, see https://github.com/stojanovic/alexa-message-builder.

In Alexa Skill Kit callback, you want to check if the event is GetPrice or AmountInfo intent and do something for each of them.

You should also check if the event is LaunchRequest and give initial instructions about your skill if it is.

LaunchRequest is one of the Alexa request types (see full list of types here). It is sent when the user invokes your skill without providing a specific intent, for example, by saying “Alexa start Crypto.”

At this point, your code should look like this:

function cryptoSkill(event, context, callback) {

alexaSkillKit(event, context, (message) => {

if (message.intent.name === 'GetPrice') {

// Get the price for selected crypto currency

} if (message.intent.name === "AmountInfo") {

// Get an amount of crypto currency that user can get for specified amount of euros

} if (message.type === 'LaunchRequest') {

// Answer to `Alexa, start Crypto` command return new MessageTemplate()

.addText(`Hello from crypto currency bot.

I can give you the info about bitcoin, litecoin and ethereum prices.

How can I help you today? You can say:

What is the current Bitcoin price?

Or How many Ethereums can I get for 100 euros?

`)

.addReprompt(`You can say:

What is the current Bitcoin price?

Or How many Ethereums can I get for 100 euros?

`)

.keepSession()

.get();

}

})

}

Then program both GetPrice and AmountInfo intents using the cryptocompare module.

For example, code for the GetPrice intent can look like this:

const token = message.intent.slots.Coin.value if (Object.keys({

bitcoin: 'BTC',

litecoin: 'LTC',

ethereum: 'ETH'

}).indexOf(token.toLowerCase()) < 0) {

return 'I can give you the info only for bitcoin, litecoin and ethereum'

} return cc.price(tokens[token], 'EUR')

.then(prices => `Current price of ${token} is ${prices.EUR} euros.`)

After adding the code for both intents, your skill.js file should look like this in the end:

skill.js

Deploying the skill

We’ll use Claudia.js to deploy the skill. Claudia.js is a Node.js tool that simplifies the deployment of AWS Lambda functions. This section assumes you have Claudia.js installed globally, as explained in this guide⁶, but you can put each of the following commands in NPM scripts and install Claudia.js as a dev dependency.

To deploy your Lambda function run the claudia create command. This command requires specifying the following:

AWS region: Alexa supports Asia Pacific (Tokyo), EU (Ireland), US East(N. Virginia), and US West (Oregon) regions. We’ll use Ireland ( eu-west-1 ).

). Handler, which is the name of your handler file without .js extension followed by .handler . In our case, it should be skill.handler because handler file is skill.js and it exports handler .

. In our case, it should be because handler file is skill.js and it exports . Version because Alexa Skills doesn’t allow usage of default latest version. You can name your version whatever you want, but my recommendation is to name it simply skill .

The full command should look like this:

claudia create --region eu-west-1 --handler skill.handler --version skill

When the command executes, your Lambda function will be deployed. The next step is to allow Alexa to trigger your function. To do so, run the following command (just make sure you are using the same version you used in the claudia create command):

claudia allow-alexa-skill-trigger --version skill

This command will return JSON that looks like this:

{

"Sid": "Alexa-1234567890123",

"Effect": "Allow",

"Principal": {

"Service": "alexa-appkit.amazon.com"

},

"Action": "lambda:InvokeFunction",

"Resource": "arn:aws:lambda:eu-west-1:123456789012:function:crypto-skill-medium:skill" }

The most important information in this response is “Resource,” which contains the Lambda function Amazon Resource Name (ARN) that you need to finalize in the Alexa skill configuration.

Connecting and testing your skill

Now that you have the Lambda function ARN, go back to the “Configuration” section of the skill creation form (https://developer.amazon.com/alexa-skills-kit).

Select “AWS Lambda ARN” as “Service Endpoint Type” and enter the ARN from the previous command as the default endpoint.

Answer with “No” to the “Provide geographical region endpoints?” question and click on the Next button.

This will save your skill configuration and take you to the “Test” section. In this section, you’ll see the “Service Simulator,” which can be used to test your skill.

Type “What is the Bitcoin price?” into “Service Simulator” and you’ll see JSON containing text similar to “Current price of Bitcoin is 9011.37 euros.” in the “Service Response.”

Congratulations, you have successfully built an Alexa skill 🎉

If your Alexa is connected to the same Amazon account, then try to say:

Alexa, start Crypto.

or

Alexa, ask Crypto what is the Bitcoin price?

It should answer with text similar to “Current price of Bitcoin is 9011.37 euros.”

Further improvements

Now that you have built an initial Alexa skill, here are the few next steps you might want to try out:

Add historic prices — Crypto skill should be able to tell you the price of Bitcoin yesterday or on any other specified day

Add better code structure by splitting the commands to the separate files

Add automated tests to the code of your skill

Submit the skill to the Alexa store by filling out the “Publishing Information” and the “Privacy & Compliance” sections

Build another skill

I might cover these topics in one of the next articles but, in the meantime, you can get some ideas on how to do those tasks in the “Serverless Apps with Node and Claudia.js” book.

Alexa limitations

After a few experiments with Alexa skills, you’ll realize that the platform still has certain limitations.

Some of the most important limitations are:

You cannot update custom slots or intents dynamically or using the script. This sounds logical, but it is also a limitations because you cannot pull the data from your API. For example, if you want to add a new crypto currency, then the only way is to edit the custom slot manually in the Alexa Developer dashboard.

Alexa doesn’t recognize your voice, which means that anyone that can talk to your Alexa can trigger all your skills.

You cannot chain the intents within certain sessions out-of-the-box. For example, if you have few intents that are followed by yes-no question, both “Yes” and “No” will be intents that you define just once, and than you need to implement the logic inside each of those intents that will respond depending on a previous command stored in the session attributes. For an example of session usage see this article⁷.

Fortunately, Amazon is constantly improving the platform, so the list of limitations is smaller with each new update or device.