Mycroft AI
  • Documentation
  • About Mycroft AI
    • Why use Mycroft AI?
    • Glossary of terms
    • Contributing
    • FAQ
  • Using Mycroft AI
    • Get Mycroft
      • Mark II
        • Mark II Dev Kit
      • Mark 1
      • Picroft
      • Linux
      • Mac OS and Windows with VirtualBox
      • Docker
      • Android
    • Pairing Your Device
    • Basic Commands
    • Installing New Skills
    • Customizations
      • Configuration Manager
      • mycroft.conf
      • Languages
        • Français (French)
        • Deutsch (German)
      • Using a Custom Wake Word
      • Speech-To-Text
      • Text-To-Speech
    • Troubleshooting
      • General Troubleshooting
      • Audio Troubleshooting
      • Wake Word Troubleshooting
      • Log Files
      • Support Skill
      • Getting more support
  • Skill Development
    • Voice User Interface Design Guidelines
      • What can a Skill do?
      • Design Process
      • Voice Assistant Personas
      • Interactions
        • Intents
        • Statements and Prompts
        • Confirmations
      • Conversations
      • Error Handling
      • Example Interaction Script
      • Prototyping
      • Design to Development
    • Development Setup
      • Python Resources
      • Your First Skill
    • Skill Structure
      • Lifecycle Methods
      • Logging
      • Skill Settings
      • Dependencies
        • Manifest.yml
        • Requirements files
      • Filesystem access
      • Skill API
    • Integration Tests
      • Test Steps
      • Scenario Outlines
      • Test Runner
      • Reviewing the Report
      • Adding Custom Steps
      • Old Test System
    • User interaction
      • Intents
        • Padatious Intents
        • Adapt Intents
      • Statements
      • Prompts
      • Parsing Utterances
      • Confirmations
      • Conversational Context
      • Converse
    • Displaying information
      • GUI Framework
      • Show Simple Content
      • Mycroft-GUI on a PC
      • Mark 1 Display
    • Advanced Skill Types
      • Fallback Skill
      • Common Play Framework
      • Common Query Framework
      • Common IoT Framework
    • Mycroft Skills Manager
      • Troubleshooting
    • Marketplace Submission
      • Skills Acceptance Process
        • Information Review Template
        • Code Review Template
        • Functional Review Template
        • Combined Template
      • Skill README.md
    • FAQ
  • Mycroft Technologies
    • Technology Overview
    • Roadmap
    • Mycroft Core
      • MessageBus
      • Message Types
      • Services
        • Enclosure
        • Voice Service
        • Audio Service
        • Skills Service
      • Plugins
        • Audioservice Plugins
        • STT Plugins
        • TTS Plugins
        • Wake Word Plugins
      • Testing
      • Legacy Repo
    • Adapt
      • Adapt Examples
      • Adapt Tutorial
    • Lingua Franca
    • Mimic TTS
      • Mimic 3
      • Mimic 2
      • Mimic 1
      • Mimic Recording Studio
    • Mycroft GUI
      • Remote STT and TTS
    • Mycroft Skills Kit
    • Mycroft Skills Manager
    • Padatious
    • Precise
    • Platforms
Powered by GitBook
On this page
  • __init__
  • Initialize
  • Converse
  • Stop
  • Shutdown

Was this helpful?

  1. Skill Development
  2. Skill Structure

Lifecycle Methods

Mycroft Skills provide a number of methods to perform actions at different points during the lifecycle of the Class instance.

PreviousSkill StructureNextLogging

Last updated 5 years ago

Was this helpful?

The MycroftSkill class that all Skills inherit from contains a number of methods that can be overridden by an instance of the Class. This enables a Skill to execute code at specific points in the lifecycle of a Skill. Each of these is optional, meaning none are required to be defined in your Skill.

__init__

The __init__ method is called when the Skill is first constructed. It is often used to declare variables or perform setup actions, however it cannot utilize other MycroftSkill methods and properties as the class does not yet exist. This includes self.busand self.settings which must instead be called from your Skill's initialize method.

Th __init__ method is optional, but if used, the __init__ method from the Super Class (MycroftSkill) must be called.

In the following example we assign a variable learning to be True. The variable is appended to the instance using self so that we can access this variable in any part of our Skill.

    def __init__(self):
        super().__init__()
        self.learning = True

Initialize

The initialize method is called after the Skill is fully constructed and registered with the system. It is used to perform any final setup for the Skill including accessing Skill settings.

In the following example we access the my_setting value, that would have been defined in the Skill's . We use the get method in case the variable my_setting is undefined.

    def initialize(self):
        my_setting = self.settings.get('my_setting')

Converse

The converse method can be used to handle follow up utterances prior to the normal intent handling process. It can be useful for handling utterances from a User that do not make sense as a standalone .

The method receives two arguments:

  • utterances (list): The utterances from the user. If there are multiple utterances, consider them all to be transcription possibilities. Commonly, the first entry is the raw utterance and the second is a normalized version of the first utterance.

  • lang (string): The language the utterance is in. This defaults to None.

Once the Skill has initially been triggered by the User, the converse method will be called each time an utterance is received. It is therefore important to check the contents of the utterance to ensure it matches what you expected.

If the utterance is handled by the converse method, we return True to indicate that the utterance should not be passed onto the normal intent matching service and no other action is required by the system. If the utterance was not handled, we return False and the utterance is passed on first to other converse methods, and then to the normal intent matching service.

In the following example, we check that utterances is not empty, and if the utterance matches vocabulary from understood.voc. If the user has understood we speak a line from great.dialog and return True to indicate the utterance has been handled. If the vocabulary does not match then we return False as the utterance should be passed to the normal intent matching service.

    def converse(self, utterances, lang):
        if utterances and self.voc_match(utterances[0], 'understood'):
            self.speak_dialog('great')
            return True
        else:
            return False

Stop

The stop method is called anytime a User says "Stop" or a similar command. It is useful for stopping any output or process that a User might want to end without needing to issue a Skill specific utterance such as media playback or an expired alarm notification.

In the following example, we call a method stop_beeping to end a notification that our Skill has created.

    def stop(self):
        self.stop_beeping()

Shutdown

The shutdown method is called during the Skill process termination. It is used to perform any final actions to ensure all processes and operations in execution are stopped safely. This might be particularly useful for Skills that have scheduled future events, may be writing to a file or database, or that have initiated new processes.

In the following example we cancel a scheduled event and call a method in our Skill to stop a subprocess we initiated.

    def shutdown(self):
        self.cancel_scheduled_event('my_event')
        self.stop_my_subprocess()
settingsmeta.json
intent