This application demonstrates a simple videocall with a Health Care Consultant persona. The application uses Tavus CVI to create an interactive AI host that responds to user inputs and performs actions through tool calls.

Prerequisites

Ensure that you have installed:

  • Node.js

Getting Started

1

Clone the Sample Project

git clone https://github.com/Tavus-Engineering/tavus-examples.git
2

Run the Sample Project

  1. Navigate to examples > health-consultation-with-tavus folder.
  2. Install modules:
npm i
  1. Run the project:
npm run start
  1. Navigate to the localhost:3000/health-consultation-with-tavus/.
  2. Enter your name and click General Health or Skin & Dermatology.

Tool Call Flow

Here’s a quick overview of how tool calls work in this Health Consultation app:

1

User Command Detected

The user says What is the cure to X ?to the replica. The application listens for messages using:

call.on('app-message', handleAppMessage);
2

Tool Call Detection

  1. The replica triggers the get_cures tool:
if (message.message_type === 'conversation' && message.event_type === 'conversation.tool_call') {
  const toolCall = message.properties;
  
    if (toolCall.name === 'get_cures') {
        try {
          const args = JSON.parse(toolCall.arguments);
          const disease = args.disease;
          console.log('User wanted to know cures for', disease);
          
          const diseaseclear = disease.trim().toLowerCase();
          const cure = cureFor[diseaseclear];
          
          const responseMessage = {
            message_type: "conversation",
            event_type: "conversation.echo",
            conversation_id: message.conversation_id,
            properties: {
              text: `The cure for ${disease} is ${cure}.`
            }
          };

          console.log('Sending echo message:', responseMessage);
          
          // Use the call object to send app message
          const call = callRef.current;
          if (call && typeof call.sendAppMessage === 'function') {
            call.sendAppMessage(responseMessage, '*');
            console.log('Message sent successfully');
          } else {
            console.error('Call object is not available or sendAppMessage method is missing');
          }
        } catch (error) {
          console.error('Error in processing cure request:', error);
        }
      }
}
  1. The app then try to search the cure based on a defined dictionary:
const cureFor = {
  "cold": "Paracetamol",
  "flu": "Oseltamivir",
  "asthma": "Salbutamol",
  "migraine": "Sumatriptan",
  "depression": "Fluoxetine",
  "epilepsy": "Sodium Valproate"
};

const diseaseclear = disease.trim().toLowerCase();
const cure = cureFor[diseaseclear];
3

Application Responds

  1. Once the result is generated, the app constructs and sends an echo message back to the replica:
const responseMessage = {
  message_type: "conversation",
  event_type: "conversation.echo",
  conversation_id: message.conversation_id,
  properties: {
    text: `The cure for ${disease} is ${cure}.`
  }
};

call.sendAppMessage(responseMessage, '*');

  1. The replica receives the echo message and replies: The cure for cold is Paracetamol.