L2P

Below are the in-depth usage of L2P. It is highly recommended to use the base template found in Templates to properly extract LLM output into the designated Python formats from these methods.

Jump to:

PromptBuilder

DomainBuilder

TaskBuilder

FeedbackBuilder

Utils

PromptBuilder

class l2p.PromptBuilder(role: str = None, format: str = None, examples: list = None, task: str = None)[source]
generate_prompt()[source]

Generates the whole prompt in proper format

get_examples()[source]

Returns list of n-examples of the prompt given

get_format()[source]

Returns prompting format of the prompt given

get_role()[source]

Returns role of the prompt given

get_task()[source]

Returns dynamic placeholder task prompt

remove_examples(idx)[source]

Removes specific index of example list

remove_format()[source]

Removes format prompt

remove_role()[source]

Removes role prompt

remove_task()[source]

Removes dynamic placeholder task prompt

set_examples(example)[source]

Appends a shot examples for LLM to follow

set_format(format)[source]

Sets the prompting format for LLM to perform task

set_role(role)[source]

Sets the role for the LLM to perform task

set_task(task)[source]

Sets a task for the LLM by providing dynamic placeholders to generate and describe domain components.

The task parameter is a structured input that includes various elements to guide the LLM in understanding and executing the task. The task may include descriptions, types, actions, and predicates that the LLM will process to generate appropriate outputs.

Here is an example of a dynamic placeholder: ‘’’ ## Domain {domain_desc} - A placeholder for the description of the domain, explaining the context and purpose. ‘’’

Parameters:

task (str) – A structured string or template containing dynamic placeholders to specify the task.

DomainBuilder

class l2p.DomainBuilder(requirements: list[str] = None, types: dict[str, str] = None, type_hierarchy: list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None, pddl_actions: list[Action] = None)[source]
__init__(requirements: list[str] = None, types: dict[str, str] = None, type_hierarchy: list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None, pddl_actions: list[Action] = None) None[source]

Initializes an L2P domain builder object.

Parameters:
  • requirements (list[str]) – list of PDDL requirements

  • types (dict[str,str]) – flat types dictionary w/ {name: description} key-value pair (PDDL :types)

  • type_hierarchy (list[dict[str,str]]) – type hierarchy dictionary list (PDDL :types)

  • constants (dict[str,str]) – flat constant dictionary w/ {name: type} key-value pair (PDDL :constants)

  • predicates (list[Predicate]) – list of Predicate objects (PDDL :predicates)

  • functions (list[Function]) – list of Function objects (PDDL :functions)

  • pddl_actions (list[Action]) – list of Action objects (PDDL :action)

delete_constants(name: str)[source]

Deletes specific constant from current specification

delete_function(name: str)[source]

Deletes specific function from current specification

delete_pddl_action(name: str)[source]

Deletes specific PDDL action from current specification

delete_predicate(name: str)[source]

Deletes specific predicate from current specification

delete_type(name: str)[source]

Deletes a specific type from both self.types and self.type_hierarchy.

extract_nl_actions(model: BaseLLM, domain_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] = None, nl_actions: dict[str, str] = None, max_retries: int = 3) tuple[dict[str, str], str][source]

Extract actions in natural language given domain description using BaseLLM.

NOTE: This is not an official formalize function. It is inspired by the NL2PLAN framework (Gestrin et al., 2024) and is designed to guide the LLM in constructing appropriate actions.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for dictionary extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • nl_actions (dict[str, str]) – NL actions currently in class object w/ {<name>: <description>} key-value pair

  • max_retries (int) – max # of retries if failure occurs

Returns:

a dictionary of extracted NL actions {<name>: <description>} llm_output (str): the raw string BaseLLM response

Return type:

nl_actions (dict[str, str])

formalize_constants(model: BaseLLM, domain_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[dict[str, str], str, tuple[bool, str]][source]

Formalizes PDDL :constants in flat dictionary format via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :constants extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated constants, defaults to None

  • max_retries (int) – max # of retries if failure occurs, defaults to 3

Returns:

dictionary of constants with {<name>: <type>} pair llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

constants (dict[str,str])

formalize_domain_level_specs(model: BaseLLM, domain_desc: str, prompt_template: str, formalize_types: bool = False, formalize_constants: bool = False, formalize_predicates: bool = False, formalize_functions: bool = False, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[dict[str, Any], str, tuple[bool, str]][source]

Formalizes domain-level specifications (i.e. :types, :constants, :predicates, :functions) via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – domain description

  • prompt_template (str) – prompt template

  • formalize_types (bool) – flag for extracting :types, defaults to False

  • formalize_constants (bool) – flag for extracting :constants, defaults to False

  • formalize_predicates (bool) – flag for extracting :predicates, defaults to False

  • formalize_functions (bool) – flag for extracting :functions, defaults to False

  • syntax_validator (SyntaxValidator) – syntax checker for domain specs., defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

domain-level specifications of user requirements llm_output (str): the raw string BaseLLM response

Return type:

spec_results (dict[str, Any])

formalize_effects(model: BaseLLM, domain_desc: str, prompt_template: str, action_name: str, action_desc: str = None, params: OrderedDict = None, preconditions: str = None, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, extract_new_preds: bool = False, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[str, list[Predicate], str, tuple[bool, str]][source]

Formalizes PDDL :effects from a single action via LLM

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :effects extraction

  • action_name (str) – action name

  • action_desc (str) – action description, defaults to None

  • params (list[str]) – list of parameters from action, defaults to None

  • precondition (str) – PDDL format of preconditions, defaults to None

  • types (dict[str,str] | list(dict[str,str])) – current types in specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in specification, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • extract_new_preds (bool) – flag for parsing new predicates generated from action, defaults to False

  • syntax_validator (SyntaxValidator) – syntax checker for generated effects, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

PDDL format of :effects new_predicates (list[Predicate]): a list of new predicates, defaults to empty list llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

effects (str)

formalize_functions(model: BaseLLM, domain_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] = None, functions: list[Function] = None, syntax_validator: SyntaxValidator = None, max_retries=3) tuple[list[Function], str, tuple[bool, str]][source]

Formalizes PDDL :functions via LLM

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :functions extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in specification, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated functions, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

a list of generated :functions llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

functions (list[Function])

formalize_parameters(model: BaseLLM, domain_desc: str, prompt_template: str, action_name: str, action_desc: str = None, types: dict[str, str] | list[dict[str, str]] | None = None, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[OrderedDict, list, str, tuple[bool, str]][source]

Formalizes PDDL :parameters for single action via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :parameters extraction

  • action_name (str) – action name

  • action_desc (str) – action description, defaults to None

  • types (dict[str,str] | list(dict[str,str])) – current types in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated params, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

ordered list of parameters {<?var>: <type>} param_raw (list()): list of raw parameters llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

param (OrderedDict)

formalize_pddl_action(model: BaseLLM, domain_desc: str, prompt_template: str, action_name: str, action_desc: str = None, action_list: list[str] = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, extract_new_preds=False, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[Action, list[Predicate], str, tuple[bool, str]][source]

Formalizes an :action and new :predicates from a given action description using BaseLLM. Users can set extract_new_preds (bool) to True if tasking LLM to generate new predicates.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :action extraction

  • action_name (str) – action name

  • action_desc (str) – action description, defaults to None

  • action_list (list[str]) – list of other actions to be translated, defaults to None

  • types (dict[str,str] | list[dict[str,str]]) – types in current specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in specification, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • extract_new_preds (bool) – flag for parsing new predicates generated from action, defaults to False

  • syntax_validator (SyntaxValidator) – syntax checker for generated actions

  • max_retries (int) – max # of retries if failure occurs

Returns:

constructed action class containing :parameters, :preconditions, and :effects new_predicates (list[Predicate]): a list of new predicates, defaults to empty list llm_output (str): the raw string BaseLLM response validation_info (tuple[bool, str]): validation info containing pass flag and error message

Return type:

action (Action)

formalize_pddl_actions(model: BaseLLM, domain_desc: str, prompt_template: str, action_list: list[str] = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, extract_new_preds=False, max_retries: int = 3) tuple[list[Action], list[Predicate], str][source]

Formalizes several :actions via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – domain description

  • prompt_template (str) – action construction prompt

  • action_list (list[str]) – list of other actions to be translated, defaults to None

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in specification, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • extract_new_preds (bool) – flag for parsing new predicates generated from action, defaults to False

  • max_retries (int) – max # of retries if failure occurs

Returns:

constructed action class new_predicates (list[Predicate]): a list of new predicates llm_output (str): the raw string BaseLLM response

Return type:

action (Action)

formalize_preconditions(model: BaseLLM, domain_desc: str, prompt_template: str, action_name: str, action_desc: str = None, params: OrderedDict = None, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, extract_new_preds: bool = False, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[str, list[Predicate], str, tuple[bool, str]][source]

Formalizes PDDL :preconditions from a single action via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :preconditions extraction

  • action_name (str) – action name

  • action_desc (str) – action description, defaults to None

  • params (OrderedDict) – dictionary of parameters from action, defaults to None

  • types (dict[str,str] | list(dict[str,str])) – current types in specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in specification, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • extract_new_preds (bool) – flag for parsing new predicates generated from action, defaults to False

  • syntax_validator (SyntaxValidator) – syntax checker for generated preconditions, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

PDDL format of :preconditions new_predicates (list[Predicate]): a list of new predicates, defaults to empty list llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

preconditions (str)

formalize_predicates(model: BaseLLM, domain_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] = None, functions: list[Function] = None, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[list[Predicate], str, tuple[bool, str]][source]

Formalizes PDDL :predicates via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :predicates extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in specification, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated predicates, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

a list of new predicates llm_output (str): the raw string BaseLLM response validation_info (tuple[bool, str]): validation info containing pass flag and error message

Return type:

new_predicates (list[Predicate])

formalize_type_hierarchy(model: BaseLLM, domain_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, check_invalid_obj_usage: bool = True, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[list[dict[str, str]], str, tuple[bool, str]][source]

Formalizes PDDL :types in hierarchy format via LLM. Recommended to use over formalize_types()

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :types extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • check_invalid_obj_usage (bool) – removes keyword object from types, defaults to True

  • syntax_validator (SyntaxValidator) – syntax checker for generated types, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

list of dictionaries containing the type hierarchy llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

type_hierarchy (list[dict[str,str]])

formalize_types(model: BaseLLM, domain_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, check_invalid_obj_usage: bool = True, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[dict[str, str], str, tuple[bool, str]][source]

Formalizes PDDL :types in singular flat hierarchy via LLM. It is recommended to use formalize_type_hierarchy() for sub-type support.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain description

  • prompt_template (str) – structured prompt template for :types extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • check_invalid_obj_usage (bool) – removes keyword object from types, defaults to True

  • syntax_validator (SyntaxValidator) – syntax checker for generated types, defaults to None

  • max_retries (int) – max # of retries if failure occurs, defaults to 3

Returns:

dictionary of types with {<name>: <description>} pair llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

types (dict[str,str])

generate_domain(domain_name: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, actions: list[Action] = [], requirements: list[str] | None = None) str[source]

Generates PDDL domain from given information.

Parameters:
  • domain_name (str) – domain name

  • types (dict[str,str] | list[dict[str,str]] | None) – domain :types, defaults to None

  • constants (dict[str,str] | None) – domain :constants, defaults to None

  • predicates (list[Predicate] | None) – domain :predicates, defaults to None

  • functions (list[Function] | None) – domain :functions, defaults to None

  • actions (list[Action]) – domain :action(s), defaults to None

  • requirements (list[str]) – domain :requirements, defaults to constant REQUIREMENTS

Returns:

PDDL domain in string format

Return type:

desc (str)

generate_requirements(types: dict[str, str] | list[dict[str, str]] | None = None, functions: list[Function] | None = None, actions: list[Action] = None) list[str][source]

Generates necessary PDDL requirements based off of rest of domain specification. Motivation was not needing LLMs to specify :requirements predeterminate of domain generation.

Currently does not support :durative-actions

Parameters:
  • types (dict[str,str] | list(dict[str,str])) – current types in specification, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • actions (list[Action]) – domain :action(s), defaults to None

Returns:

list of PDDL requirements

Return type:

requirements (list[str])

get_constants() dict[str, str][source]

Returns constants from current specification

get_functions() list[Function][source]

Returns functions from current specification

get_pddl_actions() list[Action][source]

Returns PDDL actions from current specification

get_predicates() list[Predicate][source]

Returns predicates from current specification

get_type_hierarchy() list[dict[str, str]][source]

Returns type hierarchy from current specification

get_types() dict[str, str][source]

Returns types from current specification

set_constants(constants: dict[str, str])[source]

Sets constants for current specification

set_function(function: Function)[source]

Appends a function for current specification

set_pddl_action(pddl_action: Action)[source]

Appends a PDDL action for current specification

set_predicate(predicate: Predicate)[source]

Appends a predicate for current specification

set_type_hierarchy(type_hierarchy: list[dict[str, str]])[source]

Sets type hierarchy for current specification

set_types(types: dict[str, str])[source]

Sets types for current specification

TaskBuilder

class l2p.TaskBuilder(objects: dict[str, str] = None, initial: list[dict[str, str]] = None, goal: list[dict[str, str]] = None)[source]
__init__(objects: dict[str, str] = None, initial: list[dict[str, str]] = None, goal: list[dict[str, str]] = None) None[source]

Initializes an L2P task builder object.

Parameters:
  • objects (dict[str,str]) – current dictionary of task objects in specification

  • initial (list[dict[str,str]]) – current initial states in specification

  • goal (list[dict[str,str]]) – current goal states in specification

delete_goal_state(state: dict[str, str])[source]

Deletes specific PDDL :goal state from current specification

delete_initial_state(state: dict[str, str])[source]

Deletes specific :init state from current specification

delete_objects(object: dict[str, str])[source]

Deletes specific item in :objects from current specification

formalize_goal_state(model: BaseLLM, problem_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, objects: dict[str, str] | None = None, initial: list[dict[str, str]] | None = None, goal: list[dict[str, str]] | None = None, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[list[dict[str, str]], str, tuple[bool, str]][source]

Formalizes PDDL :goal states via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • problem_desc (str) – general problem description

  • prompt_template (str) – structured prompt template for :goal extraction

  • types (dict[str,str] | list[dict[str,str]]) – current :types in domain, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in domain, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • objects (dict[str,str]) – current dictionary of task :objects in specification, defaults to None

  • initial (list[dict[str,str]]) – current :init states in specification, defaults to None

  • goal (list[dict[str,str]]) – current :goal states in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated goal states, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

list of dictionaries containing goal states consisting of:

{<predicate_name>:<str>, <params>:<list[str]>, <neg>:<bool>} OR {<function_name>:<str>, <params>:<list[str]>, <value>:<int>, <op>:<str>}

llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

goal (list[dict[str,str]])

formalize_initial_state(model: BaseLLM, problem_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, objects: dict[str, str] | None = None, initial: list[dict[str, str]] | None = None, goal: list[dict[str, str]] | None = None, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[list[dict[str, str]], str, tuple[bool, str]][source]

Formalizes PDDL :init states via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • problem_desc (str) – general problem description

  • prompt_template (str) – structured prompt template for :init extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in domain, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • objects (dict[str,str]) – current dictionary of task :objects in specification, defaults to None

  • initial (list[dict[str,str]]) – current :init states in specification, defaults to None

  • goal (list[dict[str,str]]) – current :goal states in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated initial states, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

list of dictionaries containing initial states consisting of:

{<predicate_name>:<str>, <params>:<list[str]>, <neg>:<bool>} OR {<function_name>:<str>, <params>:<list[str]>, <value>:<int>, <op>:<str>}

llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

initial (list[dict[str,str]])

formalize_objects(model: BaseLLM, problem_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[dict[str, str], str, tuple[bool, str]][source]

Formalizes PDDL :objects via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • problem_desc (str) – general problem description

  • prompt_template (str) – structured prompt template for :objects extraction

  • types (dict[str,str] | list[dict[str,str]]) – current types in specification, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated objects, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

dictionary of object types {<name>: <type>} llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

objects (dict[str,str])

formalize_task(model: BaseLLM, problem_desc: str, prompt_template: str, types: dict[str, str] | list[dict[str, str]] | None = None, constants: dict[str, str] | None = None, predicates: list[Predicate] | None = None, functions: list[Function] | None = None, syntax_validator: SyntaxValidator = None, max_retries: int = 3) tuple[dict[str, str], list[dict[str, str]], list[dict[str, str]], str, tuple[bool, str]][source]

Formalizes whole task specification via LLM.

Parameters:
  • model (BaseLLM) – LLM to query

  • problem_desc (str) – general problem description

  • prompt_template (str) – structured prompt template for :problem extraction

  • types (dict[str,str] | list[dict[str,str]]) – current :types in domain, defaults to None

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of current predicates in domain, defaults to None

  • functions (list[Function]) – list of current functions in specification, defaults to None

  • syntax_validator (SyntaxValidator) – syntax checker for generated :problem, defaults to None

  • max_retries (int) – max # of retries if failure occurs

Returns:

dictionary of object names and assigned types initial (list[dict[str,str]]): list of dictionary of initial states goal (list[dict[str,str]]): list of dictionary of goal states llm_output (str): the raw string BaseLLM response validation_info (tuple[bool,str]): validation info containing pass flag and error message

Return type:

objects (dict[str,str])

generate_task(domain_name: str, problem_name: str, objects: dict[str, str], initial: list[dict[str, str]], goal: list[dict[str, str]]) str[source]

Generates PDDL problem from given information.

Parameters:
  • domain_name (str) – domain name

  • problem_name (str) – specific task instance name

  • objects (dict[str,str]) – PDDL :objects

  • initial (list[dict[str,str]]) – PDDL :init states

  • goal (list[dict[str,str]]) – PDDL :goal states

Returns:

PDDL problem in string format

Return type:

desc (str)

get_goal() list[dict[str, str]][source]

Returns PDDL :goal states from current specification

get_initial() list[dict[str, str]][source]

Returns PDDL :init states from current specification

get_objects() dict[str, str][source]

Returns PDDL :objects from current specification

set_goal(goal: list[dict[str, str]])[source]

Sets PDDL :goal states for current specification

set_initial(initial: list[dict[str, str]])[source]

Sets PDDL :init states for current specification

set_objects(objects: dict[str, str])[source]

Sets PDDL :objects for current specification

FeedbackBuilder

class l2p.FeedbackBuilder[source]
NOTE: this class only returns feedback flag/messages from original LLM output. Users

must provide their own implementation of using this feedback to revise outputs.

effect_feedback(model: BaseLLM, domain_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', parameter: OrderedDict = None, preconditions: str = None, effects: str = None, action_name: str = None, action_desc: str = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of a PDDL action effect.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • parameter (OrderedDict) – PDDL params of current action

  • preconditions (str) – PDDL precondition of current action

  • effects (str) – PDDL effect of current action

  • action_name (str) – name of action

  • action_desc (str) – description of action

  • types (dict[str,str] | list[dict[str,str]]) – dictionary of types currently in specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of predicates currently in specification

  • functions (list[Function]) – list of functions currently in specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

feedback_state(info: str)[source]

Confirms if feedback is needed from output.

It expects a ### JUDGMENT header with enclosed (```) boxes with an answer of either ‘no feedback’ or content of suggestion.

Refer to l2p/templates/feedback_templates for proper LLM output structuring.

get_feedback(model: BaseLLM, feedback_template: str, feedback_type: str, llm_output: str) tuple[bool, str][source]

This retrieves the type of feedback user requests and returns feedack message. feedback_type takes in either “human” or “llm”

goal_state_feedback(model: BaseLLM, problem_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', objects: dict[str, str] = None, initial: list[dict[str, str]] = None, goal: list[dict[str, str]] = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of PDDL task goal states.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • objects (dict[str,str]) – objects of current task specification

  • initial (list[dict[str,str]]) – initial states of current task specification

  • goal (list[dict[str,str]]) – goal states of current task specification

  • types (dict[str,str] | list[dict[str,str]]) – dictionary of types currently in specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of predicates currently in specification

  • functions (list[Function]) – list of functions currently in specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

human_feedback(info: str)[source]

This enables human-in-the-loop feedback mechanism.

initial_state_feedback(model: BaseLLM, problem_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', objects: dict[str, str] = None, initial: list[dict[str, str]] = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of PDDL task initial states.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • objects (dict[str,str]) – objects of current task specification

  • initial (list[dict[str,str]]) – initial states of current task specification

  • types (dict[str,str] | list[dict[str,str]]) – dictionary of types currently in specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of predicates currently in specification

  • functions (list[Function]) – list of functions currently in specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

nl_action_feedback(model: BaseLLM, domain_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', types: dict[str, str] | list[dict[str, str]] = None, nl_actions: dict[str, str] = None) tuple[bool, str][source]

Provides feedback to initial LLM output for list of natural language actions for the domain

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • types (dict[str,str] | list[dict[str,str]]) – PDDL types of current specification

  • nl_actions (dict[str,str]) – optional to supplement feedback prompt

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

objects_feedback(model: BaseLLM, problem_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', objects: dict[str, str] = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of PDDL task objects.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • objects (dict[str,str]) – objects of current task specification

  • types (dict[str,str] | list[dict[str,str]]) – dictionary of types currently in specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of predicates currently in specification

  • functions (list[Function]) – list of functions currently in specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

parameter_feedback(model: BaseLLM, domain_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', parameter: OrderedDict = None, action_name: str = None, action_desc: str = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of a PDDL action parameter.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • parameter (OrderedDict) – PDDL params of current action

  • action_name (str) – name of action

  • action_desc (str) – description of action

  • types (dict[str,str] | list[dict[str,str]]) – PDDL types of current specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

pddl_action_feedback(model: BaseLLM, domain_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', action: Action = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of a PDDL action.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • action (Action) – current action specifications

  • types (dict[str,str] | list[dict[str,str]]) – PDDL types of current specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – PDDL predicates of current specification

  • functions (list[Function]) – PDDL functions of current specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

precondition_feedback(model: BaseLLM, domain_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', parameter: OrderedDict = None, preconditions: str = None, action_name: str = None, action_desc: str = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of a PDDL action precondition.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • parameter (OrderedDict) – PDDL params of current action

  • preconditions (str) – PDDL precondition of current action

  • action_name (str) – name of action

  • action_desc (str) – description of action

  • types (dict[str,str] | list[dict[str,str]]) – dictionary of types currently in specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of predicates currently in specification

  • functions (list[Function]) – list of functions currently in specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

predicate_feedback(model: BaseLLM, domain_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of PDDL predicates.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • types (dict[str,str] | list[dict[str,str]]) – dictionary of types currently in specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of predicates currently in specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

task_feedback(model: BaseLLM, problem_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', objects: dict[str, str] = None, initial: list[dict[str, str]] = None, goal: list[dict[str, str]] = None, types: dict[str, str] | list[dict[str, str]] = None, constants: dict[str, str] = None, predicates: list[Predicate] = None, functions: list[Function] = None) tuple[bool, str][source]

Provides feedback to initial LLM output of a PDDL task.

Parameters:
  • model (BaseLLM) – LLM to query

  • problem_desc (str) – general problem information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • objects (dict[str,str]) – objects of current task specification

  • initial (list[dict[str,str]]) – initial states of current task specification

  • goal (list[dict[str,str]]) – goal states of current task specification

  • types (dict[str,str] | list[dict[str,str]]) – dictionary of types currently in specification

  • constants (dict[str,str]) – current constants in specification, defaults to None

  • predicates (list[Predicate]) – list of predicates currently in specification

  • functions (list[Function]) – list of functions currently in specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

type_feedback(model: BaseLLM, domain_desc: str, feedback_template: str, feedback_type: str = 'llm', llm_output: str = '', types: dict[str, str] | list[dict[str, str]] = None) tuple[bool, str][source]

Provides feedback to initial LLM output for :types.

Parameters:
  • model (BaseLLM) – LLM to query

  • domain_desc (str) – general domain information

  • feedback_template (str) – prompt template to guide LLM to provide feedback to initial output

  • feedback_type (str) – type of feedback assistant - ‘llm’, ‘human’

  • llm_output (str) – original LLM output

  • types (dict[str,str] | list[dict[str,str]]) – PDDL types of current specification

Returns:

flag that deems if feedback is not needed fb_msg (str): feedback message from assistant

Return type:

no_fb (bool)

Utils

The utils package contains several helper modules for working with PDDL and L2P processes.

PDDL Parser

This module contains a collection of helper functions that parses information from LLM output.

l2p.utils.pddl_parser.check_parse_domain(file_path: str)[source]

Run PDDL library to check if file is syntactically correct

l2p.utils.pddl_parser.check_parse_problem(file_path: str)[source]

Run PDDL library to check if file is syntactically correct

l2p.utils.pddl_parser.combine_blocks(heading_str: str)[source]

Combine the inside of blocks from the heading string into a single string.

l2p.utils.pddl_parser.concatenate_strings(nested_list)[source]

Helper function that concatenates strings within a list together.

l2p.utils.pddl_parser.load_file(file_path: str)[source]

Helper function that loads a single file into a string

l2p.utils.pddl_parser.load_files(folder_path: str)[source]

Helper function that loads multiple files into a string list

l2p.utils.pddl_parser.parse_action(llm_output: str, action_name: str) Action[source]

Parse an action from a given LLM output.

Parameters:
  • llm_output (str) – raw LLM output

  • action_name (str) – the name of the action

Returns:

the parsed PDDL action

Return type:

Action

l2p.utils.pddl_parser.parse_constants(llm_output: str) dict[str, str] | None[source]

Safely extracts and evaluates a dictionary structure from a string (LLM response).

Parameters:

llm_output (str) – Raw string from the LLM expected to contain a flat dictionary.

Returns:

parsed dictionary if valid, else None.

Return type:

constants_parsed (dict[str, str]) | None

l2p.utils.pddl_parser.parse_effects(llm_output: str) str[source]

Parses effect string from LLM output

l2p.utils.pddl_parser.parse_functions(llm_output: str) list[Function][source]

Parses function from LLM into Python format (refer to example templates to see how these functions should be formatted in LLM response).

LLM output header should contain ‘### FUNCTIONS’ along with structured content.

l2p.utils.pddl_parser.parse_goal(llm_output: str) list[dict[str, str]][source]

Extracts goal (PDDL-goal) from LLM response and returns it as a string

Parameters:

llm_output (str) – raw LLM output

Returns:

list of goal states in dictionaries

Return type:

states (list[dict[str,str]])

l2p.utils.pddl_parser.parse_heading(llm_output: str, heading: str) str[source]

Extract the text between the heading and the next second level heading in the LLM output.

l2p.utils.pddl_parser.parse_initial(llm_output: str) list[dict[str, str]][source]

Extracts state (PDDL-init) from LLM response and returns it as a list of dict strings

Parameters:

llm_output (str) – raw LLM output

Returns:

list of initial states in dictionaries

Return type:

states (list[dict[str,str]])

l2p.utils.pddl_parser.parse_new_predicates(llm_output) list[Predicate][source]

Parses new predicates from LLM into Python format (refer to example templates to see how these predicates should be formatted in LLM response).

LLM output header should contain ‘### New Predicates’ along with structured content.

l2p.utils.pddl_parser.parse_objects(llm_output: str) dict[str, str][source]

Extract objects from LLM response and returns dictionary string pairs object(name, type)

Parameters:
  • llm_output (str) – raw LLM output

  • types (dict[str,str]) – WILL BE USED FOR CHECK ERROR RAISES

  • predicates (list[Predicate]) – WILL BE USED FOR CHECK ERROR RAISES

Returns:

PDDL task objects

Return type:

objects_parsed (dict[str,str])

l2p.utils.pddl_parser.parse_params(llm_output: str) tuple[OrderedDict, list][source]

Parses parameters from LLM into Python format (refer to example templates to see how these parameters should be formatted in LLM response).

LLM output header should contain ‘Parameters’ along with structured content.

l2p.utils.pddl_parser.parse_pddl(pddl_str: str) list[source]

Simplified PDDL parser that converts the string into a nested list structure.

l2p.utils.pddl_parser.parse_preconditions(llm_output: str) str[source]

Parses precondition string from LLM output

l2p.utils.pddl_parser.parse_predicates(all_predicates: list[Predicate]) list[Predicate][source]

This function assumes the predicate definitions adhere to PDDL grammar. Assigns params to the predicate arguments properly. This should be run after retrieving a predicate list to ensure predicates are set correctly.

l2p.utils.pddl_parser.parse_task_states(parsed_states: list) list[dict][source]
l2p.utils.pddl_parser.parse_type_hierarchy(llm_output: str) list[dict[str, str]] | None[source]

Safely parses LLM response into a list of nested dictionaries representing the type hierarchy.

Parameters:

llm_output (str) – raw LLM output expected to contain a Python list of dictionaries.

Returns:

parsed type hierarchy if valid, else None.

Return type:

types_parsed (list[dict[str,str]]) | None

l2p.utils.pddl_parser.parse_types(llm_output: str, heading: str = 'TYPES') dict[str, str] | None[source]

Safely extracts and evaluates a dictionary structure from a string (LLM response).

Parameters:

llm_output (str) – raw string from the LLM expected to contain a flat dictionary

Returns:

parsed dictionary of :types if valid, else None.

Return type:

types_parsed (dict[str, str]) | None

l2p.utils.pddl_parser.prune_predicates(predicates: list[Predicate], actions: list[Action]) list[Predicate][source]

Remove predicates that are not used in any action.

Parameters:
  • predicates (list[Predicate]) – a list of predicates

  • actions (list[Action]) – a list of actions

Returns:

the pruned list of predicates

Return type:

list[Predicate]

l2p.utils.pddl_parser.prune_types(types: dict[str, str] | list[dict[str, str]], predicates: list[Predicate], actions: list[Action]) dict[str, str][source]

Prune types that are not used in any predicate or action.

Parameters:
  • types (dict or list) – Either a flat dict of {type: description} or a nested list of type hierarchies.

  • predicates (list[Predicate]) – A list of predicates.

  • actions (list[Action]) – A list of actions.

Returns:

A dictionary of used types.

Return type:

dict[str, str]

PDDL Planner

L2P is compatible with FastDownward: https://www.fast-downward.org

For usage, users must clone or download the submodule /downward separately and direct the planner_path to the folder. This module is not necessary to use L2P, but for ease of use to produce plans from generated domain and problem PDDL specifications via LLMs.

class l2p.utils.pddl_planner.FastDownward(planner_path: str)[source]
extract_plan_steps(output)[source]
generate_portfolio_exitcode(exitcodes)[source]
handle_error(exitcode, plan_found)[source]
is_unrecoverable(exitcode)[source]
run_fast_downward(domain_file: str, problem_file: str, search_alg: str = 'lama-first')[source]

Main function to run planner.

Parameters:
Returns:

if a plan was found, otherwise False for incomplete. plan_output (str): plan output information.

Return type:

success (bool)

PDDL Types

L2P PDDL Type and Data Structure Definitions

This module defines core types and data classes used for representing components of PDDL domains, problems, and plans. These include structured representations for predicates, actions, functions, domain/task metadata, and parameterized object lists.

class l2p.utils.pddl_types.Action[source]
clear()

Remove all items from the dict.

copy()

Return a shallow copy of the dict.

desc: str | None
effects: str
classmethod fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items()

Return a set-like object providing a view on the dict’s items.

keys()

Return a set-like object providing a view on the dict’s keys.

name: str
params: ParameterList
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

preconditions: str
raw: str
setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Return an object providing a view on the dict’s values.

class l2p.utils.pddl_types.Constant[source]
clear()

Remove all items from the dict.

copy()

Return a shallow copy of the dict.

classmethod fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items()

Return a set-like object providing a view on the dict’s items.

keys()

Return a set-like object providing a view on the dict’s keys.

name: str
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

type: str
update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Return an object providing a view on the dict’s values.

class l2p.utils.pddl_types.DomainDetails(name: str, domain_desc: str, domain_pddl: str, requirements: list[str], types: dict[str, str] | list[dict[str, str]], constants: dict[str, str], predicates: list[l2p.utils.pddl_types.Predicate], functions: list[l2p.utils.pddl_types.Function], actions: list[l2p.utils.pddl_types.Action])[source]
actions: list[Action]
constants: dict[str, str]
domain_desc: str
domain_pddl: str
functions: list[Function]
name: str
predicates: list[Predicate]
requirements: list[str]
types: dict[str, str] | list[dict[str, str]]
class l2p.utils.pddl_types.Function[source]
clean: str
clear()

Remove all items from the dict.

copy()

Return a shallow copy of the dict.

desc: str | None
classmethod fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items()

Return a set-like object providing a view on the dict’s items.

keys()

Return a set-like object providing a view on the dict’s keys.

name: str
params: ParameterList
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

raw: str
setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Return an object providing a view on the dict’s values.

class l2p.utils.pddl_types.PDDLType[source]
clear()

Remove all items from the dict.

copy()

Return a shallow copy of the dict.

desc: str
classmethod fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items()

Return a set-like object providing a view on the dict’s items.

keys()

Return a set-like object providing a view on the dict’s keys.

name: str
parent: str
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Return an object providing a view on the dict’s values.

class l2p.utils.pddl_types.PlanDetails(domain_pddl: str, problem_pddl: str, plan_pddl: str, plan_nl: str)[source]
domain_pddl: str
plan_nl: str
plan_pddl: str
problem_pddl: str
class l2p.utils.pddl_types.Predicate[source]
clean: str
clear()

Remove all items from the dict.

copy()

Return a shallow copy of the dict.

desc: str | None
classmethod fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items()

Return a set-like object providing a view on the dict’s items.

keys()

Return a set-like object providing a view on the dict’s keys.

name: str
params: ParameterList
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

raw: str
setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Return an object providing a view on the dict’s values.

class l2p.utils.pddl_types.ProblemDetails(name: str, problem_desc: str, problem_pddl: str, objects: tuple[dict[str, str], str], initial: tuple[dict[str, str], str], goal: tuple[dict[str, str], str])[source]
goal: tuple[dict[str, str], str]
initial: tuple[dict[str, str], str]
name: str
objects: tuple[dict[str, str], str]
problem_desc: str
problem_pddl: str

PDDL Validator

This module contains a collection of PDDL syntax validation functions. Users MUST specify what validation checker is being used in error_types when using an extraction function found in DomainBuilder/TaskBuilder class.

For instance:

syntax_validator = SyntaxValidator()

self.syntax_validator.error_types = [

“validate_header”, “validate_duplicate_headers”, “validate_unsupported_keywords”, “validate_params”, “validate_types_predicates”, “validate_format_predicates”, “validate_usage_action”,

]

Is supported in: DomainBuilder.extract_pddl_action(**kwargs, syntax_validator)

class l2p.utils.pddl_validator.SyntaxValidator(headers: list[str] | None = None, error_types: list[str] | None = None, unsupported_keywords: list[str] | None = None)[source]
__init__(headers: list[str] | None = None, error_types: list[str] | None = None, unsupported_keywords: list[str] | None = None) None[source]

Initializes an L2P custom syntax validator checker object.

Parameters:
  • headers (list[str]) – headers to extract from LLM output

  • error_types (list[str]) – error types to execute formalization functions

  • unsupported_keywords (list[str]) – keywords to check against LLM output

validate_constant_types(constants: dict[str, str] | None = None, types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Checks if constant types are found in current :types.

Parameters:
  • constants (dict[str,str]) – current :constants in domain

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_cyclic_types(types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Checks if the types given contain an invalid cyclic hierarchy.

Parameters:

types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_duplicate_headers(llm_response: str) tuple[bool, str][source]

Checks if the LLM attempts to create a new action (so two or more actions defined in the same response). Headers to check must be declared as self.headers = [‘Action Preconditions’]

Parameters:

llm_response (str) – raw LLM output

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_duplicate_predicates(curr_predicates: list[Predicate] | None = None, new_predicates: list[Predicate] | None = None) tuple[bool, str][source]

Checks if predicates have the same name but different parameters.

Parameters:
  • curr_predicates (list[predicate]) – current predicates in domain

  • new_predicates (list[Predicate]) – new predicates generated from LLM

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_format_functions(functions: list[Function] | None = None, types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Check for any PDDL syntax found within functions, allowing untyped variables.

Parameters:
  • functions (list[Function]) – list of functions in domain

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_format_predicates(predicates: list[dict] | None = None, types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Checks for any PDDL syntactic errors found within predicates, allowing untyped variables.

Parameters:
  • predicates (list[Predicate]) – current predicates in domain / generated from LLM

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_format_types(types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Checks if type variables contain ? characters.

Parameters:

types (dict[str,str] | list[dict[str,str]]) – types given from LLM output

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_header(llm_response: str) tuple[bool, str][source]

Checks if domain headers and formatted code block syntax are found in LLM output. Headers to check must be declared as self.headers = [‘Action Preconditions’]

Parameters:

llm_response (str) – raw LLM output

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_overflow_predicates(llm_response: str, limit: int = 30) tuple[bool, str][source]

Checks if LLM output contains too many predicates in precondition/effects (based on users assigned limit). This error is very rare, but can occur. Thus, it is omitted in core functions but is still available.

Parameters:
  • llm_response (str) – raw LLM output

  • limit (int) – max number of states declared, default to 30

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_params(parameters: OrderedDict, types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Checks whether a PDDL action parameter is correctly formatted and type declaration assigned correctly.

Parameters:
  • parameters (OrderedDict) – parameters of an action

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_pddl_action(pddl: str, predicates: list[Predicate], action_params: OrderedDict, functions: list[Function] | None = None, types: dict[str, str] | list[dict[str, str]] | None = None, part='preconditions') tuple[bool, str][source]

Validates predicates and fluent expression in nested PDDL list format. There are many specific checks in this validation function. This is where LLMs encounter the most syntax errors.

Performs three main kinds of checks:
  1. if predicate / functions statements are misused or does not exist

  2. if state parameters align with original definition parameters

  3. if arguments are being passed correctly (i.e. conditional-effects)

Parameters:
  • pddl (str) – part of PDDL section from LLM

  • predicates (list[Predicate]) – current predicates in domain / generated from LLM

  • action_params (OrderedDict) – PDDL parameters of current action

  • functions (list[Function]) – list of current functions in domain

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

  • part (str) – section of the PDDL to focus on

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_task_objects(objects: dict[str, str], types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]
Checks if task objects are declared correctly. Performs the following cases:
  1. if object type is found within list of available types

  2. if object name is the same as a type (invalid)

Parameters:
  • objects (dict[str,str]) – task objects generated from LLM

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_task_states(states: list[dict[str, str]], objects: dict[str, str], predicates: list[Predicate], functions: list[Function] | None = None, state_type: str = 'initial') tuple[bool, str][source]
Checks if task states are declared correcly. Performs following checks:
  1. if predicates/functions in states exist in the domain

  2. if all object variables in states are declared in task objects

  3. if types of object variables match predicate parameter types

Parameters:
  • states (list[dict[str,str]]) – a list of dictionaries of the states

  • objects (dict[str,str]) – a dictionary of the task objects and their types

  • predicates (list[Predicate]) – current predicates in domain

  • functions (list[Function]) – list of current functions in domain

  • state_type (str) – optional; ‘initial’ or ‘goal’ to label messages

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_type(target_type: str, claimed_type: str, types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Check if the claimed_type is valid for the target_type according to the type hierarchy.

Parameters:
  • target_type (str) – type that is expected for the parameter (from :predicates)

  • claimed_type (str) – type that is provided in the LLM output PDDL.

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_types_predicates(predicates: list[Predicate] | None = None, types: dict[str, str] | list[dict[str, str]] | None = None) tuple[bool, str][source]

Check if predicate name is found within any type definitions.

Parameters:
  • predicates (list[Predicate]) – current predicates in domain / generated from LLM

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_unsupported_keywords(llm_response: str) tuple[bool, str][source]

Checks whether PDDL model uses unsupported logic keywords Unsupported keywords to check must be declared as self.unsupported_keywords = [‘lisp’]

Parameters:

llm_response (str) – raw LLM output

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])

validate_usage_action(llm_response: str, curr_predicates: list[Predicate] | None = None, types: dict[str, str] | list[dict[str, str]] | None = None, functions: list[Function] | None = None, extract_new_preds: bool = False) tuple[bool, str][source]

Higher level function that performs checks over whether the predicates/functions are used in a valid way in the PDDL action. Invokes validate_pddl_action to perform deep syntax checks.

Parameters:
  • llm_response (str) – raw LLM output

  • curr_predicates (list[predicate]) – current predicates in domain

  • types (dict[str,str] | list[dict[str,str]]) – current types in domain

  • functions (list[Function]) – list of current functions in domain

  • extract_new_preds (bool) – flag for if new predicates are being extracted, defaults to False

Returns:

validation info containing pass flag and error message

Return type:

validation_info (tuple[bool,str])