langchain-hs-core

Core typeclasses and pure AST primitives for langchain-hs

https://github.com/tusharad/langchain-hs#readme

Stackage Nightly 2026-11-14:0.0.6.2
Latest on Hackage:0.0.6.2

See all snapshots langchain-hs-core appears in

MIT licensed by Tushar Adhatrao
Maintained by [email protected]
This version can be pinned in stack with:langchain-hs-core-0.0.6.2@sha256:c9ca0e53e3d0c20a5353bbe5772da70c55f1489ab684d4a306e64e79cae8a4db,5245

Module documentation for 0.0.6.2

langchain-hs-core

The foundational, effect-polymorphic core framework of the langchain-hs AI ecosystem.

langchain-hs-core provides pure GADT abstract syntax trees, effect-polymorphic chat models, streaming protocols, tools, agents, vector stores, retrievers, document loaders, memory, cache, output parsers, guardrails, resilience, observability, and the canonical Langchain.Prelude without concrete provider-specific dependencies.

Key Primitives & Modules

  • Runnables & Pure ASTs (Langchain.Runnable): Pure GADT abstract syntax tree (RunnableTree m i o) for pipeline composition via |>> (sequential), &>& (parallel fan-out), runLambda, runPrim, and deferred evaluation via interpret.
  • Chat Models & Types (Langchain.Model, Langchain.Model.Types): Effect-polymorphic ChatModel typeclass, Message, Role, ContentBlock (multi-modal text, images, tool calls, tool results).
  • Streaming Protocols (Langchain.Stream): Conduit-based incremental token streaming via StreamEvent and LLMChunk.
  • Tools & Dynamic Calling (Langchain.Tool, Langchain.Tool.Binding): Effect-polymorphic Tool m, createTool, Generic Schemas, and built-in tools (Calculator, FileSystem, Shell). Provider-agnostic tool binding via ToolBinder.
  • Agents (Langchain.Agent.ReAct, Langchain.Agent.PlanAndExecute):
    • ReAct Agent: Full reasoning + acting agent loop with tool inspection, memory integration, callbacks, and step traces.
    • Plan-and-Execute Agent: Two-phase agent decomposing complex user goals into discrete execution plans.
  • Prompt Templates (Langchain.PromptTemplate): String prompt templates with {var} f-string interpolation and pre-bound partial variables.
  • Vector Stores (Langchain.VectorStore): Abstract VectorStore typeclass and thread-safe InMemoryVectorStore.
  • Retrievers (Langchain.Retriever): BM25 keyword search (BM25Retriever), vector similarity retriever, and Reciprocal Rank Fusion (HybridRetriever).
  • Document Loaders & Text Splitters (Langchain.DocumentLoader, Langchain.TextSplitter): Document metadata abstraction and splitters for character chunks, Markdown, programming code, and tokens.
  • Memory & Cache (Langchain.Memory, Langchain.Cache): BaseMemory, ConversationBufferMemory, WindowBufferMemory, and STM-backed in-memory LLMCache.
  • Output Parsers (Langchain.OutputParser): Strongly typed JSON Schema generation (JsonOutputParser) and structured parsing.
  • Guardrails & Safety (Langchain.Guardrails): Input and output content moderation, PII redaction, and semantic safety validations.
  • Resilience & Fault Tolerance (Langchain.Resilience): State-machine CircuitBreaker, exponential backoff RetryConfig, and fallback handlers.
  • Observability & Tracing (Langchain.Observability, Langchain.Callback): OpenTelemetry distributed tracing spans, structured JSON event logging, and lifecycle event callbacks.
  • Chains (Langchain.Chain.RetrievalQA): End-to-end question answering pipeline over indexed knowledge bases.
  • Langchain Monad (Langchain.Monad): Decoupled LangchainT env m a reader and error transformer.
  • Canonical Prelude (Langchain.Prelude): Batteries-included single-import entry point providing the full core framework API.

Installation

Add to your cabal or package.yaml dependencies:

build-depends:
    langchain-hs-core >= 0.0.6.2 && < 0.0.7.0

To connect concrete LLMs, combine with satellite provider packages:

  • langchain-hs-ollama: Local & offline models (Llama 3, DeepSeek, Gemma).
  • langchain-hs-openai: OpenAI, OpenRouter, and OpenAI-compatible cloud endpoints.
  • langchain-hs-gemini: Google Gemini with multi-modal support.
  • langchain-hs-mcp: Model Context Protocol tool client.

For cyclic state machines, checkpointers, and multi-agent coordination, add langchain-hs-graph (or use the umbrella langchain-hs package).

License

Distributed under the MIT License. See LICENSE for details.

Changes

Changelog for langchain-hs-core

All notable changes to this package will be documented in this file.

0.0.6.2 - 2026-11-14

Note: 0.0.6.1 was skipped globally after langchain-hs-ollama-v0.0.6.1.

  • Tool-Call & Agent Streaming:
    • Extended StreamEvent in Langchain.Stream with ToolStart, ToolChunk, ToolEnd, and ToolErrorEvent, plus liftChatStream and tapStreamMessage.
    • Added cancellation-safe streaming combinators liftChatStreamResource and liftChatStreamWithCancel in Langchain.Stream.
    • Added StreamingTool, createStreamingTool, fromTool, streamToolCall, and streamStreamingToolCall to Langchain.Tool.
    • Added streamingShellTool (Langchain.Tool.Shell) and withStreamingSecurity (Langchain.Tool.Security).
    • Added withStreamingTools, reactStepStream, streamReActAgent, streamReActAgentWithTrace, and runReActAgentStream to Langchain.Agent.ReAct.
    • Added streamPlanAndExecute and runPlanAndExecuteStream to Langchain.Agent.PlanAndExecute.
    • Updated Langchain.Prelude exports for streaming tools and agents.
  • Multi-Agent Primitives & ReAct Loop Detection:
    • Added LoopDetectionStrategy (NoLoopDetection, WarnOnDuplicateAction, FailOnLoop, BreakOnLoop) and iteration telemetry (traceIterations, traceTerminatedBy).
    • Added multi-agent handoff tools asAgentTool and asStreamingAgentTool.
  • Evaluation Harness (Langchain.Eval):
    • Added EvalCase, EvalScore, Scorer, and EvalReport with Aeson support.
    • Implemented exactMatchScorer, containsScorer, toolCallExactScorer, llmJudgeScorer, and runEvalSuite.
  • Security, Checkpointing, Memory & Parsers (consolidated post-0.0.6.0 alignment):
    • SecurityPolicy, FileSystem, Process, and Checkpoint tool suites (Langchain.Tool.*).
    • InVariableMemory, SessionMemory, EntityMemory, CombinedMemory, FileMemory, and buffer reset helpers.
    • Updated sqlite-simple bounds to >= 0.4.18 && < 0.5.

0.0.6.0 - 2026-10-02

  • Updated bounds for GHC 9.12 and modern Stackage LTS releases.
  • Standalone stack configuration and verified test suite.

0.0.5.0 - 2026-09-10

  • Initial standalone Hackage release of langchain-hs-core.
  • Zero-dependency pure core architecture.
  • First-class RunnableTree GADT AST with sequential (|>>), parallel (&>&), and fallback (>>>#) operators.
  • ChatModel effect-polymorphic interface.
  • Multi-modal ContentBlock and message structures.
  • Conduit-based StreamEvent and streaming protocol.
  • Decoupled LangchainT env m a transformer.
  • Typed Tool and FunctionDefinition.