Search…
Behavior Rules

Behavior Rules

Behavior Rules are very flexible in structure to cover most use cases that you will come across. Behavior Rules are clustered in Groups. Behavior Rules are executed sequential within each Group. As soon as one Behavior Rule succeeds, all remaining Behavior Rules in this Group will be skipped.

Groups

1
{
2
"behaviorGroups": [
3
{
4
"name": "GroupName",
5
"behaviorRules": [
6
{
7
"name": "RuleName",
8
"actions": [
9
"action-to-be-triggered"
10
],
11
"conditions": [
12
<CONDITIONS>
13
]
14
},
15
{
16
"name": "DifferentRule",
17
"actions": [
18
"another-action-to-be-triggered"
19
],
20
"conditions": [
21
<CONDITIONS>
22
]
23
},
24
<MORE_RULES>
25
]
26
}
27
]
28
}
Copied!

Type of Conditions

Each Behavior Rule has a list of conditions, that, depending on the condition , might have a list of sub-conditions.
If all conditions are true, then the Behavior Rule is successful and it will trigger predefined actions.

List of available conditions:

General Structure

conditions are always children of either a Behavior Rule or another condition. It will always follows that same structure.

Description of condition structure

Input Matcher

The inputmatcher is used to match user inputs. Not directly the real input of the user, but the meaning of it, represented by expressions that are resolved from by the parser.

Description

Element
Value
Description
type
inputmatcher
configs
expressions
comma separated list of
expressions such as:
expression(value),expression2(value2),
yetAnotherExpressions(anotherValue(withASubValue))
occurrence
currentStep - used in case if the user said it in this conversationStep
lastStep - used in case if the user said it in the previous conversationStep
anyStep - used in case if the user said it in any step if this whole conversation
never - used in case if the user has never said that, including the current step
If the user would type "hello", and the parser resolves this as expressions "greeting(hello)" [assuming it has been defined in one of the dictionaries], then a condition could look as following in order to match this user input meaning:
1
(...)
2
"conditions": [
3
{
4
"type": "inputmatcher",
5
"configs": {
6
"expressions": "greeting(*)",
7
"occurrence": "currentStep"
8
}
9
}
10
]
11
(...)
Copied!
This inputmatcher condition will match any expression of type greeting, may that be "greeting(hello)", "greeting(hi)" or anything else. Of course, if you would want to match greeting(hello) explicitly, you would put "greeting(hello)" as value for the "expressions" field.

Context Matcher

The contextmatcher is used to match context data that has been handed over to EDDI alongside the user input. This is great to check certain conditions that come from another system, such as the day time or to check the existence of user data.

Description

Element
Value
Description
type
contextmatcher
configs
contextKey
The key for this context (defined when handing over context to EDDI)
contextType
expressions
object
string
expressions (if contextType=expressions)
A list of comma separated expressions
objectKeyPath (if contextType=object)
objectValue
Allows match via Jsonpath, such as "profile.username" (see: https://github.com/rest-assured/rest-assured/wiki/Usage)
Exp: contextKey: userInfo , contextValue: {"profile":{"username":"John"}} The value to be match with the extracted JsonPath value
string
string matching (equals)

Examples

1
(...)
2
"conditions": [
3
{
4
"type": "contextmatcher",
5
"configs": {
6
"contextType": "expressions",
7
"contextKey": "someContextName",
8
"expressions": "contextDataExpression(*)"
9
}
10
}
11
]
12
(...)
13
14
(...)
15
"conditions": [
16
{
17
"type": "contextmatcher",
18
"configs": {
19
"contextType": "object",
20
"contextKey": "userInfo",
21
"objectKeyPath": "profile.username",
22
"objectValue": "John"
23
}
24
}
25
]
26
(...)
27
28
(...)
29
"conditions": [
30
{
31
"type": "contextmatcher",
32
"configs": {
33
"contextType": "string",
34
"contextKey": "daytime",
35
"string": "night"
36
}
37
}
38
]
39
(...)
Copied!

Connector

The connector is there to all logical OR conditions within rules. By default all conditions are AND conditions, but in some cases it might be suitable to connect conditions with a logical OR.

Description

Element
Value
type
connector
values
operator (either AND or OR)

Examples

1
(...)
2
"conditions": [
3
{
4
"type": "connector",
5
"configs": {
6
"operator": "OR"
7
},
8
"conditions": [
9
<any other conditions>
10
]
11
}
12
]
13
(...)
Copied!

Negation

Inverts the overall outcome of the children conditions
In some cases it is more relevant if a condition is false than if it is true, this is where the negation condition comes into play. The logical result of all children together (AND connected), will be inverted.

Example:

1
Child 1 - true
2
Child 2 - true
3
→ Negation = false
4
Child 1 - false
5
Child 2 - true
6
→ Negation = true
7
8
(...)
9
"conditions": [
10
{
11
"type": "negation",
12
"conditions": [
13
<any other conditions>
14
]
15
}
16
]
17
(...)
Copied!

Occurrence

Defines the occurrence/frequency of an action in a Behavior Rule.
1
(...)
2
{
3
"type": "occurrence",
4
"configs": {
5
"maxTimesOccurred": "0",
6
"minTimesOccurred": "0",
7
"behaviorRuleName": "Welcome"
8
}
9
}
10
(...)
Copied!

Dependency

Check if another Behavior Rule has met it's condition or not in the same conversationStep. Sometimes you need to know if a rule has succeeded , dependency will take that rule that hasn't been executed yet in a sandbox environment as a reference for an other behavior rule.
1
(...)
2
{
3
"type": "dependency",
4
"configs": {
5
"reference": "<name-of-another-behavior-rule>"
6
}
7
}
8
(...)
Copied!

Action Matcher

As inputMatcher doesn't look at expressions but it looks for actions instead, imagine a Behavior Rule has been triggered and you want to check if that action has been triggered before.
1
(...)
2
{
3
"type": "actionmatcher",
4
"configs": {
5
"actions": "show_available_products",
6
"occurrence": "lastStep"
7
}
8
}
9
(...)
Copied!

Dynamic Value Matcher

This will allow you to compile a condition based on any http request/properties or any sort of variables available in EDDI's context.
1
(...)
2
{
3
"type": "dynamicvaluematcher",
4
"configs": {
5
"valuePath": "memory.current.httpCalls.someObj.errors",
6
"contains": "partly matching",
7
"equals": "needs to be equals"
8
}
9
}
10
(...)
Copied!

The Behavior Rule API Endpoints

The API Endpoints below will allow you to manage the Behavior Rules in your EDDI instance.
The {id} is a path parameters that indicate which behavior rule you want to alter.

API Methods

HTTP Method
API Endpoint
Request Body
Response
DELETE
/behaviorstore/behaviorsets/{id}
N/A
N/A
GET
/behaviorstore/behaviorsets/{id}
N/A
BehaviorSet model
PUT
/behaviorstore/behaviorsets/{id}
BehaviorSet model
N/A
GET
/behaviorstore/behaviorsets/descriptors
N/A
BehaviorSet model
POST
/behaviorstore/behaviorsets
BehaviorSet model
N/A
GET
/behaviorstore/behaviorsets/{id}/currentversion
N/A
BehaviorSet model
POST
/behaviorstore/behaviorsets/{id}/currentversion
BehaviorSet model
N/A

Example

We will demonstrate here the creation of a BehaviorSet
Request URL
POST http://localhost:7070/behaviorstore/behaviorsets
Request Body
1
{
2
"behaviorGroups": [
3
{
4
"name": "Smalltalk",
5
"behaviorRules": [
6
{
7
"name": "Welcome",
8
"actions": [
9
"welcome"
10
],
11
"conditions": [
12
{
13
"type": "negation",
14
"conditions": [
15
{
16
"type": "occurrence",
17
"configs": {
18
"maxTimesOccurred": "1",
19
"behaviorRuleName": "Welcome"
20
}
21
}
22
]
23
}
24
]
25
},
26
{
27
"name": "Greeting",
28
"actions": [
29
"greet"
30
],
31
"conditions": [
32
{
33
"type": "inputmatcher",
34
"configs": {
35
"expressions": "greeting(*)",
36
"occurrence": "currentStep"
37
}
38
}
39
]
40
},
41
{
42
"name": "Goodbye",
43
"actions": [
44
"say_goodbye",
45
"CONVERSATION_END"
46
],
47
"conditions": [
48
{
49
"type": "inputmatcher",
50
"configs": {
51
"expressions": "goodbye(*)"
52
}
53
}
54
]
55
},
56
{
57
"name": "Thank",
58
"actions": [
59
"thank"
60
],
61
"conditions": [
62
{
63
"type": "inputmatcher",
64
"configs": {
65
"expressions": "thank(*)"
66
}
67
}
68
]
69
},
70
{
71
"name": "how are you",
72
"actions": [
73
"how_are_you"
74
],
75
"conditions": [
76
{
77
"type": "inputmatcher",
78
"configs": {
79
"expressions": "how_are_you"
80
}
81
}
82
]
83
}
84
]
85
}
86
]
87
}
Copied!
Response Body
no content
Response Code
201
Response Headers
1
{
2
"access-control-allow-origin": "*",
3
"date": "Thu, 21 Jun 2018 01:00:02 GMT",
4
"access-control-allow-headers": "authorization, Content-Type",
5
"content-length": "0",
6
"location": "eddi://ai.labs.behavior/behaviorstore/behaviorsets/5b2af892ee5ee72440ee1b4b?version=1",
7
"access-control-allow-methods": "GET, PUT, POST, DELETE, PATCH, OPTIONS",
8
"access-control-expose-headers": "location",
9
"content-type": null
10
}
Copied!
Last modified 5mo ago