Update code examples to not use the deprecated Google toolkit (use Gmail instead) and Web toolkit (use Firecrawl instead) |
||
|---|---|---|
| .. | ||
| src | ||
| .env.example | ||
| .gitignore | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
OpenAI Agents + Arcade AI Example
Arcade Documentation • Integrations • Arcade JS Client • OpenAI Agents
OpenAI Agents + Arcade AI
This TypeScript project demonstrates how to integrate Arcade AI with OpenAI Agents to create powerful AI agents that can interact with external services. Arcade provides access to a wide range of tools including Gmail, Slack, LinkedIn, and more through its Gmail toolkit and other integrations.
The project showcases two approaches:
- Basic integration (
src/index.ts): Simple one-time execution with Gmail toolkit - Authorization handling (
src/waitForCompletion.ts): Manual authorization flow management
For a list of all hosted tools and auth providers, see the Arcade Integrations documentation.
Prerequisites
- Node.js (v18.20.8 or higher)
- npm or pnpm
- OpenAI API key
- Arcade API key
Installation
- Clone the repository and install dependencies:
npm install
-
Set up environment variables:
-
Create a
.envfile in the root directory -
Add your API keys:
OPENAI_API_KEY=your_openai_api_key ARCADE_API_KEY=your_arcade_api_key
-
-
Update the user ID placeholder:
- In both
src/index.tsandsrc/waitForCompletion.ts - Replace
<YOUR_SYSTEM_USER_ID>with your application's user identifier (e.g., email address, UUID, etc.)
- In both
Basic Usage
This example creates an AI agent that can read and process your Gmail emails using Arcade's Gmail toolkit.
Simple Execution
Run the basic example:
npm run dev
This script will:
- Initialize the Arcade client
- Fetch available Gmail toolkit tools (up to 30)
- Convert them to OpenAI Agents compatible format
- Create an agent that can assist with Gmail API calls
- Ask "What are my latest emails?" and display the result
Authorization Flow Example
For a more robust implementation that handles authorization flows:
npm run dev:waitForCompletion
This version includes:
- Automatic authorization detection and handling
- Browser-based OAuth flow initiation
- Waiting for authorization completion
- Automatic retry after successful authorization
If you haven't authorized Arcade with Google yet, you'll see a message like:
Please complete the authorization challenge in your browser: https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&client_id=...
Visit the provided URL to authorize Arcade with your Google account. The script will automatically detect when authorization is complete and continue execution.
Project Structure
openai-ts/
├── src/
│ ├── index.ts # Basic OpenAI Agents + Arcade integration
│ └── waitForCompletion.ts # Manual authorization flow management
├── package.json # Dependencies and scripts
└── README.md # This file
Available Toolkits
You can modify the toolkit parameter to access different integrations:
"gmail"- Gmail"slack"- Slack messaging and channels"github"- GitHub repositories and issues"linkedin"- LinkedIn posts and connections- And more in Arcade Integrations documentation
Development
To extend or modify the functionality:
- Change the toolkit: Update the
toolkitparameter in theclient.tools.list()call - Modify the query: Change the question asked to the agent in the
run()function - Add custom instructions: Update the agent's
instructionsparameter for different behaviors - Handle different models: Switch the
modelparameter to use different OpenAI models
Example customization:
const slackToolkit = await client.tools.list({ toolkit: "slack", limit: 30 });
// ... rest of setup
const slackAgent = new Agent({
name: "Slack agent",
instructions: "You are a helpful assistant for managing Slack communications.",
model: "gpt-4o",
tools
});
const result = await run(slackAgent, "Send a message to the #general channel");
Security Best Practices
- Never commit your
.envfile to version control - Keep your API keys secure and rotate them regularly
- Use appropriate user identification in production
License
This project is licensed under the MIT License - see the LICENSE file for details.