{"componentChunkName":"component---src-templates-default-template-tsx","path":"/tutorials/automation-tasks/","result":{"data":{"asciidoc":{"id":"a8daa0e9-c467-57f1-a844-efc3399c30d5","html":"<div id=\"toc\" class=\"toc\">\n<div id=\"toctitle\">Table of Contents</div>\n<ul class=\"sectlevel1\">\n<li><a href=\"#_overview\">Overview</a></li>\n<li><a href=\"#_prerequisites\">Prerequisites</a></li>\n<li><a href=\"#_what_we_will_do_in_this_tutorial\">What we will do in this tutorial</a></li>\n<li><a href=\"#_create_an_automation_task\">Create an Automation Task</a></li>\n<li><a href=\"#_add_a_todo_variable\">Add a Todo Variable</a></li>\n<li><a href=\"#_teaching_hiro_to_solve_the_task\">Teaching HIRO&#8482; to Solve the Task</a></li>\n<li><a href=\"#_summary\">Summary</a></li>\n</ul>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_overview\">Overview</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>When HIRO&#8482; receives a task to automate, it will try to complete the task with its existing knowledge base.\nIn this tutorial, we will learn how to submit automation tasks to HIRO&#8482; and what happens in HIRO&#8482; after the\ntasks has been submitted. If you are not familiar yet with how HIRO&#8482; works,\nwe recommend reading the <a href=\"/7.0/overview/Intelligent-automation-with-hiro/\">HIRO&#8482; System Overview</a> first.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_prerequisites\">Prerequisites</h2>\n<div class=\"sectionbody\">\n<div class=\"ulist\">\n<ul>\n<li>\n<p>API access to a HIRO&#8482; instance</p>\n</li>\n<li>\n<p>Authenticated HIRO&#8482; session with valid access token</p>\n</li>\n<li>\n<p>Defined functions to create and read vertices via API (see <a href=\"/7.0/tutorials/basic-graph-operations/\">Basic Data Operations</a>)</p>\n</li>\n<li>\n<p>Loaded calendar data into the graph with a connector (see <a href=\"/7.0/tutorials/tutorial-google-calendar-connector/\">Writing a first connector: Google Calendar synchronization to HIRO</a>)</p>\n</li>\n</ul>\n</div>\n<div class=\"paragraph\">\n<p>Please follow the steps described in the tutorial <a href=\"/7.0/tutorials/tutorial-first-steps-with-hiro/\">First Steps with HIRO</a> to\nauthenticate before proceeding to use HIRO’s Graph API.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_what_we_will_do_in_this_tutorial\">What we will do in this tutorial</h2>\n<div class=\"sectionbody\">\n<div class=\"olist arabic\">\n<ol class=\"arabic\">\n<li>\n<p>Send a new automation task to HIRO</p>\n</li>\n<li>\n<p>Observe how HIRO&#8482; processes automation tasks without <em>Todo Variable</em></p>\n</li>\n<li>\n<p>Add a <em>Todo Variable</em> to our automation task</p>\n</li>\n<li>\n<p>Understand what happens if automation tasks cannot be resolved</p>\n</li>\n<li>\n<p>Teach knowledge to HIRO&#8482; to process our task</p>\n</li>\n<li>\n<p>Re-submit our automation issue and check if it gets resolved</p>\n</li>\n</ol>\n</div>\n<div class=\"paragraph\">\n<p>HIRO&#8482; works in a task-centric mode. An <em>Automation Task</em> (a.k.a automation issue) is the central data object that triggers\nthe automated execution of knowledge to perform this task. We will learn how we can create new automation tasks via the\nHIRO API. The diagram below shows the issue lifecycle; issues typically move from <code>NEW</code> via <code>PROCESSING</code> to <code>RESOLVED</code>.</p>\n</div>\n<div class=\"paragraph\">\n<p>In a situation when HIRO&#8482; receives an automation task that is new and the knowledge base does not contain sufficient knowledge\nin order to complete it, the automation task will be set to <code>STOPPED</code> state and presented to a Subject Matter Expert (SME) to\nteach HIRO&#8482; the steps to solve the Issue. With the help of an AI Expert (AIE), this <em>Teaching Session</em> is translated\ninto executable knowledge, which is called <em>Knowledge Items</em>. HIRO&#8482; will then use this new knowledge the next time the same\ntask is submitted.</p>\n</div>\n<div class=\"paragraph\">\n<p>In this tutorial, we will first push an automation task to HIRO&#8482;, which HIRO&#8482; cannot complete with the existing knowledge base.\nAfter adding a simple Knowledge Item to the knowledge base, we will then see that the automation task lifecycle is completed\nand automation tasks finally get resolved. For the sake of brevity of this tutorial, we will only enter a Knowledge Item that\nwill directly resolve the automation task. You will find more realistic teaching session examples in the HIRO&#8482; User Guides.</p>\n</div>\n<div class=\"imageblock\">\n<div class=\"content\">\n<img src=\"/7.0/images/tutorials/issue_state_diagram.png\" alt=\"Task State Diagram\">\n</div>\n<div class=\"title\">Figure 1. Task State Diagram</div>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_create_an_automation_task\">Create an Automation Task</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>We want to create automation tasks frequently. Therefore, we define a convenience function to create automation tasks in\nHIRO. Since an automation task is a vertex, this function will call the <code>create_vertex()</code> function, which we have already\npreviously defined in another tutorial (as mentioned in the prerequisites). Then we will create an <em>Automation Task</em> by\ncalling this function.</p>\n</div>\n<div class=\"paragraph\">\n<p>An <em>Automation Task</em> corresponds to the entity type <code>ogit/Automation/AutomationIssue</code>. We define now the function <code>create_task()</code>,\nwhich creates a vertex representing the <em>Automation Task</em> in HIRO:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">def create_task (issueType, subject, originNode, attributes={}):\n\n    vertex_data = {'ogit/Automation/issueType': issueType,\n                   'ogit/subject':subject,\n                   'ogit/Automation/originNode': originNode,\n                   'ogit/status': 'NEW'\n                  }\n    vertex_data.update(attributes)\n    task_id = create_vertex(hiro_session, 'ogit/Automation/AutomationIssue', vertex_data)\n    return task_id</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The code above creates an automation task vertex (entity type <code>ogit/Automation/AutomationIssue</code>) in the HIRO&#8482; Graph with the provided attributes:</p>\n</div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><code>issueType</code> \t: Type of task to be submitted, written to <code>ogit/Automation/issueType</code> attribute</p>\n</li>\n<li>\n<p><code>subject</code> \t: Task subject, which will be shown in user interfaces, written to <code>ogit/subject</code> attribute</p>\n</li>\n<li>\n<p><code>originNode</code> \t: vertex ID of the entity the task is initially associated with, written to <code>ogit/Automation/originNode</code> attribute</p>\n</li>\n<li>\n<p><code>attributes</code>\t: further attributes, i.e. <em>Todo Variables</em> and <em>Information Variables</em>.</p>\n</li>\n</ul>\n</div>\n<div class=\"paragraph\">\n<p>The following attributes are mandatory attributes for automation tasks and need to be always provided upon creation: <code>ogit/Automation/issueType</code>, <code>ogit/subject</code>, <code>ogit/Automation/originNode</code>.</p>\n</div>\n<div class=\"paragraph\">\n<p>Attributes of an automation task are also called <em>Variables</em> when you work with them in <em>Knowledge Items</em>. <em>Information Variables</em> provide additional information to HIRO&#8482; about the specific task to perform. If your automation task would be purchasing office material, then the products to buy and the quantities might be relevant parameters that could be provided as information variables. <em>Todo Variables</em> represent sub-tasks or objectives that need to be satisfied. You need to specify at least one <em>Todo Variable</em> upon issue creation.\nNote: You may add arbitrary attributes to an automation task – either any already defined attributes from the OGIT schema, or free attributes with a trailing <code>“/”</code>. Be aware that such free attributes need to be registered as <em>Variables</em> in HIRO&#8482; to be referenced in Knowledge Items. This is done in the <em>Knowledge Acquisition Tool</em>.</p>\n</div>\n<div class=\"paragraph\">\n<p>Next, we will proceed to create our first <em>Automation Task</em>. As an example, we will create a task for rescheduling meetings in our calendar.\nIn this example, HIRO&#8482; will attempt to reschedule a meeting when it finds that the meeting date is conflicting with a vacation period.\nAs a design decision, we set  <code>ogit/Automation/originNode</code> to the ID of the calendar vertex in the graph, so that the <code>ogit/Schedule/Calendar</code> represents the context in which the rescheduling of meetings should be processed. We find out this vertex id by a query for the external google calendar id (xid query).\nWe proceed to create the task with the following function call, by passing the parameters needed (<code>issueType</code>, <code>subject</code>, and <code>originNode</code>):</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">google_calendar_id = '7hfea2godbmajrspfp30l23q1o@group.calendar.google.com' #replace with the id of your calendar!\ncalendar_node =  read_vertex_by_xid ('CAL-' + google_calendar_id)['ogit/_id']\ntask_id = create_task('RescheduleMeeting', 'Reschedule Meeting to After Vacation', calendar_node, {})</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>After the automation task with the above parameters is created, HIRO&#8482; will immediately update the task status to <code>RESOLVED</code>, due to the fact that no <em>Todo Variable</em> has been provided in the parameters. For any <em>Automation Task</em> that is submitted without a <em>Todo Variable</em>, HIRO&#8482; will automatically consider it <code>RESOLVED</code>, without any actual processing being done. We can read the Automation Task from the Graph and see that the status is <code>RESOLVED</code>.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">task_status = read_vertex(task_id)['ogit/status']\nprint ('Task status: ' + task_status)</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The result is:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code>Task status: RESOLVED</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>When an automation task is submitted (task state: <code>NEW</code>), it must be submitted with at least one <em>Todo Variable</em> for HIRO&#8482; to work on. The task will then be processed by HIRO&#8482; (task state: <code>PROCESSING</code>).Provided that HIRO&#8482; has enough <em>Knowledge</em> to act on it, the objective of each <em>Todo Variable</em> will be achieved, and the <em>Todo Variable</em> will be removed. When all the <em>Todo Variables</em> are removed, the state of the task will be set to <code>RESOLVED</code>.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_add_a_todo_variable\">Add a Todo Variable</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>In order to have the automation task being processed by HIRO&#8482;, we add the generic <em>Todo Variable</em> <code>ProcessIssue</code>:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">task_id = create_task('RescheduleMeetings', 'Reschedule meetings during my absence', calendar_node, {'/ProcessIssue':''})</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>Now we get a different result:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">task_status = hiro.read_vertex(task_id)['ogit/status']\nprint ('Task status: ' + task_status)</code></pre>\n</div>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code>Task status: PROCESSING</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>After a few minutes, HIRO&#8482; will stop working on this issue, because there is no suitable <em>Knowledge</em> in the <em>Knowledge Base</em>:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">task_status = hiro.read_vertex(task_id)['ogit/status']\nprint ('Task status: ' + task_status)</code></pre>\n</div>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code>Task status: STOPPED</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>If there is not sufficient <em>Knowledge</em> in the <em>Knowledge Base</em> to automatically solve all objectives of the submitted <em>Automation Task</em>, HIRO&#8482;will change the status of the automation task to <code>STOPPED</code>, which means that the task needs to be completed externally by a Subject Matter Expert (SME). By default, the transition to <code>STOPPED</code> state is performed after 15 minutes of idle time have elapsed.</p>\n</div>\n<div class=\"paragraph\">\n<p>You can view the details of the task, the execution history and the associated node context in the Task Viewer tool(IV icon in HIRO Frontend). This is a helpful developer tool for troubleshooting if you encounter problems.</p>\n</div>\n<div class=\"imageblock\">\n<div class=\"content\">\n<img src=\"/7.0/images/tutorials/iv_stopped_task.png\" alt=\"Stopped task in Task Viewer\">\n</div>\n<div class=\"title\">Figure 2. Stopped Task in Task Viewer (IV)</div>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_teaching_hiro_to_solve_the_task\">Teaching HIRO&#8482; to Solve the Task</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Now that our task has been submitted to HIRO&#8482; with a <em>Todo Variable</em>, it ends up in <code>STOPPED</code> state, because there is no available knowledge to apply by the HIRO&#8482; Engine. The automation task shows up in the Automation Teaching Queue (ATQ) in the HIRO&#8482; user interface.\nWe login to HIRO&#8482; as SME user and start a Teaching Session. Afterwards we translate the Teaching Session into a Knowledge Item. For the sake of brevity of this tutorial, we will only write a simple Knowledge Item that removes the <code>ProcessIssue</code> Todo variable, so that automation tasks will be resolved.</p>\n</div>\n<div class=\"imageblock\">\n<div class=\"content\">\n<img src=\"/7.0/images/tutorials/teaching_session_automation_issue_1.png\" alt=\"Stopped task in task automation queue\">\n</div>\n<div class=\"title\">Figure 3. Stopped Task in Teaching Queue</div>\n</div>\n<div class=\"imageblock\">\n<div class=\"content\">\n<img src=\"/7.0/images/tutorials/teaching_session_automation_issue_2.png\" alt=\"Teaching session to enter knowledge\">\n</div>\n<div class=\"title\">Figure 4. Teaching session in HIRO</div>\n</div>\n<div class=\"paragraph\">\n<p>The contents of our sample <em>Knowledge Item</em> looks like this:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-yaml\" data-lang=\"yaml\">ki\n  name: \"I decide that nothing should be done.\"\n  description: \"I decide that nothing should be done, and finish the task.\"\non\n  ogit/_type == \"ogit/Schedule/Calendar\"\nwhen\n  ogit/Automation/issueType == \"RescheduleMeetings\"\n  ProcessIssue\ndo\n  NumberOfMeetingsRescheduled = 0\n  delete(ProcessIssue)</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The next time the same task is sent to HIRO&#8482;, it will be handled by HIRO&#8482; with the new <em>Knowledge Item</em>. To demonstrate this, we create another automation task with the same content as before. Then we check the task status in the Task Viewer (IV) in the HIRO&#8482; user interface. The new task should be listed as <code>RESOLVED</code>.\nFinally, we use the API to check the task status and retrieve the number of rescheduled meetings (which is 0) from the <em>Information Variable</em> <code>NumberOfMeetingsRescheduled</code>:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">task_id = create_task('RescheduleMeetings', 'Reschedule meetings during my absence', calendar_node, {'/ProcessIssue':''})</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>And after waiting until the task has been completed:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">task = hiro.read_vertex(task_id)\nprint ('Task status: ' + task['ogit/status'])\nprint ('Number of rescheduled meetings: ' + task['/NumberOfMeetingsRescheduled'])</code></pre>\n</div>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code>Task status: RESOLVED\n'Number of rescheduled meetings: 0</code></pre>\n</div>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_summary\">Summary</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>To recap, we have learned how to submit an <em>Automation Task</em> to HIRO&#8482; for processing. An <em>Automation Task</em> is represented in HIRO&#8482; as a vertex of entity type <code>ogit/Automation/AutomationIssue</code>.\nThere are a few mandatory attributes that we need to specify for each task, i.e. task type, subject, and origin node.\nAttributes of an Automation Task are also called <em>Variables</em>, when used in <em>Knowledge Items</em>. There are two types of variables: <em>Todo Variables</em> and <em>Information Variables</em>.\nAs a developer you can use <em>Information Variables</em> to provide additional parameters for the task when sending it to HIRO&#8482;, and to read out relevant results after the task has been processed.\nA submitted <em>Automation Task</em> will only be processed by HIRO&#8482;, if we provide at least one <em>Todo Variable</em> (as an additional attribute) or else, HIRO&#8482; will mark it as <code>RESOLVED</code> without any actual action being performed.\nAfter entering a new task for the first time, there is typically no suitable knowledge in the knowledge base, so that a SME and an AI Expert will conduct a Teaching Session in the HIRO&#8482; Frontend, to teach HIRO&#8482; the required knowledge.\nThe next time we submit a task with the same contents, HIRO&#8482; will be able to solve it automatically.</p>\n</div>\n<div class=\"paragraph\">\n<p>Now you are ready to build your own connector to send new tasks to HIRO&#8482; for intelligent automation.</p>\n</div>\n</div>\n</div>","document":{"main":"Tutorial","title":"Tutorial: Working with Automation Tasks in HIRO","subtitle":"Working with Automation Tasks in HIRO"},"fields":{"toc":true,"location":["tutorials","automation-tasks"]}},"sidebarYaml":{"id":"0acf6fc1-95eb-5854-8f81-d5561b07a582","showIndex":null}},"pageContext":{"id":"a8daa0e9-c467-57f1-a844-efc3399c30d5","parent":"tutorials"}},"staticQueryHashes":["1010459453","1010459453","2356112386","2356112386","2603905930","2603905930","3026652197","3026652197","3167850324","3167850324","63159454","63159454"]}