Templates ================ It is **highly** recommended to use the base templates to properly extract LLM output into the designated Python formats from these methods. Below are some examples of the base prompt structure that should be used in this library with your customized prompt using the `PromptBuilder` class. More details of each methods' prompt structure is found in **l2p/templates**. There are four main folders found in ``/templates``: .. raw:: html
templates/domain
.. raw:: html
templates/problem
.. raw:: html
templates/feedback
.. raw:: html
templates/custom (Multi-Component)

These templates extract multiple PDDL components in a single LLM call, improving cross-component consistency. Use them with formalize_component(model, cls_list=[...], ...).

Domain Extraction Prompts Example ------------------------------------------------------- This is an example using the ``PromptBuilder`` class: .. code-block:: python :linenos: from l2p import Action from l2p import PromptBuilder role_desc = "You are a PDDL action constructor. Your job is to take " \ "the task given in natural language and convert it into PDDL actions." format_desc = "You must follow the strict JSON object defined below. " \ "Enclose your final answer in ... tags." pb = (PromptBuilder() .set_role(role_str=role_desc) .set_format(format_str=format_desc) .set_format_example(component=Action) # set extraction example block for component .add_rule(rule_str="Every action parameter must reference a defined type.") .add_rule(rule_str="Preconditions and effects must only use defined predicates.") .add_example("INPUT: ...\nOUTPUT: ...") .add_example("INPUT: ...\nOUTPUT: ...") .set_task("Generate actions for a logistics domain.")) print(pb.generate_prompt()) # alternatively - pb.save_prompt(filename="my_prompt.md") The following is the output: :: ## ROLE You are a PDDL action constructor. Your job is to take the task given in natural language and convert it into PDDL actions. ## OUTPUT FORMAT You must follow the strict JSON object defined below. Enclose your final answer in ... tags. [ { "name": "move-rover", "params": [ { "variable": "?r", "type": "rover" }, { "variable": "?from", "type": "waypoint" }, { "variable": "?to", "type": "waypoint" } ], "preconditions": { "conditions": [ "(at ?r ?from)", { "operator": "not", "condition": "(= ?from ?to)" } ], "desc": "Optional (str)" }, "effects": { "add": [ "(at ?r ?to)" ], "delete": [ "(at ?r ?from)" ], "numeric": [ "(decrease (battery-level ?r) 10.0)" ], "conditional": [ { "condition": [ "(has-rock-sample ?r)" ], "effect": { "add": [ "(carrying-heavy-load ?r)" ], "delete": [], "numeric": [] } } ], "desc": "Optional (str)" }, "desc": "Optional (str)" } ] ## RULES 1. Every action parameter must reference a defined type. 2. Preconditions and effects must only use defined predicates. ## EXAMPLE(S) # Example 1: INPUT: ... OUTPUT: ... # Example 2: INPUT: ... OUTPUT: ... -------------------------------------------------- ## TASK Generate actions for a logistics domain. {description} {context} Users have the flexibility to customize all aspects of their prompts, with the exception of the provided base template. While users can include few-shot examples to guide the LLM, the base template must remain intact during inference.