golem-add-agent-scala

Create Scala agent traits and implementations for Golem WebAssembly components.

1.5k|212|Updated Nov 24, 2023
One-click install
npx skills add https://github.com/golemcloud/golem --skill golem-add-agent-scala
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-add-agent-scala
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/scala/golem-add-agent-scala
Command: npx skills add https://github.com/golemcloud/golem --skill golem-add-agent-scala

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Defining a new durable, stateful agent in a Scala Golem project requires correctly pairing an annotated trait with an implementation class, handling identity constructors, schema derivation, and error semantics. This Skill guides that process so the agent compiles and behaves correctly under Golem's invocation model.

Core Features & Use Cases

  • Agent Scaffolding: Create the @agentDefinition trait extending BaseAgent and the matching @agentImplementation() class with correct constructor identity via the inner class Id(...).
  • Typed APIs and Errors: Define custom case classes with derives Schema from zio.blocks.schema, and model domain failures as Future[Either[E, A]] instead of failed futures that trigger retries.
  • HTTP Endpoints: Expose agent methods as HTTP routes using @endpoint and @header annotations.
  • Use Case: When asked to add a CounterAgent with increment and getCount methods to a Scala Golem component, this Skill produces the trait, implementation, and build verification steps.

Quick Start

Add a new Scala agent named CounterAgent with increment and getCount methods to my Golem component.

Frequently Asked Questions about golem-add-agent-scala

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new agent to a Scala Golem project?

Create a trait annotated with @agentDefinition that extends BaseAgent, then create an implementation class annotated with @agentImplementation(). Declare constructor identity in an inner class Id(...) in the trait, then run golem build to verify.

How do I return errors from a Golem agent method in Scala?

Return domain errors as Future[Either[E, A]] where both E and A have zio.blocks.schema Schema instances. A failed Future or escaped exception is treated as a crash, triggering retries and eventually failing the agent instead of returning an error to the caller.

Does the Golem Scala SDK support custom types in agent methods?

Yes, custom case classes work as method parameters and return values if they derive a zio.blocks.schema Schema, typically with derives Schema in Scala 3. Use List[T] instead of Array[T] because Array lacks automatic Schema derivation.

How do I expose a Golem agent method as an HTTP endpoint?

Annotate the trait method with @endpoint(method = "GET", path = "/data") and use @header to bind HTTP headers to parameters. The agent trait's mount path, such as /api/{id}, defines the base route.

Why does my Scala Golem agent fail to compile with macro annotations?

The @agentDefinition and @agentImplementation macros require the scalacOptions += "-experimental" flag in the build. Without it, the macro annotations will not compile.