Semantic Composition Language

About the SCL

Semantic Composition Language (SCL - pronounced skill) is a procedural domain specific language for botlet development where the flow reads in a linear fashion and enables developers to stitch together components from different sources. This can be another SCL piece. It can be C# or JavaScript brought in as service. It can be a Bot Framework bot.

Goals of SCL

The main goals of the language are that it is easy to read and write (approaching English). Novices and non-technical developers should be able to use it to string together existing experiences out of a publicly available directory of botlets. Simple things should be simple whereas more complex tasks may require more advanced programming knowledge.

The language itself is semantic in a way that search engines can parse an SCL script and gain some understanding of what it is doing.

Purpose of SCL

The purpose of the SCL is to describe flows and user experiences in a way that is agnostic to the canvas it will eventually execute on. The same script should work across voice and chat interfaces as well as graphical (web) user interfaces and virtual reality experiences. It controls the underlaying operating system that communicates with the various system components (public/private knowledge graph, service botlets, etc.) through semantic entities. As such the language is not meant to replace existing general-purpose programming languages. It is not meant for data processing, low level computations or interfacing with non-semantic 3rd party APIs. Those tasks should be implemented as service botlets which can be written as micro services in any programming language.

Botlets are asynchronous by nature. When a prompt is sent to the user, the user may respond immediately or days later. The flow behind a botlet therefore almost always involves callbacks, and a series of prompts to the user ends up being fragmented because multiple callbacks must be chained together.

SCL consists of simple commands to handle botlet prompts and responses, invoke other botlets to send/receive semantic data, third-party authorization and more. An example of a simple botlet to prompt for your name could be:

SAY "Hi, what is your name?"
GET_INPUT
SAY "Great to meet you ${USER_INPUT}"

Even though SCL is a language with simple commands, it also needs to support more advanced flows and constructs, and we appreciate that any new language takes time to learn. That’s why it’s built on top of Python - the SCL commands control the logic flow, but expressions are evaluated by Python, so you have the full power of Python at your fingertips.

For example, SCL contains a simple IF statement and by using Python in the condition we can easily perform string operations:

SAY "Hi, how are you doing?"
GET_INPUT
IF "bad" in USER_INPUT.lower()
    SAY "Sorry to hear that"

SCL Limitations

It is important to note that even though Python expressions can be used in SCL commands, SCL commands cannot be used in Python expressions. Botlet code consists of SCL commands, and as such each line of code must start with an SCL command.

For complex logic flows or computationally expensive calls, we recommend developing the logic in your language of choice and registering its endpoint as a botlet. Use SCL code to combine the various botlets together at a higher level and to interact with the user.

Python Modules

Certain Python modules are readily available from SCL to ease development. However, to enforce a sandbox between the various SCL environments, no additional Python modules can be imported. The following modules are currently available:

  • random to generate random numbers
  • time for time conversion
  • datetime to access date and time

Furthermore, the following Python methods are available:

  • “create”: Global function to instantiate a new Entity instance. The SCL command “CREATE” is functionally identical, but since SCL commands cannot be used in Python expressions, the Python create method can be used in Python expressions to create entities. Refer below to the Advanced Python Constructs in SCL for these details.
  • “to_json”: Method on Entity to serialize the instance to JSON
  • “to_yaml”: Method on Entity to serialize the instance to YAML

Advanced Python Constructs in SCL

Below are a few examples of how Python expressions can be used in SCL:

# String operations
SET sentence = "The quick brown fox jumps over the lazy dog"
SET words = sentence.split(" ")
SAY sentence.replace("fox", "honey badger")

# String formatters
SAY "int: {0:d} - hex: {0:X}".format(255)
SET third = "{0:.2f}".format(1.0/3)

# List operations
SET numbers = range(1,11)
SET str =  [ "<%s out of %s>" % (i, len(numbers)) for i in r ]
SET half = numbers[:5]

# Lambda functions
SET removed_a_or_b = filter(lambda char: char > 'c' or char == ' ', sentence.lower())

# Create list of choice entities in Python one-liner
SET choices = map(lambda t: create("$bot.interactor.quick_reply", text=t), [ "Yes", "No" ] )

Restricted Python

The combination of Python and SCL creates a very flexible and powerful language. However, to ensure security and control flow and avoid callbacks, the following Python statements and constructs are not allowed:

  • “import” statements are not allowed
  • Any flow-related statements like “while”, “if” and “yield”
  • Assignments must be done via SET commands
  • Native Python exception cannot be raised or caught

Note: This list of restrictions is not exhaustive.

For more information about SCL syntax, see: SCL Syntax.

To see a list of SCL commands, see: SCL Commands.

For more information about SCL system variables, see: System Variables.