✨ Pure AST Pipelines & LangGraph in Haskell

Type-Safe AI Agents & Multi-Agent Graphs in Haskell

langchain-hs is a zero-unsafePerformIO, effect-polymorphic Haskell ecosystem built on pure GADT pipelines, state graphs, algebraic laws, Model Context Protocol (MCP), and production OpenTelemetry.

Get Started in 5 Min Explore 20 Components Prelude Cheat Sheet

Real Working Code: Ollama vs OpenAI

Switch between local inference (Ollama) and cloud APIs (OpenAI / OpenRouter) across all 20 components.

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad.Except (runExceptT)
import qualified Data.Text.IO as T
import Langchain.Prelude

main :: IO ()
main = do
  -- Connect to local Ollama instance (DeepSeek, Llama 3, Gemma, etc.)
  o <- newOllama "gemma3" defaultConfig
  
  let msg = [userMessage "Write a poem about functional programming in Haskell"]
  res <- runExceptT $ invoke o msg Nothing
  case res of
    Left err -> T.putStrLn $ errorMessage err
    Right m  -> T.putStrLn $ extractMessageText m
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad.Except (runExceptT)
import qualified Data.Text.IO as T
import Langchain.Prelude
import OpenAI.Common (defaultModelName, getOpenRouterModel)

main :: IO ()
main = do
  -- Connect to OpenAI or OpenRouter using environment API key
  o <- getOpenRouterModel defaultModelName
  
  let msg = [userMessage "Write a poem about functional programming in Haskell"]
  res <- runExceptT $ invoke o msg Nothing
  case res of
    Left err -> T.putStrLn $ errorMessage err
    Right m  -> T.putStrLn $ extractMessageText m

Complete Component Directory (20 Components)

Every component features dual Ollama/OpenAI examples, verified build targets, and complete Haskell signatures.

πŸ›‘οΈ
Pure Zero-Dependency Core
langchain-hs-core defines AST pipelines (RunnableTree), multi-modal ContentBlock, and streaming without ANY HTTP dependencies.
πŸ•ΈοΈ
LangGraph in Haskell
Cyclic state machines with pure state reducers, STM TVar & SQLite checkpointers, Human-in-the-Loop interrupts, time-travel history replay, and Graphviz DOT export.
πŸ”Œ
Model Context Protocol (MCP)
Native client supporting stdio and HTTP JSON-RPC 2.0 transports with automatic schema discovery and conversion to native Tool m instances.
πŸ‘₯
Advanced Multi-Agent Architectures
Plan-and-Execute, ReAct, Supervisor teams with capability routing, multi-agent debate with convergence checking, majority voting, and STM shared blackboards.
πŸ”
Hybrid Retrieval & RAG
Reciprocal Rank Fusion (RRF) combining BM25 keyword search and dense vector embeddings (SQLite-vec, InMemory, PgVector, Qdrant) with LLM rerankers.
πŸ“Š
Production Observability
OpenTelemetry spans (withSpan), structured JSON logs, three-state Circuit Breaker, exponential backoff retries, connection pooling, and token cost calculation.
ESC