Instruction component for instruct/validate/repair loops.
Instruction is the primary component type used with MelleaSession.instruct. It
packages a task description, a list of [Requirement](../../core/requirement#class-requirement) constraints, optional
in-context-learning examples, a grounding context dict, user variables for Jinja2
template interpolation, and output/input prefix overrides into a single renderable
unit. The session’s sampling strategy evaluates each requirement against the model’s
output and may repair or resample until all requirements pass.
Classes
CLASS Instruction
The Instruction in an instruct/validate/repair loop.
Args:
description: The task description shown to the model.requirements: Constraints the output must satisfy.icl_examples: In-context-learning examples.grounding_context: Named context passages injected into the prompt.user_variables: Jinja2 variable substitutions applied to all string parameters.prefix: A prefix prepended before the model’s generation.output_prefix: A prefix prepended to the model’s output token stream (currently unsupported; must beNone).images: Images to include in the prompt.
requirements: The resolved list of requirement instances attached to this instruction.
FUNC parts
FUNC format_for_llm
- A template representation containing the
- description, requirements, in-context examples, grounding context,
- and optional prefix/repair fields.
FUNC apply_user_dict_from_jinja
user_dict: Mapping of Jinja2 variable names to their string replacement values.s: A string treated as a Jinja2 template to be rendered.
- The rendered string with all Jinja2 placeholders substituted.
FUNC requirements
FUNC copy_and_repair
repair_string: The repair feedback string to attach, typically describing which requirements failed and why.
- A new
Instructionidentical to this one but with _repair_stringset torepair_string.