Google ADK
Build a Google ADK agent that authenticates users with Gmail and executes tools on their behalf using Scalekit Agent Auth.
Build a Gmail-powered AI agent using Google ADK that authenticates users via OAuth 2.0 and fetches their last 5 unread emails using Scalekit Agent Auth. Visit the Google ADK quickstart guide to set up Google ADK before starting.
Full code on GitHubPrerequisites
Section titled “Prerequisites”Before you start, ensure you have:
- Scalekit account and API credentials — Get your Client ID and Client Secret from the Scalekit dashboard
- Google API Key — Obtain from Google AI Studio
- Gmail account — For testing the OAuth authentication flow
-
Set up your environment
Section titled “Set up your environment”Install the Scalekit Python SDK and Google ADK, then initialize the client. Get your credentials from Developers → Settings → API Credentials in the dashboard.
pip install scalekit-sdk-python google-adkimport scalekit.clientimport osscalekit_client = scalekit.client.ScalekitClient(client_id=os.getenv("SCALEKIT_CLIENT_ID"),client_secret=os.getenv("SCALEKIT_CLIENT_SECRET"),env_url=os.getenv("SCALEKIT_ENV_URL"),)actions = scalekit_client.actions -
Create a connected account
Section titled “Create a connected account”Authorize a user to access their Gmail account by creating a connected account. This represents the user’s connection to their Gmail account:
# Create a connected account for user if it doesn't exist alreadyresponse = actions.get_or_create_connected_account(connection_name="GMAIL",identifier="user_123")connected_account = response.connected_accountprint(f'Connected account created: {connected_account.id}') -
Authenticate the user
Section titled “Authenticate the user”For Scalekit to execute tools on behalf of the user, the user must grant authorization to access their Gmail account. Scalekit automatically handles the entire OAuth workflow, including token refresh.
# Check if the user needs to authorize their Gmail connection# This handles both new users and cases where the access token has expiredif connected_account.status != "ACTIVE":# Generate an authorization link for the user to complete OAuth flowlink_response = actions.get_authorization_link(connection_name="GMAIL",identifier="user_123")# Display the authorization link to the userprint(f"🔗 Authorize Gmail access: {link_response.link}")input("⎆ Press Enter after completing authorization...")# In production, redirect users to the authorization URL instead of using input()# The user will be redirected back to your app after successful authorization -
Build a Google ADK agent
Section titled “Build a Google ADK agent”Build a simple agent that fetches the last 5 unread emails from the user’s inbox and generates a summary.
from google.adk.agents import Agent# Get Gmail tools from Scalekit in Google ADK formatgmail_tools = actions.google.get_tools(providers=["GMAIL"],identifier="user_123",page_size=100)# Create a Google ADK agent with Gmail toolsgmail_agent = Agent(name="gmail_assistant",model="gemini-2.5-flash",description="Gmail assistant that can read and manage emails",instruction=("You are a helpful Gmail assistant. You can read, send, and organize emails. ""When asked to fetch emails, focus on unread messages and provide clear summaries. ""Always be helpful and professional."),tools=gmail_tools)# Use the agent to fetch and summarize unread emailsresponse = gmail_agent.process_request("fetch my last 5 unread emails and summarize them")print(response)