Agent Actions - Quickstart Guide
Agent Actions will help enable your AI Agents to take actions in real world applications on behalf of your users. Scalekit automatically handles authorizing your users to grant access to third party applications like Gmail, Calendar, Slack, Notion etc and using our pre-built connectors and tool, lets your AU Agent execute actions like fetching emails, creating calendar events, updating notion pages, sending alerts via Slack etc.
This quickstart guide will show you how to get started with Agent Actions in just a few minutes. You’ll learn how to set up connections, authenticate users, and run your first tools.
What you’ll build
Section titled “What you’ll build”In this quickstart, you’ll build a simple tool calling program that:
- Authenticates a user with GMail to authenticate their Gmail account via OAuth 2.0
- Fetches last 5 unread emails from the user’s inbox
Prerequisites
Section titled “Prerequisites”Before you start, make sure you have:
- Scalekit API credentials (Client ID and Client Secret)
- Development environment (Node.js, Python, or similar)
Step 1: Set up your environment
Section titled “Step 1: Set up your environment”First, install the Scalekit Python SDK and initialize the client with your API credentials:
pip install scalekit-sdk-python
import scalekit.clientimport os
scalekit = 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.actions
Step 2: Create a connected account
Section titled “Step 2: Create a connected account”Let’s 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 alreadyconnected_account = actions.get_or_create_connected_account( connection_name="gmail", identifier="user_123")print(f'Connected account created: {connected_account.id}')
Step 3: Authenticate the user
Section titled “Step 3: Authenticate the user”Inorder to execute any tools on behalf of the user, the user first needs to grant authorization to access their gmail account. Scalekit automatically handles the entire OAuth workflow with the Gmail provider, gets the access token, refreshes the access token periodically based on the refresh token etc.
If the user’s access token is expired, Scalekit will automatically refresh the access token using the refresh token. At any time, you can check the authorization status of the connected account and determine if the user needs to re-authorize the connection.
# If the user hasn't yet authorized the gmail connection or if the user's access token is expired, generate a link for them to authorize the connectionif(connected_account.status != "ACTIVE"): print(f"gmail is not connected: {connected_account.status}") link_response = actions.get_authorization_link( connection_name="gmail", identifier="user_123" ) print(f"🔗click on the link to authorize gmail", link_response.link) input(f"⎆ Press Enter after authorizing gmail...")
# In a real app, redirect the user to this URL so that the user can complete the authentication process for their gmail account
Step 4: Execute a tool - Send an email
Section titled “Step 4: Execute a tool - Send an email”Now that the user has successfully authorized the gmail connection, you can execute tools on their behalf. For this example, let’s fetch the last 5 unread emails from the user’s inbox.
# Fetch recent emailsemails = actions.execute_tool( #connected_account_id= connected_account.id if using multiple connectors identifier="user_123", tool='gmail_fetch_mails', parameters={ 'query': 'is:unread', 'max_results': 5 })
print(f'Recent emails: {emails.result}')
Next steps
Section titled “Next steps”Congratulations! You’ve successfully implemented a program that executes action in real world applications on behalf of a user.
Let’s make it more interesting by implementing an AI agent that uses large language models from OpenAI or Anthropic and actually help determine which tool to be called with what parameters. Go through our Agentic Tool Calling guide to implement the same usecase using Langchain and Agent Actions.