prompt_generation/
prompt_generation.rs1use llm_toolkit_expertise::{
4 ContextMatcher, ContextProfile, Expertise, KnowledgeFragment, Priority, TaskHealth,
5 WeightedFragment,
6};
7
8fn main() {
9 println!("=== Context-Aware Prompt Generation ===\n");
10
11 let expertise = Expertise::new("adaptive-assistant", "1.0.0")
13 .with_tag("adaptive")
14 .with_tag("context-aware")
15 .with_fragment(
17 WeightedFragment::new(KnowledgeFragment::Text(
18 "Be helpful, concise, and accurate in all responses.".to_string(),
19 ))
20 .with_priority(Priority::Critical)
21 .with_context(ContextProfile::Always),
22 )
23 .with_fragment(
25 WeightedFragment::new(KnowledgeFragment::Logic {
26 instruction: "Optimize for speed and efficiency".to_string(),
27 steps: vec![
28 "Provide direct, concise answers".to_string(),
29 "Skip verbose explanations unless asked".to_string(),
30 "Use shortcuts and best practices".to_string(),
31 ],
32 })
33 .with_priority(Priority::High)
34 .with_context(ContextProfile::Conditional {
35 task_types: vec![],
36 user_states: vec![],
37 task_health: Some(TaskHealth::OnTrack),
38 }),
39 )
40 .with_fragment(
42 WeightedFragment::new(KnowledgeFragment::Logic {
43 instruction: "Proceed with caution and verification".to_string(),
44 steps: vec![
45 "Double-check all assumptions".to_string(),
46 "Ask clarifying questions".to_string(),
47 "Verify requirements before proceeding".to_string(),
48 "Explain reasoning for each decision".to_string(),
49 ],
50 })
51 .with_priority(Priority::High)
52 .with_context(ContextProfile::Conditional {
53 task_types: vec![],
54 user_states: vec![],
55 task_health: Some(TaskHealth::AtRisk),
56 }),
57 )
58 .with_fragment(
60 WeightedFragment::new(KnowledgeFragment::Text(
61 "STOP. The current approach is not working. Reassess the problem, consult with the user, and propose a different strategy before continuing.".to_string(),
62 ))
63 .with_priority(Priority::Critical)
64 .with_context(ContextProfile::Conditional {
65 task_types: vec![],
66 user_states: vec![],
67 task_health: Some(TaskHealth::OffTrack),
68 }),
69 )
70 .with_fragment(
72 WeightedFragment::new(KnowledgeFragment::Text(
73 "Provide detailed explanations and educational context. Avoid jargon.".to_string(),
74 ))
75 .with_priority(Priority::High)
76 .with_context(ContextProfile::Conditional {
77 task_types: vec![],
78 user_states: vec!["beginner".to_string()],
79 task_health: None,
80 }),
81 )
82 .with_fragment(
84 WeightedFragment::new(KnowledgeFragment::Logic {
85 instruction: "Systematic debugging approach".to_string(),
86 steps: vec![
87 "Reproduce the issue".to_string(),
88 "Isolate the root cause".to_string(),
89 "Propose minimal fix".to_string(),
90 "Verify fix doesn't break other functionality".to_string(),
91 ],
92 })
93 .with_priority(Priority::High)
94 .with_context(ContextProfile::Conditional {
95 task_types: vec!["debug".to_string()],
96 user_states: vec![],
97 task_health: None,
98 }),
99 );
100
101 let scenarios = vec![
103 ("Default (no context)", ContextMatcher::new()),
104 (
105 "On Track",
106 ContextMatcher::new().with_task_health(TaskHealth::OnTrack),
107 ),
108 (
109 "At Risk",
110 ContextMatcher::new().with_task_health(TaskHealth::AtRisk),
111 ),
112 (
113 "Off Track",
114 ContextMatcher::new().with_task_health(TaskHealth::OffTrack),
115 ),
116 (
117 "Beginner User",
118 ContextMatcher::new().with_user_state("beginner"),
119 ),
120 ("Debug Task", ContextMatcher::new().with_task_type("debug")),
121 (
122 "Debug + At Risk",
123 ContextMatcher::new()
124 .with_task_type("debug")
125 .with_task_health(TaskHealth::AtRisk),
126 ),
127 ];
128
129 for (name, context) in scenarios {
130 println!("### Scenario: {}\n", name);
131 let prompt = expertise.to_prompt_with_context(&context);
132 println!("{}", prompt);
133 println!("---\n");
134 }
135
136 println!("\n=== Visualization ===\n");
137 println!("{}", expertise.to_tree());
138}