Docs / Getting Started / Installation & Setup

Installation & Setup

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

Requirements


Adding to Your Project

langchain-hs is structured into modular, decoupled packages. Install the core framework and only the provider integrations you actually need:

Package Purpose Typical Use Case
langchain-hs Core Framework Agents (ReAct, PlanAndExecute), Chains, Vector Stores, Observability
langchain-hs-core Pure AST & Types Pure ASTs (RunnableTree), ChatModel, Tool
langchain-hs-graph State Graphs StateGraph, Sub-Graphs, Checkpointing, Time-Travel, HITL
langchain-hs-ollama Ollama Provider Local/offline inference via Ollama
langchain-hs-openai OpenAI Provider OpenAI & OpenAI-compatible endpoints (OpenRouter, Fireworks)
langchain-hs-gemini Gemini Provider Google Gemini API (Interactions v1 OpenAPI spec), embeddings & SSE streaming
langchain-hs-anthropic Anthropic Provider Native Anthropic Claude /v1/messages provider, prompt caching, thinking & SSE streaming
langchain-hs-mcp MCP Client Connect to Model Context Protocol servers over stdio

Using Cabal

cabal update
cabal install langchain-hs langchain-hs-ollama langchain-hs-openai

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

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

Using Stack

Add the packages to your stack.yaml:

resolver: lts-24.56 # Or nightly / lts-23+ / lts-22+

packages:
  - .

extra-deps:
  - langchain-hs-0.0.6.2
  - langchain-hs-core-0.0.6.2
  - langchain-hs-graph-0.0.6.2
  - ollama-haskell-0.4.2.0
  # Add providers as needed:
  - langchain-hs-ollama-0.0.6.2
  - langchain-hs-openai-0.0.6.2
  - langchain-hs-gemini-0.0.6.2
  - langchain-hs-anthropic-0.0.6.2
  - langchain-hs-mcp-0.0.6.2

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

dependencies:
  - base >= 4.14 && < 5
  - text
  - langchain-hs
  # Add only what you use:
  - langchain-hs-ollama
  - langchain-hs-openai
  - langchain-hs-gemini
  - langchain-hs-anthropic

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. All documentation is hosted on Hackage.

ESC