Skip to content

wtnabe/gas-agentic-tools

Repository files navigation

AgenticTools

A Google Apps Script library that uses Gemini AI.

For example, summarize Gmail messages filtered by user specified query. This library helps you process content from Google Workspace and summarize email content, making it easier to handle large volumes of emails.

Features

at present,

  • Writer ( Console / Gmail )
  • Searcher & Extracter ( Gmail )
  • EmailSummarizer ( Gemini Prompt Customizable )
  • EmailSummaryFormatter ( customizable )
  • EmailSummaryWorkflow

Installation

Add this Library to Your Google Apps Script Project as below

  1. In your Google Apps Script project, go to Libraries (+ symbol)
  2. Enter the Library ID: 13l4VrUvxRLXOfER9BJApgXxhkuqBmvYoKtZONNhUgSzbv_bsAebNKt-f
  3. Select the latest version
  4. Click Add

Usage Examples

Basic Example: Summarize Recent Emails

async function summarizeRecentEmails () {
  // Summarize emails from the last 2 days,
  // with default summarize driver ( truncate ) and default writer ( console )
  return await AgenticTools.summarizeEmailWorkflow({
    query: 'newer_than:2d'
  })
}

Gemini Summarizer

see https://github.com/mhawksey/GeminiApp?tab=readme-ov-file#setup

async function summarizeImportantEmails () {
  // Create a Gemini driver with custom configuration
  const geminiDriver = AgenticTools.createEmailSummarizeGeminiDriver({
    geminiAuthConfig: <Use your Gemini API key or project configuration>
    model: 'gemini-2.0-flash'
  })

  const summarizer = createEmailSummarizer(geminiDriver);

  return await AgenticTools.summarizeEmailWorkflow({
    query: 'is:important newer_than:7d',
    name: 'Important Emails Summary',
    summarizer
  })
}

Customizing the Gemini Prompt Template

async function summarizeWithCustomPrompt () {
  return await AgenticTools.summarizeEmailWorkflow({
    query: 'label:project-x',
    name: 'Project X Updates',
    summarizer: AgenticTools.createEmailSummarizeGeminiDriver(...),
    summarizeDriverExecOpts: { // give PromptTemplate
      instruction: 'Analyze the following project-related emails and extract key information:',
      eachMessage: (message) => {
        return message.body + '\n'
      },
      output: `Provide a structured summary with these sections:
- Project Status
- Key Decisions
- Action Items
- Risks and Issues
- Next Steps`
    }
  })
}

Customizing the Email Summary Formatter

// without format template customization
const defaultFormatter = AgenticTools.createEmailSummaryFormatter({
  name: 'Daily Email Summary',
  embedLink: true
})

// with format template customization
const customFormatter = AgenticTools.createEmailSummaryFormatter({
  name: 'Weekly Email Digest',
  embedLink: true,
  formatTemplate: {
    /** @type {EmailSummaryFormatterHeaderTemplate} */
    header: (count, name) => `${name} (${count} MESSAGES)`,
    /** @type {EmailSummaryFormatterSeparatorTemplete} */
    separator: (length = 40, char = '*') => char.repeat(length),
    /** @type {EmailSummaryFormatterTitleTemplate} */
    summaryTitle: (index, summary) => `MESSAGE #${index}: ${summary.subject}`,
    /** @type {EmailSummaryFormatterSummaryTemplate} */
    summary: (summary, embedLink) => {
      return [
        AgenticTools.normalizeLineFeeds(summary.summary),
        (embedLink) ? `\nOriginal: ${messageUrl(summary)}` : false
      ].filter((e) => e).join('\n')
    }
  }
})

Or override exec method.

References

Gemini AI Configuration

see https://github.com/mhawksey/GeminiApp?tab=readme-ov-file#setup

Gmail Query Examples

see https://support.google.com/mail/answer/7190?hl=en&co=GENIE.Platform%3DDesktop

About

Agentic Tools as Google Apps Script Library

Topics

Resources

License

Stars

Watchers

Forks