Expand description
SystemPromptStrategy — structured system prompt composition.
The system prompt is structured as ordered blocks with token budgets. Three entities form a reference chain:
- SystemPromptStrategy — defines the structure template (block names, order, max_length)
- SystemPrompt — fills content into a strategy’s blocks (text or file paths)
- 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§
- Agent
Prompt Strategy - Predefined 4-block layout for general agents.
- Custom
Prompt Strategy - User-defined strategy with custom block definitions.
- Minimal
Prompt Strategy - Predefined 2-block layout for simple agents.
- Prompt
Block Def - A block definition within a SystemPromptStrategy (structure template).
- System
Prompt - A concrete system prompt instance: content mapped to a strategy’s blocks.
Traits§
- System
Prompt Strategy - Defines the structure template for a system prompt.