Build a support assistant with LLM4S

Acme Shop is a small online shop, and its customers write in about orders, deliveries and refunds. Over this series you build the assistant that answers them: first a plain answer, then a typed ticket the rest of the system can route, then an agent that looks up the order and the refund policy before it answers.

The parts

Part Adds Shows
1. First call An answer, then a streamed answer, from a configured provider Llm4sConfig, LLMConnect, Result
2. Typed answers Classify a message into a ticket structured output, derives schemas
3. Tools and an agent Look up an order and the refund policy typed tools, ToolRegistry, an agent

Still to come, tracked in #2292: answers from the help-centre docs (RAG), safety and memory, testing with llm4s-testkit and a judge, and serving and observing the assistant.

How the series works

The code of every part is in modules/samples, one file per part, and every part runs with no API key: a scripted client from llm4s-testkit stands in for the model. Add --live to run the same code against the provider your configuration names (see running the samples); a local Ollama model is enough.

1
2
sbt "samples/runMain org.llm4s.samples.tutorial.supportassistant.Part1FirstCall"          # scripted, no key
sbt "samples/runMain org.llm4s.samples.tutorial.supportassistant.Part1FirstCall --live"   # your provider

Each part has a spec, Part1Spec to Part3Spec, that runs the part’s code against scripted clients and checks that every Scala block on its page is the code in the source file, word for word. CI runs them on every pull request, so the tutorial cannot drift from the library.

Exercises

Each part ends with an exercise. Its stub is in Exercises.scala: a method whose body is ???, marked TODO. Replace the ??? with your code and run the part’s spec:

1
sbt "samples/testOnly *Part1Spec"

The case named “Your exercise 1” is reported as pending while the ??? is there, and fails until your code does what the page asks. The worked solutions are in the solutions package, and the same spec checks them, so a solution never goes stale.

You need the installation done and a clone of the repository; Scala 3 and sbt basics are enough.


Table of contents