Skip to main content

Lifecycle Hooks

Overview

Before registering a Skill in DDNA Studio and adding it a DDNA Studio project, the lifecycle hooks can be configured and mapped to the Skill Definition file. These hooks are endpoints that will be triggered at different stages once the Skill has been registered and added to a project.

Lifecycle

Diagram of the Skill Lifecycle showing when each Lifecycle Hook is called

  • Initialize
    • optional
    • triggered when a DDNA Studio project is deployed
  • Session
    • optional for stateless Skills
    • triggered when a session starts
  • Execute
    • required
    • triggered on each user turn within a session
  • Delete
    • optional
    • triggered when a Skill is removed from a project and the project is then redeployed
    • triggered when a project is deleted

Hooks

Initialize

(optional)

Each time a DDNA Studio project using the Skill is deployed, the Initialize hook is called. This hook allows for project-specific actions or processes to be run prior to the execution of the Skill at runtime.

This is an optional implementation where it can be used to implement any project-specific configurations, data storage, or pre-training that needs to be run in advance of the Skill being executed at runtime.

A Skill must therefore expect this hook to be called multiple times for the same project but with different config values, as the project may be redeployed with changes to the Skill's configuration or other parts of the project.

The endpoint for the Initialize hook should be mapped to endpointInitialize property in the Skill Definition file.

skill-definition.json
{
"name": "My NLP Adapter",
"summary": "Connects a third-party platform as a conversation provider",
"description": "",
"status": "ACTIVE",
"serviceProvider": "SKILL_API",
"endpointInitialize": "https://yourname.loca.lt/init",
"config": {
"skillType": "BASE_CORPUS"
}
}

Implement the Initialize endpoint in your service based on the API reference for Initialize.

app.ts
app.post('/init', async (req: Request, res: Response) => {
// Add your code here

res.send();
});

Session

(optional for stateless Skills)

Upon launching a project, a session is created. At this point, this optional Session hook is called once before the very first interaction between a user and the Digital Person. This hook establishes a session with a particular projectID/sessionID/config combination based on the project's configuration, and can also be used to initialize session-specific resources for stateful Skills.

While it is required for stateful Skills, the Session hook is optional for stateless Skills.

The endpoint for the Session hook should be mapped to endpointSession in the Skill Definition file.

skill-definition.json
{
"name": "My NLP Adapter",
"summary": "Connects a third-party platform as a conversation provider",
"description": "",
"status": "ACTIVE",
"serviceProvider": "SKILL_API",
"endpointSession": "https://yourname.loca.lt/session",
"config": {
"skillType": "BASE_CORPUS"
}
}

Implement the Session endpoint in your service based on the API reference for Session.

app.ts
app.post('/session', async (req: Request, res: Response) => {
// Add your code here

// Construct SM-formatted response body
const smResponse: SessionResponse = {
// ... add your code here
};

res.send(smResponse);
});

Execute

Subsequently, within the same session, the Execute hook is the primary endpoint that will be called when user requests are sent every turn. This hook should return a response to be actioned by the Digital Person.

Being the core of the lifecycle, this hook is triggered on every turn that user requests are sent. It should also return a response for the Digital Person to execute. As such, this is a required implmentation in order for the Skill to be able to handle the ongoing interactions between a user and a Digital Person.

The endpoint for the Execute hook should be mapped to endpointExecute in the Skill Definition file.

skill-definition.json
{
"name": "My NLP Adapter",
"summary": "Connects a third-party platform as a conversation provider",
"description": "",
"status": "ACTIVE",
"serviceProvider": "SKILL_API",
"endpointExecute": "https://yourname.loca.lt/execute",
"config": {
"skillType": "BASE_CORPUS"
}
}

Implement the Execute endpoint in your service based on the API reference for Execute.

app.ts
app.post('/execute', async (req: Request, res: Response) => {
// Add your code here

// Construct SM-formatted response body
const smResponse: ExecuteResponse = {
// ... add your code here
};

res.send(smResponse);
});

Delete

(optional)

The Delete hook is triggered by two mechanisms:

  1. When a Skill is removed from the project and the project is then redeployed.
  2. When a project using the Skill is deleted from Studio

This can be used to implement any clean-up actions for a Skill when it is no longer used by a project.

Skills that make use of the Initialize hook may find the Delete hook particularly useful for cleaning up any long-running tasks or stored data associated with project.

The endpoint for the Delete hook should be mapped to endpointEndProject in the Skill Definition file.

skill-definition.json
{
"name": "My NLP Adapter",
"summary": "Connects a third-party platform as a conversation provider",
"description": "",
"status": "ACTIVE",
"serviceProvider": "SKILL_API",
"endpointEndProject": "https://yourname.loca.lt/delete",
"config": {
"skillType": "BASE_CORPUS"
}
}

Implement the Delete endpoint in your service based on the API reference for Delete.

You can rename the first part of the path /delete to your preferring naming convention but it has to be able to take in the project ID at the end of the path.

Eg. DELETE /your-path/{projectId}

app.ts
app.delete('/delete/:projectId', async (req: Request, res: Response) => {
// Add your code here

res.send();
});