How we built our Support AI Assistant for Google Workspace with Apps Script, Gen AI and Google Chat

Stéphane Giron
5 min readOct 20, 2023

With the rise of LLM and Generative AI we tested multiple model to view if this agent can provide some help in the way we handle Workspace support for our clients. As many people agree, Bard and ChatGPT are good to answer questions. But let’s be real, they excel more with basic queries rather than complex or niche topics.

Mascot AI generated with Google Imagen

At the origin

Our first steps in LLM world for support was just asking the LLM to answer our questions. We just customised a bit the ptrompt to focus on Google Workspace topics. Even if answers were interesting, use them in our daily work was not efficient for 2 main reasons :

  1. We treat advanced questions, really technical and answers were not enough precise for us, quality was not at the level expected.

2. We can’t check source of the answer provided. That lead us to spend more time validate answer is good than use it. This is part of the halucination effect in LLM.

To be honest it was a bit deceptive but lead us to better understand how LLM works and how we can benefits of this technology, because we think it is really a game changer.

The solution we work on was to provide high quality content in the context of the request to LLM and ask the LLM to answer the question using this content to generate the appropriate answer.

Support AI assistant presentation

Initial integration we made was to push AI Assistant answer in our support platform directly. It was nice to have the answer in the support tool but we really missed an on-demand solution. That is why we finally decide to implement our Assistant in Google Chat. Below the technology we used.

Google Chat is a standalone app but also integrated in Gmail which is really convenient to query our assistant when we want without moving to another application.

Google Custom Search Engine (CSE), we use it to get results that match the question. As said at the begining we need fresh content with last update and high quality content. That is why we use CSE to get relevant web pages from Google Web Search engine.

Cloud Functions, once we have the web pages, we use a cloud functions to scrap the content of the pages.

Google Apps Script, all is running with App Script. Super easy to build a Chat App for Google Chat and perfect to connect to multiple services with UrlFetchApp method.

Support AI assistant diagram

The construction is almost describe above but the detailed view is below.

Support AI Assistant technical highlights

Custom Search Engine

For Google Custom Search Engine you need an API Key, check this link. The apps script code is quite simple :

let txt = "search terms";
let url = "https://customsearch.googleapis.com/customsearch/v1?cx=YOUR_CX&q="+encodeURIComponent(txt)+"&key=YOUR_APIKEY";
let param = {
method : "get",
muteHttpExceptions:true,
};
let html = UrlFetchApp.fetch(url,param).getContentText();
let rep = JSON.parse(html);

From the Custom Search Engine you will need the “cx” reference and the API Key. In free version you have a 10k query limit per day which is really large.

Cloud Functions

We use “axios” and ‘html-to-text” module in node.js. Sample code looks like :

axios.get(url).then((response) => {
const text = convert(response.data, {
selectors: [
{ selector: 'header', format: 'skip' },
{ selector: 'a',format :'anchor', options: {ignoreHref:true, linkBrackets : false } }
]
});

Prompt

We use a simple prompt with the content from the web page in it :

You are a Google Workspace Agent Support. You are working for Devoteam G Cloud a Google Workspace reseller. Use the following pieces of context to answer the user question. Take note of the sources and include them in the answer in the format: “SOURCES: source1 source2”, use “SOURCES” in capital letters regardless of the number of sources. You create the answer using the source provided, if source provided is not relevant just share the link in your answer. Don\t try to invent an answer.\n — — — — — — — — \n

We add the source from the web page after this prompt and all his added in the “System” field of the API Call. The message sent is just the data we get from Google Chat.

Our main take aways

Initial issues

If you remember we had 2 main issues after our firsts tests, quality of answer and halucinations.

Regarding these 2 points we have seen a really huge improvement, quality is really better and halucinations still remain at some points but are really weak. For example in a 10 steps process, we can have 1 or 2 steps not completely rights, but global answer is coherent.

Personal remarks

I mainly use the bot to get a first answer when I need a confirmation. As Google Workspace expert we have deep knowledge in Workspace but sometimes you need to validate a point. The bot is really great for that, it answer our question and we have the page to check if we aren ot aligned with the answer. Really great to summarize the web page for a specific topic.

Will it replace an agent, for sure not. The bot is shared internally at Devoteam G Cloud and I can see that Sales people do not have the same level of answers. Google Workspace expert know the support pages and we can ask oriented question to point to a specific topic. Which is not the case for Sales people, they get interesting aswers but they don’t benefits at the bot at its max capabilities.

I’m really amazed by the capacity of the LLM, we tried Bison model from Google and ChatGPT from Open AI and both are really great.

We are extending the capacity to Terms of Service, News, AppSheet, etc… and it goes well, results remain interesting.

This is an custom solution but on Google Cloud side we have an amazing tool we are currently testing, “Search & Conversation” known previously as Gen App Builder. It will let you build a chat bot that will answer question based on content you push in a bucket for example. Really promising feature.

You have a project, let’s discuss it : book a slot.

--

--