Installation
Install the Gmail interface dependencies:Setup
Required environment variables:-
GMAIL_API_SECRET(optional, for endpoint protection) -
Gmail OAuth credentials (via
credentials.jsonandtoken.jsonfiles)
The interface uses a pull-based model - you manually trigger email checks via the
/gmail/check endpoint, and the agent processes unread emails.Operating Modes
- TASK (default) – Each email is processed as an independent task; no conversation history. Best for classification, auto-responders, one-off processing.
- CHAT – Emails from the same sender share a conversation session. The agent can reference earlier emails. Best for support threads and ongoing conversations.
Reset Command (CHAT mode only)
In CHAT mode, senders can clear their conversation by including the reset command in the email body (e.g./reset). You configure it with reset_command; set to None to disable.
If the agent has a workspace configured, the reset command will also trigger a dynamic greeting message based on the workspace configuration. See Workspace for details.
Access Control (Whitelist)
Passallowed_emails (list of email addresses). Only those senders are processed; others receive a fixed “This operation not allowed” response. Omit allowed_emails (or set None) to allow all senders.
Example Usage
Create an agent, expose it with theGmailInterface interface, and serve via InterfaceManager. Example with CHAT mode, reset command, and optional whitelist:
Core Components
-
GmailInterface(interface): Wraps an UpsonicAgentfor Gmail via FastAPI. -
InterfaceManager.serve: Serves the FastAPI app using Uvicorn.
GmailInterface Interface
Main entry point for Upsonic Gmail applications.
Initialization Parameters
Key Methods
Endpoints
Mounted under the/gmail prefix:
POST /gmail/check
- Manually triggers a check for unread emails and processes them.
-
Query parameter:
count(default: 3) - maximum number of emails to process. -
Requires
X-Upsonic-Gmail-Secretheader ifGMAIL_API_SECRETis configured. - Fetches unread emails, processes each with the agent, sends replies if agent decides to reply, marks emails as read.
-
Returns:
200 CheckEmailsResponsewithstatus,processed_count, andmessage_ids.
GET /gmail/health
- Health/status of the interface.

