ridergeek/-ride,code,repeat
All journal entries
Technology / 2026-10-04

No Now Assist? We Built Our Own AI Layer in ServiceNow with Gemini

Every ServiceNow team I talk to wants the same thing: AI that saves agents time. Summarize this long incident. Tell me what's in this attachment. Give me the gist so I can act.

ServiceNow's answer is Now Assist, and it is a capable product. But it is also an additional license, and not every organization is ready to buy it.

Our situation was common. We did not have Now Assist. We did have a Google Cloud Platform (GCP) footprint, and we could create a Gemini API key in Google AI Studio.

So we asked a simple question: can we get useful AI features inside ServiceNow using only what the platform already gives us, plus Gemini?

The answer was yes. This article walks through what we built, how it works, and what we learned.

THE GOAL

We wanted three things:

1. Let a user summarize a document attached to a record (Incident, RITM, and so on) with one click.

2. Let a user summarize the record itself.

3. Keep it cheap, controlled and easy to maintain.

THE ARCHITECTURE AT A GLANCE

The whole solution uses standard ServiceNow building blocks:

- UI Action

- UI Page

- Script Include

- REST Message

- Three custom tables (prompt repository, response cache, plus standard attachments)

- An archiving/cleanup rule

The flow looks like this:

User on record -> UI Action -> UI Page -> Script Include -> REST Message -> Gemini API -> summary back to the UI Page -> optional Work Note.

Let's go through each piece.

STEP 1: THE UI ACTION

We added a UI Action button, for example "Summarize with AI", on the records where it makes sense (Incident, RITM and others). Because UI Actions are configured per table, rolling this out to more record types is simple.

Clicking the button opens a UI Page in a dialog.

STEP 2: THE UI PAGE

The UI Page is the user's workspace. It does two jobs:

Attachment summarization

- It lists all attachments on the current record.

- The user selects one attachment. We deliberately allow one document per request. It keeps responses focused, predictable and cheaper.

Record summarization

- The same page offers a summary of the record's own fields and activity, using a very similar flow.

When the summary comes back, it appears in a text area. The user can read it and even edit it before doing anything with it.

STEP 3: THE SCRIPT INCLUDE

This is the brain of the solution. One reusable Script Include handles:

- Fetching the selected attachment from the attachment table

- Reading its content and encoding it to Base64

- Checking the cache for an existing answer

- Loading the right prompt from the prompt repository

- Calling the REST Message

- Saving the new response to the cache

- Returning the summary to the UI Page

Keeping all of this logic in one place means the UI stays thin and the AI logic is easy to test and change.

A simplified idea of the encoding step:

var attachmentApi = new GlideSysAttachment();

var bytes = attachmentApi.getBytes(recordGr, attachmentSysId);

var base64Content = GlideStringUtil.base64Encode(bytes);

(This is illustrative. Always validate file size and type in your real implementation.)

STEP 4: THE REST MESSAGE TO GEMINI

We created a REST Message that points to the Gemini API endpoint, with the required configuration and authentication, using the API key generated in Google AI Studio.

The Script Include calls this REST Message and sends:

- The Base64-encoded document

- The prompt text

Gemini reads the document, follows the prompt, and returns a summary.

A security note: because the call is made server-side from the Script Include, the API key never reaches the user's browser. Store it securely using the platform's credential mechanisms, not in plain text inside scripts.

STEP 5: THE PROMPT REPOSITORY

This was one of our favorite decisions.

Instead of hard-coding prompts in scripts, we created a custom table that acts as a prompt repository. Each row holds a prompt, what it applies to (attachment or record), and whether it is active.

Why it matters:

- Prompt tuning needs no code change or deployment.

- Prompts are easy to review, approve and audit.

- Different record types can have different prompts.

- Teams can improve results over time without touching the integration.

In AI projects, prompts change far more often than code. Treating them as managed data pays off quickly.

STEP 6: THE RESPONSE CACHE

AI calls cost tokens, and users often ask for the same summary more than once.

So we created another custom table to store every AI response. Before calling Gemini, the Script Include checks whether the same attachment has already been summarized.

- Cache hit: return the stored response instantly. No API call, no tokens used.

- Cache miss: call Gemini, store the result, return it.

The benefits are lower token consumption, faster responses for repeat requests, and a reduced load on the API.

STEP 7: THE 7-DAY RETENTION RULE

A cache that grows forever becomes a liability. We keep the data for only 7 days. After that, an archiving (cleanup) rule removes it.

This keeps the table small, limits how long AI-generated content sits in the instance, and still covers the real-world pattern: most repeat requests happen within days of the first.

Choose a retention window that fits your own data policies. Seven days worked for us.

STEP 8: ADD TO WORK NOTE

Once the user is happy with the summary, one button adds it to the record's work note. That makes the AI output part of the ticket history, so the next agent benefits too, with no copy-paste needed.

WHAT WE LIKE ABOUT THIS APPROACH

- No Now Assist license required

- Built from native ServiceNow components

- Prompts, keys and logic are centrally controlled

- Token usage is kept low by caching

- Easy to extend to new tables and new use cases

THINGS TO WATCH

No design is perfect. Keep these in mind:

- File size and type limits: very large files or unsupported formats need handling.

- Data privacy: be clear about what data leaves your instance and confirm it meets your organization's policies and Google's terms for the service tier you use.

- Human review: AI summaries can be wrong. That is why we show the text first and let users edit before adding it to a work note.

- Cost monitoring: caching helps, but still track usage on the Google side.

- Maintenance: model names and API versions change, so keep the REST Message configuration easy to update.

WHERE TO GO NEXT

Once the foundation exists, the ideas multiply:

- Summaries of long comment and activity histories

- Suggested next steps or draft replies

- Classification and routing hints

- Support for more record types and file formats

Each one is mostly a new prompt in the repository plus a small UI change.

FINAL THOUGHTS

You don't always need the biggest license to get real value from AI. With a Gemini API key, a few native ServiceNow components, and a bit of careful design, we added AI summarization that saves time, controls cost and stays in our hands.

If you're in a similar spot, with no Now Assist but a clear appetite for AI, this pattern is a practical place to start.

I'd love to hear from you: what would you want AI to do inside your ServiceNow instance? Share your thoughts in the comments.

#ServiceNow #GeminiAI #GoogleCloud #GenerativeAI #ITSM #Automation #LowCode #ServiceNowDeveloper