Home
Use tools
Call tools with LLMs

Call tools with LLMs

In this guide, you'll learn how to call tools in an AI workflow using OpenAI and Arcade AI.

To do this, you'll build an AI chatbot that can star GitHub repositories on your behalf using the GitHub.SetStarred tool.

Prerequisites

Initialize the OpenAI client

Start a new Python file in your favorite editor. If you followed the OpenAI quickstart guide, use the example.py file you created.

Use the OpenAI client, and change the base URL and API key to point to Arcade AI:

import os
from openai import OpenAI
 
# Initialize the OpenAI client, pointing to Arcade AI
client = OpenAI(
    api_key=os.environ["ARCADE_API_KEY"],
    base_url="https://api.arcade-ai.com/v1",
)

Requests made with this client will be routed to Arcade AI first, then to OpenAI. The AI model will instantly have access to the tools provided by Arcade AI.

Set the user ID

Authorized tools access data on behalf of an end-user, so they need to know the user's ID.

# Get a unique identifier for your end user
user_id = "[email protected]"

For now, put your own email address in user_id.

In a web or mobile app, you'd get this from the current user session.

Generate a response

With the client set up, use client.chat.completions.create to generate a response to a user's prompt:

while True:
    # Ask the user for input
    prompt = input("Enter your prompt (type 'exit' to quit):")
    if prompt.lower() == "exit":
        break
 
    # Use a tool and generate a response
    response = client.chat.completions.create(
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": prompt},
        ],
        model="gpt-4o",
        user=user_id,
        tools=[
            "GitHub.SetStarred",
        ],
        tool_choice="generate",
    )
 
    print(response.choices[0].message.content)

Try it!

Run the script:

python github_stars_chatbot.py # or example.py

Ask the AI to:

star the ArcadeAI/arcade-ai repo

You'll be prompted to authorize the connection to GitHub, and then the AI will perform the action.

How it works

When you use tool_choice="generate" and specify a tool like GitHub.SetStarred, Arcade AI coordinates the interaction between the tool and the AI model (OpenAI). To your users, it appears that the model magically has new capabilities.

In this example, Arcade Cloud Engine is executing the pre-built tool GitHub.SetStarred. You can also create your own custom tools.

Add more tools

Try adding more tools to the tools array to give the AI model more capabilities:

  • Add Math.SquareRoot and ask for the square root of a big number
  • Add X.WritePost and ask the AI to post on X for you

Next steps

This example only uses one tool, but you can add more to give the AI model even more capabilities. Next, learn how to use specific tools.

For apps and agents that aren't directly generating chat completions, you can authorize and call tools programmatically. This is useful when you need more control over the tool calling process.