arcade-mcp/examples/openai-agents-ts/README.md
Eric Gustin 7f26b83c19
Update examples (#516)
Update code examples to not use the deprecated Google toolkit (use Gmail
instead) and Web toolkit (use Firecrawl instead)
2025-07-28 09:49:00 -07:00

5.6 KiB

Arcade AI Logo

OpenAI Agents + Arcade AI Example

License

Arcade DocumentationIntegrationsArcade JS ClientOpenAI 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

Installation

  1. Clone the repository and install dependencies:
npm install
  1. Set up environment variables:

    • Create a .env file in the root directory

    • Add your API keys:

      OPENAI_API_KEY=your_openai_api_key
      ARCADE_API_KEY=your_arcade_api_key
      
  2. Update the user ID placeholder:

    • In both src/index.ts and src/waitForCompletion.ts
    • Replace <YOUR_SYSTEM_USER_ID> with your application's user identifier (e.g., email address, UUID, etc.)

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:

  1. Initialize the Arcade client
  2. Fetch available Gmail toolkit tools (up to 30)
  3. Convert them to OpenAI Agents compatible format
  4. Create an agent that can assist with Gmail API calls
  5. 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:

  1. Change the toolkit: Update the toolkit parameter in the client.tools.list() call
  2. Modify the query: Change the question asked to the agent in the run() function
  3. Add custom instructions: Update the agent's instructions parameter for different behaviors
  4. Handle different models: Switch the model parameter 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 .env file 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.