ErgoAI & LLM Integration via Ensemble Reasoning

43 views
Skip to first unread message

Marc Hadfield

unread,
Jan 21, 2025, 4:37:22 PMJan 21
to ErgoAI and XSB Users Forum

Just FYI, I'm working on "Ensemble Reasoning" which tightly integrates a reasoning LLM with other reasoning components.

For a proof-of-concept, one of the integrated components is a knowledge graph implemented with ErgoAI.  So, I thought this might be of interest here.

Here's a write-up of it:
This provides links to a github repo with the code used.

The reasoning LLMs tested were R1 which came out yesterday and QwQ which came out about 6 weeks ago.
Both were able to generate simple knowledge graph queries and process query results.

In "Ensemble Reasoning" as the inference generates tokens, these are directly piped to ensemble members (like a query engine) which generate results that are piped as tokens back into the LLM as the next part of the generated sequence, so the inference never stops, unlike LLM "tool calls" where the LLMs composes a query and then stops.  Reasoning LLMs kick out reasoning steps, and allowing those to directly trigger knowledge graph queries can allow the LLM to very dynamically explore a knowledge graph as it continues to reason.  So, there's an opportunity to join LLMs with more "traditional" logical inference for a neuro-symbolic "ensemble".

-- Marc Hadfield

Theresa Swift

unread,
Jan 22, 2025, 9:04:15 AMJan 22
to Marc Hadfield, ErgoAI and XSB Users Forum
That sounds very interesting.  I wanted to make sure you were aware of XSB's Python Interface Janus, which is very fast and powerful.  

It's easily called from ErgoAI as a Prolog module.  If you're interested, I can tell you more.

Theresa

--
You received this message because you are subscribed to the Google Groups "ErgoAI and XSB Users Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ErgoAI-XSB-for...@coherentknowledge.com.
To view this discussion visit https://groups.google.com/a/coherentknowledge.com/d/msgid/ErgoAI-XSB-forum/CABgggufcoiV9ZH545mO%2Bwws090To26JSYkmQ_tWC6w6L4WX0PA%40mail.gmail.com.

Marc Hadfield

unread,
Jan 22, 2025, 9:53:36 AMJan 22
to Theresa Swift, ErgoAI and XSB Users Forum

Thanks, please share a link! The current code just uses the "pyergo" and "pyxsb" packages so far.

Marc Hadfield

unread,
May 16, 2025, 2:53:40 PMMay 16
to Theresa Swift, ErgoAI and XSB Users Forum
Hello!

Is there a guide somewhere for using Ergo/XSB with Janus for the XSB calling Python case?

This would be the case of: Python calling Ergo via pyergo/pyxsb, Ergo calling XSB prolog, and the prolog calling a Python function.

When I try to use Ergo with an updated XSB with the Janus package, I run into segfault/malloc errors, and to get it to compile on Mac OS I have to edit some lines like: (in xsbext.c)
    {"jns_next", px_next, METH_VARARGS, "XSB query execution via structures and terator"},
to:
    {"jns_next", (PyCFunction)px_next, METH_VARARGS, "XSB query execution via structures and terator"},

i.e. add the casting "(PyCFunction)"
to stop the compiler from complaining.

So, there are probably version mismatches, so I was looking for a guide to start from a fresh install with a working Ergo/XSB/Janus with the python callback capability that would work in Mac OS and Linux.

Thanks for any help!
-- Marc

Theresa Swift

unread,
May 16, 2025, 4:30:12 PMMay 16
to Marc Hadfield, ErgoAI and XSB Users Forum
Which version of XSB does your ErgoAI use?

Marc Hadfield

unread,
May 16, 2025, 5:32:03 PMMay 16
to Theresa Swift, ErgoAI and XSB Users Forum
Regarding versions:

I started with the ergo official release:
which has an embedded XSB:
./XSB/bin/xsb
[xsb_configuration loaded]
[sysinitrc loaded]
[xsbbrat loaded]

XSB Version 5.0.0 (Green Tea) of May 15, 2022
[aarch64-apple-darwin23.6.0 64 bits; mode: optimal; engine: slg-wam; scheduling: local]
[Build date: 2025-05-15]

| ?- 

This XSB version does not have "janus".

I attempted to use the most recent XSB code from the git repo, but ran into the problems mentioned.

I am happy to build from source, but I do not know the correct combination of Ergo, XSB, xsbpy, janus, etc. to use.

The goal is to use the most recent ergo from python with ergo-to-python callbacks (via XSB).  I've been using pyergo/pyxsb for the python to ergo thus far.  I'm using Python 3.11 and above.  It looks like what is in the XSB manual is for the pre-janus interface, and as far as I can see no Ergo docs mention Janus or the xsb-to-python callbacks.

-- Marc

Marc Hadfield

unread,
May 17, 2025, 12:40:22 PMMay 17
to Theresa Swift, ErgoAI and XSB Users Forum
Quick follow-up, with pyergo/pyxsb, python is using xsb as a shared library.  I don't know how Janus works, but potentially it uses python as a shared lib, so the other way around.

The end goal, in my case, is to have python and ergo/xsb-prolog able to call each other within the same process.
It seems a bit more natural to have python launch xsb, but in principle either way would work.
So, if it turns out it is easier to have XSB + Janus init some top-level python code with that code able to call Ergo as well as that code base able to be called back from Janus that could work.

Trying to mix both with python-exe initing xsb-shared-lib which inits python-shared-lib seems like it could be problematic, but I haven't fully thought it through.

-- Marc

Marc Hadfield

unread,
May 23, 2025, 1:14:04 PMMay 23
to Theresa Swift, ErgoAI and XSB Users Forum
Any info on this?  I don't see any resources for Ergo/Janus and prolog --> python available.
Reply all
Reply to author
Forward
0 new messages