Skip to main content
LangChain tools that use Prolog rules to generate answers.

Overview

The PrologTool class allows the generation of langchain tools that use Prolog rules to generate answers.

Setup

Let’s use the following Prolog rules in the file family.pl: parent(john, bianca, mary).
parent(john, bianca, michael).
parent(peter, patricia, jennifer).
partner(X, Y) :- parent(X, Y, _).

Instantiation

First create the Prolog tool:

Invocation

Using a Prolog tool with an LLM and function calling

To use the tool, bind it to the LLM model:
and then query the model:
The LLM will respond with a tool call request:
The tool takes this request and queries the Prolog database:
The tool returns a list with all the solutions for the query:
That we then pass to the LLM, and the LLM answers the original query using the tool response:

Chaining

Using a Prolog Tool with an agent

To use the prolog tool with an agent, pass it to the agent’s constructor:
The agent takes the query and use the Prolog tool if needed:
Then the agent receives​ the tool response and generates the answer:

API reference

See langchain-prolog.readthedocs.io/en/latest/modules.html for detail.