Skip to main content

vv_agent/prompt/builder/
system_builder.rs

1use super::section::{PromptBundle, PromptSection};
2
3#[derive(Clone, Default)]
4pub struct SystemPromptBuilder {
5    sections: Vec<PromptSection>,
6}
7
8impl SystemPromptBuilder {
9    pub fn add_section(&mut self, section: PromptSection) {
10        self.sections.push(section);
11    }
12
13    pub fn build(&self) -> String {
14        self.build_result().flatten()
15    }
16
17    pub fn build_result(&self) -> PromptBundle {
18        PromptBundle::new(
19            self.sections
20                .iter()
21                .filter(|section| !section.text.is_empty())
22                .cloned()
23                .collect(),
24        )
25        .expect("SystemPromptBuilder contains valid non-empty sections")
26    }
27}