LogoLogo
Github
  • 🚀Getting Started
    • About Jugalbandi Manager
  • Introduction
    • About OpenyAI
    • What is Jugalbandi?
    • Why dive in: How will this playbook help you?
    • Importance and Relevance of Jugalbandi
    • Key Principles powering Jugalbandi
    • Demystifying Jugalbandi: What Jugalbandi isn’t?
  • Breaking Down Jugalbandi's Anatomy
    • Jugalbandi Manager: Your companion for building and managing AI services
    • Jugalbandi’s Key Services
    • Key Features for Enhancing Security and Privacy
  • Building with Jugalbandi
    • Technical Guide
      • explanations
        • JB Manager Architecture
        • Explanations
      • how-tos
        • Local Development
        • Write Your Own Bot
        • How to Guides
      • references
        • Dependencies
        • FSMOutput
        • References
        • Speech and Translation
        • Azure Storage
        • Whatsapp
        • Telegram
        • example-grievance-bot
          • Example Grievance Bots
      • tutorials
        • Tutorials
        • Quickstart
    • Getting Started
    • Local Development / Writing your own bot
    • Dependencies
    • Configuring the FSM to modify flows
    • Cost of building with Jugalbandi
    • Tips and Best Practices / FAQs (Including best practices for creating a knowledge base)
  • Use cases of Jugalbandi
    • Jugalbandi for Access to Legal Information
    • Jugalbandi for Govt. Schemes
    • Accessing Legal Services
    • Jugalbandi for Grievance Redressal
    • Climate Action with Wildlife First
    • Affordable Housing with Bandhu
    • Paralegal Services with Nyaya Mitra
    • UNESCO X Jugalbandi
  • Is Jugalbandi Manager Applicable to your Use case?
    • The versatile applications of Jugalbandi
    • Some other example use cases
  • Possibilities and Future Directions
    • Potential Technological Advancements
    • Jugalbandi Studio: Building with AI has never been more accessible
  • Community and Collaboration
    • Understanding the community-led spirit of our mission
    • Our current collaborators and community
  • Get Involved
    • How can volunteers contribute?
    • How can maintenance of the stack be open-sourced?
    • Technical Support and Contact Information
Powered by GitBook
On this page
  • Architecture
  • DB Structure
  • Services

Was this helpful?

Edit on GitHub
Export as PDF
  1. Building with Jugalbandi
  2. Technical Guide
  3. explanations

JB Manager Architecture

PreviousexplanationsNextExplanations

Last updated 9 months ago

Was this helpful?

This document explains the inner workings of the JB Manager.

Architecture

All the services are generic i.e. they are designed for multiple bots or use cases. The only customization that exists lies in the tiny bot code (finite state machine code) which is published by the Studio.

To change this diagram edit this

DB Structure

Bot

bot_id (e.g. "12345") is at the highest level. All other entries like person, sessions are against a particular bot. We support multiple bots from the same backend.

User

A user needs to be registered for the bot. Phone Number & Bot ID make the user unique.

Session

This table stores the state (stage in the workflow) and variables for every user. We maintain session for 24 hours. After that a fresh conversation starts.

Turn

Every message received from the user creates a new turn in the conversation. Against one user message, we can have multiple bot responses.

Message

Every message received or sent is logged to the DB.

Services

API

Provides APIs to interact with JB Manager. Here are the top buckets of APIs:

  1. Callback from channels like WhatsApp or Telegram

  2. JB Studio like publishing the bot

  3. Managing bots changing their states and variables

  4. Viewing chat logs and analytics

  5. Triggering indexing jobs

Callback

  1. Figure out bot_id based on the callback

  2. Create person if doesn't exists. Fetch pid

  3. Create session_id if session has expired (> 24 hours).

  4. Creates turn_id for the new conversation

  5. Create msg_id

Channel

Responsible for both input and output communication with the channel (WhatsApp / Telegram). It needs to handle channel specific API calls and rendering of UI messages (e.g. WhatsApp Flow, List & Buttons)

  1. If media present in the message, fetch and upload to Azure.

  2. Provides standard dialogues (list/buttons) for features that are common to all bots. It handles rendering (outbound) and the related user action. It let's Flow service know that the user has completed a dialogue.

    1. Language - It shows the dialog and saves the user's language preference

    2. Reset (not yet there)

In the inbound scenario:

  • It mostly enqueues messages for the Language service

  • Unless the message related to a dialogue (e.g. language), WhatsApp Flow or Button. In this case it directly talks to the Flow service.

In the outbound scenario:

  • It mostly receives messages from the Language service.

  • Unless the message is related to WhatsApp flow in which case Flow directly writes to it's queue.

Language

  1. There are two flows:

    1. Receiving users message

    2. Sending the response to the user.

It's responsible for translating labels in case of interactives messages e.g. Lists & Buttons

We assume that all messages sent by the user obey the user's preferred_language.

For outbound messages, Language service will look at the message type from the Flow Service and then decide on the following:

  1. If text

    1. Then fetch details about the turn -- In what mode did the user ask their question:

      1. If user asks in text / form / interactive, we respond in text

      2. If user asks in voice, we respond in voice + text -- Language service creates two inputs for Channel service

      3. In all other cases, send text

  2. If document,

    1. Translate the caption

  3. image

  4. Translate the caption

  5. If interactive

    1. Translate the text, header, footer

    2. Translate the labels for buttons

Flow

  1. Retrieve session from DB based on session_id. This provides it memory of the current state (stage of the workflow), variables.

  2. Process the message via a finite state machine code (this code is generated in the Studio and pushed to the JB Manager)

    1. It can send multiple messages for every user message

    2. It can make API calls or use plugins

    3. The responses that it sends can include the following:

      1. Text

      2. Interactive - WhatsApp flow, List, Buttons

      3. Documents, Images

      4. Dialogues -- it uses keywords language to trigger Channel service into sending a standardized dialogue.

  3. On complete (or logical pause in the workflow e.g. user input or plugin input), save the state and variables.

Retrieval

This fetches data from the Vector DB (PG Vector / Postgres) based on query and metadata if any. The metadata is used to create filter query to restrict the similarity search even further.

Indexer

This service receives input files (urls from Azure) and pre-processes them and indexes them into the Vector DB.

file