Golem stateless agent scala

From golemcloud/golem · View interactive version

Golem stateless agent scala is an AI agent skill from the GitHub repository golemcloud/golem. Creating ephemeral (stateless) agents in a Scala Golem project. Use when the user wants a stateless agent, a fresh instance per invocation, no shared state between calls, or a request-handler style agent.

How to use this skill

Skill file

Creating Ephemeral (Stateless) Agents (Scala)

Overview

An ephemeral agent is a Golem agent that gets a fresh instance for every invocation. Unlike the default durable agents, ephemeral agents:

This makes ephemeral agents ideal for pure request handlers, stateless transformers, adapters, and serverless-style functions where each call is independent.

How to Create an Ephemeral Agent

Pass mode = DurabilityMode.Ephemeral to the @agentDefinition annotation:

import golem.runtime.annotations.{agentDefinition, agentImplementation, DurabilityMode}
import golem.BaseAgent

import scala.concurrent.Future

@agentDefinition(mode = DurabilityMode.Ephemeral)
trait RequestHandler extends BaseAgent {
  class Id()
  def handle(input: String): Future[String]
}

@agentImplementation()
final class RequestHandlerImpl extends RequestHandler {
  override def handle(input: String): Future[String] =
    Future.successful(s"processed: $input")
}

What "Fresh Instance Per Invocation" Means

Consider a durable agent vs an ephemeral one:

// DURABLE (default) — state accumulates across calls
@agentDefinition()
trait DurableCounter extends BaseAgent {
  class Id(val name: String)
  def increment(): Future[Int]
}

@agentImplementation()
final class DurableCounterImpl(name: String) extends DurableCounter {
  private var count: Int = 0
  override def increment(): Future[Int] = Future.successful {
    count += 1
    count
  }
}
// Call increment() three times → returns 1, 2, 3

// EPHEMERAL — state resets every call
@agentDefinition(mode = DurabilityMode.Ephemeral)
trait EphemeralCounter extends BaseAgent {
  class Id(val name: String)
  def increment(): Future[Int]
}

@agentImplementation()
final class EphemeralCounterImpl(name: String) extends EphemeralCounter {
  private var count: Int = 0
  override def increment(): Future[Int] = Future.successful {
    count += 1
    count
  }
}
// Call increment() three times → returns 1, 1, 1

Each invocation of an ephemeral agent:

  1. Creates a fresh instance via the constructor
  2. Executes the method
  3. Discards the instance entirely

Combining with HTTP Endpoints

Ephemeral agents are a natural fit for HTTP request handlers:

import golem.runtime.annotations._
import golem.BaseAgent

import scala.concurrent.Future

@agentDefinition(mode = DurabilityMode.Ephemeral, mount = "/api/convert/{name}")
trait ConverterAgent extends BaseAgent {
  class Id(val name: String)

  @endpoint(method = "POST", path = "/to-upper")
  def toUpper(input: String): Future[String]

  @endpoint(method = "POST", path = "/to-lower")
  def toLower(input: String): Future[String]
}

@agentImplementation()
final class ConverterAgentImpl(private val name: String) extends ConverterAgent {
  override def toUpper(input: String): Future[String] =
    Future.successful(input.toUpperCase)

  override def toLower(input: String): Future[String] =
    Future.successful(input.toLowerCase)
}

When to Use Ephemeral Agents

Both POST endpoints expect a structured JSON body such as {"input":"Hello"}, not a bare string.

| Use Case | Why Ephemeral? |

|----------|---------------|

| Stateless HTTP API (REST adapter, proxy) | No state to persist between requests |

| Data transformation / format conversion | Pure function — input in, output out |

| Validation service | Each validation is independent |

| Webhook receiver that forwards events | No need to remember previous webhooks |

| Stateless computation (math, encoding) | No side effects worth persisting |

When NOT to Use Ephemeral Agents

Key Points

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.