> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Customer support chatbot pattern

> Build customer support chatbots with Orq.ai. Create conversational AI with memory, context awareness, and intelligent escalation to human agents.

## Objective

A Chatbot provides a conversational AI solution for handling customer inquiries through natural language interactions. This document demonstrates how to build an intelligent support system using orq.ai, enabling automated responses to common questions while maintaining the ability to escalate complex issues to human agents.

## Use Case

Customer Support Chatbot is ideal for applications that need:

* **Automated Customer Service**: Handle common inquiries about orders, products, policies, and troubleshooting.
* **24/7 Availability**: Provide instant responses to customers outside business hours.
* **Conversation Memory**: Maintain context throughout multi-turn conversations for a better user experience.
* **Escalation Handling**: Intelligent routing to human agents when automated responses are insufficient.
* **Multi-Channel Support**: Deploy across web chat, mobile apps, or messaging platforms.

## Prerequisite

Before configuring a Chatbot, ensure you have:

* **orq.ai Account**: Active workspace in the AI Studio.
* **API Access**: Valid API key from [Workspace Settings > API Keys](/docs/administer/api-keys).
* **Model Access**: At least one conversational model enabled in the [AI Router](/docs/model-garden/overview), such as `gpt-4`, `claude-3-sonnet`, or `gpt-3.5-turbo`. See [Using the AI Router](/docs/model-garden/using-ui).

## Configuring a Deployment

To create a [Prompt](/docs/prompts/overview) for your chatbot, head to the AI Studio:

* Choose a [Project](/docs/projects/overview) and Folder and select the `+` button.
* Choose **Deployment**.
* Enter name **myChatbot**.
* Choose a primary **Model**.

Then configure your prompt messages. Click **Add Message** and select **System** role:

```
You are a helpful customer support assistant for TechShop, an online electronics retailer.

Your responsibilities:
- Answer questions about orders, products, returns, and company policies
- Be friendly, professional, and empathetic  
- If you cannot help with a specific issue, politely escalate to a human agent
- Always ask for order numbers when discussing specific orders
- Keep responses concise but informative

Company Information:
- Business hours: Monday-Friday 9AM-6PM EST
- Return policy: 30 days with receipt
- Free shipping on orders over $50
- Phone support: 1-800-TECHSHOP

When you cannot provide a specific answer, say: "Let me connect you with one of our specialists who can help you further."
```

<Frame caption="Configure your system message to define the chatbot's personality and capabilities.">
  <img src="https://mintcdn.com/orqai/dw2ZHifUWLDAlqTf/images/docs/80e6aecba08ae92c8ee08ed70ccf8c7dd9fe8746ee5b40ac6a287f641d69c946-image.png?fit=max&auto=format&n=dw2ZHifUWLDAlqTf&q=85&s=52be008162879ced0410cdf4bf7ee6f2" alt="Deployment editor for myChatbot with a system prompt defining a TechShop customer support assistant with responsibilities and company information." width="1440" height="991" data-path="images/docs/80e6aecba08ae92c8ee08ed70ccf8c7dd9fe8746ee5b40ac6a287f641d69c946-image.png" />
</Frame>

Open the **Test** tab to test responses for your chatbot.

<img src="https://mintcdn.com/orqai/dw2ZHifUWLDAlqTf/images/docs/78f385d6906e196cd92e9b403f70053e152777b63cd3537eec9bfa86506cb4bf-Screenshot_2025-08-14_at_14-07-05_orq.ai_Prompt_Studio.png?fit=max&auto=format&n=dw2ZHifUWLDAlqTf&q=85&s=e968b7cc236bc12fa1479005c1863ef2" alt="Deployment editor showing the myChatbot system prompt alongside a live chat preview with a user asking about Friday hours." width="1699" height="991" data-path="images/docs/78f385d6906e196cd92e9b403f70053e152777b63cd3537eec9bfa86506cb4bf-Screenshot_2025-08-14_at_14-07-05_orq.ai_Prompt_Studio.png" />

<Info>
  Learn more about the possibilities of Prompts in Orq.ai, see [Creating a Prompt](/docs/prompts/creating).
</Info>

<Check>
  When ready with your Deployment choose **Deploy**, learn more about [Deployment Versioning](/docs/deployments/creating#versioning).
</Check>

## Integrating with the SDK

Choose your preferred programming language and install the corresponding SDK:

<CodeGroup>
  ```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
  pip install orq-ai-sdk
  ```

  ```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
  npm install @orq-ai/node
  ```
</CodeGroup>

Get your integration ready by initializing the SDK as follows:

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  from orq_ai_sdk import Orq

  client = Orq(
      api_key=os.environ.get("ORQ_API_KEY", "__API_KEY__"),
      environment="production",
      identity_id="customer_support" # optional
  )
  ```

  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const client = new Orq({
      apiKey: process.env.ORQ_API_KEY || "__API_KEY__",
      environment: "production",
      identityId: "customer_support" // optional
  });
  ```
</CodeGroup>

To create a conversational Chatbot that maintains context, implement conversation memory:

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  class CustomerSupportBot:
      def __init__(self, client, deployment_key):
          self.client = client
          self.deployment_key = deployment_key
          self.conversation_memory = []
      
      def chat(self, user_message):
          """Send a message to the chatbot and get response"""
          # Add user message to conversation history
          self.conversation_memory.append({
              "role": "user", 
              "content": user_message
          })
          
          try:
              # Invoke the deployment with conversation history
              generation = self.client.deployments.invoke(
                  key=self.deployment_key,
                  messages=self.conversation_memory,
                  metadata={
                      "session_id": "unique_session_id",
                      "user_type": "customer"
                  }
              )
              
              # Extract the assistant's response
              assistant_message = generation.choices[0].message.content
              
              # Add assistant response to conversation history
              self.conversation_memory.append({
                  "role": "assistant",
                  "content": assistant_message
              })
              
              return assistant_message
              
          except Exception as e:
              return "I'm sorry, I'm having technical difficulties. Please contact support at 1-800-TECHSHOP."
      
      def reset_conversation(self):
          """Reset conversation for a new customer"""
          self.conversation_memory = []

  # Initialize and use the chatbot
  bot = CustomerSupportBot(client, "myChatbot")
  response = bot.chat("Hi, are you opened next Friday?")
  print(response)
  ```

  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  class CustomerSupportBot {
      constructor(client, deploymentKey) {
          this.client = client;
          this.deploymentKey = deploymentKey;
          this.conversationMemory = [];
      }

      async chat(userMessage) {
          // Add user message to conversation
          this.conversationMemory.push({
              role: "user",
              content: userMessage
          });

          try {
              const response = await this.client.deployments.invoke({
                  key: this.deploymentKey,
                  messages: this.conversationMemory,
                  metadata: {
                      session_id: "unique_session_id",
                      user_type: "customer"
                  }
              });

              const assistantMessage = response.choices[0].message.content;
              
              // Add assistant response to conversation
              this.conversationMemory.push({
                  role: "assistant",
                  content: assistantMessage
              });

              return assistantMessage;

          } catch (error) {
              return "I'm sorry, I'm having technical difficulties. Please contact support.";
          }
      }

      resetConversation() {
          this.conversationMemory = [];
      }
  }

  // Initialize and use the chatbot
  const bot = new CustomerSupportBot(client, "myChatbot");
  const response = await bot.chat("Hi, are you opened next friday ?");
  console.log(response);
  ```
</CodeGroup>

Here is what the output looks like:

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
   ❯ python3 chatbot.py
  Yes, we're open on Fridays! Our business hours are Monday through Friday, 9AM to 6PM EST.

  Is there anything I can help you with regarding your order or our products today?
  ```
</CodeGroup>

## Viewing Logs

Going back to the [Deployment](/docs/deployments/overview) page, you can view the calls made through your chatbot application. You can view details for a single log by clicking on a log line. This opens a panel containing all the details for the log, including context, requests, and parameters sent to your [Deployment](/docs/deployments/overview).

<img src="https://mintcdn.com/orqai/dw2ZHifUWLDAlqTf/images/docs/90eb8e3cde9129544542684c552b83425366f26ec4970fb45c774c5395be22b7-image.png?fit=max&auto=format&n=dw2ZHifUWLDAlqTf&q=85&s=bc7414ca2a367a8faefcb9b66db0e783" alt="Logs table showing five gpt-3.5-turbo requests with 200 status, latency between 1.4s and 2.6s, and cost around 0.0001-0.0002 each." width="2964" height="554" data-path="images/docs/90eb8e3cde9129544542684c552b83425366f26ec4970fb45c774c5395be22b7-image.png" />

Monitor your chatbot's performance by tracking:

* Response times and success rates
* Common customer questions and patterns
* Escalation frequency to human agents
* User satisfaction and conversation completion rates

<Info>
  To learn more about logs see [Logs](/docs/observability/logs).
</Info>
