Skip to content
Talk to an Engineer Dashboard

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 GitHub

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
  1. 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-adk

    import scalekit.client
    import os
    scalekit_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

  2. 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 already
    response = actions.get_or_create_connected_account(
    connection_name="GMAIL",
    identifier="user_123"
    )
    connected_account = response.connected_account
    print(f'Connected account created: {connected_account.id}')
  3. 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 expired
    if connected_account.status != "ACTIVE":
    # Generate an authorization link for the user to complete OAuth flow
    link_response = actions.get_authorization_link(
    connection_name="GMAIL",
    identifier="user_123"
    )
    # Display the authorization link to the user
    print(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
  4. 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 format
    gmail_tools = actions.google.get_tools(
    providers=["GMAIL"],
    identifier="user_123",
    page_size=100
    )
    # Create a Google ADK agent with Gmail tools
    gmail_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 emails
    response = gmail_agent.process_request(
    "fetch my last 5 unread emails and summarize them"
    )
    print(response)