Library to connect LLMs and planning tasks
Project description
l2p : LLM-driven Planning Model library kit
This library is a collection of tools for PDDL model generation extracted from natural language driven by large language models. This library is an expansion from the survey paper LLMs as Planning Formalizers: A Survey for Leveraging Large Language Models to Construct Automated Planning Specifications.
L2P is an offline, natural language-to-planning model system that supports domain-agnostic planning. It does this via creating an intermediate PDDL representation of the domain and task, which can then be solved by a classical planner. To stay up to date with the most current papers, please visit here.
Full library documentation can be found: L2P Documention
Quickstart
This is the general setup to build domain predicates:
import os
from l2p import UnifiedLLM
from l2p.domain_builder import DomainBuilder
from l2p.utils.pddl_types import Predicate, PDDLType
from l2p.utils.pddl_format import format_predicates
# set up LLM
api_key = os.getenv("OPENAI_API_KEY")
llm = UnifiedLLM(provider="openai", model="gpt-5-nano", api_key=api_key)
db = DomainBuilder() # instantiate DomainBuilder class
# context
types = [PDDLType(name="block", parent="object")]
desc = "I want you to model predicates from a standard PDDL blocksworld domain."
# generate predicates
results, raw_output = db.formalize_component(
model=llm,
component_class=Predicate, # component to generate
description=desc,
types=types # pass in kwargs context
)
# parse out predicates list from dictionary
predicates = results[Predicate]
predicates_str = format_predicates(predicates) # format nicely
print(predicates_str)
# OUTPUT:
# (clear ?x - block)
# (arm-empty )
# (holding ?x - block)
# (on ?x - block ?y - block)
# (on-table ?x - block)
Here is how you would setup a PDDL problem:
from l2p.problem_builder import ProblemBuilder
from l2p.utils.pddl_types import ProblemDetails, PDDLType, Predicate
pb = ProblemBuilder() # instantiate ProblemBuilder class
# context
types = [PDDLType(name="block", parent="object")]
predicates = [
Predicate(name="on", params=[
{"variable": "?x", "type": "block"},
{"variable": "?y", "type": "block"}
]),
Predicate(name="on-table", params=[{"variable": "?x", "type": "block"}]),
Predicate(name="holding", params=[{"variable": "?x", "type": "block"}]),
Predicate(name="clear", params=[{"variable": "?x", "type": "block"}]),
Predicate(name="arm-empty", params=[])
]
problem_desc = """
You have 3 blocks.
b2 is on top of b3.
b3 is on top of b1.
b1 is on the table.
b2 is clear.
Your arm is empty.
Your goal is to move the blocks.
b2 should be on top of b3.
b3 should be on top of b1.
"""
# generate problem
results, llm_output = pb.formalize_component(
model=llm,
component_class=ProblemDetails, # component to generate
description=problem_desc,
types=types, # pass in kwargs context
predicates=predicates # pass in kwargs context
)
# parse out problem from dictionary
problem = results[ProblemDetails]
# format problem in PDDL format
problem_str = pb.generate_problem(problem[0])
print(problem_str)
# OUTPUT:
# (define (problem blocks-problem)
# (:domain blocks-world)
# (:objects b1 b2 b3 - block)
# (:init
# (on b2 b3)
# (on b3 b1)
# (on-table b1)
# (clear b2)
# (arm-empty)
# )
# (:goal
# (and (on b2 b3) (on b3 b1))
# )
# )
Installation and Setup
Currently, this repo has been tested for Python 3.11.10 but should be fine to install newer versions.
You can set up a Python environment using either Conda or venv and install the dependencies via the following steps.
Conda
conda create -n L2P python=3.11.10
conda activate L2P
pip install -r requirements.txt
venv
python3.11.10 -m venv env
source env/bin/activate
pip install -r requirements.txt
These environments can then be exited with conda deactivate and deactivate respectively. The instructions below assume that a suitable environemnt is active.
API keys
L2P requires access to an LLM. L2P provides support for models compatible with OpenAI SDK or LLM. To configure these, provide the necessary API-key in an environment variable.
export OPENAI_API_KEY='YOUR-KEY' # e.g. OPENAI_API_KEY='sk-123456'
export CLAUDE_API_KEY='...'
export DEEPSEEK_API_KEY='...'
export OLLAMA_API_KEY='...'
We can then use the OPENAI class for OpenAI-SDK supported models OR UnifiedLLM class (recommended). Refer to here for more information:
import os
from l2p.llm.openai import OPENAI
from l2p.llm.unified import UnifiedLLM
api_key = os.getenv("OPENAI_API_KEY")
# OPENAI SDK BACKEND
llm = OPENAI(
provider="openai",
model="gpt-5-nano",
config_path="l2p/llm/utils/openaiSDK.yaml", # LLM configs stored here
api_key=api_key
)
# LLM BACKEND
llm = UnifiedLLM(
provider="openai",
model="gpt-5-nano",
config_path="l2p/llm/utils/llm.yaml", # LLM configs stored here
api_key=api_key
)
response = llm.query("Hello, world!")
print(response)
Ollama
Additionally, we have included support for using local Ollama models under UnifiedLLM. One can set up their environment like so:
from l2p.llm.unified import UnifiedLLM
llm = UnifiedLLM(
provider="ollama",
model="llama2:7b",
config_path="l2p/llm/utils/llm.yaml" # Ollama model configs stored here
)
response = llm.query("Hello, world!")
print(response)
Users can refer to l2p/llm/utils/llm.yaml (for UnifiedLLM) or l2p/llm/utils/openaiSDK.yaml (for OPENAI) to better understand (and create their own) model configuration options, including tokenizer settings, generation parameters, and provider-specific settings.
l2p/llm/base.py contains an abstract class and method for implementing any model classes in the case of other third-party LLM uses.
External Planner Support
L2P contains an abstract class Planner found in l2p/planner_builder.py. Users can use this class to run planners on top to solve for generated domain and problems.
For ease of use, our library contains submodule FastDownward. Fast Downward is a domain-independent classical planning system that users can run their PDDL domain and problem files on. The motivation is that the majority of papers involving PDDL-LLM usage uses this library as their planner.
IMPORTANT FastDownward is a submodule in L2P. To use the planner, you must clone the GitHub repo of FastDownward and run the executable_path to that directory.
Here is a quick test set up:
from l2p.planner_builder import FastDownward
domain_file = "<PATH_TO>/domain.pddl"
problem_file = "<PATH_TO>/problem.pddl"
# instantiate FastDownward class
planner = FastDownward(executable_path="<PATH_TO>/downward/fast-downward.py")
# run plan
plan_result = planner.run_planner(
domain_file=domain_file,
problem_file=problem_file,
alias="lama-first"
)
print(plan_result.is_successful)
print(plan_result.plan)
Additionally, L2P also supports Unified Planning backend. Users must first download: pip install unified-planning. After installing unified-planning library, you must install specific planner: pip install 'unified-planning[engine]' to pass into the solver function.
from l2p.planner_builder import UnifiedPlanning
planner = UnifiedPlanning()
plan_result = planner.run_planner(
domain_path="<PATH_TO>/domain.pddl",
problem_path="<PATH_TO>/problem.pddl",
engine="aries" # specific planning backend
)
print(plan_result.is_successful)
print(plan_result.plan)
Agentic CLI (for LLM agents & automation)
The fastest way to build PDDL models is piping structured JSON between non-interactive commands:
# 1. Look up the JSON schema an LLM should follow
l2p schema domain --examples
# 2. Set individual components (validate + format in one step)
l2p set types --data '[{"name":"block","parent":"object"}]' --json
l2p set predicates --data '[
{"name":"clear","params":[{"variable":"?x","type":"block"}]},
{"name":"on","params":[{"variable":"?x","type":"block"},{"variable":"?y","type":"block"}]}
]' --pddl
# 3. Assemble and render the full PDDL domain
l2p build domain --data '{
"name":"blocksworld",
"types":[{"name":"block","parent":"object"}],
"predicates":[
{"name":"clear","params":[{"variable":"?x","type":"block"}]},
{"name":"on","params":[{"variable":"?x","type":"block"},{"variable":"?y","type":"block"}]}
],
"actions":[
{"name":"stack","params":[{"variable":"?x","type":"block"},{"variable":"?y","type":"block"}],
"preconditions":{"conditions":["(clear ?y)","(holding ?x)"]},
"effects":{"add":["(on ?x ?y)"],"delete":["(clear ?y)","(holding ?x)"]}}
]
}' -o domain.pddl
# 4. Validate the generated file
l2p validate domain domain.pddl
# 5. Run a planner on it
l2p plan --domain @domain.pddl --problem @problem.pddl --planner fast-downward --json
Every command is stateless: pass full JSON via --data or compose from individual flags. LLM agents can chain them naturally:
# Pipe validated JSON between commands
l2p set types --data '[...]' --json | l2p set predicates --stdin --json
Contact
Please contact 20mt1@queensu.ca for questions, comments, or feedback about the L2P library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file l2p-0.4.0.tar.gz.
File metadata
- Download URL: l2p-0.4.0.tar.gz
- Upload date:
- Size: 142.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fa563e502ea6e3cc17f34715e93e28203a92d2b8a878a1fdd7f818c5dc7939c
|
|
| MD5 |
2a6a4972168bc3dc1ad1f03ad484657a
|
|
| BLAKE2b-256 |
9625fc7527a377a13bf0b33fd846ab2ea05a6c8267f51ad47f50a8e6184c7d03
|
Provenance
The following attestation bundles were made for l2p-0.4.0.tar.gz:
Publisher:
python-publish.yml on AI-Planning/l2p
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
l2p-0.4.0.tar.gz -
Subject digest:
9fa563e502ea6e3cc17f34715e93e28203a92d2b8a878a1fdd7f818c5dc7939c - Sigstore transparency entry: 1672209290
- Sigstore integration time:
-
Permalink:
AI-Planning/l2p@7cf4b3dfb9200a51b4c20607e30670273c27cfc8 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/AI-Planning
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7cf4b3dfb9200a51b4c20607e30670273c27cfc8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file l2p-0.4.0-py3-none-any.whl.
File metadata
- Download URL: l2p-0.4.0-py3-none-any.whl
- Upload date:
- Size: 168.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3197cf31c1312317e8df109b304d66025960ab41b58e392ebfafe8f09354f684
|
|
| MD5 |
15a52e9642f7c3313ad993bf5d7896f0
|
|
| BLAKE2b-256 |
e133612cccddc6b505023db5f0e6bf21cffcbeeb2fc5538dce2f8c055644188e
|
Provenance
The following attestation bundles were made for l2p-0.4.0-py3-none-any.whl:
Publisher:
python-publish.yml on AI-Planning/l2p
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
l2p-0.4.0-py3-none-any.whl -
Subject digest:
3197cf31c1312317e8df109b304d66025960ab41b58e392ebfafe8f09354f684 - Sigstore transparency entry: 1672209302
- Sigstore integration time:
-
Permalink:
AI-Planning/l2p@7cf4b3dfb9200a51b4c20607e30670273c27cfc8 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/AI-Planning
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7cf4b3dfb9200a51b4c20607e30670273c27cfc8 -
Trigger Event:
release
-
Statement type: