golem-add-llm-scala

Integrate LLM chat and AI provider APIs into Scala Golem agents via fetch.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adding LLM capabilities to a Scala Golem agent is tricky because agents compile to JavaScript via Scala.js, so JVM HTTP clients and most Scala libraries simply do not work. This Skill guides you through the working approaches for calling OpenAI-style chat completion and embedding APIs from a Scala agent.

Core Features & Use Cases

  • Direct REST API calls with fetch: Call LLM provider endpoints using the global fetch function available in Scala.js, the most reliable approach.
  • ZIO HTTP client option: Use zio-http with a typed client for ZIO-based agents.
  • Secret management for API keys: Store provider keys with Golem's typed config system using Secret[String] and the golem secret create CLI command.
  • Use Case: Build a chat agent mounted at /chats/{value} that maintains conversation history in agent state and answers questions through the OpenAI chat completions API.

Quick Start

Add an LLM chat endpoint to my Scala Golem agent that calls the OpenAI API using fetch and stores the API key as a Golem secret.

Frequently Asked Questions about golem-add-llm-scala

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

FAQPage Schema
How do I call the OpenAI API from a Scala Golem agent?

Call the OpenAI chat completions endpoint directly with the global fetch function available in Scala.js. Build the JSON payload with js.Dynamic.literal, set the Authorization bearer header, and convert the returned promise to a Future using Thenable implicits.

Can I use Scala HTTP client libraries in Golem agents?

Only Scala.js-compatible libraries that use fetch under the hood will work. JVM-based clients like Apache HttpClient, OkHttp, or sttp with JVM backends fail because Golem Scala agents compile to JavaScript. Declare compatible dependencies with %%% in build.sbt.

How do I store LLM API keys securely in Golem?

Declare the key as Secret[String] in a config case class using Golem's typed config system, then create it with the golem secret create CLI command. Access the value in code through config.value.apiKey.get.

Does zio-http work for LLM calls in Scala Golem agents?

Yes, zio-http provides a typed client usable in ZIO-based agents. Construct the request with ZClient, add the bearer authorization header, post the JSON body, and run the effect to a Future with Runtime.default.unsafe.runToFuture.

Why does my Scala library dependency fail in a Golem agent?

The library is likely published only for the JVM or uses JVM networking internally. Golem Scala agents run as JavaScript via Scala.js, so dependencies must be published for Scala.js (_sjs1_ artifact) and use browser-compatible HTTP mechanisms like fetch.