MyShell 백서

MyShell

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 43쪽

<figcaption><p>MyShell 워크숍 페이지.</p></figcaption></figure> 3. 아래로 스크롤하여 “Classic Mode”에서 “Dev Mode”로 전환하세요. <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/hlF2VBEIrdz16XFzVD1R/image.png" alt=""><figcaption><p>봇에서 Dev 모드 활성화.</p></figcaption></figure> 4. 이제 나중에 튜토리얼에서 작업할 JSON 파일을 붙여넣고 “Validate”를 클릭할 수 있습니다. 검증이 완료되면 “Save”를 클릭하면 앱이 사용 준비가 됩니다. <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/snAuhZ1vzqJ9PqBW11yw/image.png" alt=""><figcaption><p>봇 생성 페이지의 Validate 및 Save 버튼.</p></figcaption></figure> ## 시작하기 준비가 되셨나요? “Next”를 클릭하여 Pro Config와 함께 여정을 시작하세요. # 튜토리얼 구조 This tutorial will help you get started with pro config and enable you to build workflows that utilise powerful functionality, such as using LLM or complex widgets available on the [MyShell widget centre](https://app.myshell.ai/robot-workshop). The following are the tutorial chapters and what you can expect from each. ## Chapter 1: Hello World with Pro Config In this chapter, you will learn to do the following: * Creating a basic "Hello World" agent using pro config. * Various types of input/output methods. * Creating buttons for user interactivity. * Enabling users to chat with your agent. * Converting text sent by users to voice. ## Chapter 2: Building Workflow In this chapter, you will learn to do the following: * Building workflows using modules. * Using widgets from the widget centre as a part of your workflow tasks. This chapter should allow you to utilise the power of modules like LLM and widget modules to add related features to your agent. ## Chapter 3: Transitions In this chapter, you will learn to do the following: * Transitioning between different states in your agent workflow. * Using events like `CHAT`, `ALWAYS`, and `DONE` that can trigger transitions. * Implementing conditional transitions. This chapter should allow you to manage the flow of your agent's different states effectively. ## Chapter 4: Expressions and Variables In this chapter, you will learn to do the following: * Using variables to store data that can be used later by the same/another state. * Using JavaScript expressions to perform different operations such as mathematical operations, equality checks, generating random numbers, etc. * Enabling `LLMModule` to have a memory using variables that store the conversation between the user and the agent. This chapter should allow you to build a complex agent with memory retention and conditional execution. ## Chapter 5: Integration with Any Widget In this chapter, you will learn to leverage all widgets available at MyShell Widget Center * How to adjust the parameters for a specific widget * How to integrate a widget into your Pro Config JSON&#x20; ## Chapter 6: An Advanced Example In this chapter, you will use everything you learnt in this tutorial. You will build an agent that assesses the user's pro config skills and transitions to different states based on the user's score. They will be presented with a pro config tutorial agent if the score is too low. This agent uses transitions, modules, variables, expressions and a new concept for button ID. You will also learn about advanced concepts such as nested routes and recursion. ## More Examples We have also included more examples. These examples are mainly from the feedback of our learning labs, covering more advanced usages. We will continue to update this chapter to include examples that are helpful for understanding Pro Config. # Pro Config를 사용한 Hello World {% hint style="info" %} 이 챕터의 핵심 개념 * **렌더 유형** * **입력/출력** {% endhint %} {% hint style="info" %} For better readability of this code block, you could copy and paste this into any code editor app like [VS Code](https://code.visualstudio.org/) and select JSON as its format.&#x20; {% endhint %} ```json { "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" } } } } ``` Above is the syntax with all the available fields for a Pro Config JSON file. Using the code above should allow you to do the following interaction with your bot. <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/6QokKLCfnuy57vBkTa2g/image.png" alt=""><figcaption><p>Hello world using pro config</p></figcaption></figure> In Pro Config, each `Automata` can be defined using a JSON file. An `Automata`has a unified `id` and several states as its children. In the simple example above, the `Automata`has only one state called `home_page_state` which simply outputs an intro message. It also has a button called `Start` which can jump to `home_page_state` itself like an iteration (we will get to more complicated transitions in the future.) #### AtomicState An atomic state is a state executing real tasks, which usually are small functional modules, such as LLM module and TTS module. These are usually embedded as a part of a bigger automata. #### Automata `Automata` shares many fields with `AtomicState`. They differ by the following: * `AtomicState` has the lack of `properties.is_chat_allowed` and `tasks` fields. * The different special events it can handle. * `initial` , `states` and `context` fields. Put in simpler words, one `Automata` can contain different `AtomicState`. Your Pro Config should be of the type `Automata` and tasks should be `AtomicState`. For more information about the difference between AtomicState and Automata, please refer to the [dev doc](https://docs.myshell.ai/product-manual/create/pro-config-mode-beta/basic/automata). ### Defining Inputs/Outputs The states of an `Automata` is a dictionary of `AtomicState` . An `AtomicState` take inputs from the user, process some tasks, return outputs, and render some content (such as text/image/button). In the example above, we rendered a text message and a button. \ \ We will now demonstrate how to add `inputs` and `outputs` to an `Automata` <pre class="language-json"><code class="lang-json"><strong>{ </strong> "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" } } } } </code></pre> In the example above, we are doing the following: * **Lines 7-18:** Gathering inputs `intro_message` and `tts_widget_url` from the user. The type is `text` which means that the user will be prompted to input data (unlike `IM` where user needs to type in the chat to provide an input). If the `user_input` property is `false`, the user will not be prompted to input via a form, and a new variable with the value of `default_value` will be automatically generated. <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/tDwuCQ7Apq3nLCCnhL6L/image.png" alt=""><figcaption><p>Input fields prompted to user when input type <code>text</code> is used</p></figcaption></figure> * **Lines 19-22:** The `output` section in pro config runs after all the tasks are completed for the automata or atomic state. In this section, you can create or manipulate variables. This is also the place you can manipulate any variables you create in `context`. If you want to store output for the task performed, this is the way. We use an expression wrapped by double curly braces `{{expression}}` to assign the value of an output variable. The expression should be written in [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide), adhering to the [ECMAScript 5.1](https://262.ecma-international.org/5.1/) standard, as we currently support only this version. In the example, we are using this section to save the inputs to variables. Now, you have learned how to build a basic app with inputs and outputs. In the next chapter, we will learn how to build a workflow to achieve more complicated functionalities empowered by AI Modules. {% hint style="info" %} Whenever you upload a new Pro Config, you can click the ≡ button on the bottom left and click "Clear Memory" button to reset your agent. {% endhint %} # 워크플로우 구축 {% hint style="info" %} 이 챕터의 핵심 개념 * **모듈 및 그 설정** {% endhint %} ### A Simple Agent Example In Pro Config, a workflow is a cascade of multiple Modules that can perform a series of tasks. In this chapter, we will build a simple agent that involves the cascade of two Modules.&#x20; ```json { "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" } } } } ``` In the above config, we have created an agent that generates a reply to the user's input. Please note that this is a very simple agent without any memory (we will implement an agent with memory in [Expressions and Variables](/ko/create/pro-config-mode/tutorial/expressions-and-variables)). Now let's delve into the details of the above example: In the agent above, we define the variable `user_message` of type `IM` (Instant Messaging). This allows the agent to take input in the form of messages sent to the agent. In the above example, we have set a transition on event `CHAT` to point to `chat_page_state`. So, whenever a user sends a message in the chat, the state is reloaded and the message is taken as in `IM` input. This `user_message` is then passed into the tasks. ### Configuration of Each Module Tasks contain multiple modules that execute sequentially. For each module, we need to specify the `module_type` and `module_config`. Rather, `name` is optional (for readability). In the example above, we include a GPT-3.5 LLM widget and a TTS widget provided on MyShell.&#x20; For demonstration purposes, we only used a simple system prompt `"You are a teacher teaching Pro Config."` In real-world applications, it is required to put some effort into prompt engineering and optimizing this system prompt for better performance. \ \ As for the TTS Widgets, you can choose any of your favorite voices from <https://app.myshell.ai/robot-workshop> and paste the widget ID into the config.&#x20; Specifically, after clicking the "workshop" button on the left menu bar, you will see this widget center. On the very top selection bar, select "TTS". Then pick your favorite voice model, use the "more" button to copy the widget ID, and paste into the config file. &#x20;![](https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/4QMBooG6juTPuSJMKwOw/widget%20center.png)![](https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/M7QUcoQSnUKpGZTpZxls/copy_tts_id.jpg) {% hint style="info" %} If you would like to add more modules or widgets, please refer to\ [모든 위젯과의 통합](/ko/create/pro-config-mode/tutorial/integration-with-any-widget) and [모듈](/ko/create/pro-config-mode/basic/modules) {% endhint %} ### Render and Transitions After the execution of the tasks, two variables called `reply` and `reply_voice` are obtained and ready to be rendered in a message that would appear in the User Interface. We have also handled a special event called `CHAT` in the transitions, which means when a user sends a message, the automata will jump into `chat_page_state` and execute that state. In the next section, we will describe how to handle and use different types of transitions. # 전환 {% hint style="info" %} 이 챕터의 핵심 개념 * **전환 유형, 전환 속성, 전환 범위** {% endhint %} In this chapter, we will show how to perform the transition between different states. Here is an example config: ```json { "type": "automata", "id": "transition_demo", "initial": "home_page_state", "inputs": {}, "outputs": {}, "transitions": { "go_home": "home_page_state" }, "states": { "home_page_state": { "render": { "text": "Click 'Start' to chat!", "buttons": [ { "content": "Start Chat", "description": "Click to Start Chatting.", "on_click": "start_chat" } ] }, "transitions": { "start_chat": "intro_message_state" } }, "intro_message_state": { "render": { "text": "Hi, welcome to the Pro Config tutorial. How can I assist you today?", "buttons": [ { "content": "Home", "description": "Click to Go Back to Home.", "on_click": "go_home" } ] }, "transitions": { "CHAT": "chat_page_state" } }, "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}}", "buttons": [ { "content": "Home", "description": "Click to Go Back to Home.", "on_click": "go_home" } ] }, "transitions": { "CHAT": "chat_page_state" } } } } ``` <figure><img src="https://content.gitbook.com/content/ltA4oqsKoJ26g4ArBpEA/blobs/4iOxWbMQOey4znXkO7y4/image.png" alt=""><figcaption><p>Output for the pro config</p></figcaption></figure> ### State Transition Process In the Above Example In the above agent, the user will start from a home page. In `home_page_state`, when the user clicks the `Start Chat` button, the state machine jumps to `intro_message_state` and display the intro message.&#x20; At `intro_message_state` , user can transit to `chat_page_state` by chatting with the agent. &#x20; \ We have included several concepts related to transitions in the above example. Let's explain them one by one. ### Transition & Its Attributes A transition is usually defined as:&#x20; ```json "transitions": { "<action_name>": "<target_state>" } ``` Where `<action_name>` is the name of action, usually which you provide in the `on_click` property of button, and `<target_state>` is the state to transition when the action is run. This way, you can create a flow where the user gets to choose the path they want the workflow to go by clicking buttons. There are also some **reserved action names** that allow you to transition when a specific event happens in your agent.&#x20; We currently support three reserved action names: * **CHAT**: triggered when the user sends a message * **ALWAYS**: triggered when an AtomicState has finished. Usually used to connect two consecutive states. * **DONE:** triggered when an Automata is finished. This can be useful in nested automata (to determine the next state of a child automata). ### The Scope of Transitions The `transitions` can be defined either in an `AtomicState` or in an `Automata`. If a transition is defined in an `AtomicState`, it will only handle the action triggered in that AtomicState (such as `start_chat` in the `home_page_state`). However, if a transition is defined in the `Automata`, it will handle the actions in all its states. For example, since `go_home` is handled in the `transitions` of the whole `transition_demo`, any button within `transition_demo` that can trigger the action `go_home` and make the automata jump to `home_page_state`. ### Conditional Transitioning Pro Config also supports conditional transition, which means performing validation of some boolean expressions during the transition. The syntax is as follows: ```json "transitions": { "<action_name>": [ { "target": "<target_name1>", "condition": "<condition1>", }, { "target": "<target_name2>", "condition": "<condition2>", } ... ] } ``` When `<action_name>` is triggered, Pro Config will check the conditions sequentially (first check `<condition1>`, and then `<condition2>`) to decide which state to jump to. If no condition is satisfied, the automata will stay in the original state. We will show how to leverage this advanced syntax in later examples. # 표현식과 변수 {% hint style="info" %} 이 챕터의 핵심 개념 * 데이터를 저장하고 유지하는 변수 * 변수 내에서 조건을 수행하는 표현식 {% endhint %} ### Variables: Concepts and Basic Use Cases&#x20; In this chapter, we will demonstrate how variables are defined, updated, and passed. As mentioned before, variables can be created within `inputs` of a state. For example: ```json { "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 Agent" }, }, "render": { "text": "{{intro_message}}", }, } } } ``` The above simple example creates a variable called `intro_message` of type `text` with a default value and render it in the message. If `user_input` is `false`, user will not be prompted to input via a form, and a new variable with the value `default_value` will be automatically generated.&#x20; ### Expressions We can use expressions to take value of previously defined variables and perform basic calculations from it. In Pro Config, expressions are represented in a string wrapped by double curly braces like `{{expression}}`. Expressions uses the grammar of JavaScript, and supports most of the basic syntaxes. Unlike defining a variable through `inputs`, the result type of an expression can be dynamically deduced during the execution of that expression. A more common use case is to use expressions inside a string (such as the prompts of LLM): ```json "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" } }, ... ], "render": { "text": "{{reply}}", ... }, ... } ``` In this case, Pro Config will replace the expression with the evaluated result of `user_message` (which is converted to string) and use that as the `user_prompt`.&#x20; ### Scope of Variables It is also important to understand the scope of variables. Currently, there are two ways to retrieve a variable: 1. **Referring to a variable that's defined within an AutomicState**: we can directly use the variable name to refer to that variable (such as the `{{user_message}}` in the user\_prompt). Note that the execution of the AutomicState follows the order of `inputs->tasks->outputs->render` 2. **Passing a vari
프로젝트로 돌아가기