Prompt

How do I build an AI agent that can take actions in Slack and Gmail?

Artificial Intelligence / AI Agents1 observationLast seen Oct 9, 2026

Latest observation

Oct 9, 2026OpenAI APIWeb search: off

To build an AI agent that can take actions in Slack and Gmail, you generally want this architecture:

  1. LLM / reasoning layer — decides what to do.
  2. Tool layer — functions the agent can call, like “send Slack message” or “draft Gmail reply.”
  3. Permissions + auth — OAuth for Slack/Gmail, scoped minimally.
  4. Safety / approval layer — especially for sending messages or emails.
  5. Event loop / orchestration — listens for triggers, runs the agent, executes actions.

1) Define the agent’s job

Be explicit about what actions it can take, for example:

  • Slack:
    • read channel messages
    • post messages
    • reply in threads
    • mention users
  • Gmail:
    • read inbox summaries
    • draft replies
    • send emails
    • label/archive messages

Start with draft-only actions for Gmail if you want to reduce risk.


2) Connect Slack and Gmail APIs

Slack

Use the Slack API with a Slack app.

Typical OAuth scopes:

  • chat:write
  • channels:history
  • groups:history if needed
  • im:history if needed
  • users:read
  • channels:read
  • reactions:write if you want reactions

Use:

  • Events API or Socket Mode to receive messages/events
  • chat.postMessage to send messages
  • conversations.replies to fetch thread context

Gmail

Use the Gmail API with Google OAuth.

Typical scopes:

  • gmail.readonly for reading
  • gmail.compose for drafts
  • gmail.send for sending
  • gmail.modify for labels/archive actions

Use:

  • Gmail API to list messages
  • create drafts
  • send messages
  • modify labels

3) Wrap each capability as a tool/function

Your LLM shouldn’t directly talk to Slack/Gmail APIs. Instead, expose safe functions like:

def send_slack_message(channel_id: str, text: str) -> str:
    ...

def reply_to_slack_thread(channel_id: str, thread_ts: str, text: str) -> str:
    ...

def create_gmail_draft(to: str, subject: str, body: str) -> str:
    ...

def send_gmail_email(to: str, subject: str, body: str) -> str:
    ...

Then give the LLM a tool-calling interface. The agent can decide:

  • “This message needs a Slack reply”
  • “This email should be drafted”
  • “This task needs human approval before sending”

4) Add an approval workflow

Best practice: don’t let the agent send emails or post to Slack without guardrails.

Common pattern:

  • Agent proposes action
  • System shows draft to human
  • Human approves/edits
  • System executes

For example:

  • If confidence is low, create a draft
  • If action is high impact, require approval
  • If content includes sensitive info, block or escalate

5) Build the orchestration loop

You need a process that:

  1. receives an event from Slack or Gmail
  2. fetches context
  3. passes context to the agent
  4. the agent decides what tool to call
  5. execute tool
  6. log outcome

Example flow:

  • Slack message comes in
  • Agent sees: “Can you summarize the latest customer feedback?”
  • Agent fetches thread and maybe recent emails
  • Agent posts a summary back to Slack

6) Recommended stack

A simple practical stack:

  • Python or Node.js
  • Slack Bolt for Slack app handling
  • Google Gmail API client
  • OpenAI API or another LLM provider with tool calling
  • A backend framework:
    • FastAPI / Flask
    • Express / NestJS
  • Database for state:
    • Postgres / SQLite
  • Queue/background jobs:
    • Celery / RQ / BullMQ
  • Secrets storage:
    • environment variables for development
    • secret manager in production

7) Minimal architecture

Slack/Gmail event
      ↓
Webhook / polling service
      ↓
Context fetcher
      ↓
LLM agent with tools
      ↓
Approval check
      ↓
Slack/Gmail API action
      ↓
Log + audit trail

8) Example agent behavior

Example 1: Slack

User in Slack says:

“Please send a status update to #team about the release delay.”

Agent:

  1. drafts a message
  2. asks for approval
  3. posts to channel after approval

Example 2: Gmail

New email arrives from a customer

“Can you reschedule our meeting?”

Agent:

  1. reads email
  2. drafts reply with available times
  3. sends only if approved

9) Important safety considerations

  • Use least-privilege OAuth scopes
  • Maintain an audit log
  • Keep a human-in-the-loop for send/post actions
  • Prevent prompt injection from email/Slack content:
    • don’t let message content override system instructions
    • treat all external text as untrusted
  • Rate limit actions
  • Make actions idempotent to avoid duplicate sends

10) A good first MVP

I’d recommend this MVP:

  • Slack bot that:
    • responds to mentions
    • summarizes threads
    • drafts suggested replies
  • Gmail agent that:
    • monitors inbox
    • drafts replies
    • never sends automatically

Then later:

  • add auto-send for low-risk cases
  • add calendar actions
  • add CRM actions

11) If you want to implement it with tool calling

A typical pattern is:

  • system prompt defines behavior
  • tools represent Slack/Gmail actions
  • model chooses a tool
  • backend executes it
  • backend returns result to model

Example pseudo-flow:

messages = [
    {"role": "system", "content": "You are an assistant that can draft Slack and Gmail actions safely."},
    {"role": "user", "content": "Reply to this email saying I can meet Friday at 3."}
]

response = llm.chat(messages, tools=[create_gmail_draft, send_gmail_email])

The model may choose create_gmail_draft first.


12) If you want, I can give you:

  1. a Python starter project for Slack + Gmail agent
  2. a Node.js version
  3. a tool-calling example with OpenAI
  4. a secure architecture diagram and deployment plan

If you want, I can generate a working Python FastAPI example that connects to Slack and Gmail and lets the model draft actions.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.