HomeTool CallingScheduled execution

Schedule tool execution

In this guide, you’ll learn how to schedule tools to run at a future time with Arcade.dev.

Scheduled tool execution allows you to set up tools to run automatically at a specific time in the future. This is useful for tasks like sending notifications, generating reports, or performing maintenance operations on a schedule.

Prerequisites

Set environment variables

You can find your Arcade.dev API key in one of these locations:

Export your Arcade.dev API key as an environment variable:

export ARCADE_API_KEY=<your-api-key>

Initialize the client

Import and initialize the Arcade.dev client. The client automatically uses the ARCADE_API_KEY environment variable.

from arcade import Arcade
from datetime import datetime, timedelta, timezone
 

Schedule a tool execution

Let’s schedule the Github.CreateIssue tool to run at a future time. You’ll need to specify:

  1. The tool name
  2. The input parameters for the tool
  3. The time when the tool should run
  4. Optionally, a user ID for attribution
arcade = Arcade()
 
# Schedule a tool execution for 1 hour in the future
future_time = datetime.now(timezone.utc) + timedelta(hours=1)
 
# Schedule the GitHub.CreateIssue tool to run at the specified time
scheduled_execution = arcade.tools.schedule(
    tool_name="Github.CreateIssue",
    input={
        "owner": "ArcadeAI",
        "repo": "Docs",
        "title": "Scheduled issue creation",
        "body": "This issue was created by a scheduled tool execution"
    },
    run_at=future_time,

The response includes an ID that you can use to check the status of the scheduled execution later.

List scheduled tool executions

You can retrieve a list of all scheduled tool executions to monitor their status.

)
 
print(f"Scheduled execution ID: {scheduled_execution.id}")

Get details of a scheduled execution

You can retrieve detailed information about a specific scheduled execution using its ID.

print(f"Will run at: {scheduled_execution.run_at}")
 
# List all scheduled tool executions
scheduled_tools = arcade.tools.list_scheduled()
print(f"Total scheduled executions: {len(scheduled_tools.items)}")
 
# Get details of a specific scheduled execution
execution_details = arcade.tools.get_scheduled(scheduled_execution.id)
print(f"Tool: {execution_details.tool_name}")
print(f"Status: {execution_details.execution_status}")

The response includes detailed information about the scheduled execution, including:

  • The execution status
  • The input parameters
  • The time it was scheduled to run
  • The time it actually ran (if it has run)
  • The output of the execution (if it has run)
  • Any attempts that were made to run the tool

Use cases for scheduled tool execution

Let’s explore some common use cases for scheduled tool execution:

  1. Automated reporting: Schedule tools to generate and send reports at regular intervals
  2. Maintenance tasks: Schedule cleanup operations or database maintenance during off-peak hours
  3. Delayed notifications: Schedule notifications to be sent at appropriate times
  4. Workflow automation: Trigger the next step in a workflow after a specified delay
  5. Scheduled content updates: Automatically update content or publish posts at optimal times

By scheduling tool executions, you can automate repetitive tasks and ensure they run at the most appropriate times.