Preface#
First, I would like to recommend an introductory tutorial on MyShell by Jiao Ge from the Robot community, titled “MyShell Tool Bot Creation Guide”.
This tutorial provides a guide on how to create tool bots on the MyShell platform. MyShell is a decentralized generative AI creator platform that offers various AI large models for users to use for free. The author shares their experience transitioning from ChatGPT to MyShell, emphasizing the advantages of MyShell, including free access to multiple AI large models, avoiding account suspension risks, earning points rewards, community support, and cost savings. The article also introduces how to write effective prompts, define roles, rules, and workflows, as well as how to choose models and enhance prompts.
Additionally, Jiao Ge shares some of the tool bots they have created, providing advice on how to test, promote, and look forward to the future. Finally, the article discusses prompt writing techniques for the Claude3 model, including the use of XML tags and marking input variables.
When we use MyShell to create character bots, mastering the above content can generally help us achieve our character. However, the downside is that AI is uncontrollable in many processes, and we also need some program logic when building a bot to help us control the bot's workflow during user interactions.
Thus, this article will formally discuss the Pro Config mode. This mode will balance programming logic with flexible interactions of AI prompt logic.
Hello World#
First Example#
Since the Pro Config mode is quite similar to programming logic, it is hoped that you have a certain coding foundation so that you can quickly grasp the JSON description of Pro Config and implement development.
Following a coder's habit, let's quickly conduct a Hello World practice.
{
"type": "automata",
"id": "hello_demo",
"initial": "home_page_state",
"inputs": {},
"outputs": {},
"transitions": {},
"states": {
"home_page_state": {
"inputs": {},
"tasks": [],
"outputs": {},
"render": {
"text": "Hello World! Welcome to this demo. Click 'Start' to chat!",
"buttons": [
{
"content": "Start",
"description": "Click to Start.",
"on_click": "start_demo"
}
]
},
"transitions": {
"start_demo": "home_page_state"
}
}
}
}
By inputting the above configuration into our bot's developer mode, we will achieve the following effect:
Now, let's explain the meaning of the above JSON:
- First, we define this segment of JSON as an automaton (Automata), and in Pro Config, each automaton can be defined using JSON;
- In this automaton, we define what kind of text the bot needs to output, i.e., the
text
field; we define a button, and in theon_click
automaton, we specify what state it will transition to upon clicking;
Thus, we have completed the writing of the Hello World example for the Pro Config mode.
Atomic State and Automata#
In the Hello World example above, we have roughly understood what an automaton is. In summary, it is an abstraction used to control the bot to enter different states.
Next, let's introduce the concept of Atomic State. To describe its relationship with automata in the simplest terms, an automaton can contain different atomic states. If the automaton is used to describe the switching relationships between different states, then the atomic state is used to describe the abstraction of a certain complex state.
Here we will briefly understand this concept, and it will be explained in detail when used later.
Of course, if you want to learn more, you can directly refer to MyShell's official documentation.
Defining Inputs/Outputs#
In the above Hello World example, we defined the atomic state with the text
field and the Button
field, and we see that there are other fields as well.
Now let's introduce the roles of the inputs
and outputs
fields.
Talk is cheap, let's look directly at the following code:
{
"type": "automata",
"id": "hello_demo",
"initial": "home_page_state",
"inputs": {},
"outputs": {},
"transitions": {},
"states": {
"home_page_state": {
"inputs": {
"intro_message": {
"type": "text",
"user_input": true,
"default_value": "Hi, this is your Pro Config Tutorial Bot"
},
"tts_widget_url": {
"type": "text",
"user_input": true,
"default_value": "https://app.myshell.ai/widget/mEjUNr"
}
},
"tasks": [],
"outputs": {
"intro_message": "{{intro_message}}",
"voice_id": "{{tts_widget_url}}"
},
"render": {
"text": "Hello Word! Welcome to this demo. Click 'Start' to chat!",
"buttons": [
{
"content": "Start",
"description": "Click to Start.",
"on_click": "start_demo"
}
]
},
"transitions": {
"start_demo": "home_page_state"
}
}
}
}
Replacing the previous Hello World code with this code, we will find that after the user clicks the Start Button, an interactive form will pop up:
This form is the effect we achieved through the above code. Let's interpret some key parts of the code:
- inputs: Here we set the
intro_message
andtts_widget_url
fields, which are essentially the titles of the two text boxes for input. Thetype
field istext
, indicating this is a text box,user_input
indicates whether user input is required, anddefault_value
is the preset value.
When we set it this way, after the user fills in the expression and clicks save, the input values will be saved as the intro_message
and tts_widget_url
variables, which we can reference in other expressions using the variable expression {{<variable>}}
.
- outputs: This variable represents the content of the conversation initiated by the bot according to our text template after the user has filled in the expression. Just like this:
As we mentioned earlier, we can use {{<variable>}}
to reference the variables we constructed, and there is nothing difficult about it; I believe you can understand it at a glance.
MyShell officially uses double curly braces
{{expression}}
to wrap expressions to assign the output variable's value to it. This expression should be written in JavaScript language, following the ECMAScript 5.1 standard, as MyShell currently only supports this version.
Building Workflows#
Creating a Chatbot#
In Pro Config, workflows can connect multiple modules to handle the events we need to process. Below, we will use a chatbot example to explain how to use workflows.
{
"type": "automata",
"id": "chat_demo",
"initial": "chat_page_state",
"inputs": {},
"outputs": {},
"transitions": {},
"states": {
"chat_page_state": {
"inputs": {
"user_message": {
"type": "IM",
"user_input": true
}
},
"tasks": [
{
"name": "generate_reply",
"module_type": "AnyWidgetModule",
"module_config": {
"widget_id": "1744214024104448000",
"system_prompt": "You are a teacher teaching Pro Config.",
"user_prompt": "{{user_message}}",
"output_name": "reply"
}
},
{
"name": "generate_voice",
"module_type": "AnyWidgetModule",
"module_config": {
"content": "{{reply}}",
"widget_id": "1743159010695057408",
"output_name": "reply_voice"
}
}
],
"render": {
"text": "{{reply}}",
"audio": "{{reply_voice}}"
},
"transitions": {
"CHAT": "chat_page_state"
}
}
}
}
This code will implement a Pro Config Teacher role.
Workflow Analysis#
Let's explain the meaning of each module one by one:
"inputs": {
"user_message": {
"type": "IM",
"user_input": true
}
}
In the inputs module, we define the type
as IM
, which means instant messaging type. This type indicates that the bot can accept input in the form of messages sent to the bot.
"transitions": {
"CHAT": "chat_page_state"
}
Next, let's look at the state transition definition transitions
. Here, we set the event CHAT
directly to the previously defined chat_page_state
. This means that when the user sends a message in the chat, the state will reset, and the sent message will be passed as input to this state. Then the user_message
will be passed to the task
.
"tasks": [
{
"name": "generate_reply",
"module_type": "AnyWidgetModule",
"module_config": {
"widget_id": "1744214024104448000",
"system_prompt": "You are a teacher teaching Pro Config.",
"user_prompt": "{{user_message}}",
"output_name": "reply"
}
},
{
"name": "generate_voice",
"module_type": "AnyWidgetModule",
"module_config": {
"content": "{{reply}}",
"widget_id": "1743159010695057408",
"output_name": "reply_voice"
}
}
]
Next, let's look at the tasks
section. This section contains multiple modules to be executed, and for each module, we need to specify module_type
and module_config
. The name
is an optional field and not required.
For demonstration, in the first task, we provided a preset prompt - "You are a teacher teaching Pro Config."
, which specifies the bot's role.
In the second task, we want to send a voice reply. At this point, we can use MyShell's TSS Widget to set up a voice reply. If you have a preferred TSS voice you want to use, you can find it in MyShell's workshop and use its widget_id
to incorporate it.
Here, I briefly introduced two modules used for replies. If you are interested in modules for handling events, you can visit the official documentation to study the module modules.
After the two tasks are executed, two variables reply
and reply_voice
will be generated according to our definitions, and once ready, they will be presented to the user through the following definition:
"render": {
"text": "{{reply}}",
"audio": "{{reply_voice}}"
}
Throughout the process, we note that the bot also implicitly handles a "black box" event - the special event CHAT
. It is precisely because this special event is executed that it can transition to chat_page_state
according to our rules and execute the corresponding tasks.
I believe that through this example, you can understand the overall workflow of using Pro Config bots. Once you learn this, you can start writing your own bots and implement a general processing framework.
Summary#
Through this article, we have learned the basic concepts and application methods of the Pro Config mode on the MyShell platform. Through a Hello World example and a chatbot example, we demonstrated how to use automata and atomic states in the Pro Config mode to control the bot to enter different states and handle user inputs and outputs. Through these examples, we can not only quickly get started with the Pro Config mode but also gain a deeper understanding of its working principles.
In the next article, we will continue to discuss some detailed fields, such as how to specifically define transitions
, the specific usage of expressions and variables, how to integrate other widgets, and so on. Let's encourage each other.
Reference#
Additionally, we hope more developers will participate in the co-construction of MyShell's Bot market. The invitation link click here. There will be more Airdrop activities waiting for you to participate.