Module prompt

Source
Expand description

Prompt generation for AI model inference

This module generates structured prompts from AIMX workflow rules for AI inference. It transforms modifier rules (UPPERCASE identifiers) and assignment rules (_ prefix) into well-formatted prompts that guide AI models to produce the desired outputs.

§Overview

When an AIMX expression contains an inference call (e.g., $tool.function_name(args)), the prompt generation system:

  1. Scans workflow rules for relevant modifier and assignment rules
  2. Structures the prompt into logical sections (ROLE, INSTRUCTIONS, OUTPUT FORMAT, etc.)
  3. Formats output rules with examples and validation criteria
  4. Generates system and user prompts optimized for the model’s capability level

§Core Concepts

§Modifier Rules

Modifier rules are workflow rules with UPPERCASE identifiers that construct the prompt:

  • ROLE: Defines the AI’s persona and primary function
  • INSTRUCTIONS: Provides task-specific guidance
  • OUTPUT: Specifies the desired output format and validation rules
  • SYSTEM: Overrides the default system prompt
  • Other UPPERCASE rules: General prompt modifiers and guidelines

§Assignment Rules

Assignment rules (prefixed with _) are the targets that AI inference will populate:

  • _variable_name: Populated by AI with the parsed value
  • Rules with Value::Format provide formatting instructions and examples

§Capability-Based Formatting

The prompt structure adapts to the model’s capability level:

  • Capability::Minimal: Simple prompts with basic formatting
  • Capability::Limited: Moderate complexity with section headers
  • Capability::Standard: Full formatting with rich examples and instructions

§Prompt Structure

The generated prompt follows this standardized structure:

ROLE SECTION
You are a helpful assistant.

GUIDELINES SECTION
- First guideline
- Second guideline
 
INSTRUCTIONS SECTION
Derive the following values from the content:
- variable_name: Description of what to extract
 
OUTPUT FORMAT SECTION
Provide your answer in this exact format:
variable_name: <expected_format>
 
EXAMPLES SECTION
USER TEXT: "Example input text"
variable_name: Example output value
 
USER TEXT SECTION
Actual input text to process

§Error Handling

The module returns anyhow::Result for error handling. Common errors include:

  • Missing assignment rules (nothing to populate)
  • Invalid rule configurations
  • Formatting errors during prompt generation

§Integration with AIMX Workflows

This module is typically used internally by the inference system when processing expressions like $tool.function_name(args). The generated prompts are sent to AI providers, and the responses are used to populate assignment rules in workflows.

Functions§

generate_prompt
Generate structured prompts from workflow rules for AI model inference