Golem schedule future call scala

From golemcloud/golem · View interactive version

Golem schedule future call scala is an AI agent skill from the GitHub repository golemcloud/golem. Scheduling a future agent invocation in a Scala Golem project. Use when the user asks about delayed invocations, scheduling calls for later, or timed agent execution.

How to use this skill

Skill file

Scheduling a Future Agent Invocation (Scala)

Overview

A scheduled invocation enqueues a method call on the target agent to be executed at a specific future time. The call returns immediately; the target agent processes it when the scheduled time arrives.

Usage

For stream-free methods, .scheduleAt(when) enqueues the call for the given time. Durable guest clients return Future[Unit]; ephemeral guest clients return Future[InvocationReceipt] with invocation metadata. Return or compose the future to observe enqueue errors; it does not await execution of the scheduled method.

import golem.Datetime

val counter = CounterAgentClient.upsert("my-counter")

// Schedule increment to run 5 seconds from now
counter.increment.scheduleAt(Datetime.afterSeconds(5))

// Schedule with arguments — method params first, then when
val reporter = ReportAgentClient.upsert("daily")
reporter.generateReport.scheduleAt(
  "summary",
  when = Datetime.afterSeconds(3600) // 1 hour from now
)

Datetime Helper

The golem.Datetime type provides helper methods:

import golem.Datetime

Datetime.afterSeconds(60)     // 60 seconds from now
Datetime.afterSeconds(3600)   // 1 hour from now

Cancelable Variant

For a durable, stream-free target, scheduleCancelableAt returns Future[CancellationToken]. Ephemeral guest clients instead return Future[CancelableInvocationReceipt] (golem.runtime.rpc), which carries metadata and a cancellation token. Use asynchronous composition in Scala.js, never Await.result:

import golem.runtime.rpc.CancellationToken
import scala.concurrent.{ExecutionContext, Future}

given ExecutionContext = ExecutionContext.parasitic
var pending: Option[CancellationToken] = None

val scheduled: Future[Unit] =
  counter.increment.scheduleCancelableAt(Datetime.afterSeconds(60)).map { token =>
    pending = Some(token)
  }

// From a later invocation, after scheduled has completed:
def cancelPending(): Unit = {
  pending.foreach(_.cancel())
  pending = None
}

Use Cases

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.