Get the FREE Ultimate OpenClaw Setup Guide →

Logic Query

Scanned
npx machina-cli add skill NewJerseyStyle/plugin-logic-llm/logic-query --openclaw
Files (1)
SKILL.md
3.7 KB

/logic-query

Query symbolic knowledge bases using natural language or formal logic syntax.

Description

This skill enables querying knowledge bases that have been created through /logic-convert or manually. It translates natural language questions into formal queries and returns human-readable answers using the appropriate solver.

Supported Solvers

SolverMCP ServerQuery Types
Prologprolog-mcpYes/no, find values, find all
Clingoclingo-mcpAnswer sets, optimization
Z3z3smt-mcpSatisfiability, models, proofs
FOLfolprover-mcpTheorem proving
Pykepyke-mcpGoal proving, variable bindings

Usage

/logic-query [options] <question>

Options

  • --format <prolog|clingo|z3|fol|pyke> - Query format (auto-detected if KB loaded)
  • --kb <path> - Path to knowledge base file(s) to load
  • --session <name> - Use named session (persists loaded facts/rules)
  • --explain - Show reasoning trace/proof
  • --all - Return all solutions/answer sets/models
  • --timeout <ms> - Query timeout in milliseconds

Examples

/logic-query "Is John allowed to access the confidential files?"
/logic-query --kb ./legal/rules.pl --explain "Can contractors view salary data?"
/logic-query --format clingo --all "What are the valid schedules?"
/logic-query --format z3 "Is it possible to assign all tasks within budget?"
/logic-query --format fol --explain "Does mortality follow from the premises?"
/logic-query --format pyke --session hr "Who reports to the CEO?"

Query Types by Solver

Prolog Queries

# Yes/No
?- can_access(john, file_a).

# Find values
?- can_access(john, What).

# Find all
?- findall(X, can_access(X, confidential), People).

Clingo Queries

# Check satisfiability (answer sets exist?)
# Find all answer sets
# Optimization (minimize/maximize)

Z3 Queries

# Satisfiability check
s.check()

# Get model
s.model()

# Prove theorem
prove(theorem)

FOL Queries

# Prove from premises
prove(premises, conclusion)

# Check validity

Pyke Queries

# Test fact
query("Mortal(socrates, True)")

# Find bindings
prove_goal("Descendant(tom, $who, True)")

Behavior

  1. Session Management: Load or create query session
  2. Knowledge Base Loading: Load specified KB files if not in session
  3. Query Translation: Convert natural language to formal query
  4. Registry Lookup: Use registry to resolve predicate names
  5. Solver Selection: Choose appropriate solver based on format
  6. Execution: Run query through MCP server
  7. Result Interpretation: Translate formal results to natural language

Output

The skill returns:

  • Answer to the query (yes/no, values, or explanations)
  • Reasoning trace if --explain is used
  • Multiple solutions if --all is specified
  • Confidence indicator when translation is ambiguous

Session Persistence

Sessions are stored in data/sessions/ and can be resumed across conversations:

  • Use --session myproject to name a session
  • Sessions preserve loaded facts, rules, and query history
  • Sessions support incremental knowledge base updates
  • Each solver has its own session namespace

Integration

This skill uses:

  • prolog-mcp: runPrologQuery, loadProgram
  • clingo-mcp: solve, getProgram
  • z3smt-mcp: check_sat, solve, prove
  • folprover-mcp: prove, add_premise
  • pyke-mcp: query, prove_goal
  • logic-registry for predicate resolution

Notes

  • Natural language queries are mapped to formal queries using the registry's predicate descriptions
  • Complex queries may be decomposed into sub-queries for better accuracy
  • The skill handles negation appropriately for each solver type
  • Timeout helps prevent long-running queries from blocking

Source

git clone https://github.com/NewJerseyStyle/plugin-logic-llm/blob/main/skills/logic-query/SKILL.mdView on GitHub

Overview

Logic Query lets you ask questions against knowledge bases built via /logic-convert or manual entries. It translates natural-language questions into formal queries and returns human-readable results using the appropriate solver (Prolog, Clingo, Z3, FOL, or Pyke). This makes symbolic reasoning accessible from conversational prompts.

How This Skill Works

It loads the target KB (from a session or --kb path), translates NL questions into a formal query using the registry, then selects the correct solver via the --format or auto-detected format. The MCP server executes the query and the skill translates the solver results into natural-language answers, optionally including explanations with --explain.

When to Use It

  • When you have a knowledge base built with /logic-convert or manual facts and rules
  • When you need yes/no answers, specific values, or all answer sets from a Prolog/Clingo/Z3/FOL/Pyke query
  • When you require explanations or proofs of a query with --explain
  • When you need all solutions or models (--all) or optimizations
  • When you want to persist work in a named session and reuse loaded KBs across conversations

Quick Start

  1. Step 1: Load or create a session and load your KB with --kb <path> or --session <name>
  2. Step 2: Run a query using natural language or a specified --format (e.g., /logic-query --format clingo --explain ...)
  3. Step 3: Optional - add --explain for reasoning trace or --all to retrieve all solutions

Best Practices

  • Load the KB into a named session (or use --kb) before querying repeatedly
  • Choose the correct --format corresponding to your KB's solver for accurate results
  • Use --explain to get a reasoning trace only when debugging or validating logic
  • Use --all when you need multiple solutions, but be mindful of output verbosity
  • Ensure predicates are resolved via the logic-registry to avoid missing or renamed predicates

Example Use Cases

  • "Is John allowed to access the confidential files?"
  • "Can contractors view salary data?"
  • "What are the valid schedules?"
  • "Is it possible to assign all tasks within budget?"
  • "Does mortality follow from the premises?"

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers