LLM4S - Large Language Models for Scala

A comprehensive, type-safe framework for building LLM-powered applications in Scala.

Maven Central CI License Discord

Get Started View on GitHub


Upcoming Events

Meet the LLM4S community at a talk near you, or join the weekly Dev Hour online.

  • ยท 10:00-15:00 IST

    E-Cell Orientation & Pitch Roulette, VIPS-TC

    LLM4S Foundation: A Retrospective

    VIPS Technical Campus, Pitampura, Delhi, India ๐Ÿ‡ฎ๐Ÿ‡ณ
    Kannupriya Kalra

  • ยท 12:00-13:00 IST

    DataverseHub

    LLM4S Foundation: A Retrospective

    Apple India, Gachibowli, Hyderabad, India ๐Ÿ‡ฎ๐Ÿ‡ณ
    Kannupriya Kalra

  • Open Source Singapore

    LLM4S 1.0: From Idea to Production AI in Scala/JVM

    Singapore ๐Ÿ‡ธ๐Ÿ‡ฌ
    Kannupriya Kalra

  • LLMday + Prompt Engineering Conference London Q4 2026

    LLM4S 1.0: From Idea to Production AI in Scala/JVM

    Everyman Canary Wharf, London, UK ๐Ÿ‡ฌ๐Ÿ‡ง
    Kannupriya Kalra, Rory Graves

LLM4S Dev Hour: every Sunday at 09:00 London time on Discord. Next: Sunday, 09:00 London time.

Explore events Follow the Luma calendar


Why LLM4S?

LLM4S brings the power of large language models to the Scala ecosystem with a focus on type safety, functional programming, and production-oriented design.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import org.llm4s.config.Llm4sConfig
import org.llm4s.llmconnect.LLMConnect
import org.llm4s.llmconnect.model.{ Conversation, UserMessage }
import org.llm4s.model.ModelRegistryService

// Simple LLM call using the default provider section from application.conf
val result = for {
  providerConfig <- Llm4sConfig.defaultProvider()
  registry       <- Llm4sConfig.modelRegistryService()
  given ModelRegistryService = registry
  client   <- LLMConnect.getClient(providerConfig)
  response <- client.complete(Conversation(Seq(UserMessage("Explain quantum computing"))))
} yield response

result match {
  case Right(completion) => println(completion.content)
  case Left(error) => println(s"Error: $error")
}

Key Features

Core LLM Platform

๐Ÿ”Œ Multi-Provider Support

Connect to OpenAI, Anthropic, Azure OpenAI, Google Gemini, DeepSeek, Cohere, Mistral, OpenRouter, Requesty, Z.ai, and Ollama with a unified API. Switch providers with configuration. Learn more โ†’

๐Ÿ“ก Streaming Responses

Real-time token streaming with backpressure handling and error recovery. View examples โ†’

๐Ÿ” RAG & Embeddings

Complete RAG pipeline: vector storage (SQLite, pgvector, Qdrant), hybrid search with BM25 keyword matching (SQLite FTS5 or PostgreSQL native), Cohere cross-encoder reranking, and sentence-aware document chunking. For production deployment, see RAG in a Box. Vector stores โ†’ | Examples โ†’

๐Ÿ–ผ๏ธ Multimodal Support

Generate and analyze images, convert speech-to-text and text-to-speech, and work with multiple content modalities. Image generation โ†’ | Speech โ†’

๐Ÿ“Š Observability

Comprehensive tracing with Langfuse integration for debugging, monitoring, and production analytics. Learn more โ†’

๐Ÿ› ๏ธ Type-Safe Tool Calling

Define tools with automatic schema generation and type-safe execution. Supports both local tools and Model Context Protocol (MCP) servers. See examples โ†’

Agent Framework

๐Ÿค– Agent Framework

Build sophisticated single and multi-agent workflows with built-in tool calling, conversation management, and state persistence. Explore agents โ†’

๐Ÿ’ฌ Multi-Turn Conversations

Functional, immutable conversation management with automatic context window pruning and conversation persistence. View patterns โ†’

๐Ÿ›ก๏ธ Guardrails & Validation

Declarative input/output validation framework for production safety. Built-in guardrails for length checks, profanity filtering, JSON validation, tone validation, and LLM-as-Judge. Learn more โ†’

๐Ÿ”„ Agent Handoffs

LLM-driven agent-to-agent delegation for specialist routing. Simple API for handing off queries to domain experts with automatic context preservation. See examples โ†’

๐Ÿง  Memory System

Short-term and long-term memory with entity tracking. In-memory, SQLite, and vector store backends for semantic search across conversations. Explore memory โ†’

๐Ÿ’ญ Reasoning Modes

Extended thinking support for OpenAI o1/o3 and Anthropic Claude. Configure reasoning effort levels and access thinking content. Learn more โ†’

Infrastructure

โšก Built-in Tools

Pre-built tools for common tasks: DateTime, Calculator, UUID, JSON parsing, HTTP requests, web search, and file operations with security controls. Browse tools โ†’

๐Ÿณ Secure Execution

Containerized workspace for safe tool execution with Docker isolation. Advanced topics โ†’


Quick Start

Installation

Add LLM4S and the provider module you call to your build.sbt:

1
2
libraryDependencies += "org.llm4s" %% "llm4s-core" % "0.5.1"
libraryDependencies += "org.llm4s" %% "llm4s-openai" % "0.5.1"

llm4s-core ships no provider client: each is a module of its own (llm4s-openai, llm4s-anthropic, llm4s-gemini, llm4s-ollama, llm4s-openai-compatible, โ€ฆ), registered by adding its dependency.

Latest release: 0.5.1 Check Maven Central for the latest release.

Configuration

Define a named provider section in src/main/resources/application.conf and select it as the default. The section needs no API key line: llm4s-openai reads OPENAI_API_KEY for any OpenAI section that sets no apiKey of its own. llm4s does not read LLM_MODEL:

1
2
3
4
5
6
7
8
9
10
llm4s {
  providers {
    provider = "openai-main"          # the default: the name of a section below

    openai-main {
      provider = "openai"
      model    = "gpt-4o-mini"
    }
  }
}
1
export OPENAI_API_KEY=sk-...

Configuration guide โ†’

Your First Program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import org.llm4s.config.Llm4sConfig
import org.llm4s.llmconnect.LLMConnect
import org.llm4s.llmconnect.model._
import org.llm4s.model.ModelRegistryService

object HelloLLM extends App {
  val result = for {
    providerConfig <- Llm4sConfig.defaultProvider()
    registry       <- Llm4sConfig.modelRegistryService()
    given ModelRegistryService = registry
    client   <- LLMConnect.getClient(providerConfig)
    response <- client.complete(
      Conversation(Seq(
        SystemMessage("You are a helpful assistant."),
        UserMessage("What is Scala?")
      ))
    )
  } yield response.content

  result.fold(
    error => println(s"Error: $error"),
    content => println(s"Response: $content")
  )
}

Complete installation guide โ†’


Explore 69 working examples covering all features:

Basic Examples

Agent Examples

Guardrails & Safety

Handoffs & Memory

Tools & Streaming

Browse all examples โ†’


Documentation

๐Ÿค– Agent Framework

Tools, guardrails, memory, handoffs

Learn agents โ†’

๐Ÿ“– User Guide

RAG, vector stores, multimodal

Browse guides โ†’

๐Ÿ’ป Examples

70 working code examples

Browse examples โ†’

๐Ÿš€ Advanced Topics

Production readiness & optimization

Learn more โ†’

๐Ÿ“š API Reference

Complete API documentation

View API docs โ†’

๐Ÿ“– Scaladoc

Generated API documentation

Browse Scaladoc โ†’

Why Scala for LLMs?

โœ… **Type Safety** - Catch errors at compile time, not in production โœ… **Functional Programming** - Immutable data and pure functions for predictable systems โœ… **JVM Ecosystem** - Access to mature, production-grade libraries โœ… **Concurrency** - Advanced models for safe, efficient parallelism โœ… **Performance** - JVM speed with functional elegance โœ… **Enterprise Ready** - Seamless integration with JVM systems

Compatibility

Scala & JDK Support

Scala Version JDK Version Status
3.7.x 21 โœ… Supported (built with 3.7.1)

Scala 2.13 is not published: 1.0 targets Scala 3 only, and 2.13 support is deferred to after 1.0. JDK 21 is the minimum for every artifact; see Scala and JDK support.

LLM Provider Support

Provider Status Models
OpenAI โœ… Complete GPT-4o, GPT-4, GPT-3.5, o1, o3
Anthropic โœ… Complete Claude 3.5, Claude 3
Azure OpenAI โœ… Complete All Azure-hosted models
Ollama โœ… Complete Llama, Mistral, local models
Google Gemini โœ… Complete Gemini 2.0, 1.5 Pro/Flash
DeepSeek, OpenRouter, Z.ai, Mistral, Cohere โœ… Chat, streaming, tools via llm4s-openai-compatible

Community


Project Status

LLM4S is under active development with comprehensive LLM capabilities.

Core Framework (Complete)

Category Features
LLM Providers OpenAI, Anthropic, Azure, Ollama
Content Generation Text, Images, Speech (STT/TTS), Embeddings
Tools & Integration Tool Calling, MCP Servers, Built-in Tools, Workspace Isolation
Infrastructure Type-Safe Config, Result Error Handling, Langfuse Tracing

Agent Framework Phases

  • โœ… Phase 1.0-1.4: Core agents, conversations, guardrails, handoffs, memory
  • โœ… Phase 2.1-2.2: Event streaming, async tool execution
  • โœ… Phase 3.2: Built-in tools module
  • โœ… Phase 4.1, 4.3: Reasoning modes, session serialization
  • ๐Ÿšง Next: Enhanced observability, provider expansion
  • ๐Ÿ“‹ v1.0.0: Production readiness

View detailed roadmap โ†’


Getting Help


Ready to get started? Install LLM4S โ†’