Sitemap

Logic in Chatbots: Business vs Interaction

Sean Wu
4 min readDec 2, 2024

Separating business logic from interaction logic is essential for building GUI applications. One could argue that the same separation is equally valuable for chatbot development. Unfortunately, this separation is not emphasized enough within the conversation designers community, and these two concepts are often used interchangeably, leading to unnecessary confusion when interacting with product managers and developers. In this blog, we’ll explore the differences between business logic and interaction logic in the context of chatbots, with examples to illustrate how they work together.

What is Business Logic?

Business logic represents the core functionality and rules of an application. It defines how data is processed, validated, and manipulated according to business requirements. This logic is independent of how users interact with the system and focuses on ensuring the application behaves correctly in various scenarios.

Consider an e-commerce application where customers can place buy movie tickets. The business logic might look like this:

data class Order(
val movie: Movie,
val showTime: LocalDateTime,
val customer: Customer)

fun calculateOrderTotal(order: Order): Double {
if (hasSeat(movie, showTime) == false) raise RuntimeException("no seat")
val discount = if (order.customer.isLoyalCustomer()) 0.1 else 0.0
val total = order.items.sumOf { it.price * it.quantity }
return total - (total * discount)
}

Here, the business logic ensures that seats are still available for the ticket order at the given showtime, calculates the order total, and applies a discount if the customer is loyal. This logic is independent of how or where the customer places the order (web, mobile app, chatbot, etc.).

What is interaction logic?

In general, interaction logic handles how users interact with the application. In a chatbot, interaction logic — commonly known as dialog management — controls the conversation flow. It determines how the chatbot interacts with users, including handling different user intents, maintaining context, and guiding the conversation, with the goal of creating API calls that serve the user well while meeting the requirements of the business logic.

Continuing with the ticketing chatbot, to guide the user in successfully ordering a ticket through conversation, we need to ensure that seats are still available for the selected movie and showtime. There are several ways to design the interaction for this. For example, we can add a value check after the user selects the showtime:

User: I'd like to get two tickets for Star Wars.
Bot: What time?
User: How about 8:00pm?
Bot: Sorry, the 8:00pm show is sold out. There are still
seats available for 10:00pm, do you want that instead?
User: Yes, please.
Bot: Would you like the front seats or the back ones?

Another way to ensure seat availability for a ticket order is by adding a recommended value when prompting the user for a showtime. By providing a list of options based on the production database, we can make it easier for the user to select a valid option:

User: I'd like to get two tickets for Star Wars.
Bot: What time? We still have seats available for 6:00pm and 10:00pm.
User: How about 10:00pm?
Bot: Would you like the front seats or the back ones?

In these examples, the interaction logic is designed to guide the conversation toward a successful ticket order as quickly as possible. Business-logic-aware interaction logic can help users avoid frustrating, unproductive conversations while also achieving business objectives by leveraging upsell opportunities when available.

Separating Business Logic from Interaction Logic

Business logic implements business rules and processes and typically resides in the backend or service layer. It is designed by business or product owners to serve various user interfaces and does not directly depend on interaction logic.

Interaction logic manages the conversation flow and user interactions based on user experience and business objectives. It should be language-independent, ensuring users have a consistent conversational experience regardless of the language they speak. Typically, interaction logic resides in the dialog management module as part of the chatbot frontend. Interaction logic should depend on business logic and is the responsibility of product managers and conversation designers.

While conversation designer does not have final say at architecture level of the chatbot/agent, they can promote separation of business logic and interaction logic in the following way:

  1. If some logic is needed by other frontend like mobile app, that logic is business logic and should be kept in the backend. Do not let such business rules seep into the conversational layer. This ensures that users get consistent services across different touch points.
  2. Design the interaction logic based on a well-defined API interface rather than its implementation. By mapping user intents to the carefully designed API interface, we ensure that the resulting natural and intuitive conversational experience remains resilient to changes in the business logic implementation in the backend.
  3. Document Both Layers: Maintain clear documentation for both business logic and interaction logic to ensure smooth collaboration between developers and conversation designers.

Conclusion

In chatbot development, business logic and interaction logic serve distinct yet complementary roles. Business logic focuses on the “what” — the rules and data processing required to fulfill user requests. Interaction logic focuses on the “how” — guiding the conversation to effectively create the calls into backend APIs. By separating these concerns, developers can build chatbots that are more maintainable, scalable, and capable of delivering accurate and engaging user interactions across different platforms. When you build chatbot/agent, make sure you pick a framework that has built-in support for such separation.

--

--

No responses yet