Tutorials

LangChain on the BEAM

A conversational agent in Elixir: the chain inside a process, tools the model can call, and streaming all the way to the screen.

3 parts Ongoing
  • elixir
  • langchain
  • llm
  • otp

Elixir LangChain handles each provider's message format and the tool-calling loop. Beyond that it has no opinion, which leaves you three decisions: where the conversation state lives, what to do when the model takes its time, and who receives the pieces of the answer while they arrive.

OTP has had answers to those three for decades: process, supervisor, mailbox. This series uses those pieces to assemble a conversational agent:

  1. The chain inside a process. Why a conversation is a GenServer, and how to spin one up per user without leaking processes.
  2. Tools the model can call. What the model controls when you hand it a function, and where to validate.
  3. The LiveView cannot wait. Token-by-token streaming, and where the call to the model has to run.

The code assumes {:langchain, "~> 0.9.0"} and a Phoenix nearby. Each part stands on its own, but they were written to be read in order.

03Parts

1 person is here