langchain-hs-0.0.2.0: Haskell implementation of Langchain
Copyright(c) 2025 Tushar Adhatrao
LicenseMIT
MaintainerTushar Adhatrao <[email protected]>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Langchain.Tool.Core

Description

Core module defining the Tool typeclass for Langchain-Haskell integration.

This module provides a typeclass interface for creating interoperable tools that can be used with Large Language Models (LLMs) in Haskell applications. The design mirrors LangChain's Python tooling system while maintaining Haskell's type safety and functional programming principles.

Example use case:

data Calculator = Calculator

instance Tool Calculator where
  type Input Calculator = (Int, Int)
  type Output Calculator = Int
  toolName _ = "calculator"
  toolDescription _ = "Performs arithmetic operations on two integers"
  runTool _ (a, b) = pure (a + b)
Synopsis

Documentation

class Tool a where Source #

Typeclass defining the interface for tools that can be used with LLMs.

Tools represent capabilities that can be invoked by language models, following the LangChain framework's tooling pattern. Each tool must:

  • Define input/output types using type families
  • Provide a unique name and description
  • Implement an IO-based execution function

The use of type families allows for flexible yet type-safe tool composition, while the IO monad accommodates both pure and effectful implementations.

Associated Types

type Input a Source #

Input type required by the tool

Example: For a weather lookup tool, this might be LocationCoordinates

type Output a Source #

Output type produced by the tool

Example: For a calculator tool, this could be Int or Double

Methods

toolName :: a -> Text Source #

Get the tool's unique identifier

>>> toolName (undefined :: Calculator)
"calculator"

toolDescription :: a -> Text Source #

Get human-readable description of the tool's purpose

>>> toolDescription (undefined :: Calculator)
"Performs arithmetic operations on two integers"

runTool :: a -> Input a -> IO (Output a) Source #

Execute the tool with given input

This function bridges the gap between LLM abstractions and concrete implementations. The IO context allows for:

  • Pure computations (via pure)
  • External API calls
  • Database queries

Example implementation:

runTool _ (a, b) = do
  putStrLn "Calculating..."
  pure (a + b)

Instances

Instances details
Tool CalculatorTool Source # 
Instance details

Defined in Langchain.Tool.Calculator

Associated Types

type Input CalculatorTool 
Instance details

Defined in Langchain.Tool.Calculator

type Output CalculatorTool 
Instance details

Defined in Langchain.Tool.Calculator

Tool WebScraper Source #

Implement the Tool typeclass for WebScraper

Instance details

Defined in Langchain.Tool.WebScraper

Associated Types

type Input WebScraper 
Instance details

Defined in Langchain.Tool.WebScraper

type Output WebScraper 
Instance details

Defined in Langchain.Tool.WebScraper

Tool WikipediaTool Source #

Tool instance for WikipediaTool.

Instance details

Defined in Langchain.Tool.WikipediaTool

Associated Types

type Input WikipediaTool 
Instance details

Defined in Langchain.Tool.WikipediaTool

type Output WikipediaTool 
Instance details

Defined in Langchain.Tool.WikipediaTool