1. Template Guidelines
  2. Message Flow

Template Guidelines

Message Flow

Explains how a message travels between a notification platform, the _create and default contexts and the LLM, and how stubsessions route replies.

A typical agent conversation is facilitated by the Stubber Platform using the built-in communication platforms (notification platforms), stubsessions and the template contexts.

The Whatsapp example below is typical of how every notification platform works.

First message

  1. A message is sent to a Whatsapp number that is configured on a Whatsapp profile in Stubber.
  2. The Whatsapp integration uses the profile to look up the stubref of the stub to trigger the feedback action on. This is typically a _create context stub.
  3. The integration triggers _update_from_whatsapp on that stub. stubpost.message is the incoming message text, and stubpost.data holds information about the message, including the from number and profile name.
  4. The _update_from_whatsapp action on the _create context has a task that creates a new default context stub and passes all the data into it.
  5. The new default context stub triggers the _create lifecycle action when it is created.
  6. The _create action has a gpt_chat_task that initializes the LLM chat with a system message, and might inject the Whatsapp message as a user role message.

Reply from the LLM

  1. The task submits to the specified LLM model. When the reply is received, the _update_from_chat_assistant_task feedback action is triggered, with stubpost.message set to the reply.
  2. _update_from_chat_assistant_task has a notification that sends a Whatsapp message to the incoming number, with the message set to the reply from the LLM.
  3. The notification also sets a new stubsession on the incoming Whatsapp number, with a timeout in hours:
        "stubsession": {
  "set_new_with_timeout_hours": 24
}

      

Conversational loop

  1. When the user replies, the Whatsapp integration sees the active stubsession and triggers _update_from_whatsapp directly on the default context stub.
  2. The _update_from_whatsapp action on the default context has a gpt_chat_task that relays the incoming message to the LLM chat.
  3. The user and the LLM can now chat over Whatsapp. Each outgoing message resets the stubsession timeout another 24 hours into the future (or more if set otherwise).

Summary

  • Initial messages trigger a feedback action on a _create context stub.
  • A default context stub is created per conversation.
  • A gpt_chat_task on the platform's feedback action passes the user message to the LLM.
  • The _update_from_chat_assistant_task action routes notifications back out on the relevant platform.
  • The stubsession set on outgoing notifications routes later replies straight to the default context stub.