Docs / Getting Started / Installation & Setup

Installation & Setup

Setting up langchain-hs in your Haskell project using Stack, Cabal, or Nix.

Requirements

  • GHC: 9.6.x through 9.10.x supported (GHC 9.6.7 recommended)
  • Stack (>= 2.9) or Cabal (>= 3.8)
  • Local LLM provider (e.g.Β Ollama) or API keys (OpenAI, Gemini, OpenRouter)

Adding to Your Project

langchain-hs is structured into three composable packages. Depending on your needs, you can depend on the full umbrella package or just the pure core.

Package Purpose Typical Use Case
langchain-hs Full ecosystem Providers, MCP, Vector Stores, Chains, Agents, Observability
langchain-hs-graph Graph & Multi-Agent StateGraph, Checkpointing, Time-Travel, Parallel Nodes
langchain-hs-core Pure AST & Types Zero-dependency pure ASTs (RunnableTree), ChatModel, Tool

Using Stack

Add the packages and required extra dependencies to your stack.yaml:

resolver: lts-22.44 # Or nightly / lts-23+

packages:
  - .

extra-deps:
  # langchain-hs packages (or from Hackage)
  - langchain-hs-0.5.0.0
  - langchain-hs-graph-0.5.0.0
  - langchain-hs-core-0.2.0.0

  # Upstream dependencies
  - git: https://github.com/tusharad/ollama-haskell
    commit: e38a92529d83303c5d05c38b73d73a278721700e
  - git: https://github.com/MercuryTechnologies/openai
    commit: 2031a05135b892a82b461558d19b813ab67cfb8f
  - git: https://github.com/lbobylev/format-heavy
    commit: 81196f86a16de8378a0ad264bf12af42c5ca7b65
  - mcp-server-0.2.0.1

In your package.yaml (or .cabal file):

dependencies:
  - base >= 4.14 && < 5
  - text
  - langchain-hs

Using Cabal

Add to your cabal.project or .cabal build-depends:

build-depends:
    base >= 4.14 && < 5,
    text,
    langchain-hs >= 0.5.0

Canonical Import: Langchain.Prelude

langchain-hs provides a unified prelude module that exposes all common constructors, operators, types, and runners:

{-# LANGUAGE OverloadedStrings #-}

import Langchain.Prelude
πŸ’‘ Pro Tip

Langchain.Prelude does not conflict with Haskell’s standard Prelude. You can safely import both without name shadowing.

ESC