8000 GitHub - iyadi/llm4s: Agentic and LLM Programming in Scala
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

iyadi/llm4s

Β 
Β 

Repository files navigation

LLM4S - Large Language Models for Scala

LLM4S Logo

Overview

LLM4S provides a simple, robust, and scalable framework for building LLM applications in Scala. While most LLM work is done in Python, we believe that Scala offers a fundamentally better foundation for building reliable, maintainable AI-powered applications.


LLM4S Overview


Note: This is a work in progress project and is likely to change significantly over time.

Why Scala for LLMs?

  • Type Safety: Catch errors at compile time rather than runtime
  • Functional Programming: Immutable data structures and pure functions for more predictable code
  • JVM Ecosystem: Access to a vast array of libraries and tools
  • Concurrency: Better handling of concurrent operations with Scala's actor model
  • Performance: JVM performance with functional programming elegance

Features

  • Containerized Workspace: Secure execution environment for LLM-driven operations
  • Workspace Agent Interface: Standardized protocol for file operations and command execution
  • Multi-Provider Support: Planned support for multiple LLM providers (OpenAI, Anthropic, etc.)
  • Agent Trace Logging: Detailed markdown logs of agent execution for debugging and analysis

Project Structure

  • llm4s: Main project - contains the core LLM4S framework
  • shared: Shared code between main project and workspace runner
  • workspaceRunner: Code that performs the requested actions on the workspace within the docker container
  • samples: Usage examples demonstrating various features

Getting Started

To get started with the LLM4S project, check out this teaser talk presented by Kannupriya Kalra at the Bay Area Scala Conference. This recording is essential for understanding where we’re headed:

πŸŽ₯ Teaser Talk: https://www.youtube.com/watch?v=SXybj2P3_DE&ab_channel=SalarRahmanian


Bay Area Scala Conference at Tubi Office Bay Area Scala Conference Generative AI Slide
LLM4S was officially introduced at the Bay Area Scala Conference in San Francisco on February 25, 2025.


Setting Up Pre-commit Hooks

To ensure code quality, we use a Git pre-commit hook that automatically checks code formatting and runs tests before allowing commits:

# Install the pre-commit hook
./hooks/install.sh

# The hook will automatically:
# - Check code formatting with scalafmt
# - Compile code for both Scala 2.13 and 3
# - Run tests for both Scala versions

# To skip the hook temporarily (not recommended):
# git commit --no-verify

Prerequisites

  • JDK 21+
  • SBT
  • Docker (for containerized workspace)

Building the Project

sbt compile

# For all supported Scala versions (2.13 and 3)
sbt +compile

# Build and test all versions
sbt buildAll

Setup your LLM Environment

You will need an API key for either OpenAI (https://platform.openai.com/) or Anthropic (https://console.anthropic.com/) other LLMS may be supported in the future (see the backlog).

Set the environment variables:

LLM_MODEL=openai/gpt-4o
OPENAI_API_KEY=<your_openai_api_key>

or Anthropic:

LLM_MODEL=anthropic/claude-3-7-sonnet-latest
ANTHROPIC_API_KEY=<your_anthropic_api_key>

or OpenRouter:

LLM_MODEL=openai/gpt-4o
OPENAI_API_KEY=<your_openai_api_key>
OPENAI_BASE_URL=https://openrouter.ai/api/v1

This will allow you to run the non-containerized examples.

Running the Examples

# Using Scala 3
sbt "samples/runMain org.llm4s.samples.basic.BasicLLMCallingExample"

Run containerised test

sbt docker:publishLocal
sbt "samples/runMain org.llm4s.samples.workspace.ContainerisedWorkspaceDemo"

# Using Scala 2.13
sbt ++2.13.14 "samples/runMain org.llm4s.samples.basic.BasicLLMCallingExample"

Cross Compilation

LLM4S supports both Scala 2.13 and Scala 3.3. The codebase is set up to handle version-specific code through source directories:

  • src/main/scala - Common code for both Scala 2.13 and 3.3
  • src/main/scala-2.13 - Scala 2.13 specific code
  • src/main/scala-3 - Scala 3 specific code

When you need to use version-specific features, place the code in the appropriate directory.

We've added convenient aliases for cross-compilation:

# Compile for all Scala versions
sbt compileAll

# Test all Scala versions
sbt testAll

# Both compile and test
sbt buildAll

# Publish for all versions
sbt publishAll

Cross-Compilation Testing

We use specialized test projects to verify cross-version compatibility against the published artifacts. These tests ensure that the library works correctly across different Scala versions by testing against actual published JARs rather than local target directories.

# Run tests for both Scala 2 and 3 against published JARs
sbt testCross

# Full clean, publish, and test verification
sbt fullCrossTest

Note: For detailed information about our cross-testing strategy and setup, see crossTest/README.md

Roadmap

Our goal is to implement Scala equivalents of popular Python LLM frameworks:

  • * Single API access to multiple LLM providers (like LiteLLM) - llmconnect
  • A comprehensive toolchain for building LLM apps (like LangChain/LangGraph)
    • * RAG search
    • * tool calling
    • * logging/tracking/monitoring
  • * An agentic framework (like PydanticAI, CrewAI)
    • Single agent
    • Multi-agent
  • Tokenization utilities (port of tiktoken)
  • Examples/ support
    • * Standard tool calling libraries
    • * examples of all use-cases
  • stable platform -tests etc
  • Scala Coding SWE Agent - an agent that can do SWE bench type tasks on Scala codebases.
    • code maps
    • generation
    • templates for library use?

Tool Calling

Tool calling is a critical integration - we aim to make it as simple as possible:

Tool Signature Generation

Using ScalaMeta to automatically generate tool definitions from Scala methods:

/** My tool does some funky things with a & b...
 * @param a The first thing
 * @param b The second thing
 */
def myTool(a: Int, b: String): ToolResponse = {
  // Implementation
}

ScalaMeta extracts method parameters, types, and documentation to generate OpenAI-compatible tool definitions.

Tool Call Mapping

Mapping LLM tool call requests to actual method invocations through:

  • Code generation
  • Reflection-based approaches
  • ScalaMeta-based parameter mapping

Secure Execution

Tools run in a protected Docker container environment to prevent accidental system damage or data leakage.

Comprehensive Tracing System

LLM4S provides a powerful, configurable tracing system for monitoring, debugging, and analyzing your LLM applications with support for multiple backends.

Tracing Modes

Configure tracing behavior using the TRACING_MODE environment variable:

# Send traces to Langfuse (default)
TRACING_MODE=langfuse
LANGFUSE_PUBLIC_KEY=pk-lf-your-key
LANGFUSE_SECRET_KEY=sk-lf-your-secret

# Print detailed traces to console with colors and token usage
TRACING_MODE=print

# Disable tracing completely
TRACING_MODE=none

Basic Usage

import org.llm4s.trace.Tracing

// Create tracer based on TRACING_MODE environment variable
val tracer = Tracing.create()

// Trace events, completions, and token usage
tracer.traceEvent("Starting LLM operation")
tracer.traceCompletion(completion, model)
tracer.traceTokenUsage(tokenUsage, model, "chat-completion")
tracer.traceAgentState(agentState)

πŸ“’ Talks & Presentations

See the talks being given by maintainers and open source developers globally and witness the engagement by developers around the world.

Stay updated with talks, workshops, and presentations about LLM4S happening globally. These sessions dive into the architecture, features, and future plans of the project.



Bay Area Scala Conference Generative AI Slide Functional World 2025 Poland Talk Scala India Talk Banner Dallas Scala Enthusiasts Talk Banner

Snapshots from LLM4S talks held around the world 🌍.



Upcoming & Past Talks

Date Event/Conference Talk Title Location Speaker Name Details URL Recording Link URL
25-Feb-2025 Bay Area Scala Let's Teach LLMs to Write Great Scala! (Original version) Tubi office, San Francisco, CA, USA Kannupriya Kalra Event Info
Reddit Discussion
Mastodon Post
Bluesky Post
X/Twitter Post
Watch Recording
20-Apr-2025 Scala India Let's Teach LLMs to Write Great Scala! (Updated from Feb 2025) India Kannupriya Kalra Event Info
Reddit Discussion
X/Twitter Post
Watch Recording
28-May-2025 Functional World 2025 by Scalac Let's Teach LLMs to Write Great Scala! (Updated from Apr 2025) Gdansk, Poland Kannupriya Kalra LinkedIn Post 1
LinkedIn Post 2
Reddit Discussion
Meetup Link
X/Twitter Post
Scalendar Newsletter
Watch Recording
13-Jun-2025 Dallas Scala Enthusiasts Let's Teach LLMs to Write Great Scala! (Updated from May 2025) Dallas, Texas, USA Kannupriya Kalra Meetup Event
Scalendar June Newsletter
LinkedIn Post
X/Twitter Post
Reddit Discussion
Bluesky Post
Mastodon Post
Recording will be posted once the event is done
21-Aug-2025 Scala Days 2025 Scala Meets GenAI: Build the Cool Stuff with LLM4S SwissTech Convention Center, EPFL (Γ‰cole Polytechnique FΓ©dΓ©rale de Lausanne) campus, Lausanne, Switzerland Kannupriya Kalra, Rory Graves Talk Info Recording will be posted once the event is done

πŸ“ Want to invite us for a talk or workshop? Reach out via our respective emails or connect on Discord: https://discord.gg/4uvTPn6qww

Why You Should Contribute to LLM4S?

  • Build AI-powered applications in a statically typed, functional language designed for large systems.
  • Help shape the Scala ecosystem’s future in the AI/LLM space.
  • Learn modern LLM techniques like zero-shot prompting, tool calling, and agentic workflows.
  • Collaborate with experienced Scala engineers and open-source contributors.
  • Gain real-world experience working with Dockerized environments and multi-LLM providers.
  • Contribute to a project that offers you the opportunity to become a mentor or contributor funded by Google through its Google Summer of Code (GSoC) program.
  • Join a global developer community focused on type-safe, maintainable AI systems.

Contributing

Interested in contributing? Start here:

LLM4S GitHub Issues: https://lnkd.in/eXrhwgWY

Join the Community

Want to be part of developing this and interact with other developers? Join our Discord community!

LLM4S Discord: https://lnkd.in/eb4ZFdtG

Google Summer of Code (GSoC)


GSoC Logo
LLM4S was selected for GSoC 2025 under the Scala Center Organisation.


This project is also participating in Google Summer of Code (GSoC) 2025! If you're interested in contributing to the project as a contributor, check out the details here:

πŸ‘‰ Scala Center 928F GSoC Ideas: https://lnkd.in/enXAepQ3

To know everything about GSoC and how it works, check out this talk:

πŸŽ₯ GSoC Process Explained: https://lnkd.in/e_dM57bZ

To learn about the experience of GSoC contributors of LLM4S, check out their blogs in the section below.

πŸ“š Explore Past GSoC Projects with Scala Center: https://www.gsocorganizations.dev/organization/scala-center/
This page includes detailed information on all GSoC projects with Scala Center from past years β€” including project descriptions, code repositories, contributor blogs, and mentor details.

πŸ‘₯ GSoC Contributor Onboarding Resources

Hello GSoCers and future GSoC aspirants! Here are some essential onboarding links to help you collaborate and stay organized within the LLM4S community.

  • πŸ”— LLM4S GSoC GitHub Team:
    You have been invited to join the LLM4S GitHub team for GSoC participants. Accepting this invite will grant you access to internal resources and coordination tools.
    πŸ‘‰ https://github.com/orgs/llm4s/teams/gsoc/members

  • πŸ“Œ Private GSoC Project Tracking Board:
    Once you're part of the team, you will have access to our private GSoC tracking board. This board helps you track tasks, timelines, and project deliverables throughout the GSoC period.
    πŸ‘‰ https://github.com/orgs/llm4s/projects/3

GSoC 2025: Funded Project Ideas from LLM4S

LLM4S - Implement an agentic toolkit for Large Language Models

LLM4S - RAG in a box

LLM4S - Support image, voice and other LLM modalites

LLM4S - Tracing support

Feel free to reach out to the contributors or mentors listed for any guidance or questions related to GSoC 2026.

Maintainers

Want to connect with maintainers? The LLM4S project is maintained by:

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

About

Agentic and LLM Programming in Scala

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 99.4%
  • Shell 0.6%
0