Skip to main content

Module system_prompt

Module system_prompt 

Source
Expand description

SystemPromptStrategy — structured system prompt composition.

The system prompt is structured as ordered blocks with token budgets. Three entities form a reference chain:

  1. SystemPromptStrategy — defines the structure template (block names, order, max_length)
  2. SystemPrompt — fills content into a strategy’s blocks (text or file paths)
  3. AgentProfile.system_prompt — references a SystemPrompt instance (or is raw text)

§Example

use phi_core::agents::system_prompt::*;
use std::collections::HashMap;
use std::path::Path;

// Define a strategy template
let strategy = CustomPromptStrategy {
    blocks: vec![
        PromptBlockDef { name: "identity".into(), order: 0, max_length: 500 },
        PromptBlockDef { name: "instructions".into(), order: 1, max_length: 2000 },
    ],
};

// Fill content into the template
let mut blocks = HashMap::new();
blocks.insert("identity".into(), "You are Phi, an expert coder.".into());
blocks.insert("instructions".into(), "Write clean, well-tested code.".into());

let prompt = SystemPrompt {
    id: "coder".into(),
    description: Some("Coding agent prompt".into()),
    strategy_ref: "agent_layout".into(),
    blocks,
};

let result = prompt.compose(&strategy, Path::new(".")).unwrap();
assert!(result.contains("Phi"));
assert!(result.contains("well-tested"));

Structs§

AgentPromptStrategy
Predefined 4-block layout for general agents.
CustomPromptStrategy
User-defined strategy with custom block definitions.
MinimalPromptStrategy
Predefined 2-block layout for simple agents.
PromptBlockDef
A block definition within a SystemPromptStrategy (structure template).
SystemPrompt
A concrete system prompt instance: content mapped to a strategy’s blocks.

Traits§

SystemPromptStrategy
Defines the structure template for a system prompt.