Golem stateless agent go

From golemcloud/golem · View interactive version

Golem stateless agent go is an AI agent skill from the GitHub repository golemcloud/golem. Creating ephemeral (stateless) agents in a Go 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 in a Go Golem project.

How to use this skill

Skill file

Creating Ephemeral (Stateless) Agents (Go)

Overview

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

This fits pure request handlers, stateless transformers, adapters, and serverless-style functions where each call is independent.

How to make an agent ephemeral

Set Mode: golem.Ephemeral on the Spec. Mode defaults to golem.Durable.

// Package handler is the DEFINITION of a stateless request-handler agent.
package handler

import "github.com/golemcloud/golem/sdks/go/golem"

// No constructor inputs; each ephemeral invocation still gets fresh state.
type ID struct{}

type HandleIn struct{ Input string }

var Agent = golem.DefineAgent[ID](golem.Spec{
    Name:        "RequestHandlerAgent",
    Description: "Stateless request handler — fresh instance per invocation",
    Mode:        golem.Ephemeral, // <- makes every invocation start clean
})

var Handle = Agent.Method[HandleIn, string]("handle", golem.Description("Process one request and return the result"))

Implementation

The implementation is written exactly like a durable agent's — the state type just holds nothing meaningful across calls (or is empty), because it is recreated each invocation:

package impl

import (
    "strings"

    "myapp/agents/handler"

    "github.com/golemcloud/golem/sdks/go/golem"
)

// state is empty: an ephemeral agent keeps nothing between invocations.
type state struct{}

var agent = handler.Agent.Implement(func(handler.ID) *state { return &state{} })

func init() {
    agent.Handle(handler.Handle, func(_ *golem.Context[state], in handler.HandleIn) string {
        return "processed: " + strings.ToUpper(in.Input)
    })
}

What "fresh instance per invocation" means

Mode controls state lifetime; an ephemeral target is addressed with Upsert.

Each invocation through an Upsert client of an ephemeral agent runs on a new one-shot instance, so one client serves independent invocations. For the handler defined above:

c := handler.Agent.Upsert(handler.ID{})
for _, input := range inputs {
    result := handler.Handle.MustCall(c, handler.HandleIn{Input: input})
    _ = result
}

The InvocationMetadata that Trigger returns names, in AgentID, the one-shot instance that ran the invocation.

// DURABLE (default) — state accumulates across calls.
var Durable = golem.DefineAgent[ID](golem.Spec{Name: "DurableCounter"})
// increment() three times → 1, 2, 3

// EPHEMERAL — state resets every call.
var Ephemeral = golem.DefineAgent[ID](golem.Spec{Name: "EphemeralCounter", Mode: golem.Ephemeral})
// increment() three times → 1, 1, 1

Each invocation of an ephemeral agent:

  1. Runs the init function (func(ID) *state) to build a fresh state.
  2. Executes the method handler.
  3. Discards the instance entirely.

Combining with HTTP endpoints

Ephemeral agents are a natural fit for HTTP request handlers — declare an HTTP mount alongside Mode: golem.Ephemeral. Every mount {var} must be an ID field, so a singleton ID struct{} mounts at a path with no variables:

var Agent = golem.DefineAgent[ID](golem.Spec{
    Name: "ConverterAgent",
    Mode: golem.Ephemeral,
    HTTP: &golem.Mount{Path: "/api/convert"},
})

var (
    ToUpper = Agent.Method[ConvertIn, string]("toUpper", golem.HTTP(golem.POST("/to-upper")))
    ToLower = Agent.Method[ConvertIn, string]("toLower", golem.HTTP(golem.POST("/to-lower")))
)

When to use ephemeral agents

| 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 events |

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

When NOT to use ephemeral agents

Key Constraints

Related Skills

| Skill | When to Load |

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

| golem-add-agent-go | Define the agent and its methods (durable baseline) |

| golem-add-http-endpoint-go | Expose the stateless agent over HTTP |

| golem-call-another-agent-go | An ephemeral agent calling other agents |

| golem-configure-durability-go | Durability controls for the durable alternative |

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.