pub struct Goal {
pub description: String,
pub success_criteria: Vec<SuccessCriterion>,
pub sub_goals: Vec<SubGoal>,
pub status: GoalStatus,
}Expand description
Represents a structured goal with sub-goals and success criteria.
Goals help agents understand what they’re trying to achieve and how to measure success. Each goal can have multiple sub-goals and success criteria.
§Examples
use ceylon_next::goal::{Goal, GoalStatus};
let mut goal = Goal::new("Build a REST API".to_string());
// Add success criteria
goal.add_criterion("API responds to HTTP requests".to_string());
goal.add_criterion("All endpoints return valid JSON".to_string());
// Add sub-goals in priority order
goal.add_sub_goal("Design API endpoints".to_string(), 1);
goal.add_sub_goal("Implement request handlers".to_string(), 2);
goal.add_sub_goal("Add error handling".to_string(), 3);
// Mark sub-goal as complete
goal.complete_sub_goal(0, Some("Endpoints designed".to_string()));
println!("{}", goal.get_summary());Fields§
§description: StringWhat we’re trying to accomplish
success_criteria: Vec<SuccessCriterion>How to know when we’re successful
sub_goals: Vec<SubGoal>Smaller steps to achieve the goal
status: GoalStatusCurrent status
Implementations§
Source§impl Goal
impl Goal
Sourcepub fn new(description: String) -> Self
pub fn new(description: String) -> Self
Creates a new goal with the given description.
§Arguments
description- A description of what the goal aims to achieve
Examples found in repository?
22async fn example_1_manual_goal() {
23 println!("=== Example 1: Manual Goal Creation ===\n");
24
25 // Create an agent
26 let mut agent = Agent::new("MealPlanner", "ollama::gemma3:latest");
27
28 // Create a goal manually for a complex task
29 let mut goal = Goal::new(
30 "Plan a healthy meal prep for the week".to_string()
31 );
32
33 // Define what success looks like
34 println!("📋 Setting success criteria...");
35 goal.add_criterion("7 breakfast recipes selected".to_string());
36 goal.add_criterion("7 lunch recipes selected".to_string());
37 goal.add_criterion("7 dinner recipes selected".to_string());
38 goal.add_criterion("Shopping list created".to_string());
39 goal.add_criterion("Prep schedule created".to_string());
40
41 // Break down into steps (sub-goals)
42 println!("🎯 Breaking down into sub-goals...\n");
43 goal.add_sub_goal("Ask user about dietary preferences".to_string(), 0);
44 goal.add_sub_goal("Ask about time available for prep".to_string(), 1);
45 goal.add_sub_goal("Suggest breakfast options".to_string(), 2);
46 goal.add_sub_goal("Suggest lunch options".to_string(), 3);
47 goal.add_sub_goal("Suggest dinner options".to_string(), 4);
48 goal.add_sub_goal("Create shopping list".to_string(), 5);
49 goal.add_sub_goal("Create prep schedule".to_string(), 6);
50
51 // Start working on the goal
52 goal.status = GoalStatus::InProgress;
53
54 // Set the goal on the agent
55 agent.set_goal(goal.clone());
56
57 // Create a task aligned with the goal
58 let task = TaskRequest::new("I need help with meal planning");
59
60 // Run the agent
61 println!("⏳ Agent is working on the meal planning task...\n");
62 let _response = agent.run(task).await;
63
64 // Show the goal summary
65 println!("\n📊 Goal Summary:");
66 println!("{}", goal.get_summary());
67
68 println!("\n✅ Example 1 completed!\n");
69}
70
71// ============================================
72// Example 2: Goal Progress Tracking
73// ============================================
74
75async fn example_2_goal_progress_tracking() {
76 println!("\n=== Example 2: Goal Progress Tracking ===\n");
77
78 // Create a goal for a project
79 let mut goal = Goal::new(
80 "Create a project plan for building a mobile app".to_string()
81 );
82
83 // Add success criteria
84 goal.add_criterion("Project requirements documented".to_string());
85 goal.add_criterion("Timeline created with milestones".to_string());
86 goal.add_criterion("Resource allocation plan completed".to_string());
87 goal.add_criterion("Risk assessment performed".to_string());
88
89 // Add sub-goals
90 goal.add_sub_goal("Gather stakeholder requirements".to_string(), 0);
91 goal.add_sub_goal("Define project scope".to_string(), 1);
92 goal.add_sub_goal("Create development timeline".to_string(), 2);
93 goal.add_sub_goal("Allocate resources".to_string(), 3);
94 goal.add_sub_goal("Identify risks and mitigation strategies".to_string(), 4);
95
96 goal.status = GoalStatus::InProgress;
97
98 // Simulate progress through the goal
99 println!("📈 Tracking goal progress...\n");
100
101 // Complete first sub-goal
102 println!("Step 1: Gathering requirements");
103 goal.complete_sub_goal(0, Some("Interviewed 5 stakeholders".to_string()));
104 goal.mark_criterion_met(0, "Requirements documented".to_string());
105 println!(" Progress: {}%\n", goal.get_progress());
106
107 // Complete second sub-goal
108 println!("Step 2: Defining scope");
109 goal.complete_sub_goal(1, Some("Scope document created".to_string()));
110 println!(" Progress: {}%\n", goal.get_progress());
111
112 // Complete third sub-goal
113 println!("Step 3: Creating timeline");
114 goal.complete_sub_goal(2, Some("12-month timeline with milestones".to_string()));
115 goal.mark_criterion_met(1, "Timeline created".to_string());
116 println!(" Progress: {}%\n", goal.get_progress());
117
118 // Complete fourth sub-goal
119 println!("Step 4: Allocating resources");
120 goal.complete_sub_goal(3, Some("Resource allocation table created".to_string()));
121 goal.mark_criterion_met(2, "Resources allocated".to_string());
122 println!(" Progress: {}%\n", goal.get_progress());
123
124 // Complete fifth sub-goal
125 println!("Step 5: Assessing risks");
126 goal.complete_sub_goal(4, Some("Risk register created with 8 identified risks".to_string()));
127 goal.mark_criterion_met(3, "Risks identified".to_string());
128 println!(" Progress: {}%\n", goal.get_progress());
129
130 // Show final status
131 println!("\n📊 Final Goal Status:");
132 println!("{}", goal.get_summary());
133
134 println!("\n✅ Example 2 completed!\n");
135}
136
137// ============================================
138// Example 3: Job Interview Preparation Goal
139// ============================================
140
141async fn example_3_interview_preparation() {
142 println!("\n=== Example 3: Job Interview Preparation Goal ===\n");
143
144 let mut agent = Agent::new("InterviewCoach", "ollama::gemma3:latest");
145
146 // Create a structured goal for interview prep
147 let mut goal = Goal::new(
148 "Prepare for a senior software engineer interview at a tech company".to_string()
149 );
150
151 // Define success criteria
152 println!("🎯 Success criteria:");
153 goal.add_criterion("Technical topics reviewed (algorithms, data structures, system design)".to_string());
154 goal.add_criterion("Behavioral questions prepared with STAR method examples".to_string());
155 goal.add_criterion("Company research completed".to_string());
156 goal.add_criterion("Practice mock interview conducted".to_string());
157 goal.add_criterion("Questions to ask the interviewer prepared".to_string());
158
159 for criterion in &goal.success_criteria {
160 println!(" • {}", criterion.description);
161 }
162
163 // Define steps
164 println!("\n📋 Steps to take:");
165 goal.add_sub_goal("Review core algorithms and data structures".to_string(), 0);
166 goal.add_sub_goal("Study system design patterns".to_string(), 1);
167 goal.add_sub_goal("Prepare STAR method stories from past projects".to_string(), 2);
168 goal.add_sub_goal("Research company background and culture".to_string(), 3);
169 goal.add_sub_goal("Practice mock interview with a friend".to_string(), 4);
170 goal.add_sub_goal("Prepare thoughtful questions about the role".to_string(), 5);
171
172 for sub_goal in &goal.sub_goals {
173 println!(" {}. {}", sub_goal.priority + 1, sub_goal.description);
174 }
175
176 goal.status = GoalStatus::InProgress;
177
178 // Set goal on agent
179 agent.set_goal(goal.clone());
180
181 // Create related task
182 let task = TaskRequest::new("Help me prepare for my senior engineer interview");
183
184 println!("\n⏳ Agent is creating interview preparation plan...\n");
185 let _response = agent.run(task).await;
186
187 println!("\n📊 Goal Summary:");
188 println!("{}", goal.get_summary());
189
190 println!("\n✅ Example 3 completed!\n");
191}
192
193// ============================================
194// Example 4: Goal Analysis from Task Description
195// ============================================
196
197fn example_4_goal_analysis() {
198 println!("\n=== Example 4: Goal Analysis from Task Description ===\n");
199
200 // Simulate LLM analyzing a task and breaking it down into a goal
201 let task_description = "Help me learn Python programming";
202
203 println!("📝 Original task: \"{}\"", task_description);
204 println!("\n🔍 LLM analyzing task...\n");
205
206 // This is what the LLM would return
207 let analysis = GoalAnalysis {
208 main_goal: "Help user learn Python programming from basics to practical skills".to_string(),
209 success_criteria: vec![
210 "User's current skill level identified".to_string(),
211 "Learning path created based on skill level".to_string(),
212 "Resources (tutorials, books) provided".to_string(),
213 "Practice exercises suggested".to_string(),
214 "Study schedule created".to_string(),
215 ],
216 sub_goals: vec![
217 "Ask about current programming experience".to_string(),
218 "Identify learning goals (web dev, data science, etc)".to_string(),
219 "Create structured learning path".to_string(),
220 "Recommend learning resources".to_string(),
221 "Suggest practice projects".to_string(),
222 "Create study timeline".to_string(),
223 ],
224 };
225
226 // Convert analysis to a Goal
227 let goal = analysis.to_goal();
228
229 println!("✅ Goal created from analysis:\n");
230 println!("{}", goal.get_summary());
231
232 println!("\n✅ Example 4 completed!\n");
233}
234
235// ============================================
236// Example 5: Goal Completion Verification
237// ============================================
238
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}More examples
38async fn example_1_basic_nextjs_app() {
39 println!("=== Example 1: Generate a Basic Next.js App ===\n");
40
41 // Create an agent that will generate the app
42 let mut agent = Agent::new("NextJsGenerator", "ollama::gemma3:latest");
43
44 // Create a goal for generating a Next.js app
45 let mut goal = Goal::new(
46 "Generate a Next.js web application with essential structure".to_string()
47 );
48
49 // Define success criteria
50 goal.add_criterion("package.json created with dependencies".to_string());
51 goal.add_criterion("next.config.js configuration file generated".to_string());
52 goal.add_criterion("pages directory with index and api route created".to_string());
53 goal.add_criterion("styles directory with global CSS".to_string());
54 goal.add_criterion("README.md with setup instructions".to_string());
55
56 // Define sub-goals (steps to generate the app)
57 goal.add_sub_goal("Analyze Next.js requirements and best practices".to_string(), 0);
58 goal.add_sub_goal("Generate package.json with required dependencies".to_string(), 1);
59 goal.add_sub_goal("Create next.config.js configuration".to_string(), 2);
60 goal.add_sub_goal("Generate pages (index.tsx, _app.tsx, _document.tsx)".to_string(), 3);
61 goal.add_sub_goal("Create API route examples".to_string(), 4);
62 goal.add_sub_goal("Generate styling setup (global.css, utilities)".to_string(), 5);
63 goal.add_sub_goal("Create components directory with example components".to_string(), 6);
64 goal.add_sub_goal("Generate README with setup and usage instructions".to_string(), 7);
65
66 goal.status = GoalStatus::InProgress;
67 agent.set_goal(goal.clone());
68
69 // Create a task to generate a Next.js app
70 let task = TaskRequest::new(
71 "Generate a modern Next.js 14 application with TypeScript, Tailwind CSS, and best practices. \
72 Include package.json, next.config.js, sample pages, API routes, and components. \
73 The app should be production-ready and follow Next.js conventions."
74 );
75
76 println!("📝 Task: Generate a Next.js application\n");
77 println!("🎯 Success Criteria:");
78 for criterion in &goal.success_criteria {
79 println!(" • {}", criterion.description);
80 }
81
82 println!("\n⏳ Agent is generating the Next.js app...\n");
83 let response = agent.run(task).await;
84
85 // Extract and display the output
86 let output = extract_output_text(&response.result());
87 println!("📄 Generated Output:\n");
88 println!("{}\n", output);
89
90 // Show progress
91 println!("📊 Goal Progress: {}%", goal.get_progress());
92 println!("Status: {:?}", goal.status);
93
94 println!("\n✅ Example 1 completed!\n");
95}
96
97// ============================================
98// Example 2: E-Commerce Next.js App
99// ============================================
100
101async fn example_2_ecommerce_app() {
102 println!("\n=== Example 2: Generate E-Commerce Next.js App ===\n");
103
104 let mut agent = Agent::new("EcommerceGenerator", "ollama::gemma3:latest");
105
106 let mut goal = Goal::new(
107 "Generate a complete e-commerce Next.js application".to_string()
108 );
109
110 // Success criteria for e-commerce
111 goal.add_criterion("Product listing page with filtering and sorting".to_string());
112 goal.add_criterion("Product detail pages with dynamic routes".to_string());
113 goal.add_criterion("Shopping cart functionality".to_string());
114 goal.add_criterion("User authentication setup".to_string());
115 goal.add_criterion("Payment integration structure".to_string());
116 goal.add_criterion("Database models and API endpoints".to_string());
117 goal.add_criterion("Admin dashboard layout".to_string());
118
119 // Sub-goals
120 goal.add_sub_goal("Design database schema for products and orders".to_string(), 0);
121 goal.add_sub_goal("Create product API endpoints".to_string(), 1);
122 goal.add_sub_goal("Build product listing and search components".to_string(), 2);
123 goal.add_sub_goal("Implement product detail pages".to_string(), 3);
124 goal.add_sub_goal("Create shopping cart context and management".to_string(), 4);
125 goal.add_sub_goal("Build checkout flow pages".to_string(), 5);
126 goal.add_sub_goal("Integrate payment gateway API".to_string(), 6);
127 goal.add_sub_goal("Create admin dashboard pages".to_string(), 7);
128 goal.add_sub_goal("Add authentication middleware".to_string(), 8);
129
130 goal.status = GoalStatus::InProgress;
131 agent.set_goal(goal.clone());
132
133 let task = TaskRequest::new(
134 "Generate a complete e-commerce Next.js application with: \
135 1. Product management system (listing, search, filters)\n\
136 2. Shopping cart with add/remove/update functionality\n\
137 3. User authentication and profile pages\n\
138 4. Payment integration endpoints\n\
139 5. Order history and tracking\n\
140 6. Admin dashboard for managing products and orders\n\
141 7. Database models for PostgreSQL or MongoDB\n\
142 8. RESTful API endpoints\n\
143 Use TypeScript, Tailwind CSS, and modern React patterns."
144 );
145
146 println!("📝 Task: Generate E-Commerce Next.js Application\n");
147 println!("🎯 Features to Generate:");
148 for criterion in &goal.success_criteria {
149 println!(" ✓ {}", criterion.description);
150 }
151
152 println!("\n⏳ Agent is generating e-commerce app...\n");
153 let response = agent.run(task).await;
154
155 let output = extract_output_text(&response.result());
156 println!("📄 Generated Output:\n");
157 println!("{}\n", output);
158
159 println!("📊 Goal Progress: {}%", goal.get_progress());
160 println!("\n✅ Example 2 completed!\n");
161}
162
163// ============================================
164// Example 3: SaaS Dashboard App
165// ============================================
166
167async fn example_3_saas_dashboard() {
168 println!("\n=== Example 3: Generate SaaS Dashboard Next.js App ===\n");
169
170 let mut agent = Agent::new("SaasDashboardGenerator", "ollama::gemma3:latest");
171
172 let mut goal = Goal::new(
173 "Generate a SaaS dashboard application with user management".to_string()
174 );
175
176 goal.add_criterion("User authentication and authorization".to_string());
177 goal.add_criterion("Multi-tenant database structure".to_string());
178 goal.add_criterion("Dashboard with analytics and metrics".to_string());
179 goal.add_criterion("User and team management pages".to_string());
180 goal.add_criterion("Settings and preferences pages".to_string());
181 goal.add_criterion("Billing and subscription management".to_string());
182 goal.add_criterion("API for data collection and reporting".to_string());
183
184 goal.add_sub_goal("Design multi-tenant database schema".to_string(), 0);
185 goal.add_sub_goal("Implement OAuth authentication".to_string(), 1);
186 goal.add_sub_goal("Create dashboard with charts and metrics".to_string(), 2);
187 goal.add_sub_goal("Build team and user management interfaces".to_string(), 3);
188 goal.add_sub_goal("Create settings pages for users and organization".to_string(), 4);
189 goal.add_sub_goal("Implement billing API integration".to_string(), 5);
190 goal.add_sub_goal("Create analytics and reporting system".to_string(), 6);
191 goal.add_sub_goal("Add email notification templates".to_string(), 7);
192
193 goal.status = GoalStatus::InProgress;
194 agent.set_goal(goal.clone());
195
196 let task = TaskRequest::new(
197 "Generate a complete SaaS dashboard Next.js application with:\n\
198 1. Multi-tenant authentication (OAuth + JWT)\n\
199 2. Organization and team management\n\
200 3. Comprehensive dashboard with charts and analytics\n\
201 4. User permission and role management\n\
202 5. Billing integration with Stripe\n\
203 6. Settings pages for users and teams\n\
204 7. Email notifications system\n\
205 8. API logging and activity tracking\n\
206 9. Dark mode support\n\
207 10. Mobile responsive design\n\
208 Include TypeScript, Tailwind CSS, Recharts for visualizations, \
209 and PostgreSQL database models."
210 );
211
212 println!("📝 Task: Generate SaaS Dashboard Application\n");
213 println!("🎯 Dashboard Features:");
214 for criterion in &goal.success_criteria {
215 println!(" ✓ {}", criterion.description);
216 }
217
218 println!("\n⏳ Agent is generating SaaS dashboard...\n");
219 let response = agent.run(task).await;
220
221 let output = extract_output_text(&response.result());
222 println!("📄 Generated Output:\n");
223 println!("{}\n", output);
224
225 println!("📊 Goal Progress: {}%", goal.get_progress());
226 println!("\n✅ Example 3 completed!\n");
227}
228
229// ============================================
230// Example 4: Blog Platform with CMS
231// ============================================
232
233async fn example_4_blog_platform() {
234 println!("\n=== Example 4: Generate Blog Platform with CMS ===\n");
235
236 let mut agent = Agent::new("BlogCMSGenerator", "ollama::gemma3:latest");
237
238 let mut goal = Goal::new(
239 "Generate a comprehensive blog platform with CMS".to_string()
240 );
241
242 goal.add_criterion("Blog post management system".to_string());
243 goal.add_criterion("Rich text editor with markdown support".to_string());
244 goal.add_criterion("Category and tag system".to_string());
245 goal.add_criterion("Search and filtering functionality".to_string());
246 goal.add_criterion("Comments system with moderation".to_string());
247 goal.add_criterion("SEO optimization (meta tags, sitemap)".to_string());
248 goal.add_criterion("Author management and permissions".to_string());
249 goal.add_criterion("Analytics and engagement tracking".to_string());
250
251 goal.add_sub_goal("Design blog database schema".to_string(), 0);
252 goal.add_sub_goal("Create CMS backend API".to_string(), 1);
253 goal.add_sub_goal("Build post editor with markdown".to_string(), 2);
254 goal.add_sub_goal("Create blog listing and search pages".to_string(), 3);
255 goal.add_sub_goal("Build individual post pages with SEO".to_string(), 4);
256 goal.add_sub_goal("Implement comments system".to_string(), 5);
257 goal.add_sub_goal("Create author profiles and bio".to_string(), 6);
258 goal.add_sub_goal("Build admin dashboard for content management".to_string(), 7);
259 goal.add_sub_goal("Add analytics tracking and reporting".to_string(), 8);
260
261 goal.status = GoalStatus::InProgress;
262 agent.set_goal(goal.clone());
263
264 let task = TaskRequest::new(
265 "Generate a full-featured blog platform with CMS:\n\
266 1. Post creation and editing with rich text editor\n\
267 2. Markdown support with preview\n\
268 3. Category and tag system\n\
269 4. Advanced search with filters\n\
270 5. Comments system with nested replies\n\
271 6. Author profiles with biography\n\
272 7. SEO optimization (sitemaps, meta tags, structured data)\n\
273 8. Social sharing integration\n\
274 9. Email newsletter subscription\n\
275 10. Analytics dashboard for authors\n\
276 11. Reading time estimates\n\
277 12. Related posts suggestions\n\
278 Include TypeScript, Tailwind CSS, next-mdx-remote for markdown, \
279 and MongoDB/PostgreSQL models."
280 );
281
282 println!("📝 Task: Generate Blog Platform with CMS\n");
283 println!("🎯 Blog Features:");
284 for criterion in &goal.success_criteria {
285 println!(" ✓ {}", criterion.description);
286 }
287
288 println!("\n⏳ Agent is generating blog platform...\n");
289 let response = agent.run(task).await;
290
291 let output = extract_output_text(&response.result());
292 println!("📄 Generated Output:\n");
293 println!("{}\n", output);
294
295 println!("📊 Goal Progress: {}%", goal.get_progress());
296 println!("\n✅ Example 4 completed!\n");
297}109async fn example_1_basic_cli_app() {
110 println!("=== Example 1: Generate a Basic Python CLI Application ===\n");
111
112 let mut agent = Agent::new("PythonCliGenerator", "ollama::gemma3:latest");
113
114 // Create a goal for generating a Python CLI app
115 let mut goal = Goal::new(
116 "Generate a Python command-line application with core structure".to_string()
117 );
118
119 // Define success criteria
120 goal.add_criterion("requirements.txt with dependencies listed".to_string());
121 goal.add_criterion("setup.py or pyproject.toml for packaging".to_string());
122 goal.add_criterion("Main CLI entry point with argument parsing".to_string());
123 goal.add_criterion("Command structure with subcommands".to_string());
124 goal.add_criterion("Basic error handling and logging".to_string());
125 goal.add_criterion("README.md with usage instructions".to_string());
126 goal.add_criterion(".gitignore for Python projects".to_string());
127
128 // Define sub-goals (steps to generate the app)
129 goal.add_sub_goal("Analyze Python CLI best practices".to_string(), 0);
130 goal.add_sub_goal("Generate project structure and directories".to_string(), 1);
131 goal.add_sub_goal("Create requirements.txt with dependencies (Click, Typer, etc)".to_string(), 2);
132 goal.add_sub_goal("Generate pyproject.toml or setup.py".to_string(), 3);
133 goal.add_sub_goal("Create main CLI module with argument parser".to_string(), 4);
134 goal.add_sub_goal("Generate subcommands and command handlers".to_string(), 5);
135 goal.add_sub_goal("Create utility modules and helpers".to_string(), 6);
136 goal.add_sub_goal("Add logging and error handling".to_string(), 7);
137 goal.add_sub_goal("Generate README with installation and usage".to_string(), 8);
138
139 goal.status = GoalStatus::InProgress;
140 agent.set_goal(goal.clone());
141
142 // Create a task to generate a Python CLI app
143 let task = TaskRequest::new(
144 "Generate a professional Python command-line application with the following structure:\n\
145 1. Modern argument parsing using Click or Typer\n\
146 2. Multiple subcommands (e.g., init, run, config, help)\n\
147 3. Configuration file support (YAML or JSON)\n\
148 4. Logging with different verbosity levels\n\
149 5. Error handling and graceful failure messages\n\
150 6. Proper project structure with src/ and tests/ directories\n\
151 7. pyproject.toml or setup.py for packaging\n\
152 8. requirements.txt with dev dependencies\n\
153 9. .gitignore for Python\n\
154 10. Comprehensive README with examples\n\
155 The app should be production-ready and follow Python best practices (PEP 8)."
156 );
157
158 println!("📝 Task: Generate a Python CLI Application\n");
159 println!("🎯 Success Criteria:");
160 for criterion in &goal.success_criteria {
161 println!(" • {}", criterion.description);
162 }
163
164 println!("\n⏳ Agent is generating the Python CLI app...\n");
165 let response = agent.run(task).await;
166
167 // Extract and display the output
168 let output = extract_output_text(&response.result());
169 println!("📄 Generated Output:\n");
170 println!("{}\n", output);
171
172 // Show progress
173 println!("📊 Goal Progress: {}%", goal.get_progress());
174 println!("Status: {:?}", goal.status);
175
176 println!("\n✅ Example 1 completed!\n");
177}
178
179// ============================================
180// Example 2: Python Web API with FastAPI
181// ============================================
182
183async fn example_2_fastapi_web_app() {
184 println!("\n=== Example 2: Generate Python FastAPI Web Application ===\n");
185
186 let mut agent = Agent::new("FastApiGenerator", "ollama::gemma3:latest");
187
188 let mut goal = Goal::new(
189 "Generate a complete FastAPI web application with database integration".to_string()
190 );
191
192 // Success criteria for FastAPI app
193 goal.add_criterion("FastAPI application structure with routers".to_string());
194 goal.add_criterion("Database models using SQLAlchemy".to_string());
195 goal.add_criterion("RESTful API endpoints with CRUD operations".to_string());
196 goal.add_criterion("Request/response schemas using Pydantic".to_string());
197 goal.add_criterion("Authentication and authorization middleware".to_string());
198 goal.add_criterion("Database migrations with Alembic".to_string());
199 goal.add_criterion("Configuration management with environment variables".to_string());
200 goal.add_criterion("Unit and integration test examples".to_string());
201 goal.add_criterion("Docker setup for containerization".to_string());
202
203 // Sub-goals
204 goal.add_sub_goal("Design REST API endpoints structure".to_string(), 0);
205 goal.add_sub_goal("Create Pydantic models for request/response validation".to_string(), 1);
206 goal.add_sub_goal("Set up SQLAlchemy ORM with database models".to_string(), 2);
207 goal.add_sub_goal("Implement CRUD routers for resources".to_string(), 3);
208 goal.add_sub_goal("Add authentication and JWT tokens".to_string(), 4);
209 goal.add_sub_goal("Create Alembic migrations setup".to_string(), 5);
210 goal.add_sub_goal("Set up configuration with environment variables".to_string(), 6);
211 goal.add_sub_goal("Create test fixtures and example tests".to_string(), 7);
212 goal.add_sub_goal("Generate Docker and docker-compose files".to_string(), 8);
213 goal.add_sub_goal("Create comprehensive API documentation".to_string(), 9);
214
215 goal.status = GoalStatus::InProgress;
216 agent.set_goal(goal.clone());
217
218 let task = TaskRequest::new(
219 "Generate a production-ready FastAPI web application with:\n\
220 1. Modular project structure with routers for different resources\n\
221 2. Pydantic models for request/response validation\n\
222 3. SQLAlchemy ORM setup with database models\n\
223 4. CRUD operations for users, products, and orders\n\
224 5. JWT authentication and authorization middleware\n\
225 6. Role-based access control (RBAC)\n\
226 7. Alembic database migrations\n\
227 8. Environment configuration (.env support)\n\
228 9. Error handling with proper HTTP status codes\n\
229 10. Logging configuration\n\
230 11. Unit tests with pytest\n\
231 12. Integration tests with test database\n\
232 13. Docker and docker-compose for local development\n\
233 14. requirements.txt with all dependencies\n\
234 15. Comprehensive API documentation\n\
235 Use async/await patterns, follow REST conventions, and include examples."
236 );
237
238 println!("📝 Task: Generate FastAPI Web Application\n");
239 println!("🎯 FastAPI Features:");
240 for criterion in &goal.success_criteria {
241 println!(" ✓ {}", criterion.description);
242 }
243
244 println!("\n⏳ Agent is generating FastAPI app...\n");
245 let response = agent.run(task).await;
246
247 let output = extract_output_text(&response.result());
248 println!("📄 Generated Output:\n");
249 println!("{}\n", output);
250
251 println!("📊 Goal Progress: {}%", goal.get_progress());
252 println!("\n✅ Example 2 completed!\n");
253}
254
255// ============================================
256// Example 3: Python Data Science Project
257// ============================================
258
259async fn example_3_data_science_project() {
260 println!("\n=== Example 3: Generate Python Data Science Project ===\n");
261
262 let mut agent = Agent::new("DataScienceGenerator", "ollama::gemma3:latest");
263
264 let mut goal = Goal::new(
265 "Generate a data science project with ML pipeline and analysis".to_string()
266 );
267
268 goal.add_criterion("Project structure following cookiecutter-data-science".to_string());
269 goal.add_criterion("Data loading and preprocessing modules".to_string());
270 goal.add_criterion("Exploratory data analysis (EDA) notebooks".to_string());
271 goal.add_criterion("Feature engineering pipeline".to_string());
272 goal.add_criterion("Model training and evaluation".to_string());
273 goal.add_criterion("Hyperparameter tuning setup".to_string());
274 goal.add_criterion("Model persistence and versioning".to_string());
275 goal.add_criterion("Visualization utilities".to_string());
276 goal.add_criterion("Unit tests for data pipeline".to_string());
277
278 goal.add_sub_goal("Create cookiecutter-style directory structure".to_string(), 0);
279 goal.add_sub_goal("Set up Jupyter notebook for EDA".to_string(), 1);
280 goal.add_sub_goal("Create data loading and preprocessing modules".to_string(), 2);
281 goal.add_sub_goal("Implement feature engineering pipeline".to_string(), 3);
282 goal.add_sub_goal("Set up scikit-learn model training".to_string(), 4);
283 goal.add_sub_goal("Create model evaluation and metrics".to_string(), 5);
284 goal.add_sub_goal("Implement hyperparameter tuning with GridSearchCV".to_string(), 6);
285 goal.add_sub_goal("Add model persistence with joblib/pickle".to_string(), 7);
286 goal.add_sub_goal("Create visualization utilities with matplotlib/seaborn".to_string(), 8);
287 goal.add_sub_goal("Write tests for data pipeline".to_string(), 9);
288
289 goal.status = GoalStatus::InProgress;
290 agent.set_goal(goal.clone());
291
292 let task = TaskRequest::new(
293 "Generate a comprehensive Python data science project with:\n\
294 1. Proper project structure for data science work\n\
295 2. Data loading module supporting CSV, JSON, Parquet\n\
296 3. Data preprocessing and validation pipeline\n\
297 4. Exploratory Data Analysis (EDA) notebook template\n\
298 5. Feature engineering module\n\
299 6. Model training with scikit-learn or XGBoost\n\
300 7. Cross-validation and evaluation metrics\n\
301 8. Hyperparameter tuning with GridSearchCV/RandomSearch\n\
302 9. Model persistence and loading utilities\n\
303 10. Visualization utilities (matplotlib, seaborn, plotly)\n\
304 11. Unit tests for data loading and preprocessing\n\
305 12. Configuration management for experiments\n\
306 13. Logging for training pipeline\n\
307 14. Requirements.txt with ML libraries (pandas, numpy, scikit-learn)\n\
308 15. Makefile for common tasks\n\
309 16. README with dataset description and results\n\
310 Include example workflows and best practices for reproducibility."
311 );
312
313 println!("📝 Task: Generate Data Science Project\n");
314 println!("🎯 Data Science Features:");
315 for criterion in &goal.success_criteria {
316 println!(" ✓ {}", criterion.description);
317 }
318
319 println!("\n⏳ Agent is generating data science project...\n");
320 let response = agent.run(task).await;
321
322 let output = extract_output_text(&response.result());
323 println!("📄 Generated Output:\n");
324 println!("{}\n", output);
325
326 println!("📊 Goal Progress: {}%", goal.get_progress());
327 println!("\n✅ Example 3 completed!\n");
328}
329
330// ============================================
331// Example 4: Python Package/Library
332// ============================================
333
334async fn example_4_python_library() {
335 println!("\n=== Example 4: Generate Python Library/Package ===\n");
336
337 let mut agent = Agent::new("PythonLibraryGenerator", "ollama::gemma3:latest");
338
339 let mut goal = Goal::new(
340 "Generate a well-structured Python package ready for distribution".to_string()
341 );
342
343 goal.add_criterion("Proper package structure with namespace".to_string());
344 goal.add_criterion("setup.py and pyproject.toml for distribution".to_string());
345 goal.add_criterion("Comprehensive docstrings and type hints".to_string());
346 goal.add_criterion("Unit tests with pytest".to_string());
347 goal.add_criterion("Documentation with Sphinx".to_string());
348 goal.add_criterion("CI/CD configuration (GitHub Actions)".to_string());
349 goal.add_criterion("Version management strategy".to_string());
350 goal.add_criterion("Contributing guidelines".to_string());
351
352 goal.add_sub_goal("Create package structure with __init__.py files".to_string(), 0);
353 goal.add_sub_goal("Write setup.py and pyproject.toml".to_string(), 1);
354 goal.add_sub_goal("Create core modules with type hints".to_string(), 2);
355 goal.add_sub_goal("Add comprehensive docstrings".to_string(), 3);
356 goal.add_sub_goal("Create test structure with pytest".to_string(), 4);
357 goal.add_sub_goal("Set up documentation with Sphinx".to_string(), 5);
358 goal.add_sub_goal("Create GitHub Actions workflows".to_string(), 6);
359 goal.add_sub_goal("Add CONTRIBUTING.md and CODE_OF_CONDUCT.md".to_string(), 7);
360 goal.add_sub_goal("Create MANIFEST.in and manifest files".to_string(), 8);
361
362 goal.status = GoalStatus::InProgress;
363 agent.set_goal(goal.clone());
364
365 let task = TaskRequest::new(
366 "Generate a professional Python library/package with:\n\
367 1. Standard package structure (src layout)\n\
368 2. __init__.py with version and exports\n\
369 3. Core modules with complete implementations\n\
370 4. Type hints throughout (PEP 484)\n\
371 5. Comprehensive docstrings (Google style)\n\
372 6. setup.py with metadata\n\
373 7. pyproject.toml with build system\n\
374 8. MANIFEST.in for package data\n\
375 9. Pytest test structure with fixtures\n\
376 10. pytest.ini configuration\n\
377 11. Sphinx documentation setup\n\
378 12. GitHub Actions workflow for CI/CD\n\
379 13. Pre-commit hooks configuration\n\
380 14. LICENSE (MIT or Apache 2.0)\n\
381 15. .gitignore for Python\n\
382 16. README.md with installation and usage\n\
383 17. CONTRIBUTING.md for contributors\n\
384 18. CODE_OF_CONDUCT.md\n\
385 19. Changelog/HISTORY.md template\n\
386 20. Version management with __version__\n\
387 Include examples for public API and best practices for library development."
388 );
389
390 println!("📝 Task: Generate Python Library Package\n");
391 println!("🎯 Library Features:");
392 for criterion in &goal.success_criteria {
393 println!(" ✓ {}", criterion.description);
394 }
395
396 println!("\n⏳ Agent is generating Python library...\n");
397 let response = agent.run(task).await;
398
399 let output = extract_output_text(&response.result());
400 println!("📄 Generated Output:\n");
401 println!("{}\n", output);
402
403 println!("📊 Goal Progress: {}%", goal.get_progress());
404 println!("\n✅ Example 4 completed!\n");
405}
406
407// ============================================
408// Example 5: Django Web Application
409// ============================================
410
411async fn example_5_django_web_app() {
412 println!("\n=== Example 5: Generate Django Web Application ===\n");
413
414 let mut agent = Agent::new("DjangoGenerator", "ollama::gemma3:latest");
415
416 let mut goal = Goal::new(
417 "Generate a complete Django web application with admin and authentication".to_string()
418 );
419
420 goal.add_criterion("Django project structure with multiple apps".to_string());
421 goal.add_criterion("Custom user model implementation".to_string());
422 goal.add_criterion("Database models for core features".to_string());
423 goal.add_criterion("Admin interface customization".to_string());
424 goal.add_criterion("Views and URL routing".to_string());
425 goal.add_criterion("Templates with Bootstrap styling".to_string());
426 goal.add_criterion("Authentication and permissions".to_string());
427 goal.add_criterion("Database migrations".to_string());
428 goal.add_criterion("Django REST Framework API".to_string());
429
430 goal.add_sub_goal("Create Django project and app structure".to_string(), 0);
431 goal.add_sub_goal("Design and implement custom user model".to_string(), 1);
432 goal.add_sub_goal("Create models for core features".to_string(), 2);
433 goal.add_sub_goal("Configure admin interface".to_string(), 3);
434 goal.add_sub_goal("Create views and templates".to_string(), 4);
435 goal.add_sub_goal("Set up URL routing".to_string(), 5);
436 goal.add_sub_goal("Implement authentication views".to_string(), 6);
437 goal.add_sub_goal("Create Django REST Framework serializers".to_string(), 7);
438 goal.add_sub_goal("Set up static files and media handling".to_string(), 8);
439
440 goal.status = GoalStatus::InProgress;
441 agent.set_goal(goal.clone());
442
443 let task = TaskRequest::new(
444 "Generate a full-featured Django web application with:\n\
445 1. Django project structure with multiple apps\n\
446 2. Custom user model extending AbstractBaseUser\n\
447 3. Models for main features (e.g., Blog posts, Comments, Categories)\n\
448 4. Django ORM relationships (ForeignKey, ManyToMany)\n\
449 5. Admin interface with custom actions\n\
450 6. Class-based views (ListView, DetailView, CreateView)\n\
451 7. Django templates with template inheritance\n\
452 8. Bootstrap styling integration\n\
453 9. Authentication and login required decorators\n\
454 10. Permission-based access control\n\
455 11. Database migrations\n\
456 12. Forms with validation\n\
457 13. Django REST Framework setup\n\
458 14. API serializers and viewsets\n\
459 15. Pagination and filtering\n\
460 16. Settings for dev and production\n\
461 17. Environment variable configuration\n\
462 18. Logging configuration\n\
463 19. Tests with Django TestCase\n\
464 20. Static files and media management\n\
465 21. Docker setup\n\
466 22. Requirements.txt\n\
467 Include examples and docstrings following Django conventions."
468 );
469
470 println!("📝 Task: Generate Django Web Application\n");
471 println!("🎯 Django Features:");
472 for criterion in &goal.success_criteria {
473 println!(" ✓ {}", criterion.description);
474 }
475
476 println!("\n⏳ Agent is generating Django app...\n");
477 let response = agent.run(task).await;
478
479 let output = extract_output_text(&response.result());
480 println!("📄 Generated Output:\n");
481 println!("{}\n", output);
482
483 println!("📊 Goal Progress: {}%", goal.get_progress());
484 println!("\n✅ Example 5 completed!\n");
485}Sourcepub fn add_criterion(&mut self, description: String)
pub fn add_criterion(&mut self, description: String)
Adds a success criterion to the goal.
§Arguments
description- The condition that must be true for success
Examples found in repository?
22async fn example_1_manual_goal() {
23 println!("=== Example 1: Manual Goal Creation ===\n");
24
25 // Create an agent
26 let mut agent = Agent::new("MealPlanner", "ollama::gemma3:latest");
27
28 // Create a goal manually for a complex task
29 let mut goal = Goal::new(
30 "Plan a healthy meal prep for the week".to_string()
31 );
32
33 // Define what success looks like
34 println!("📋 Setting success criteria...");
35 goal.add_criterion("7 breakfast recipes selected".to_string());
36 goal.add_criterion("7 lunch recipes selected".to_string());
37 goal.add_criterion("7 dinner recipes selected".to_string());
38 goal.add_criterion("Shopping list created".to_string());
39 goal.add_criterion("Prep schedule created".to_string());
40
41 // Break down into steps (sub-goals)
42 println!("🎯 Breaking down into sub-goals...\n");
43 goal.add_sub_goal("Ask user about dietary preferences".to_string(), 0);
44 goal.add_sub_goal("Ask about time available for prep".to_string(), 1);
45 goal.add_sub_goal("Suggest breakfast options".to_string(), 2);
46 goal.add_sub_goal("Suggest lunch options".to_string(), 3);
47 goal.add_sub_goal("Suggest dinner options".to_string(), 4);
48 goal.add_sub_goal("Create shopping list".to_string(), 5);
49 goal.add_sub_goal("Create prep schedule".to_string(), 6);
50
51 // Start working on the goal
52 goal.status = GoalStatus::InProgress;
53
54 // Set the goal on the agent
55 agent.set_goal(goal.clone());
56
57 // Create a task aligned with the goal
58 let task = TaskRequest::new("I need help with meal planning");
59
60 // Run the agent
61 println!("⏳ Agent is working on the meal planning task...\n");
62 let _response = agent.run(task).await;
63
64 // Show the goal summary
65 println!("\n📊 Goal Summary:");
66 println!("{}", goal.get_summary());
67
68 println!("\n✅ Example 1 completed!\n");
69}
70
71// ============================================
72// Example 2: Goal Progress Tracking
73// ============================================
74
75async fn example_2_goal_progress_tracking() {
76 println!("\n=== Example 2: Goal Progress Tracking ===\n");
77
78 // Create a goal for a project
79 let mut goal = Goal::new(
80 "Create a project plan for building a mobile app".to_string()
81 );
82
83 // Add success criteria
84 goal.add_criterion("Project requirements documented".to_string());
85 goal.add_criterion("Timeline created with milestones".to_string());
86 goal.add_criterion("Resource allocation plan completed".to_string());
87 goal.add_criterion("Risk assessment performed".to_string());
88
89 // Add sub-goals
90 goal.add_sub_goal("Gather stakeholder requirements".to_string(), 0);
91 goal.add_sub_goal("Define project scope".to_string(), 1);
92 goal.add_sub_goal("Create development timeline".to_string(), 2);
93 goal.add_sub_goal("Allocate resources".to_string(), 3);
94 goal.add_sub_goal("Identify risks and mitigation strategies".to_string(), 4);
95
96 goal.status = GoalStatus::InProgress;
97
98 // Simulate progress through the goal
99 println!("📈 Tracking goal progress...\n");
100
101 // Complete first sub-goal
102 println!("Step 1: Gathering requirements");
103 goal.complete_sub_goal(0, Some("Interviewed 5 stakeholders".to_string()));
104 goal.mark_criterion_met(0, "Requirements documented".to_string());
105 println!(" Progress: {}%\n", goal.get_progress());
106
107 // Complete second sub-goal
108 println!("Step 2: Defining scope");
109 goal.complete_sub_goal(1, Some("Scope document created".to_string()));
110 println!(" Progress: {}%\n", goal.get_progress());
111
112 // Complete third sub-goal
113 println!("Step 3: Creating timeline");
114 goal.complete_sub_goal(2, Some("12-month timeline with milestones".to_string()));
115 goal.mark_criterion_met(1, "Timeline created".to_string());
116 println!(" Progress: {}%\n", goal.get_progress());
117
118 // Complete fourth sub-goal
119 println!("Step 4: Allocating resources");
120 goal.complete_sub_goal(3, Some("Resource allocation table created".to_string()));
121 goal.mark_criterion_met(2, "Resources allocated".to_string());
122 println!(" Progress: {}%\n", goal.get_progress());
123
124 // Complete fifth sub-goal
125 println!("Step 5: Assessing risks");
126 goal.complete_sub_goal(4, Some("Risk register created with 8 identified risks".to_string()));
127 goal.mark_criterion_met(3, "Risks identified".to_string());
128 println!(" Progress: {}%\n", goal.get_progress());
129
130 // Show final status
131 println!("\n📊 Final Goal Status:");
132 println!("{}", goal.get_summary());
133
134 println!("\n✅ Example 2 completed!\n");
135}
136
137// ============================================
138// Example 3: Job Interview Preparation Goal
139// ============================================
140
141async fn example_3_interview_preparation() {
142 println!("\n=== Example 3: Job Interview Preparation Goal ===\n");
143
144 let mut agent = Agent::new("InterviewCoach", "ollama::gemma3:latest");
145
146 // Create a structured goal for interview prep
147 let mut goal = Goal::new(
148 "Prepare for a senior software engineer interview at a tech company".to_string()
149 );
150
151 // Define success criteria
152 println!("🎯 Success criteria:");
153 goal.add_criterion("Technical topics reviewed (algorithms, data structures, system design)".to_string());
154 goal.add_criterion("Behavioral questions prepared with STAR method examples".to_string());
155 goal.add_criterion("Company research completed".to_string());
156 goal.add_criterion("Practice mock interview conducted".to_string());
157 goal.add_criterion("Questions to ask the interviewer prepared".to_string());
158
159 for criterion in &goal.success_criteria {
160 println!(" • {}", criterion.description);
161 }
162
163 // Define steps
164 println!("\n📋 Steps to take:");
165 goal.add_sub_goal("Review core algorithms and data structures".to_string(), 0);
166 goal.add_sub_goal("Study system design patterns".to_string(), 1);
167 goal.add_sub_goal("Prepare STAR method stories from past projects".to_string(), 2);
168 goal.add_sub_goal("Research company background and culture".to_string(), 3);
169 goal.add_sub_goal("Practice mock interview with a friend".to_string(), 4);
170 goal.add_sub_goal("Prepare thoughtful questions about the role".to_string(), 5);
171
172 for sub_goal in &goal.sub_goals {
173 println!(" {}. {}", sub_goal.priority + 1, sub_goal.description);
174 }
175
176 goal.status = GoalStatus::InProgress;
177
178 // Set goal on agent
179 agent.set_goal(goal.clone());
180
181 // Create related task
182 let task = TaskRequest::new("Help me prepare for my senior engineer interview");
183
184 println!("\n⏳ Agent is creating interview preparation plan...\n");
185 let _response = agent.run(task).await;
186
187 println!("\n📊 Goal Summary:");
188 println!("{}", goal.get_summary());
189
190 println!("\n✅ Example 3 completed!\n");
191}
192
193// ============================================
194// Example 4: Goal Analysis from Task Description
195// ============================================
196
197fn example_4_goal_analysis() {
198 println!("\n=== Example 4: Goal Analysis from Task Description ===\n");
199
200 // Simulate LLM analyzing a task and breaking it down into a goal
201 let task_description = "Help me learn Python programming";
202
203 println!("📝 Original task: \"{}\"", task_description);
204 println!("\n🔍 LLM analyzing task...\n");
205
206 // This is what the LLM would return
207 let analysis = GoalAnalysis {
208 main_goal: "Help user learn Python programming from basics to practical skills".to_string(),
209 success_criteria: vec![
210 "User's current skill level identified".to_string(),
211 "Learning path created based on skill level".to_string(),
212 "Resources (tutorials, books) provided".to_string(),
213 "Practice exercises suggested".to_string(),
214 "Study schedule created".to_string(),
215 ],
216 sub_goals: vec![
217 "Ask about current programming experience".to_string(),
218 "Identify learning goals (web dev, data science, etc)".to_string(),
219 "Create structured learning path".to_string(),
220 "Recommend learning resources".to_string(),
221 "Suggest practice projects".to_string(),
222 "Create study timeline".to_string(),
223 ],
224 };
225
226 // Convert analysis to a Goal
227 let goal = analysis.to_goal();
228
229 println!("✅ Goal created from analysis:\n");
230 println!("{}", goal.get_summary());
231
232 println!("\n✅ Example 4 completed!\n");
233}
234
235// ============================================
236// Example 5: Goal Completion Verification
237// ============================================
238
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}More examples
38async fn example_1_basic_nextjs_app() {
39 println!("=== Example 1: Generate a Basic Next.js App ===\n");
40
41 // Create an agent that will generate the app
42 let mut agent = Agent::new("NextJsGenerator", "ollama::gemma3:latest");
43
44 // Create a goal for generating a Next.js app
45 let mut goal = Goal::new(
46 "Generate a Next.js web application with essential structure".to_string()
47 );
48
49 // Define success criteria
50 goal.add_criterion("package.json created with dependencies".to_string());
51 goal.add_criterion("next.config.js configuration file generated".to_string());
52 goal.add_criterion("pages directory with index and api route created".to_string());
53 goal.add_criterion("styles directory with global CSS".to_string());
54 goal.add_criterion("README.md with setup instructions".to_string());
55
56 // Define sub-goals (steps to generate the app)
57 goal.add_sub_goal("Analyze Next.js requirements and best practices".to_string(), 0);
58 goal.add_sub_goal("Generate package.json with required dependencies".to_string(), 1);
59 goal.add_sub_goal("Create next.config.js configuration".to_string(), 2);
60 goal.add_sub_goal("Generate pages (index.tsx, _app.tsx, _document.tsx)".to_string(), 3);
61 goal.add_sub_goal("Create API route examples".to_string(), 4);
62 goal.add_sub_goal("Generate styling setup (global.css, utilities)".to_string(), 5);
63 goal.add_sub_goal("Create components directory with example components".to_string(), 6);
64 goal.add_sub_goal("Generate README with setup and usage instructions".to_string(), 7);
65
66 goal.status = GoalStatus::InProgress;
67 agent.set_goal(goal.clone());
68
69 // Create a task to generate a Next.js app
70 let task = TaskRequest::new(
71 "Generate a modern Next.js 14 application with TypeScript, Tailwind CSS, and best practices. \
72 Include package.json, next.config.js, sample pages, API routes, and components. \
73 The app should be production-ready and follow Next.js conventions."
74 );
75
76 println!("📝 Task: Generate a Next.js application\n");
77 println!("🎯 Success Criteria:");
78 for criterion in &goal.success_criteria {
79 println!(" • {}", criterion.description);
80 }
81
82 println!("\n⏳ Agent is generating the Next.js app...\n");
83 let response = agent.run(task).await;
84
85 // Extract and display the output
86 let output = extract_output_text(&response.result());
87 println!("📄 Generated Output:\n");
88 println!("{}\n", output);
89
90 // Show progress
91 println!("📊 Goal Progress: {}%", goal.get_progress());
92 println!("Status: {:?}", goal.status);
93
94 println!("\n✅ Example 1 completed!\n");
95}
96
97// ============================================
98// Example 2: E-Commerce Next.js App
99// ============================================
100
101async fn example_2_ecommerce_app() {
102 println!("\n=== Example 2: Generate E-Commerce Next.js App ===\n");
103
104 let mut agent = Agent::new("EcommerceGenerator", "ollama::gemma3:latest");
105
106 let mut goal = Goal::new(
107 "Generate a complete e-commerce Next.js application".to_string()
108 );
109
110 // Success criteria for e-commerce
111 goal.add_criterion("Product listing page with filtering and sorting".to_string());
112 goal.add_criterion("Product detail pages with dynamic routes".to_string());
113 goal.add_criterion("Shopping cart functionality".to_string());
114 goal.add_criterion("User authentication setup".to_string());
115 goal.add_criterion("Payment integration structure".to_string());
116 goal.add_criterion("Database models and API endpoints".to_string());
117 goal.add_criterion("Admin dashboard layout".to_string());
118
119 // Sub-goals
120 goal.add_sub_goal("Design database schema for products and orders".to_string(), 0);
121 goal.add_sub_goal("Create product API endpoints".to_string(), 1);
122 goal.add_sub_goal("Build product listing and search components".to_string(), 2);
123 goal.add_sub_goal("Implement product detail pages".to_string(), 3);
124 goal.add_sub_goal("Create shopping cart context and management".to_string(), 4);
125 goal.add_sub_goal("Build checkout flow pages".to_string(), 5);
126 goal.add_sub_goal("Integrate payment gateway API".to_string(), 6);
127 goal.add_sub_goal("Create admin dashboard pages".to_string(), 7);
128 goal.add_sub_goal("Add authentication middleware".to_string(), 8);
129
130 goal.status = GoalStatus::InProgress;
131 agent.set_goal(goal.clone());
132
133 let task = TaskRequest::new(
134 "Generate a complete e-commerce Next.js application with: \
135 1. Product management system (listing, search, filters)\n\
136 2. Shopping cart with add/remove/update functionality\n\
137 3. User authentication and profile pages\n\
138 4. Payment integration endpoints\n\
139 5. Order history and tracking\n\
140 6. Admin dashboard for managing products and orders\n\
141 7. Database models for PostgreSQL or MongoDB\n\
142 8. RESTful API endpoints\n\
143 Use TypeScript, Tailwind CSS, and modern React patterns."
144 );
145
146 println!("📝 Task: Generate E-Commerce Next.js Application\n");
147 println!("🎯 Features to Generate:");
148 for criterion in &goal.success_criteria {
149 println!(" ✓ {}", criterion.description);
150 }
151
152 println!("\n⏳ Agent is generating e-commerce app...\n");
153 let response = agent.run(task).await;
154
155 let output = extract_output_text(&response.result());
156 println!("📄 Generated Output:\n");
157 println!("{}\n", output);
158
159 println!("📊 Goal Progress: {}%", goal.get_progress());
160 println!("\n✅ Example 2 completed!\n");
161}
162
163// ============================================
164// Example 3: SaaS Dashboard App
165// ============================================
166
167async fn example_3_saas_dashboard() {
168 println!("\n=== Example 3: Generate SaaS Dashboard Next.js App ===\n");
169
170 let mut agent = Agent::new("SaasDashboardGenerator", "ollama::gemma3:latest");
171
172 let mut goal = Goal::new(
173 "Generate a SaaS dashboard application with user management".to_string()
174 );
175
176 goal.add_criterion("User authentication and authorization".to_string());
177 goal.add_criterion("Multi-tenant database structure".to_string());
178 goal.add_criterion("Dashboard with analytics and metrics".to_string());
179 goal.add_criterion("User and team management pages".to_string());
180 goal.add_criterion("Settings and preferences pages".to_string());
181 goal.add_criterion("Billing and subscription management".to_string());
182 goal.add_criterion("API for data collection and reporting".to_string());
183
184 goal.add_sub_goal("Design multi-tenant database schema".to_string(), 0);
185 goal.add_sub_goal("Implement OAuth authentication".to_string(), 1);
186 goal.add_sub_goal("Create dashboard with charts and metrics".to_string(), 2);
187 goal.add_sub_goal("Build team and user management interfaces".to_string(), 3);
188 goal.add_sub_goal("Create settings pages for users and organization".to_string(), 4);
189 goal.add_sub_goal("Implement billing API integration".to_string(), 5);
190 goal.add_sub_goal("Create analytics and reporting system".to_string(), 6);
191 goal.add_sub_goal("Add email notification templates".to_string(), 7);
192
193 goal.status = GoalStatus::InProgress;
194 agent.set_goal(goal.clone());
195
196 let task = TaskRequest::new(
197 "Generate a complete SaaS dashboard Next.js application with:\n\
198 1. Multi-tenant authentication (OAuth + JWT)\n\
199 2. Organization and team management\n\
200 3. Comprehensive dashboard with charts and analytics\n\
201 4. User permission and role management\n\
202 5. Billing integration with Stripe\n\
203 6. Settings pages for users and teams\n\
204 7. Email notifications system\n\
205 8. API logging and activity tracking\n\
206 9. Dark mode support\n\
207 10. Mobile responsive design\n\
208 Include TypeScript, Tailwind CSS, Recharts for visualizations, \
209 and PostgreSQL database models."
210 );
211
212 println!("📝 Task: Generate SaaS Dashboard Application\n");
213 println!("🎯 Dashboard Features:");
214 for criterion in &goal.success_criteria {
215 println!(" ✓ {}", criterion.description);
216 }
217
218 println!("\n⏳ Agent is generating SaaS dashboard...\n");
219 let response = agent.run(task).await;
220
221 let output = extract_output_text(&response.result());
222 println!("📄 Generated Output:\n");
223 println!("{}\n", output);
224
225 println!("📊 Goal Progress: {}%", goal.get_progress());
226 println!("\n✅ Example 3 completed!\n");
227}
228
229// ============================================
230// Example 4: Blog Platform with CMS
231// ============================================
232
233async fn example_4_blog_platform() {
234 println!("\n=== Example 4: Generate Blog Platform with CMS ===\n");
235
236 let mut agent = Agent::new("BlogCMSGenerator", "ollama::gemma3:latest");
237
238 let mut goal = Goal::new(
239 "Generate a comprehensive blog platform with CMS".to_string()
240 );
241
242 goal.add_criterion("Blog post management system".to_string());
243 goal.add_criterion("Rich text editor with markdown support".to_string());
244 goal.add_criterion("Category and tag system".to_string());
245 goal.add_criterion("Search and filtering functionality".to_string());
246 goal.add_criterion("Comments system with moderation".to_string());
247 goal.add_criterion("SEO optimization (meta tags, sitemap)".to_string());
248 goal.add_criterion("Author management and permissions".to_string());
249 goal.add_criterion("Analytics and engagement tracking".to_string());
250
251 goal.add_sub_goal("Design blog database schema".to_string(), 0);
252 goal.add_sub_goal("Create CMS backend API".to_string(), 1);
253 goal.add_sub_goal("Build post editor with markdown".to_string(), 2);
254 goal.add_sub_goal("Create blog listing and search pages".to_string(), 3);
255 goal.add_sub_goal("Build individual post pages with SEO".to_string(), 4);
256 goal.add_sub_goal("Implement comments system".to_string(), 5);
257 goal.add_sub_goal("Create author profiles and bio".to_string(), 6);
258 goal.add_sub_goal("Build admin dashboard for content management".to_string(), 7);
259 goal.add_sub_goal("Add analytics tracking and reporting".to_string(), 8);
260
261 goal.status = GoalStatus::InProgress;
262 agent.set_goal(goal.clone());
263
264 let task = TaskRequest::new(
265 "Generate a full-featured blog platform with CMS:\n\
266 1. Post creation and editing with rich text editor\n\
267 2. Markdown support with preview\n\
268 3. Category and tag system\n\
269 4. Advanced search with filters\n\
270 5. Comments system with nested replies\n\
271 6. Author profiles with biography\n\
272 7. SEO optimization (sitemaps, meta tags, structured data)\n\
273 8. Social sharing integration\n\
274 9. Email newsletter subscription\n\
275 10. Analytics dashboard for authors\n\
276 11. Reading time estimates\n\
277 12. Related posts suggestions\n\
278 Include TypeScript, Tailwind CSS, next-mdx-remote for markdown, \
279 and MongoDB/PostgreSQL models."
280 );
281
282 println!("📝 Task: Generate Blog Platform with CMS\n");
283 println!("🎯 Blog Features:");
284 for criterion in &goal.success_criteria {
285 println!(" ✓ {}", criterion.description);
286 }
287
288 println!("\n⏳ Agent is generating blog platform...\n");
289 let response = agent.run(task).await;
290
291 let output = extract_output_text(&response.result());
292 println!("📄 Generated Output:\n");
293 println!("{}\n", output);
294
295 println!("📊 Goal Progress: {}%", goal.get_progress());
296 println!("\n✅ Example 4 completed!\n");
297}109async fn example_1_basic_cli_app() {
110 println!("=== Example 1: Generate a Basic Python CLI Application ===\n");
111
112 let mut agent = Agent::new("PythonCliGenerator", "ollama::gemma3:latest");
113
114 // Create a goal for generating a Python CLI app
115 let mut goal = Goal::new(
116 "Generate a Python command-line application with core structure".to_string()
117 );
118
119 // Define success criteria
120 goal.add_criterion("requirements.txt with dependencies listed".to_string());
121 goal.add_criterion("setup.py or pyproject.toml for packaging".to_string());
122 goal.add_criterion("Main CLI entry point with argument parsing".to_string());
123 goal.add_criterion("Command structure with subcommands".to_string());
124 goal.add_criterion("Basic error handling and logging".to_string());
125 goal.add_criterion("README.md with usage instructions".to_string());
126 goal.add_criterion(".gitignore for Python projects".to_string());
127
128 // Define sub-goals (steps to generate the app)
129 goal.add_sub_goal("Analyze Python CLI best practices".to_string(), 0);
130 goal.add_sub_goal("Generate project structure and directories".to_string(), 1);
131 goal.add_sub_goal("Create requirements.txt with dependencies (Click, Typer, etc)".to_string(), 2);
132 goal.add_sub_goal("Generate pyproject.toml or setup.py".to_string(), 3);
133 goal.add_sub_goal("Create main CLI module with argument parser".to_string(), 4);
134 goal.add_sub_goal("Generate subcommands and command handlers".to_string(), 5);
135 goal.add_sub_goal("Create utility modules and helpers".to_string(), 6);
136 goal.add_sub_goal("Add logging and error handling".to_string(), 7);
137 goal.add_sub_goal("Generate README with installation and usage".to_string(), 8);
138
139 goal.status = GoalStatus::InProgress;
140 agent.set_goal(goal.clone());
141
142 // Create a task to generate a Python CLI app
143 let task = TaskRequest::new(
144 "Generate a professional Python command-line application with the following structure:\n\
145 1. Modern argument parsing using Click or Typer\n\
146 2. Multiple subcommands (e.g., init, run, config, help)\n\
147 3. Configuration file support (YAML or JSON)\n\
148 4. Logging with different verbosity levels\n\
149 5. Error handling and graceful failure messages\n\
150 6. Proper project structure with src/ and tests/ directories\n\
151 7. pyproject.toml or setup.py for packaging\n\
152 8. requirements.txt with dev dependencies\n\
153 9. .gitignore for Python\n\
154 10. Comprehensive README with examples\n\
155 The app should be production-ready and follow Python best practices (PEP 8)."
156 );
157
158 println!("📝 Task: Generate a Python CLI Application\n");
159 println!("🎯 Success Criteria:");
160 for criterion in &goal.success_criteria {
161 println!(" • {}", criterion.description);
162 }
163
164 println!("\n⏳ Agent is generating the Python CLI app...\n");
165 let response = agent.run(task).await;
166
167 // Extract and display the output
168 let output = extract_output_text(&response.result());
169 println!("📄 Generated Output:\n");
170 println!("{}\n", output);
171
172 // Show progress
173 println!("📊 Goal Progress: {}%", goal.get_progress());
174 println!("Status: {:?}", goal.status);
175
176 println!("\n✅ Example 1 completed!\n");
177}
178
179// ============================================
180// Example 2: Python Web API with FastAPI
181// ============================================
182
183async fn example_2_fastapi_web_app() {
184 println!("\n=== Example 2: Generate Python FastAPI Web Application ===\n");
185
186 let mut agent = Agent::new("FastApiGenerator", "ollama::gemma3:latest");
187
188 let mut goal = Goal::new(
189 "Generate a complete FastAPI web application with database integration".to_string()
190 );
191
192 // Success criteria for FastAPI app
193 goal.add_criterion("FastAPI application structure with routers".to_string());
194 goal.add_criterion("Database models using SQLAlchemy".to_string());
195 goal.add_criterion("RESTful API endpoints with CRUD operations".to_string());
196 goal.add_criterion("Request/response schemas using Pydantic".to_string());
197 goal.add_criterion("Authentication and authorization middleware".to_string());
198 goal.add_criterion("Database migrations with Alembic".to_string());
199 goal.add_criterion("Configuration management with environment variables".to_string());
200 goal.add_criterion("Unit and integration test examples".to_string());
201 goal.add_criterion("Docker setup for containerization".to_string());
202
203 // Sub-goals
204 goal.add_sub_goal("Design REST API endpoints structure".to_string(), 0);
205 goal.add_sub_goal("Create Pydantic models for request/response validation".to_string(), 1);
206 goal.add_sub_goal("Set up SQLAlchemy ORM with database models".to_string(), 2);
207 goal.add_sub_goal("Implement CRUD routers for resources".to_string(), 3);
208 goal.add_sub_goal("Add authentication and JWT tokens".to_string(), 4);
209 goal.add_sub_goal("Create Alembic migrations setup".to_string(), 5);
210 goal.add_sub_goal("Set up configuration with environment variables".to_string(), 6);
211 goal.add_sub_goal("Create test fixtures and example tests".to_string(), 7);
212 goal.add_sub_goal("Generate Docker and docker-compose files".to_string(), 8);
213 goal.add_sub_goal("Create comprehensive API documentation".to_string(), 9);
214
215 goal.status = GoalStatus::InProgress;
216 agent.set_goal(goal.clone());
217
218 let task = TaskRequest::new(
219 "Generate a production-ready FastAPI web application with:\n\
220 1. Modular project structure with routers for different resources\n\
221 2. Pydantic models for request/response validation\n\
222 3. SQLAlchemy ORM setup with database models\n\
223 4. CRUD operations for users, products, and orders\n\
224 5. JWT authentication and authorization middleware\n\
225 6. Role-based access control (RBAC)\n\
226 7. Alembic database migrations\n\
227 8. Environment configuration (.env support)\n\
228 9. Error handling with proper HTTP status codes\n\
229 10. Logging configuration\n\
230 11. Unit tests with pytest\n\
231 12. Integration tests with test database\n\
232 13. Docker and docker-compose for local development\n\
233 14. requirements.txt with all dependencies\n\
234 15. Comprehensive API documentation\n\
235 Use async/await patterns, follow REST conventions, and include examples."
236 );
237
238 println!("📝 Task: Generate FastAPI Web Application\n");
239 println!("🎯 FastAPI Features:");
240 for criterion in &goal.success_criteria {
241 println!(" ✓ {}", criterion.description);
242 }
243
244 println!("\n⏳ Agent is generating FastAPI app...\n");
245 let response = agent.run(task).await;
246
247 let output = extract_output_text(&response.result());
248 println!("📄 Generated Output:\n");
249 println!("{}\n", output);
250
251 println!("📊 Goal Progress: {}%", goal.get_progress());
252 println!("\n✅ Example 2 completed!\n");
253}
254
255// ============================================
256// Example 3: Python Data Science Project
257// ============================================
258
259async fn example_3_data_science_project() {
260 println!("\n=== Example 3: Generate Python Data Science Project ===\n");
261
262 let mut agent = Agent::new("DataScienceGenerator", "ollama::gemma3:latest");
263
264 let mut goal = Goal::new(
265 "Generate a data science project with ML pipeline and analysis".to_string()
266 );
267
268 goal.add_criterion("Project structure following cookiecutter-data-science".to_string());
269 goal.add_criterion("Data loading and preprocessing modules".to_string());
270 goal.add_criterion("Exploratory data analysis (EDA) notebooks".to_string());
271 goal.add_criterion("Feature engineering pipeline".to_string());
272 goal.add_criterion("Model training and evaluation".to_string());
273 goal.add_criterion("Hyperparameter tuning setup".to_string());
274 goal.add_criterion("Model persistence and versioning".to_string());
275 goal.add_criterion("Visualization utilities".to_string());
276 goal.add_criterion("Unit tests for data pipeline".to_string());
277
278 goal.add_sub_goal("Create cookiecutter-style directory structure".to_string(), 0);
279 goal.add_sub_goal("Set up Jupyter notebook for EDA".to_string(), 1);
280 goal.add_sub_goal("Create data loading and preprocessing modules".to_string(), 2);
281 goal.add_sub_goal("Implement feature engineering pipeline".to_string(), 3);
282 goal.add_sub_goal("Set up scikit-learn model training".to_string(), 4);
283 goal.add_sub_goal("Create model evaluation and metrics".to_string(), 5);
284 goal.add_sub_goal("Implement hyperparameter tuning with GridSearchCV".to_string(), 6);
285 goal.add_sub_goal("Add model persistence with joblib/pickle".to_string(), 7);
286 goal.add_sub_goal("Create visualization utilities with matplotlib/seaborn".to_string(), 8);
287 goal.add_sub_goal("Write tests for data pipeline".to_string(), 9);
288
289 goal.status = GoalStatus::InProgress;
290 agent.set_goal(goal.clone());
291
292 let task = TaskRequest::new(
293 "Generate a comprehensive Python data science project with:\n\
294 1. Proper project structure for data science work\n\
295 2. Data loading module supporting CSV, JSON, Parquet\n\
296 3. Data preprocessing and validation pipeline\n\
297 4. Exploratory Data Analysis (EDA) notebook template\n\
298 5. Feature engineering module\n\
299 6. Model training with scikit-learn or XGBoost\n\
300 7. Cross-validation and evaluation metrics\n\
301 8. Hyperparameter tuning with GridSearchCV/RandomSearch\n\
302 9. Model persistence and loading utilities\n\
303 10. Visualization utilities (matplotlib, seaborn, plotly)\n\
304 11. Unit tests for data loading and preprocessing\n\
305 12. Configuration management for experiments\n\
306 13. Logging for training pipeline\n\
307 14. Requirements.txt with ML libraries (pandas, numpy, scikit-learn)\n\
308 15. Makefile for common tasks\n\
309 16. README with dataset description and results\n\
310 Include example workflows and best practices for reproducibility."
311 );
312
313 println!("📝 Task: Generate Data Science Project\n");
314 println!("🎯 Data Science Features:");
315 for criterion in &goal.success_criteria {
316 println!(" ✓ {}", criterion.description);
317 }
318
319 println!("\n⏳ Agent is generating data science project...\n");
320 let response = agent.run(task).await;
321
322 let output = extract_output_text(&response.result());
323 println!("📄 Generated Output:\n");
324 println!("{}\n", output);
325
326 println!("📊 Goal Progress: {}%", goal.get_progress());
327 println!("\n✅ Example 3 completed!\n");
328}
329
330// ============================================
331// Example 4: Python Package/Library
332// ============================================
333
334async fn example_4_python_library() {
335 println!("\n=== Example 4: Generate Python Library/Package ===\n");
336
337 let mut agent = Agent::new("PythonLibraryGenerator", "ollama::gemma3:latest");
338
339 let mut goal = Goal::new(
340 "Generate a well-structured Python package ready for distribution".to_string()
341 );
342
343 goal.add_criterion("Proper package structure with namespace".to_string());
344 goal.add_criterion("setup.py and pyproject.toml for distribution".to_string());
345 goal.add_criterion("Comprehensive docstrings and type hints".to_string());
346 goal.add_criterion("Unit tests with pytest".to_string());
347 goal.add_criterion("Documentation with Sphinx".to_string());
348 goal.add_criterion("CI/CD configuration (GitHub Actions)".to_string());
349 goal.add_criterion("Version management strategy".to_string());
350 goal.add_criterion("Contributing guidelines".to_string());
351
352 goal.add_sub_goal("Create package structure with __init__.py files".to_string(), 0);
353 goal.add_sub_goal("Write setup.py and pyproject.toml".to_string(), 1);
354 goal.add_sub_goal("Create core modules with type hints".to_string(), 2);
355 goal.add_sub_goal("Add comprehensive docstrings".to_string(), 3);
356 goal.add_sub_goal("Create test structure with pytest".to_string(), 4);
357 goal.add_sub_goal("Set up documentation with Sphinx".to_string(), 5);
358 goal.add_sub_goal("Create GitHub Actions workflows".to_string(), 6);
359 goal.add_sub_goal("Add CONTRIBUTING.md and CODE_OF_CONDUCT.md".to_string(), 7);
360 goal.add_sub_goal("Create MANIFEST.in and manifest files".to_string(), 8);
361
362 goal.status = GoalStatus::InProgress;
363 agent.set_goal(goal.clone());
364
365 let task = TaskRequest::new(
366 "Generate a professional Python library/package with:\n\
367 1. Standard package structure (src layout)\n\
368 2. __init__.py with version and exports\n\
369 3. Core modules with complete implementations\n\
370 4. Type hints throughout (PEP 484)\n\
371 5. Comprehensive docstrings (Google style)\n\
372 6. setup.py with metadata\n\
373 7. pyproject.toml with build system\n\
374 8. MANIFEST.in for package data\n\
375 9. Pytest test structure with fixtures\n\
376 10. pytest.ini configuration\n\
377 11. Sphinx documentation setup\n\
378 12. GitHub Actions workflow for CI/CD\n\
379 13. Pre-commit hooks configuration\n\
380 14. LICENSE (MIT or Apache 2.0)\n\
381 15. .gitignore for Python\n\
382 16. README.md with installation and usage\n\
383 17. CONTRIBUTING.md for contributors\n\
384 18. CODE_OF_CONDUCT.md\n\
385 19. Changelog/HISTORY.md template\n\
386 20. Version management with __version__\n\
387 Include examples for public API and best practices for library development."
388 );
389
390 println!("📝 Task: Generate Python Library Package\n");
391 println!("🎯 Library Features:");
392 for criterion in &goal.success_criteria {
393 println!(" ✓ {}", criterion.description);
394 }
395
396 println!("\n⏳ Agent is generating Python library...\n");
397 let response = agent.run(task).await;
398
399 let output = extract_output_text(&response.result());
400 println!("📄 Generated Output:\n");
401 println!("{}\n", output);
402
403 println!("📊 Goal Progress: {}%", goal.get_progress());
404 println!("\n✅ Example 4 completed!\n");
405}
406
407// ============================================
408// Example 5: Django Web Application
409// ============================================
410
411async fn example_5_django_web_app() {
412 println!("\n=== Example 5: Generate Django Web Application ===\n");
413
414 let mut agent = Agent::new("DjangoGenerator", "ollama::gemma3:latest");
415
416 let mut goal = Goal::new(
417 "Generate a complete Django web application with admin and authentication".to_string()
418 );
419
420 goal.add_criterion("Django project structure with multiple apps".to_string());
421 goal.add_criterion("Custom user model implementation".to_string());
422 goal.add_criterion("Database models for core features".to_string());
423 goal.add_criterion("Admin interface customization".to_string());
424 goal.add_criterion("Views and URL routing".to_string());
425 goal.add_criterion("Templates with Bootstrap styling".to_string());
426 goal.add_criterion("Authentication and permissions".to_string());
427 goal.add_criterion("Database migrations".to_string());
428 goal.add_criterion("Django REST Framework API".to_string());
429
430 goal.add_sub_goal("Create Django project and app structure".to_string(), 0);
431 goal.add_sub_goal("Design and implement custom user model".to_string(), 1);
432 goal.add_sub_goal("Create models for core features".to_string(), 2);
433 goal.add_sub_goal("Configure admin interface".to_string(), 3);
434 goal.add_sub_goal("Create views and templates".to_string(), 4);
435 goal.add_sub_goal("Set up URL routing".to_string(), 5);
436 goal.add_sub_goal("Implement authentication views".to_string(), 6);
437 goal.add_sub_goal("Create Django REST Framework serializers".to_string(), 7);
438 goal.add_sub_goal("Set up static files and media handling".to_string(), 8);
439
440 goal.status = GoalStatus::InProgress;
441 agent.set_goal(goal.clone());
442
443 let task = TaskRequest::new(
444 "Generate a full-featured Django web application with:\n\
445 1. Django project structure with multiple apps\n\
446 2. Custom user model extending AbstractBaseUser\n\
447 3. Models for main features (e.g., Blog posts, Comments, Categories)\n\
448 4. Django ORM relationships (ForeignKey, ManyToMany)\n\
449 5. Admin interface with custom actions\n\
450 6. Class-based views (ListView, DetailView, CreateView)\n\
451 7. Django templates with template inheritance\n\
452 8. Bootstrap styling integration\n\
453 9. Authentication and login required decorators\n\
454 10. Permission-based access control\n\
455 11. Database migrations\n\
456 12. Forms with validation\n\
457 13. Django REST Framework setup\n\
458 14. API serializers and viewsets\n\
459 15. Pagination and filtering\n\
460 16. Settings for dev and production\n\
461 17. Environment variable configuration\n\
462 18. Logging configuration\n\
463 19. Tests with Django TestCase\n\
464 20. Static files and media management\n\
465 21. Docker setup\n\
466 22. Requirements.txt\n\
467 Include examples and docstrings following Django conventions."
468 );
469
470 println!("📝 Task: Generate Django Web Application\n");
471 println!("🎯 Django Features:");
472 for criterion in &goal.success_criteria {
473 println!(" ✓ {}", criterion.description);
474 }
475
476 println!("\n⏳ Agent is generating Django app...\n");
477 let response = agent.run(task).await;
478
479 let output = extract_output_text(&response.result());
480 println!("📄 Generated Output:\n");
481 println!("{}\n", output);
482
483 println!("📊 Goal Progress: {}%", goal.get_progress());
484 println!("\n✅ Example 5 completed!\n");
485}Sourcepub fn add_sub_goal(&mut self, description: String, priority: u32)
pub fn add_sub_goal(&mut self, description: String, priority: u32)
Adds a sub-goal to the goal.
§Arguments
description- What this sub-goal accomplishespriority- Execution order (lower numbers are executed first)
Examples found in repository?
22async fn example_1_manual_goal() {
23 println!("=== Example 1: Manual Goal Creation ===\n");
24
25 // Create an agent
26 let mut agent = Agent::new("MealPlanner", "ollama::gemma3:latest");
27
28 // Create a goal manually for a complex task
29 let mut goal = Goal::new(
30 "Plan a healthy meal prep for the week".to_string()
31 );
32
33 // Define what success looks like
34 println!("📋 Setting success criteria...");
35 goal.add_criterion("7 breakfast recipes selected".to_string());
36 goal.add_criterion("7 lunch recipes selected".to_string());
37 goal.add_criterion("7 dinner recipes selected".to_string());
38 goal.add_criterion("Shopping list created".to_string());
39 goal.add_criterion("Prep schedule created".to_string());
40
41 // Break down into steps (sub-goals)
42 println!("🎯 Breaking down into sub-goals...\n");
43 goal.add_sub_goal("Ask user about dietary preferences".to_string(), 0);
44 goal.add_sub_goal("Ask about time available for prep".to_string(), 1);
45 goal.add_sub_goal("Suggest breakfast options".to_string(), 2);
46 goal.add_sub_goal("Suggest lunch options".to_string(), 3);
47 goal.add_sub_goal("Suggest dinner options".to_string(), 4);
48 goal.add_sub_goal("Create shopping list".to_string(), 5);
49 goal.add_sub_goal("Create prep schedule".to_string(), 6);
50
51 // Start working on the goal
52 goal.status = GoalStatus::InProgress;
53
54 // Set the goal on the agent
55 agent.set_goal(goal.clone());
56
57 // Create a task aligned with the goal
58 let task = TaskRequest::new("I need help with meal planning");
59
60 // Run the agent
61 println!("⏳ Agent is working on the meal planning task...\n");
62 let _response = agent.run(task).await;
63
64 // Show the goal summary
65 println!("\n📊 Goal Summary:");
66 println!("{}", goal.get_summary());
67
68 println!("\n✅ Example 1 completed!\n");
69}
70
71// ============================================
72// Example 2: Goal Progress Tracking
73// ============================================
74
75async fn example_2_goal_progress_tracking() {
76 println!("\n=== Example 2: Goal Progress Tracking ===\n");
77
78 // Create a goal for a project
79 let mut goal = Goal::new(
80 "Create a project plan for building a mobile app".to_string()
81 );
82
83 // Add success criteria
84 goal.add_criterion("Project requirements documented".to_string());
85 goal.add_criterion("Timeline created with milestones".to_string());
86 goal.add_criterion("Resource allocation plan completed".to_string());
87 goal.add_criterion("Risk assessment performed".to_string());
88
89 // Add sub-goals
90 goal.add_sub_goal("Gather stakeholder requirements".to_string(), 0);
91 goal.add_sub_goal("Define project scope".to_string(), 1);
92 goal.add_sub_goal("Create development timeline".to_string(), 2);
93 goal.add_sub_goal("Allocate resources".to_string(), 3);
94 goal.add_sub_goal("Identify risks and mitigation strategies".to_string(), 4);
95
96 goal.status = GoalStatus::InProgress;
97
98 // Simulate progress through the goal
99 println!("📈 Tracking goal progress...\n");
100
101 // Complete first sub-goal
102 println!("Step 1: Gathering requirements");
103 goal.complete_sub_goal(0, Some("Interviewed 5 stakeholders".to_string()));
104 goal.mark_criterion_met(0, "Requirements documented".to_string());
105 println!(" Progress: {}%\n", goal.get_progress());
106
107 // Complete second sub-goal
108 println!("Step 2: Defining scope");
109 goal.complete_sub_goal(1, Some("Scope document created".to_string()));
110 println!(" Progress: {}%\n", goal.get_progress());
111
112 // Complete third sub-goal
113 println!("Step 3: Creating timeline");
114 goal.complete_sub_goal(2, Some("12-month timeline with milestones".to_string()));
115 goal.mark_criterion_met(1, "Timeline created".to_string());
116 println!(" Progress: {}%\n", goal.get_progress());
117
118 // Complete fourth sub-goal
119 println!("Step 4: Allocating resources");
120 goal.complete_sub_goal(3, Some("Resource allocation table created".to_string()));
121 goal.mark_criterion_met(2, "Resources allocated".to_string());
122 println!(" Progress: {}%\n", goal.get_progress());
123
124 // Complete fifth sub-goal
125 println!("Step 5: Assessing risks");
126 goal.complete_sub_goal(4, Some("Risk register created with 8 identified risks".to_string()));
127 goal.mark_criterion_met(3, "Risks identified".to_string());
128 println!(" Progress: {}%\n", goal.get_progress());
129
130 // Show final status
131 println!("\n📊 Final Goal Status:");
132 println!("{}", goal.get_summary());
133
134 println!("\n✅ Example 2 completed!\n");
135}
136
137// ============================================
138// Example 3: Job Interview Preparation Goal
139// ============================================
140
141async fn example_3_interview_preparation() {
142 println!("\n=== Example 3: Job Interview Preparation Goal ===\n");
143
144 let mut agent = Agent::new("InterviewCoach", "ollama::gemma3:latest");
145
146 // Create a structured goal for interview prep
147 let mut goal = Goal::new(
148 "Prepare for a senior software engineer interview at a tech company".to_string()
149 );
150
151 // Define success criteria
152 println!("🎯 Success criteria:");
153 goal.add_criterion("Technical topics reviewed (algorithms, data structures, system design)".to_string());
154 goal.add_criterion("Behavioral questions prepared with STAR method examples".to_string());
155 goal.add_criterion("Company research completed".to_string());
156 goal.add_criterion("Practice mock interview conducted".to_string());
157 goal.add_criterion("Questions to ask the interviewer prepared".to_string());
158
159 for criterion in &goal.success_criteria {
160 println!(" • {}", criterion.description);
161 }
162
163 // Define steps
164 println!("\n📋 Steps to take:");
165 goal.add_sub_goal("Review core algorithms and data structures".to_string(), 0);
166 goal.add_sub_goal("Study system design patterns".to_string(), 1);
167 goal.add_sub_goal("Prepare STAR method stories from past projects".to_string(), 2);
168 goal.add_sub_goal("Research company background and culture".to_string(), 3);
169 goal.add_sub_goal("Practice mock interview with a friend".to_string(), 4);
170 goal.add_sub_goal("Prepare thoughtful questions about the role".to_string(), 5);
171
172 for sub_goal in &goal.sub_goals {
173 println!(" {}. {}", sub_goal.priority + 1, sub_goal.description);
174 }
175
176 goal.status = GoalStatus::InProgress;
177
178 // Set goal on agent
179 agent.set_goal(goal.clone());
180
181 // Create related task
182 let task = TaskRequest::new("Help me prepare for my senior engineer interview");
183
184 println!("\n⏳ Agent is creating interview preparation plan...\n");
185 let _response = agent.run(task).await;
186
187 println!("\n📊 Goal Summary:");
188 println!("{}", goal.get_summary());
189
190 println!("\n✅ Example 3 completed!\n");
191}
192
193// ============================================
194// Example 4: Goal Analysis from Task Description
195// ============================================
196
197fn example_4_goal_analysis() {
198 println!("\n=== Example 4: Goal Analysis from Task Description ===\n");
199
200 // Simulate LLM analyzing a task and breaking it down into a goal
201 let task_description = "Help me learn Python programming";
202
203 println!("📝 Original task: \"{}\"", task_description);
204 println!("\n🔍 LLM analyzing task...\n");
205
206 // This is what the LLM would return
207 let analysis = GoalAnalysis {
208 main_goal: "Help user learn Python programming from basics to practical skills".to_string(),
209 success_criteria: vec![
210 "User's current skill level identified".to_string(),
211 "Learning path created based on skill level".to_string(),
212 "Resources (tutorials, books) provided".to_string(),
213 "Practice exercises suggested".to_string(),
214 "Study schedule created".to_string(),
215 ],
216 sub_goals: vec![
217 "Ask about current programming experience".to_string(),
218 "Identify learning goals (web dev, data science, etc)".to_string(),
219 "Create structured learning path".to_string(),
220 "Recommend learning resources".to_string(),
221 "Suggest practice projects".to_string(),
222 "Create study timeline".to_string(),
223 ],
224 };
225
226 // Convert analysis to a Goal
227 let goal = analysis.to_goal();
228
229 println!("✅ Goal created from analysis:\n");
230 println!("{}", goal.get_summary());
231
232 println!("\n✅ Example 4 completed!\n");
233}
234
235// ============================================
236// Example 5: Goal Completion Verification
237// ============================================
238
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}More examples
38async fn example_1_basic_nextjs_app() {
39 println!("=== Example 1: Generate a Basic Next.js App ===\n");
40
41 // Create an agent that will generate the app
42 let mut agent = Agent::new("NextJsGenerator", "ollama::gemma3:latest");
43
44 // Create a goal for generating a Next.js app
45 let mut goal = Goal::new(
46 "Generate a Next.js web application with essential structure".to_string()
47 );
48
49 // Define success criteria
50 goal.add_criterion("package.json created with dependencies".to_string());
51 goal.add_criterion("next.config.js configuration file generated".to_string());
52 goal.add_criterion("pages directory with index and api route created".to_string());
53 goal.add_criterion("styles directory with global CSS".to_string());
54 goal.add_criterion("README.md with setup instructions".to_string());
55
56 // Define sub-goals (steps to generate the app)
57 goal.add_sub_goal("Analyze Next.js requirements and best practices".to_string(), 0);
58 goal.add_sub_goal("Generate package.json with required dependencies".to_string(), 1);
59 goal.add_sub_goal("Create next.config.js configuration".to_string(), 2);
60 goal.add_sub_goal("Generate pages (index.tsx, _app.tsx, _document.tsx)".to_string(), 3);
61 goal.add_sub_goal("Create API route examples".to_string(), 4);
62 goal.add_sub_goal("Generate styling setup (global.css, utilities)".to_string(), 5);
63 goal.add_sub_goal("Create components directory with example components".to_string(), 6);
64 goal.add_sub_goal("Generate README with setup and usage instructions".to_string(), 7);
65
66 goal.status = GoalStatus::InProgress;
67 agent.set_goal(goal.clone());
68
69 // Create a task to generate a Next.js app
70 let task = TaskRequest::new(
71 "Generate a modern Next.js 14 application with TypeScript, Tailwind CSS, and best practices. \
72 Include package.json, next.config.js, sample pages, API routes, and components. \
73 The app should be production-ready and follow Next.js conventions."
74 );
75
76 println!("📝 Task: Generate a Next.js application\n");
77 println!("🎯 Success Criteria:");
78 for criterion in &goal.success_criteria {
79 println!(" • {}", criterion.description);
80 }
81
82 println!("\n⏳ Agent is generating the Next.js app...\n");
83 let response = agent.run(task).await;
84
85 // Extract and display the output
86 let output = extract_output_text(&response.result());
87 println!("📄 Generated Output:\n");
88 println!("{}\n", output);
89
90 // Show progress
91 println!("📊 Goal Progress: {}%", goal.get_progress());
92 println!("Status: {:?}", goal.status);
93
94 println!("\n✅ Example 1 completed!\n");
95}
96
97// ============================================
98// Example 2: E-Commerce Next.js App
99// ============================================
100
101async fn example_2_ecommerce_app() {
102 println!("\n=== Example 2: Generate E-Commerce Next.js App ===\n");
103
104 let mut agent = Agent::new("EcommerceGenerator", "ollama::gemma3:latest");
105
106 let mut goal = Goal::new(
107 "Generate a complete e-commerce Next.js application".to_string()
108 );
109
110 // Success criteria for e-commerce
111 goal.add_criterion("Product listing page with filtering and sorting".to_string());
112 goal.add_criterion("Product detail pages with dynamic routes".to_string());
113 goal.add_criterion("Shopping cart functionality".to_string());
114 goal.add_criterion("User authentication setup".to_string());
115 goal.add_criterion("Payment integration structure".to_string());
116 goal.add_criterion("Database models and API endpoints".to_string());
117 goal.add_criterion("Admin dashboard layout".to_string());
118
119 // Sub-goals
120 goal.add_sub_goal("Design database schema for products and orders".to_string(), 0);
121 goal.add_sub_goal("Create product API endpoints".to_string(), 1);
122 goal.add_sub_goal("Build product listing and search components".to_string(), 2);
123 goal.add_sub_goal("Implement product detail pages".to_string(), 3);
124 goal.add_sub_goal("Create shopping cart context and management".to_string(), 4);
125 goal.add_sub_goal("Build checkout flow pages".to_string(), 5);
126 goal.add_sub_goal("Integrate payment gateway API".to_string(), 6);
127 goal.add_sub_goal("Create admin dashboard pages".to_string(), 7);
128 goal.add_sub_goal("Add authentication middleware".to_string(), 8);
129
130 goal.status = GoalStatus::InProgress;
131 agent.set_goal(goal.clone());
132
133 let task = TaskRequest::new(
134 "Generate a complete e-commerce Next.js application with: \
135 1. Product management system (listing, search, filters)\n\
136 2. Shopping cart with add/remove/update functionality\n\
137 3. User authentication and profile pages\n\
138 4. Payment integration endpoints\n\
139 5. Order history and tracking\n\
140 6. Admin dashboard for managing products and orders\n\
141 7. Database models for PostgreSQL or MongoDB\n\
142 8. RESTful API endpoints\n\
143 Use TypeScript, Tailwind CSS, and modern React patterns."
144 );
145
146 println!("📝 Task: Generate E-Commerce Next.js Application\n");
147 println!("🎯 Features to Generate:");
148 for criterion in &goal.success_criteria {
149 println!(" ✓ {}", criterion.description);
150 }
151
152 println!("\n⏳ Agent is generating e-commerce app...\n");
153 let response = agent.run(task).await;
154
155 let output = extract_output_text(&response.result());
156 println!("📄 Generated Output:\n");
157 println!("{}\n", output);
158
159 println!("📊 Goal Progress: {}%", goal.get_progress());
160 println!("\n✅ Example 2 completed!\n");
161}
162
163// ============================================
164// Example 3: SaaS Dashboard App
165// ============================================
166
167async fn example_3_saas_dashboard() {
168 println!("\n=== Example 3: Generate SaaS Dashboard Next.js App ===\n");
169
170 let mut agent = Agent::new("SaasDashboardGenerator", "ollama::gemma3:latest");
171
172 let mut goal = Goal::new(
173 "Generate a SaaS dashboard application with user management".to_string()
174 );
175
176 goal.add_criterion("User authentication and authorization".to_string());
177 goal.add_criterion("Multi-tenant database structure".to_string());
178 goal.add_criterion("Dashboard with analytics and metrics".to_string());
179 goal.add_criterion("User and team management pages".to_string());
180 goal.add_criterion("Settings and preferences pages".to_string());
181 goal.add_criterion("Billing and subscription management".to_string());
182 goal.add_criterion("API for data collection and reporting".to_string());
183
184 goal.add_sub_goal("Design multi-tenant database schema".to_string(), 0);
185 goal.add_sub_goal("Implement OAuth authentication".to_string(), 1);
186 goal.add_sub_goal("Create dashboard with charts and metrics".to_string(), 2);
187 goal.add_sub_goal("Build team and user management interfaces".to_string(), 3);
188 goal.add_sub_goal("Create settings pages for users and organization".to_string(), 4);
189 goal.add_sub_goal("Implement billing API integration".to_string(), 5);
190 goal.add_sub_goal("Create analytics and reporting system".to_string(), 6);
191 goal.add_sub_goal("Add email notification templates".to_string(), 7);
192
193 goal.status = GoalStatus::InProgress;
194 agent.set_goal(goal.clone());
195
196 let task = TaskRequest::new(
197 "Generate a complete SaaS dashboard Next.js application with:\n\
198 1. Multi-tenant authentication (OAuth + JWT)\n\
199 2. Organization and team management\n\
200 3. Comprehensive dashboard with charts and analytics\n\
201 4. User permission and role management\n\
202 5. Billing integration with Stripe\n\
203 6. Settings pages for users and teams\n\
204 7. Email notifications system\n\
205 8. API logging and activity tracking\n\
206 9. Dark mode support\n\
207 10. Mobile responsive design\n\
208 Include TypeScript, Tailwind CSS, Recharts for visualizations, \
209 and PostgreSQL database models."
210 );
211
212 println!("📝 Task: Generate SaaS Dashboard Application\n");
213 println!("🎯 Dashboard Features:");
214 for criterion in &goal.success_criteria {
215 println!(" ✓ {}", criterion.description);
216 }
217
218 println!("\n⏳ Agent is generating SaaS dashboard...\n");
219 let response = agent.run(task).await;
220
221 let output = extract_output_text(&response.result());
222 println!("📄 Generated Output:\n");
223 println!("{}\n", output);
224
225 println!("📊 Goal Progress: {}%", goal.get_progress());
226 println!("\n✅ Example 3 completed!\n");
227}
228
229// ============================================
230// Example 4: Blog Platform with CMS
231// ============================================
232
233async fn example_4_blog_platform() {
234 println!("\n=== Example 4: Generate Blog Platform with CMS ===\n");
235
236 let mut agent = Agent::new("BlogCMSGenerator", "ollama::gemma3:latest");
237
238 let mut goal = Goal::new(
239 "Generate a comprehensive blog platform with CMS".to_string()
240 );
241
242 goal.add_criterion("Blog post management system".to_string());
243 goal.add_criterion("Rich text editor with markdown support".to_string());
244 goal.add_criterion("Category and tag system".to_string());
245 goal.add_criterion("Search and filtering functionality".to_string());
246 goal.add_criterion("Comments system with moderation".to_string());
247 goal.add_criterion("SEO optimization (meta tags, sitemap)".to_string());
248 goal.add_criterion("Author management and permissions".to_string());
249 goal.add_criterion("Analytics and engagement tracking".to_string());
250
251 goal.add_sub_goal("Design blog database schema".to_string(), 0);
252 goal.add_sub_goal("Create CMS backend API".to_string(), 1);
253 goal.add_sub_goal("Build post editor with markdown".to_string(), 2);
254 goal.add_sub_goal("Create blog listing and search pages".to_string(), 3);
255 goal.add_sub_goal("Build individual post pages with SEO".to_string(), 4);
256 goal.add_sub_goal("Implement comments system".to_string(), 5);
257 goal.add_sub_goal("Create author profiles and bio".to_string(), 6);
258 goal.add_sub_goal("Build admin dashboard for content management".to_string(), 7);
259 goal.add_sub_goal("Add analytics tracking and reporting".to_string(), 8);
260
261 goal.status = GoalStatus::InProgress;
262 agent.set_goal(goal.clone());
263
264 let task = TaskRequest::new(
265 "Generate a full-featured blog platform with CMS:\n\
266 1. Post creation and editing with rich text editor\n\
267 2. Markdown support with preview\n\
268 3. Category and tag system\n\
269 4. Advanced search with filters\n\
270 5. Comments system with nested replies\n\
271 6. Author profiles with biography\n\
272 7. SEO optimization (sitemaps, meta tags, structured data)\n\
273 8. Social sharing integration\n\
274 9. Email newsletter subscription\n\
275 10. Analytics dashboard for authors\n\
276 11. Reading time estimates\n\
277 12. Related posts suggestions\n\
278 Include TypeScript, Tailwind CSS, next-mdx-remote for markdown, \
279 and MongoDB/PostgreSQL models."
280 );
281
282 println!("📝 Task: Generate Blog Platform with CMS\n");
283 println!("🎯 Blog Features:");
284 for criterion in &goal.success_criteria {
285 println!(" ✓ {}", criterion.description);
286 }
287
288 println!("\n⏳ Agent is generating blog platform...\n");
289 let response = agent.run(task).await;
290
291 let output = extract_output_text(&response.result());
292 println!("📄 Generated Output:\n");
293 println!("{}\n", output);
294
295 println!("📊 Goal Progress: {}%", goal.get_progress());
296 println!("\n✅ Example 4 completed!\n");
297}109async fn example_1_basic_cli_app() {
110 println!("=== Example 1: Generate a Basic Python CLI Application ===\n");
111
112 let mut agent = Agent::new("PythonCliGenerator", "ollama::gemma3:latest");
113
114 // Create a goal for generating a Python CLI app
115 let mut goal = Goal::new(
116 "Generate a Python command-line application with core structure".to_string()
117 );
118
119 // Define success criteria
120 goal.add_criterion("requirements.txt with dependencies listed".to_string());
121 goal.add_criterion("setup.py or pyproject.toml for packaging".to_string());
122 goal.add_criterion("Main CLI entry point with argument parsing".to_string());
123 goal.add_criterion("Command structure with subcommands".to_string());
124 goal.add_criterion("Basic error handling and logging".to_string());
125 goal.add_criterion("README.md with usage instructions".to_string());
126 goal.add_criterion(".gitignore for Python projects".to_string());
127
128 // Define sub-goals (steps to generate the app)
129 goal.add_sub_goal("Analyze Python CLI best practices".to_string(), 0);
130 goal.add_sub_goal("Generate project structure and directories".to_string(), 1);
131 goal.add_sub_goal("Create requirements.txt with dependencies (Click, Typer, etc)".to_string(), 2);
132 goal.add_sub_goal("Generate pyproject.toml or setup.py".to_string(), 3);
133 goal.add_sub_goal("Create main CLI module with argument parser".to_string(), 4);
134 goal.add_sub_goal("Generate subcommands and command handlers".to_string(), 5);
135 goal.add_sub_goal("Create utility modules and helpers".to_string(), 6);
136 goal.add_sub_goal("Add logging and error handling".to_string(), 7);
137 goal.add_sub_goal("Generate README with installation and usage".to_string(), 8);
138
139 goal.status = GoalStatus::InProgress;
140 agent.set_goal(goal.clone());
141
142 // Create a task to generate a Python CLI app
143 let task = TaskRequest::new(
144 "Generate a professional Python command-line application with the following structure:\n\
145 1. Modern argument parsing using Click or Typer\n\
146 2. Multiple subcommands (e.g., init, run, config, help)\n\
147 3. Configuration file support (YAML or JSON)\n\
148 4. Logging with different verbosity levels\n\
149 5. Error handling and graceful failure messages\n\
150 6. Proper project structure with src/ and tests/ directories\n\
151 7. pyproject.toml or setup.py for packaging\n\
152 8. requirements.txt with dev dependencies\n\
153 9. .gitignore for Python\n\
154 10. Comprehensive README with examples\n\
155 The app should be production-ready and follow Python best practices (PEP 8)."
156 );
157
158 println!("📝 Task: Generate a Python CLI Application\n");
159 println!("🎯 Success Criteria:");
160 for criterion in &goal.success_criteria {
161 println!(" • {}", criterion.description);
162 }
163
164 println!("\n⏳ Agent is generating the Python CLI app...\n");
165 let response = agent.run(task).await;
166
167 // Extract and display the output
168 let output = extract_output_text(&response.result());
169 println!("📄 Generated Output:\n");
170 println!("{}\n", output);
171
172 // Show progress
173 println!("📊 Goal Progress: {}%", goal.get_progress());
174 println!("Status: {:?}", goal.status);
175
176 println!("\n✅ Example 1 completed!\n");
177}
178
179// ============================================
180// Example 2: Python Web API with FastAPI
181// ============================================
182
183async fn example_2_fastapi_web_app() {
184 println!("\n=== Example 2: Generate Python FastAPI Web Application ===\n");
185
186 let mut agent = Agent::new("FastApiGenerator", "ollama::gemma3:latest");
187
188 let mut goal = Goal::new(
189 "Generate a complete FastAPI web application with database integration".to_string()
190 );
191
192 // Success criteria for FastAPI app
193 goal.add_criterion("FastAPI application structure with routers".to_string());
194 goal.add_criterion("Database models using SQLAlchemy".to_string());
195 goal.add_criterion("RESTful API endpoints with CRUD operations".to_string());
196 goal.add_criterion("Request/response schemas using Pydantic".to_string());
197 goal.add_criterion("Authentication and authorization middleware".to_string());
198 goal.add_criterion("Database migrations with Alembic".to_string());
199 goal.add_criterion("Configuration management with environment variables".to_string());
200 goal.add_criterion("Unit and integration test examples".to_string());
201 goal.add_criterion("Docker setup for containerization".to_string());
202
203 // Sub-goals
204 goal.add_sub_goal("Design REST API endpoints structure".to_string(), 0);
205 goal.add_sub_goal("Create Pydantic models for request/response validation".to_string(), 1);
206 goal.add_sub_goal("Set up SQLAlchemy ORM with database models".to_string(), 2);
207 goal.add_sub_goal("Implement CRUD routers for resources".to_string(), 3);
208 goal.add_sub_goal("Add authentication and JWT tokens".to_string(), 4);
209 goal.add_sub_goal("Create Alembic migrations setup".to_string(), 5);
210 goal.add_sub_goal("Set up configuration with environment variables".to_string(), 6);
211 goal.add_sub_goal("Create test fixtures and example tests".to_string(), 7);
212 goal.add_sub_goal("Generate Docker and docker-compose files".to_string(), 8);
213 goal.add_sub_goal("Create comprehensive API documentation".to_string(), 9);
214
215 goal.status = GoalStatus::InProgress;
216 agent.set_goal(goal.clone());
217
218 let task = TaskRequest::new(
219 "Generate a production-ready FastAPI web application with:\n\
220 1. Modular project structure with routers for different resources\n\
221 2. Pydantic models for request/response validation\n\
222 3. SQLAlchemy ORM setup with database models\n\
223 4. CRUD operations for users, products, and orders\n\
224 5. JWT authentication and authorization middleware\n\
225 6. Role-based access control (RBAC)\n\
226 7. Alembic database migrations\n\
227 8. Environment configuration (.env support)\n\
228 9. Error handling with proper HTTP status codes\n\
229 10. Logging configuration\n\
230 11. Unit tests with pytest\n\
231 12. Integration tests with test database\n\
232 13. Docker and docker-compose for local development\n\
233 14. requirements.txt with all dependencies\n\
234 15. Comprehensive API documentation\n\
235 Use async/await patterns, follow REST conventions, and include examples."
236 );
237
238 println!("📝 Task: Generate FastAPI Web Application\n");
239 println!("🎯 FastAPI Features:");
240 for criterion in &goal.success_criteria {
241 println!(" ✓ {}", criterion.description);
242 }
243
244 println!("\n⏳ Agent is generating FastAPI app...\n");
245 let response = agent.run(task).await;
246
247 let output = extract_output_text(&response.result());
248 println!("📄 Generated Output:\n");
249 println!("{}\n", output);
250
251 println!("📊 Goal Progress: {}%", goal.get_progress());
252 println!("\n✅ Example 2 completed!\n");
253}
254
255// ============================================
256// Example 3: Python Data Science Project
257// ============================================
258
259async fn example_3_data_science_project() {
260 println!("\n=== Example 3: Generate Python Data Science Project ===\n");
261
262 let mut agent = Agent::new("DataScienceGenerator", "ollama::gemma3:latest");
263
264 let mut goal = Goal::new(
265 "Generate a data science project with ML pipeline and analysis".to_string()
266 );
267
268 goal.add_criterion("Project structure following cookiecutter-data-science".to_string());
269 goal.add_criterion("Data loading and preprocessing modules".to_string());
270 goal.add_criterion("Exploratory data analysis (EDA) notebooks".to_string());
271 goal.add_criterion("Feature engineering pipeline".to_string());
272 goal.add_criterion("Model training and evaluation".to_string());
273 goal.add_criterion("Hyperparameter tuning setup".to_string());
274 goal.add_criterion("Model persistence and versioning".to_string());
275 goal.add_criterion("Visualization utilities".to_string());
276 goal.add_criterion("Unit tests for data pipeline".to_string());
277
278 goal.add_sub_goal("Create cookiecutter-style directory structure".to_string(), 0);
279 goal.add_sub_goal("Set up Jupyter notebook for EDA".to_string(), 1);
280 goal.add_sub_goal("Create data loading and preprocessing modules".to_string(), 2);
281 goal.add_sub_goal("Implement feature engineering pipeline".to_string(), 3);
282 goal.add_sub_goal("Set up scikit-learn model training".to_string(), 4);
283 goal.add_sub_goal("Create model evaluation and metrics".to_string(), 5);
284 goal.add_sub_goal("Implement hyperparameter tuning with GridSearchCV".to_string(), 6);
285 goal.add_sub_goal("Add model persistence with joblib/pickle".to_string(), 7);
286 goal.add_sub_goal("Create visualization utilities with matplotlib/seaborn".to_string(), 8);
287 goal.add_sub_goal("Write tests for data pipeline".to_string(), 9);
288
289 goal.status = GoalStatus::InProgress;
290 agent.set_goal(goal.clone());
291
292 let task = TaskRequest::new(
293 "Generate a comprehensive Python data science project with:\n\
294 1. Proper project structure for data science work\n\
295 2. Data loading module supporting CSV, JSON, Parquet\n\
296 3. Data preprocessing and validation pipeline\n\
297 4. Exploratory Data Analysis (EDA) notebook template\n\
298 5. Feature engineering module\n\
299 6. Model training with scikit-learn or XGBoost\n\
300 7. Cross-validation and evaluation metrics\n\
301 8. Hyperparameter tuning with GridSearchCV/RandomSearch\n\
302 9. Model persistence and loading utilities\n\
303 10. Visualization utilities (matplotlib, seaborn, plotly)\n\
304 11. Unit tests for data loading and preprocessing\n\
305 12. Configuration management for experiments\n\
306 13. Logging for training pipeline\n\
307 14. Requirements.txt with ML libraries (pandas, numpy, scikit-learn)\n\
308 15. Makefile for common tasks\n\
309 16. README with dataset description and results\n\
310 Include example workflows and best practices for reproducibility."
311 );
312
313 println!("📝 Task: Generate Data Science Project\n");
314 println!("🎯 Data Science Features:");
315 for criterion in &goal.success_criteria {
316 println!(" ✓ {}", criterion.description);
317 }
318
319 println!("\n⏳ Agent is generating data science project...\n");
320 let response = agent.run(task).await;
321
322 let output = extract_output_text(&response.result());
323 println!("📄 Generated Output:\n");
324 println!("{}\n", output);
325
326 println!("📊 Goal Progress: {}%", goal.get_progress());
327 println!("\n✅ Example 3 completed!\n");
328}
329
330// ============================================
331// Example 4: Python Package/Library
332// ============================================
333
334async fn example_4_python_library() {
335 println!("\n=== Example 4: Generate Python Library/Package ===\n");
336
337 let mut agent = Agent::new("PythonLibraryGenerator", "ollama::gemma3:latest");
338
339 let mut goal = Goal::new(
340 "Generate a well-structured Python package ready for distribution".to_string()
341 );
342
343 goal.add_criterion("Proper package structure with namespace".to_string());
344 goal.add_criterion("setup.py and pyproject.toml for distribution".to_string());
345 goal.add_criterion("Comprehensive docstrings and type hints".to_string());
346 goal.add_criterion("Unit tests with pytest".to_string());
347 goal.add_criterion("Documentation with Sphinx".to_string());
348 goal.add_criterion("CI/CD configuration (GitHub Actions)".to_string());
349 goal.add_criterion("Version management strategy".to_string());
350 goal.add_criterion("Contributing guidelines".to_string());
351
352 goal.add_sub_goal("Create package structure with __init__.py files".to_string(), 0);
353 goal.add_sub_goal("Write setup.py and pyproject.toml".to_string(), 1);
354 goal.add_sub_goal("Create core modules with type hints".to_string(), 2);
355 goal.add_sub_goal("Add comprehensive docstrings".to_string(), 3);
356 goal.add_sub_goal("Create test structure with pytest".to_string(), 4);
357 goal.add_sub_goal("Set up documentation with Sphinx".to_string(), 5);
358 goal.add_sub_goal("Create GitHub Actions workflows".to_string(), 6);
359 goal.add_sub_goal("Add CONTRIBUTING.md and CODE_OF_CONDUCT.md".to_string(), 7);
360 goal.add_sub_goal("Create MANIFEST.in and manifest files".to_string(), 8);
361
362 goal.status = GoalStatus::InProgress;
363 agent.set_goal(goal.clone());
364
365 let task = TaskRequest::new(
366 "Generate a professional Python library/package with:\n\
367 1. Standard package structure (src layout)\n\
368 2. __init__.py with version and exports\n\
369 3. Core modules with complete implementations\n\
370 4. Type hints throughout (PEP 484)\n\
371 5. Comprehensive docstrings (Google style)\n\
372 6. setup.py with metadata\n\
373 7. pyproject.toml with build system\n\
374 8. MANIFEST.in for package data\n\
375 9. Pytest test structure with fixtures\n\
376 10. pytest.ini configuration\n\
377 11. Sphinx documentation setup\n\
378 12. GitHub Actions workflow for CI/CD\n\
379 13. Pre-commit hooks configuration\n\
380 14. LICENSE (MIT or Apache 2.0)\n\
381 15. .gitignore for Python\n\
382 16. README.md with installation and usage\n\
383 17. CONTRIBUTING.md for contributors\n\
384 18. CODE_OF_CONDUCT.md\n\
385 19. Changelog/HISTORY.md template\n\
386 20. Version management with __version__\n\
387 Include examples for public API and best practices for library development."
388 );
389
390 println!("📝 Task: Generate Python Library Package\n");
391 println!("🎯 Library Features:");
392 for criterion in &goal.success_criteria {
393 println!(" ✓ {}", criterion.description);
394 }
395
396 println!("\n⏳ Agent is generating Python library...\n");
397 let response = agent.run(task).await;
398
399 let output = extract_output_text(&response.result());
400 println!("📄 Generated Output:\n");
401 println!("{}\n", output);
402
403 println!("📊 Goal Progress: {}%", goal.get_progress());
404 println!("\n✅ Example 4 completed!\n");
405}
406
407// ============================================
408// Example 5: Django Web Application
409// ============================================
410
411async fn example_5_django_web_app() {
412 println!("\n=== Example 5: Generate Django Web Application ===\n");
413
414 let mut agent = Agent::new("DjangoGenerator", "ollama::gemma3:latest");
415
416 let mut goal = Goal::new(
417 "Generate a complete Django web application with admin and authentication".to_string()
418 );
419
420 goal.add_criterion("Django project structure with multiple apps".to_string());
421 goal.add_criterion("Custom user model implementation".to_string());
422 goal.add_criterion("Database models for core features".to_string());
423 goal.add_criterion("Admin interface customization".to_string());
424 goal.add_criterion("Views and URL routing".to_string());
425 goal.add_criterion("Templates with Bootstrap styling".to_string());
426 goal.add_criterion("Authentication and permissions".to_string());
427 goal.add_criterion("Database migrations".to_string());
428 goal.add_criterion("Django REST Framework API".to_string());
429
430 goal.add_sub_goal("Create Django project and app structure".to_string(), 0);
431 goal.add_sub_goal("Design and implement custom user model".to_string(), 1);
432 goal.add_sub_goal("Create models for core features".to_string(), 2);
433 goal.add_sub_goal("Configure admin interface".to_string(), 3);
434 goal.add_sub_goal("Create views and templates".to_string(), 4);
435 goal.add_sub_goal("Set up URL routing".to_string(), 5);
436 goal.add_sub_goal("Implement authentication views".to_string(), 6);
437 goal.add_sub_goal("Create Django REST Framework serializers".to_string(), 7);
438 goal.add_sub_goal("Set up static files and media handling".to_string(), 8);
439
440 goal.status = GoalStatus::InProgress;
441 agent.set_goal(goal.clone());
442
443 let task = TaskRequest::new(
444 "Generate a full-featured Django web application with:\n\
445 1. Django project structure with multiple apps\n\
446 2. Custom user model extending AbstractBaseUser\n\
447 3. Models for main features (e.g., Blog posts, Comments, Categories)\n\
448 4. Django ORM relationships (ForeignKey, ManyToMany)\n\
449 5. Admin interface with custom actions\n\
450 6. Class-based views (ListView, DetailView, CreateView)\n\
451 7. Django templates with template inheritance\n\
452 8. Bootstrap styling integration\n\
453 9. Authentication and login required decorators\n\
454 10. Permission-based access control\n\
455 11. Database migrations\n\
456 12. Forms with validation\n\
457 13. Django REST Framework setup\n\
458 14. API serializers and viewsets\n\
459 15. Pagination and filtering\n\
460 16. Settings for dev and production\n\
461 17. Environment variable configuration\n\
462 18. Logging configuration\n\
463 19. Tests with Django TestCase\n\
464 20. Static files and media management\n\
465 21. Docker setup\n\
466 22. Requirements.txt\n\
467 Include examples and docstrings following Django conventions."
468 );
469
470 println!("📝 Task: Generate Django Web Application\n");
471 println!("🎯 Django Features:");
472 for criterion in &goal.success_criteria {
473 println!(" ✓ {}", criterion.description);
474 }
475
476 println!("\n⏳ Agent is generating Django app...\n");
477 let response = agent.run(task).await;
478
479 let output = extract_output_text(&response.result());
480 println!("📄 Generated Output:\n");
481 println!("{}\n", output);
482
483 println!("📊 Goal Progress: {}%", goal.get_progress());
484 println!("\n✅ Example 5 completed!\n");
485}Sourcepub fn mark_criterion_met(&mut self, index: usize, reason: String)
pub fn mark_criterion_met(&mut self, index: usize, reason: String)
Marks a success criterion as met.
§Arguments
index- The index of the criterion to markreason- Why the criterion is now met
Examples found in repository?
75async fn example_2_goal_progress_tracking() {
76 println!("\n=== Example 2: Goal Progress Tracking ===\n");
77
78 // Create a goal for a project
79 let mut goal = Goal::new(
80 "Create a project plan for building a mobile app".to_string()
81 );
82
83 // Add success criteria
84 goal.add_criterion("Project requirements documented".to_string());
85 goal.add_criterion("Timeline created with milestones".to_string());
86 goal.add_criterion("Resource allocation plan completed".to_string());
87 goal.add_criterion("Risk assessment performed".to_string());
88
89 // Add sub-goals
90 goal.add_sub_goal("Gather stakeholder requirements".to_string(), 0);
91 goal.add_sub_goal("Define project scope".to_string(), 1);
92 goal.add_sub_goal("Create development timeline".to_string(), 2);
93 goal.add_sub_goal("Allocate resources".to_string(), 3);
94 goal.add_sub_goal("Identify risks and mitigation strategies".to_string(), 4);
95
96 goal.status = GoalStatus::InProgress;
97
98 // Simulate progress through the goal
99 println!("📈 Tracking goal progress...\n");
100
101 // Complete first sub-goal
102 println!("Step 1: Gathering requirements");
103 goal.complete_sub_goal(0, Some("Interviewed 5 stakeholders".to_string()));
104 goal.mark_criterion_met(0, "Requirements documented".to_string());
105 println!(" Progress: {}%\n", goal.get_progress());
106
107 // Complete second sub-goal
108 println!("Step 2: Defining scope");
109 goal.complete_sub_goal(1, Some("Scope document created".to_string()));
110 println!(" Progress: {}%\n", goal.get_progress());
111
112 // Complete third sub-goal
113 println!("Step 3: Creating timeline");
114 goal.complete_sub_goal(2, Some("12-month timeline with milestones".to_string()));
115 goal.mark_criterion_met(1, "Timeline created".to_string());
116 println!(" Progress: {}%\n", goal.get_progress());
117
118 // Complete fourth sub-goal
119 println!("Step 4: Allocating resources");
120 goal.complete_sub_goal(3, Some("Resource allocation table created".to_string()));
121 goal.mark_criterion_met(2, "Resources allocated".to_string());
122 println!(" Progress: {}%\n", goal.get_progress());
123
124 // Complete fifth sub-goal
125 println!("Step 5: Assessing risks");
126 goal.complete_sub_goal(4, Some("Risk register created with 8 identified risks".to_string()));
127 goal.mark_criterion_met(3, "Risks identified".to_string());
128 println!(" Progress: {}%\n", goal.get_progress());
129
130 // Show final status
131 println!("\n📊 Final Goal Status:");
132 println!("{}", goal.get_summary());
133
134 println!("\n✅ Example 2 completed!\n");
135}
136
137// ============================================
138// Example 3: Job Interview Preparation Goal
139// ============================================
140
141async fn example_3_interview_preparation() {
142 println!("\n=== Example 3: Job Interview Preparation Goal ===\n");
143
144 let mut agent = Agent::new("InterviewCoach", "ollama::gemma3:latest");
145
146 // Create a structured goal for interview prep
147 let mut goal = Goal::new(
148 "Prepare for a senior software engineer interview at a tech company".to_string()
149 );
150
151 // Define success criteria
152 println!("🎯 Success criteria:");
153 goal.add_criterion("Technical topics reviewed (algorithms, data structures, system design)".to_string());
154 goal.add_criterion("Behavioral questions prepared with STAR method examples".to_string());
155 goal.add_criterion("Company research completed".to_string());
156 goal.add_criterion("Practice mock interview conducted".to_string());
157 goal.add_criterion("Questions to ask the interviewer prepared".to_string());
158
159 for criterion in &goal.success_criteria {
160 println!(" • {}", criterion.description);
161 }
162
163 // Define steps
164 println!("\n📋 Steps to take:");
165 goal.add_sub_goal("Review core algorithms and data structures".to_string(), 0);
166 goal.add_sub_goal("Study system design patterns".to_string(), 1);
167 goal.add_sub_goal("Prepare STAR method stories from past projects".to_string(), 2);
168 goal.add_sub_goal("Research company background and culture".to_string(), 3);
169 goal.add_sub_goal("Practice mock interview with a friend".to_string(), 4);
170 goal.add_sub_goal("Prepare thoughtful questions about the role".to_string(), 5);
171
172 for sub_goal in &goal.sub_goals {
173 println!(" {}. {}", sub_goal.priority + 1, sub_goal.description);
174 }
175
176 goal.status = GoalStatus::InProgress;
177
178 // Set goal on agent
179 agent.set_goal(goal.clone());
180
181 // Create related task
182 let task = TaskRequest::new("Help me prepare for my senior engineer interview");
183
184 println!("\n⏳ Agent is creating interview preparation plan...\n");
185 let _response = agent.run(task).await;
186
187 println!("\n📊 Goal Summary:");
188 println!("{}", goal.get_summary());
189
190 println!("\n✅ Example 3 completed!\n");
191}
192
193// ============================================
194// Example 4: Goal Analysis from Task Description
195// ============================================
196
197fn example_4_goal_analysis() {
198 println!("\n=== Example 4: Goal Analysis from Task Description ===\n");
199
200 // Simulate LLM analyzing a task and breaking it down into a goal
201 let task_description = "Help me learn Python programming";
202
203 println!("📝 Original task: \"{}\"", task_description);
204 println!("\n🔍 LLM analyzing task...\n");
205
206 // This is what the LLM would return
207 let analysis = GoalAnalysis {
208 main_goal: "Help user learn Python programming from basics to practical skills".to_string(),
209 success_criteria: vec![
210 "User's current skill level identified".to_string(),
211 "Learning path created based on skill level".to_string(),
212 "Resources (tutorials, books) provided".to_string(),
213 "Practice exercises suggested".to_string(),
214 "Study schedule created".to_string(),
215 ],
216 sub_goals: vec![
217 "Ask about current programming experience".to_string(),
218 "Identify learning goals (web dev, data science, etc)".to_string(),
219 "Create structured learning path".to_string(),
220 "Recommend learning resources".to_string(),
221 "Suggest practice projects".to_string(),
222 "Create study timeline".to_string(),
223 ],
224 };
225
226 // Convert analysis to a Goal
227 let goal = analysis.to_goal();
228
229 println!("✅ Goal created from analysis:\n");
230 println!("{}", goal.get_summary());
231
232 println!("\n✅ Example 4 completed!\n");
233}
234
235// ============================================
236// Example 5: Goal Completion Verification
237// ============================================
238
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}Sourcepub fn complete_sub_goal(&mut self, index: usize, notes: Option<String>)
pub fn complete_sub_goal(&mut self, index: usize, notes: Option<String>)
Marks a sub-goal as complete.
§Arguments
index- The index of the sub-goal to completenotes- Optional notes about the completion
Examples found in repository?
75async fn example_2_goal_progress_tracking() {
76 println!("\n=== Example 2: Goal Progress Tracking ===\n");
77
78 // Create a goal for a project
79 let mut goal = Goal::new(
80 "Create a project plan for building a mobile app".to_string()
81 );
82
83 // Add success criteria
84 goal.add_criterion("Project requirements documented".to_string());
85 goal.add_criterion("Timeline created with milestones".to_string());
86 goal.add_criterion("Resource allocation plan completed".to_string());
87 goal.add_criterion("Risk assessment performed".to_string());
88
89 // Add sub-goals
90 goal.add_sub_goal("Gather stakeholder requirements".to_string(), 0);
91 goal.add_sub_goal("Define project scope".to_string(), 1);
92 goal.add_sub_goal("Create development timeline".to_string(), 2);
93 goal.add_sub_goal("Allocate resources".to_string(), 3);
94 goal.add_sub_goal("Identify risks and mitigation strategies".to_string(), 4);
95
96 goal.status = GoalStatus::InProgress;
97
98 // Simulate progress through the goal
99 println!("📈 Tracking goal progress...\n");
100
101 // Complete first sub-goal
102 println!("Step 1: Gathering requirements");
103 goal.complete_sub_goal(0, Some("Interviewed 5 stakeholders".to_string()));
104 goal.mark_criterion_met(0, "Requirements documented".to_string());
105 println!(" Progress: {}%\n", goal.get_progress());
106
107 // Complete second sub-goal
108 println!("Step 2: Defining scope");
109 goal.complete_sub_goal(1, Some("Scope document created".to_string()));
110 println!(" Progress: {}%\n", goal.get_progress());
111
112 // Complete third sub-goal
113 println!("Step 3: Creating timeline");
114 goal.complete_sub_goal(2, Some("12-month timeline with milestones".to_string()));
115 goal.mark_criterion_met(1, "Timeline created".to_string());
116 println!(" Progress: {}%\n", goal.get_progress());
117
118 // Complete fourth sub-goal
119 println!("Step 4: Allocating resources");
120 goal.complete_sub_goal(3, Some("Resource allocation table created".to_string()));
121 goal.mark_criterion_met(2, "Resources allocated".to_string());
122 println!(" Progress: {}%\n", goal.get_progress());
123
124 // Complete fifth sub-goal
125 println!("Step 5: Assessing risks");
126 goal.complete_sub_goal(4, Some("Risk register created with 8 identified risks".to_string()));
127 goal.mark_criterion_met(3, "Risks identified".to_string());
128 println!(" Progress: {}%\n", goal.get_progress());
129
130 // Show final status
131 println!("\n📊 Final Goal Status:");
132 println!("{}", goal.get_summary());
133
134 println!("\n✅ Example 2 completed!\n");
135}
136
137// ============================================
138// Example 3: Job Interview Preparation Goal
139// ============================================
140
141async fn example_3_interview_preparation() {
142 println!("\n=== Example 3: Job Interview Preparation Goal ===\n");
143
144 let mut agent = Agent::new("InterviewCoach", "ollama::gemma3:latest");
145
146 // Create a structured goal for interview prep
147 let mut goal = Goal::new(
148 "Prepare for a senior software engineer interview at a tech company".to_string()
149 );
150
151 // Define success criteria
152 println!("🎯 Success criteria:");
153 goal.add_criterion("Technical topics reviewed (algorithms, data structures, system design)".to_string());
154 goal.add_criterion("Behavioral questions prepared with STAR method examples".to_string());
155 goal.add_criterion("Company research completed".to_string());
156 goal.add_criterion("Practice mock interview conducted".to_string());
157 goal.add_criterion("Questions to ask the interviewer prepared".to_string());
158
159 for criterion in &goal.success_criteria {
160 println!(" • {}", criterion.description);
161 }
162
163 // Define steps
164 println!("\n📋 Steps to take:");
165 goal.add_sub_goal("Review core algorithms and data structures".to_string(), 0);
166 goal.add_sub_goal("Study system design patterns".to_string(), 1);
167 goal.add_sub_goal("Prepare STAR method stories from past projects".to_string(), 2);
168 goal.add_sub_goal("Research company background and culture".to_string(), 3);
169 goal.add_sub_goal("Practice mock interview with a friend".to_string(), 4);
170 goal.add_sub_goal("Prepare thoughtful questions about the role".to_string(), 5);
171
172 for sub_goal in &goal.sub_goals {
173 println!(" {}. {}", sub_goal.priority + 1, sub_goal.description);
174 }
175
176 goal.status = GoalStatus::InProgress;
177
178 // Set goal on agent
179 agent.set_goal(goal.clone());
180
181 // Create related task
182 let task = TaskRequest::new("Help me prepare for my senior engineer interview");
183
184 println!("\n⏳ Agent is creating interview preparation plan...\n");
185 let _response = agent.run(task).await;
186
187 println!("\n📊 Goal Summary:");
188 println!("{}", goal.get_summary());
189
190 println!("\n✅ Example 3 completed!\n");
191}
192
193// ============================================
194// Example 4: Goal Analysis from Task Description
195// ============================================
196
197fn example_4_goal_analysis() {
198 println!("\n=== Example 4: Goal Analysis from Task Description ===\n");
199
200 // Simulate LLM analyzing a task and breaking it down into a goal
201 let task_description = "Help me learn Python programming";
202
203 println!("📝 Original task: \"{}\"", task_description);
204 println!("\n🔍 LLM analyzing task...\n");
205
206 // This is what the LLM would return
207 let analysis = GoalAnalysis {
208 main_goal: "Help user learn Python programming from basics to practical skills".to_string(),
209 success_criteria: vec![
210 "User's current skill level identified".to_string(),
211 "Learning path created based on skill level".to_string(),
212 "Resources (tutorials, books) provided".to_string(),
213 "Practice exercises suggested".to_string(),
214 "Study schedule created".to_string(),
215 ],
216 sub_goals: vec![
217 "Ask about current programming experience".to_string(),
218 "Identify learning goals (web dev, data science, etc)".to_string(),
219 "Create structured learning path".to_string(),
220 "Recommend learning resources".to_string(),
221 "Suggest practice projects".to_string(),
222 "Create study timeline".to_string(),
223 ],
224 };
225
226 // Convert analysis to a Goal
227 let goal = analysis.to_goal();
228
229 println!("✅ Goal created from analysis:\n");
230 println!("{}", goal.get_summary());
231
232 println!("\n✅ Example 4 completed!\n");
233}
234
235// ============================================
236// Example 5: Goal Completion Verification
237// ============================================
238
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}Sourcepub fn is_successful(&self) -> bool
pub fn is_successful(&self) -> bool
Examples found in repository?
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}Sourcepub fn all_sub_goals_complete(&self) -> bool
pub fn all_sub_goals_complete(&self) -> bool
Examples found in repository?
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}Sourcepub fn get_next_sub_goal(&self) -> Option<&SubGoal>
pub fn get_next_sub_goal(&self) -> Option<&SubGoal>
Returns the next sub-goal to work on.
Returns the incomplete sub-goal with the lowest priority number.
§Returns
The next sub-goal to work on, or None if all are complete
Examples found in repository?
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}Sourcepub fn get_progress(&self) -> u32
pub fn get_progress(&self) -> u32
Examples found in repository?
75async fn example_2_goal_progress_tracking() {
76 println!("\n=== Example 2: Goal Progress Tracking ===\n");
77
78 // Create a goal for a project
79 let mut goal = Goal::new(
80 "Create a project plan for building a mobile app".to_string()
81 );
82
83 // Add success criteria
84 goal.add_criterion("Project requirements documented".to_string());
85 goal.add_criterion("Timeline created with milestones".to_string());
86 goal.add_criterion("Resource allocation plan completed".to_string());
87 goal.add_criterion("Risk assessment performed".to_string());
88
89 // Add sub-goals
90 goal.add_sub_goal("Gather stakeholder requirements".to_string(), 0);
91 goal.add_sub_goal("Define project scope".to_string(), 1);
92 goal.add_sub_goal("Create development timeline".to_string(), 2);
93 goal.add_sub_goal("Allocate resources".to_string(), 3);
94 goal.add_sub_goal("Identify risks and mitigation strategies".to_string(), 4);
95
96 goal.status = GoalStatus::InProgress;
97
98 // Simulate progress through the goal
99 println!("📈 Tracking goal progress...\n");
100
101 // Complete first sub-goal
102 println!("Step 1: Gathering requirements");
103 goal.complete_sub_goal(0, Some("Interviewed 5 stakeholders".to_string()));
104 goal.mark_criterion_met(0, "Requirements documented".to_string());
105 println!(" Progress: {}%\n", goal.get_progress());
106
107 // Complete second sub-goal
108 println!("Step 2: Defining scope");
109 goal.complete_sub_goal(1, Some("Scope document created".to_string()));
110 println!(" Progress: {}%\n", goal.get_progress());
111
112 // Complete third sub-goal
113 println!("Step 3: Creating timeline");
114 goal.complete_sub_goal(2, Some("12-month timeline with milestones".to_string()));
115 goal.mark_criterion_met(1, "Timeline created".to_string());
116 println!(" Progress: {}%\n", goal.get_progress());
117
118 // Complete fourth sub-goal
119 println!("Step 4: Allocating resources");
120 goal.complete_sub_goal(3, Some("Resource allocation table created".to_string()));
121 goal.mark_criterion_met(2, "Resources allocated".to_string());
122 println!(" Progress: {}%\n", goal.get_progress());
123
124 // Complete fifth sub-goal
125 println!("Step 5: Assessing risks");
126 goal.complete_sub_goal(4, Some("Risk register created with 8 identified risks".to_string()));
127 goal.mark_criterion_met(3, "Risks identified".to_string());
128 println!(" Progress: {}%\n", goal.get_progress());
129
130 // Show final status
131 println!("\n📊 Final Goal Status:");
132 println!("{}", goal.get_summary());
133
134 println!("\n✅ Example 2 completed!\n");
135}
136
137// ============================================
138// Example 3: Job Interview Preparation Goal
139// ============================================
140
141async fn example_3_interview_preparation() {
142 println!("\n=== Example 3: Job Interview Preparation Goal ===\n");
143
144 let mut agent = Agent::new("InterviewCoach", "ollama::gemma3:latest");
145
146 // Create a structured goal for interview prep
147 let mut goal = Goal::new(
148 "Prepare for a senior software engineer interview at a tech company".to_string()
149 );
150
151 // Define success criteria
152 println!("🎯 Success criteria:");
153 goal.add_criterion("Technical topics reviewed (algorithms, data structures, system design)".to_string());
154 goal.add_criterion("Behavioral questions prepared with STAR method examples".to_string());
155 goal.add_criterion("Company research completed".to_string());
156 goal.add_criterion("Practice mock interview conducted".to_string());
157 goal.add_criterion("Questions to ask the interviewer prepared".to_string());
158
159 for criterion in &goal.success_criteria {
160 println!(" • {}", criterion.description);
161 }
162
163 // Define steps
164 println!("\n📋 Steps to take:");
165 goal.add_sub_goal("Review core algorithms and data structures".to_string(), 0);
166 goal.add_sub_goal("Study system design patterns".to_string(), 1);
167 goal.add_sub_goal("Prepare STAR method stories from past projects".to_string(), 2);
168 goal.add_sub_goal("Research company background and culture".to_string(), 3);
169 goal.add_sub_goal("Practice mock interview with a friend".to_string(), 4);
170 goal.add_sub_goal("Prepare thoughtful questions about the role".to_string(), 5);
171
172 for sub_goal in &goal.sub_goals {
173 println!(" {}. {}", sub_goal.priority + 1, sub_goal.description);
174 }
175
176 goal.status = GoalStatus::InProgress;
177
178 // Set goal on agent
179 agent.set_goal(goal.clone());
180
181 // Create related task
182 let task = TaskRequest::new("Help me prepare for my senior engineer interview");
183
184 println!("\n⏳ Agent is creating interview preparation plan...\n");
185 let _response = agent.run(task).await;
186
187 println!("\n📊 Goal Summary:");
188 println!("{}", goal.get_summary());
189
190 println!("\n✅ Example 3 completed!\n");
191}
192
193// ============================================
194// Example 4: Goal Analysis from Task Description
195// ============================================
196
197fn example_4_goal_analysis() {
198 println!("\n=== Example 4: Goal Analysis from Task Description ===\n");
199
200 // Simulate LLM analyzing a task and breaking it down into a goal
201 let task_description = "Help me learn Python programming";
202
203 println!("📝 Original task: \"{}\"", task_description);
204 println!("\n🔍 LLM analyzing task...\n");
205
206 // This is what the LLM would return
207 let analysis = GoalAnalysis {
208 main_goal: "Help user learn Python programming from basics to practical skills".to_string(),
209 success_criteria: vec![
210 "User's current skill level identified".to_string(),
211 "Learning path created based on skill level".to_string(),
212 "Resources (tutorials, books) provided".to_string(),
213 "Practice exercises suggested".to_string(),
214 "Study schedule created".to_string(),
215 ],
216 sub_goals: vec![
217 "Ask about current programming experience".to_string(),
218 "Identify learning goals (web dev, data science, etc)".to_string(),
219 "Create structured learning path".to_string(),
220 "Recommend learning resources".to_string(),
221 "Suggest practice projects".to_string(),
222 "Create study timeline".to_string(),
223 ],
224 };
225
226 // Convert analysis to a Goal
227 let goal = analysis.to_goal();
228
229 println!("✅ Goal created from analysis:\n");
230 println!("{}", goal.get_summary());
231
232 println!("\n✅ Example 4 completed!\n");
233}
234
235// ============================================
236// Example 5: Goal Completion Verification
237// ============================================
238
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}More examples
38async fn example_1_basic_nextjs_app() {
39 println!("=== Example 1: Generate a Basic Next.js App ===\n");
40
41 // Create an agent that will generate the app
42 let mut agent = Agent::new("NextJsGenerator", "ollama::gemma3:latest");
43
44 // Create a goal for generating a Next.js app
45 let mut goal = Goal::new(
46 "Generate a Next.js web application with essential structure".to_string()
47 );
48
49 // Define success criteria
50 goal.add_criterion("package.json created with dependencies".to_string());
51 goal.add_criterion("next.config.js configuration file generated".to_string());
52 goal.add_criterion("pages directory with index and api route created".to_string());
53 goal.add_criterion("styles directory with global CSS".to_string());
54 goal.add_criterion("README.md with setup instructions".to_string());
55
56 // Define sub-goals (steps to generate the app)
57 goal.add_sub_goal("Analyze Next.js requirements and best practices".to_string(), 0);
58 goal.add_sub_goal("Generate package.json with required dependencies".to_string(), 1);
59 goal.add_sub_goal("Create next.config.js configuration".to_string(), 2);
60 goal.add_sub_goal("Generate pages (index.tsx, _app.tsx, _document.tsx)".to_string(), 3);
61 goal.add_sub_goal("Create API route examples".to_string(), 4);
62 goal.add_sub_goal("Generate styling setup (global.css, utilities)".to_string(), 5);
63 goal.add_sub_goal("Create components directory with example components".to_string(), 6);
64 goal.add_sub_goal("Generate README with setup and usage instructions".to_string(), 7);
65
66 goal.status = GoalStatus::InProgress;
67 agent.set_goal(goal.clone());
68
69 // Create a task to generate a Next.js app
70 let task = TaskRequest::new(
71 "Generate a modern Next.js 14 application with TypeScript, Tailwind CSS, and best practices. \
72 Include package.json, next.config.js, sample pages, API routes, and components. \
73 The app should be production-ready and follow Next.js conventions."
74 );
75
76 println!("📝 Task: Generate a Next.js application\n");
77 println!("🎯 Success Criteria:");
78 for criterion in &goal.success_criteria {
79 println!(" • {}", criterion.description);
80 }
81
82 println!("\n⏳ Agent is generating the Next.js app...\n");
83 let response = agent.run(task).await;
84
85 // Extract and display the output
86 let output = extract_output_text(&response.result());
87 println!("📄 Generated Output:\n");
88 println!("{}\n", output);
89
90 // Show progress
91 println!("📊 Goal Progress: {}%", goal.get_progress());
92 println!("Status: {:?}", goal.status);
93
94 println!("\n✅ Example 1 completed!\n");
95}
96
97// ============================================
98// Example 2: E-Commerce Next.js App
99// ============================================
100
101async fn example_2_ecommerce_app() {
102 println!("\n=== Example 2: Generate E-Commerce Next.js App ===\n");
103
104 let mut agent = Agent::new("EcommerceGenerator", "ollama::gemma3:latest");
105
106 let mut goal = Goal::new(
107 "Generate a complete e-commerce Next.js application".to_string()
108 );
109
110 // Success criteria for e-commerce
111 goal.add_criterion("Product listing page with filtering and sorting".to_string());
112 goal.add_criterion("Product detail pages with dynamic routes".to_string());
113 goal.add_criterion("Shopping cart functionality".to_string());
114 goal.add_criterion("User authentication setup".to_string());
115 goal.add_criterion("Payment integration structure".to_string());
116 goal.add_criterion("Database models and API endpoints".to_string());
117 goal.add_criterion("Admin dashboard layout".to_string());
118
119 // Sub-goals
120 goal.add_sub_goal("Design database schema for products and orders".to_string(), 0);
121 goal.add_sub_goal("Create product API endpoints".to_string(), 1);
122 goal.add_sub_goal("Build product listing and search components".to_string(), 2);
123 goal.add_sub_goal("Implement product detail pages".to_string(), 3);
124 goal.add_sub_goal("Create shopping cart context and management".to_string(), 4);
125 goal.add_sub_goal("Build checkout flow pages".to_string(), 5);
126 goal.add_sub_goal("Integrate payment gateway API".to_string(), 6);
127 goal.add_sub_goal("Create admin dashboard pages".to_string(), 7);
128 goal.add_sub_goal("Add authentication middleware".to_string(), 8);
129
130 goal.status = GoalStatus::InProgress;
131 agent.set_goal(goal.clone());
132
133 let task = TaskRequest::new(
134 "Generate a complete e-commerce Next.js application with: \
135 1. Product management system (listing, search, filters)\n\
136 2. Shopping cart with add/remove/update functionality\n\
137 3. User authentication and profile pages\n\
138 4. Payment integration endpoints\n\
139 5. Order history and tracking\n\
140 6. Admin dashboard for managing products and orders\n\
141 7. Database models for PostgreSQL or MongoDB\n\
142 8. RESTful API endpoints\n\
143 Use TypeScript, Tailwind CSS, and modern React patterns."
144 );
145
146 println!("📝 Task: Generate E-Commerce Next.js Application\n");
147 println!("🎯 Features to Generate:");
148 for criterion in &goal.success_criteria {
149 println!(" ✓ {}", criterion.description);
150 }
151
152 println!("\n⏳ Agent is generating e-commerce app...\n");
153 let response = agent.run(task).await;
154
155 let output = extract_output_text(&response.result());
156 println!("📄 Generated Output:\n");
157 println!("{}\n", output);
158
159 println!("📊 Goal Progress: {}%", goal.get_progress());
160 println!("\n✅ Example 2 completed!\n");
161}
162
163// ============================================
164// Example 3: SaaS Dashboard App
165// ============================================
166
167async fn example_3_saas_dashboard() {
168 println!("\n=== Example 3: Generate SaaS Dashboard Next.js App ===\n");
169
170 let mut agent = Agent::new("SaasDashboardGenerator", "ollama::gemma3:latest");
171
172 let mut goal = Goal::new(
173 "Generate a SaaS dashboard application with user management".to_string()
174 );
175
176 goal.add_criterion("User authentication and authorization".to_string());
177 goal.add_criterion("Multi-tenant database structure".to_string());
178 goal.add_criterion("Dashboard with analytics and metrics".to_string());
179 goal.add_criterion("User and team management pages".to_string());
180 goal.add_criterion("Settings and preferences pages".to_string());
181 goal.add_criterion("Billing and subscription management".to_string());
182 goal.add_criterion("API for data collection and reporting".to_string());
183
184 goal.add_sub_goal("Design multi-tenant database schema".to_string(), 0);
185 goal.add_sub_goal("Implement OAuth authentication".to_string(), 1);
186 goal.add_sub_goal("Create dashboard with charts and metrics".to_string(), 2);
187 goal.add_sub_goal("Build team and user management interfaces".to_string(), 3);
188 goal.add_sub_goal("Create settings pages for users and organization".to_string(), 4);
189 goal.add_sub_goal("Implement billing API integration".to_string(), 5);
190 goal.add_sub_goal("Create analytics and reporting system".to_string(), 6);
191 goal.add_sub_goal("Add email notification templates".to_string(), 7);
192
193 goal.status = GoalStatus::InProgress;
194 agent.set_goal(goal.clone());
195
196 let task = TaskRequest::new(
197 "Generate a complete SaaS dashboard Next.js application with:\n\
198 1. Multi-tenant authentication (OAuth + JWT)\n\
199 2. Organization and team management\n\
200 3. Comprehensive dashboard with charts and analytics\n\
201 4. User permission and role management\n\
202 5. Billing integration with Stripe\n\
203 6. Settings pages for users and teams\n\
204 7. Email notifications system\n\
205 8. API logging and activity tracking\n\
206 9. Dark mode support\n\
207 10. Mobile responsive design\n\
208 Include TypeScript, Tailwind CSS, Recharts for visualizations, \
209 and PostgreSQL database models."
210 );
211
212 println!("📝 Task: Generate SaaS Dashboard Application\n");
213 println!("🎯 Dashboard Features:");
214 for criterion in &goal.success_criteria {
215 println!(" ✓ {}", criterion.description);
216 }
217
218 println!("\n⏳ Agent is generating SaaS dashboard...\n");
219 let response = agent.run(task).await;
220
221 let output = extract_output_text(&response.result());
222 println!("📄 Generated Output:\n");
223 println!("{}\n", output);
224
225 println!("📊 Goal Progress: {}%", goal.get_progress());
226 println!("\n✅ Example 3 completed!\n");
227}
228
229// ============================================
230// Example 4: Blog Platform with CMS
231// ============================================
232
233async fn example_4_blog_platform() {
234 println!("\n=== Example 4: Generate Blog Platform with CMS ===\n");
235
236 let mut agent = Agent::new("BlogCMSGenerator", "ollama::gemma3:latest");
237
238 let mut goal = Goal::new(
239 "Generate a comprehensive blog platform with CMS".to_string()
240 );
241
242 goal.add_criterion("Blog post management system".to_string());
243 goal.add_criterion("Rich text editor with markdown support".to_string());
244 goal.add_criterion("Category and tag system".to_string());
245 goal.add_criterion("Search and filtering functionality".to_string());
246 goal.add_criterion("Comments system with moderation".to_string());
247 goal.add_criterion("SEO optimization (meta tags, sitemap)".to_string());
248 goal.add_criterion("Author management and permissions".to_string());
249 goal.add_criterion("Analytics and engagement tracking".to_string());
250
251 goal.add_sub_goal("Design blog database schema".to_string(), 0);
252 goal.add_sub_goal("Create CMS backend API".to_string(), 1);
253 goal.add_sub_goal("Build post editor with markdown".to_string(), 2);
254 goal.add_sub_goal("Create blog listing and search pages".to_string(), 3);
255 goal.add_sub_goal("Build individual post pages with SEO".to_string(), 4);
256 goal.add_sub_goal("Implement comments system".to_string(), 5);
257 goal.add_sub_goal("Create author profiles and bio".to_string(), 6);
258 goal.add_sub_goal("Build admin dashboard for content management".to_string(), 7);
259 goal.add_sub_goal("Add analytics tracking and reporting".to_string(), 8);
260
261 goal.status = GoalStatus::InProgress;
262 agent.set_goal(goal.clone());
263
264 let task = TaskRequest::new(
265 "Generate a full-featured blog platform with CMS:\n\
266 1. Post creation and editing with rich text editor\n\
267 2. Markdown support with preview\n\
268 3. Category and tag system\n\
269 4. Advanced search with filters\n\
270 5. Comments system with nested replies\n\
271 6. Author profiles with biography\n\
272 7. SEO optimization (sitemaps, meta tags, structured data)\n\
273 8. Social sharing integration\n\
274 9. Email newsletter subscription\n\
275 10. Analytics dashboard for authors\n\
276 11. Reading time estimates\n\
277 12. Related posts suggestions\n\
278 Include TypeScript, Tailwind CSS, next-mdx-remote for markdown, \
279 and MongoDB/PostgreSQL models."
280 );
281
282 println!("📝 Task: Generate Blog Platform with CMS\n");
283 println!("🎯 Blog Features:");
284 for criterion in &goal.success_criteria {
285 println!(" ✓ {}", criterion.description);
286 }
287
288 println!("\n⏳ Agent is generating blog platform...\n");
289 let response = agent.run(task).await;
290
291 let output = extract_output_text(&response.result());
292 println!("📄 Generated Output:\n");
293 println!("{}\n", output);
294
295 println!("📊 Goal Progress: {}%", goal.get_progress());
296 println!("\n✅ Example 4 completed!\n");
297}109async fn example_1_basic_cli_app() {
110 println!("=== Example 1: Generate a Basic Python CLI Application ===\n");
111
112 let mut agent = Agent::new("PythonCliGenerator", "ollama::gemma3:latest");
113
114 // Create a goal for generating a Python CLI app
115 let mut goal = Goal::new(
116 "Generate a Python command-line application with core structure".to_string()
117 );
118
119 // Define success criteria
120 goal.add_criterion("requirements.txt with dependencies listed".to_string());
121 goal.add_criterion("setup.py or pyproject.toml for packaging".to_string());
122 goal.add_criterion("Main CLI entry point with argument parsing".to_string());
123 goal.add_criterion("Command structure with subcommands".to_string());
124 goal.add_criterion("Basic error handling and logging".to_string());
125 goal.add_criterion("README.md with usage instructions".to_string());
126 goal.add_criterion(".gitignore for Python projects".to_string());
127
128 // Define sub-goals (steps to generate the app)
129 goal.add_sub_goal("Analyze Python CLI best practices".to_string(), 0);
130 goal.add_sub_goal("Generate project structure and directories".to_string(), 1);
131 goal.add_sub_goal("Create requirements.txt with dependencies (Click, Typer, etc)".to_string(), 2);
132 goal.add_sub_goal("Generate pyproject.toml or setup.py".to_string(), 3);
133 goal.add_sub_goal("Create main CLI module with argument parser".to_string(), 4);
134 goal.add_sub_goal("Generate subcommands and command handlers".to_string(), 5);
135 goal.add_sub_goal("Create utility modules and helpers".to_string(), 6);
136 goal.add_sub_goal("Add logging and error handling".to_string(), 7);
137 goal.add_sub_goal("Generate README with installation and usage".to_string(), 8);
138
139 goal.status = GoalStatus::InProgress;
140 agent.set_goal(goal.clone());
141
142 // Create a task to generate a Python CLI app
143 let task = TaskRequest::new(
144 "Generate a professional Python command-line application with the following structure:\n\
145 1. Modern argument parsing using Click or Typer\n\
146 2. Multiple subcommands (e.g., init, run, config, help)\n\
147 3. Configuration file support (YAML or JSON)\n\
148 4. Logging with different verbosity levels\n\
149 5. Error handling and graceful failure messages\n\
150 6. Proper project structure with src/ and tests/ directories\n\
151 7. pyproject.toml or setup.py for packaging\n\
152 8. requirements.txt with dev dependencies\n\
153 9. .gitignore for Python\n\
154 10. Comprehensive README with examples\n\
155 The app should be production-ready and follow Python best practices (PEP 8)."
156 );
157
158 println!("📝 Task: Generate a Python CLI Application\n");
159 println!("🎯 Success Criteria:");
160 for criterion in &goal.success_criteria {
161 println!(" • {}", criterion.description);
162 }
163
164 println!("\n⏳ Agent is generating the Python CLI app...\n");
165 let response = agent.run(task).await;
166
167 // Extract and display the output
168 let output = extract_output_text(&response.result());
169 println!("📄 Generated Output:\n");
170 println!("{}\n", output);
171
172 // Show progress
173 println!("📊 Goal Progress: {}%", goal.get_progress());
174 println!("Status: {:?}", goal.status);
175
176 println!("\n✅ Example 1 completed!\n");
177}
178
179// ============================================
180// Example 2: Python Web API with FastAPI
181// ============================================
182
183async fn example_2_fastapi_web_app() {
184 println!("\n=== Example 2: Generate Python FastAPI Web Application ===\n");
185
186 let mut agent = Agent::new("FastApiGenerator", "ollama::gemma3:latest");
187
188 let mut goal = Goal::new(
189 "Generate a complete FastAPI web application with database integration".to_string()
190 );
191
192 // Success criteria for FastAPI app
193 goal.add_criterion("FastAPI application structure with routers".to_string());
194 goal.add_criterion("Database models using SQLAlchemy".to_string());
195 goal.add_criterion("RESTful API endpoints with CRUD operations".to_string());
196 goal.add_criterion("Request/response schemas using Pydantic".to_string());
197 goal.add_criterion("Authentication and authorization middleware".to_string());
198 goal.add_criterion("Database migrations with Alembic".to_string());
199 goal.add_criterion("Configuration management with environment variables".to_string());
200 goal.add_criterion("Unit and integration test examples".to_string());
201 goal.add_criterion("Docker setup for containerization".to_string());
202
203 // Sub-goals
204 goal.add_sub_goal("Design REST API endpoints structure".to_string(), 0);
205 goal.add_sub_goal("Create Pydantic models for request/response validation".to_string(), 1);
206 goal.add_sub_goal("Set up SQLAlchemy ORM with database models".to_string(), 2);
207 goal.add_sub_goal("Implement CRUD routers for resources".to_string(), 3);
208 goal.add_sub_goal("Add authentication and JWT tokens".to_string(), 4);
209 goal.add_sub_goal("Create Alembic migrations setup".to_string(), 5);
210 goal.add_sub_goal("Set up configuration with environment variables".to_string(), 6);
211 goal.add_sub_goal("Create test fixtures and example tests".to_string(), 7);
212 goal.add_sub_goal("Generate Docker and docker-compose files".to_string(), 8);
213 goal.add_sub_goal("Create comprehensive API documentation".to_string(), 9);
214
215 goal.status = GoalStatus::InProgress;
216 agent.set_goal(goal.clone());
217
218 let task = TaskRequest::new(
219 "Generate a production-ready FastAPI web application with:\n\
220 1. Modular project structure with routers for different resources\n\
221 2. Pydantic models for request/response validation\n\
222 3. SQLAlchemy ORM setup with database models\n\
223 4. CRUD operations for users, products, and orders\n\
224 5. JWT authentication and authorization middleware\n\
225 6. Role-based access control (RBAC)\n\
226 7. Alembic database migrations\n\
227 8. Environment configuration (.env support)\n\
228 9. Error handling with proper HTTP status codes\n\
229 10. Logging configuration\n\
230 11. Unit tests with pytest\n\
231 12. Integration tests with test database\n\
232 13. Docker and docker-compose for local development\n\
233 14. requirements.txt with all dependencies\n\
234 15. Comprehensive API documentation\n\
235 Use async/await patterns, follow REST conventions, and include examples."
236 );
237
238 println!("📝 Task: Generate FastAPI Web Application\n");
239 println!("🎯 FastAPI Features:");
240 for criterion in &goal.success_criteria {
241 println!(" ✓ {}", criterion.description);
242 }
243
244 println!("\n⏳ Agent is generating FastAPI app...\n");
245 let response = agent.run(task).await;
246
247 let output = extract_output_text(&response.result());
248 println!("📄 Generated Output:\n");
249 println!("{}\n", output);
250
251 println!("📊 Goal Progress: {}%", goal.get_progress());
252 println!("\n✅ Example 2 completed!\n");
253}
254
255// ============================================
256// Example 3: Python Data Science Project
257// ============================================
258
259async fn example_3_data_science_project() {
260 println!("\n=== Example 3: Generate Python Data Science Project ===\n");
261
262 let mut agent = Agent::new("DataScienceGenerator", "ollama::gemma3:latest");
263
264 let mut goal = Goal::new(
265 "Generate a data science project with ML pipeline and analysis".to_string()
266 );
267
268 goal.add_criterion("Project structure following cookiecutter-data-science".to_string());
269 goal.add_criterion("Data loading and preprocessing modules".to_string());
270 goal.add_criterion("Exploratory data analysis (EDA) notebooks".to_string());
271 goal.add_criterion("Feature engineering pipeline".to_string());
272 goal.add_criterion("Model training and evaluation".to_string());
273 goal.add_criterion("Hyperparameter tuning setup".to_string());
274 goal.add_criterion("Model persistence and versioning".to_string());
275 goal.add_criterion("Visualization utilities".to_string());
276 goal.add_criterion("Unit tests for data pipeline".to_string());
277
278 goal.add_sub_goal("Create cookiecutter-style directory structure".to_string(), 0);
279 goal.add_sub_goal("Set up Jupyter notebook for EDA".to_string(), 1);
280 goal.add_sub_goal("Create data loading and preprocessing modules".to_string(), 2);
281 goal.add_sub_goal("Implement feature engineering pipeline".to_string(), 3);
282 goal.add_sub_goal("Set up scikit-learn model training".to_string(), 4);
283 goal.add_sub_goal("Create model evaluation and metrics".to_string(), 5);
284 goal.add_sub_goal("Implement hyperparameter tuning with GridSearchCV".to_string(), 6);
285 goal.add_sub_goal("Add model persistence with joblib/pickle".to_string(), 7);
286 goal.add_sub_goal("Create visualization utilities with matplotlib/seaborn".to_string(), 8);
287 goal.add_sub_goal("Write tests for data pipeline".to_string(), 9);
288
289 goal.status = GoalStatus::InProgress;
290 agent.set_goal(goal.clone());
291
292 let task = TaskRequest::new(
293 "Generate a comprehensive Python data science project with:\n\
294 1. Proper project structure for data science work\n\
295 2. Data loading module supporting CSV, JSON, Parquet\n\
296 3. Data preprocessing and validation pipeline\n\
297 4. Exploratory Data Analysis (EDA) notebook template\n\
298 5. Feature engineering module\n\
299 6. Model training with scikit-learn or XGBoost\n\
300 7. Cross-validation and evaluation metrics\n\
301 8. Hyperparameter tuning with GridSearchCV/RandomSearch\n\
302 9. Model persistence and loading utilities\n\
303 10. Visualization utilities (matplotlib, seaborn, plotly)\n\
304 11. Unit tests for data loading and preprocessing\n\
305 12. Configuration management for experiments\n\
306 13. Logging for training pipeline\n\
307 14. Requirements.txt with ML libraries (pandas, numpy, scikit-learn)\n\
308 15. Makefile for common tasks\n\
309 16. README with dataset description and results\n\
310 Include example workflows and best practices for reproducibility."
311 );
312
313 println!("📝 Task: Generate Data Science Project\n");
314 println!("🎯 Data Science Features:");
315 for criterion in &goal.success_criteria {
316 println!(" ✓ {}", criterion.description);
317 }
318
319 println!("\n⏳ Agent is generating data science project...\n");
320 let response = agent.run(task).await;
321
322 let output = extract_output_text(&response.result());
323 println!("📄 Generated Output:\n");
324 println!("{}\n", output);
325
326 println!("📊 Goal Progress: {}%", goal.get_progress());
327 println!("\n✅ Example 3 completed!\n");
328}
329
330// ============================================
331// Example 4: Python Package/Library
332// ============================================
333
334async fn example_4_python_library() {
335 println!("\n=== Example 4: Generate Python Library/Package ===\n");
336
337 let mut agent = Agent::new("PythonLibraryGenerator", "ollama::gemma3:latest");
338
339 let mut goal = Goal::new(
340 "Generate a well-structured Python package ready for distribution".to_string()
341 );
342
343 goal.add_criterion("Proper package structure with namespace".to_string());
344 goal.add_criterion("setup.py and pyproject.toml for distribution".to_string());
345 goal.add_criterion("Comprehensive docstrings and type hints".to_string());
346 goal.add_criterion("Unit tests with pytest".to_string());
347 goal.add_criterion("Documentation with Sphinx".to_string());
348 goal.add_criterion("CI/CD configuration (GitHub Actions)".to_string());
349 goal.add_criterion("Version management strategy".to_string());
350 goal.add_criterion("Contributing guidelines".to_string());
351
352 goal.add_sub_goal("Create package structure with __init__.py files".to_string(), 0);
353 goal.add_sub_goal("Write setup.py and pyproject.toml".to_string(), 1);
354 goal.add_sub_goal("Create core modules with type hints".to_string(), 2);
355 goal.add_sub_goal("Add comprehensive docstrings".to_string(), 3);
356 goal.add_sub_goal("Create test structure with pytest".to_string(), 4);
357 goal.add_sub_goal("Set up documentation with Sphinx".to_string(), 5);
358 goal.add_sub_goal("Create GitHub Actions workflows".to_string(), 6);
359 goal.add_sub_goal("Add CONTRIBUTING.md and CODE_OF_CONDUCT.md".to_string(), 7);
360 goal.add_sub_goal("Create MANIFEST.in and manifest files".to_string(), 8);
361
362 goal.status = GoalStatus::InProgress;
363 agent.set_goal(goal.clone());
364
365 let task = TaskRequest::new(
366 "Generate a professional Python library/package with:\n\
367 1. Standard package structure (src layout)\n\
368 2. __init__.py with version and exports\n\
369 3. Core modules with complete implementations\n\
370 4. Type hints throughout (PEP 484)\n\
371 5. Comprehensive docstrings (Google style)\n\
372 6. setup.py with metadata\n\
373 7. pyproject.toml with build system\n\
374 8. MANIFEST.in for package data\n\
375 9. Pytest test structure with fixtures\n\
376 10. pytest.ini configuration\n\
377 11. Sphinx documentation setup\n\
378 12. GitHub Actions workflow for CI/CD\n\
379 13. Pre-commit hooks configuration\n\
380 14. LICENSE (MIT or Apache 2.0)\n\
381 15. .gitignore for Python\n\
382 16. README.md with installation and usage\n\
383 17. CONTRIBUTING.md for contributors\n\
384 18. CODE_OF_CONDUCT.md\n\
385 19. Changelog/HISTORY.md template\n\
386 20. Version management with __version__\n\
387 Include examples for public API and best practices for library development."
388 );
389
390 println!("📝 Task: Generate Python Library Package\n");
391 println!("🎯 Library Features:");
392 for criterion in &goal.success_criteria {
393 println!(" ✓ {}", criterion.description);
394 }
395
396 println!("\n⏳ Agent is generating Python library...\n");
397 let response = agent.run(task).await;
398
399 let output = extract_output_text(&response.result());
400 println!("📄 Generated Output:\n");
401 println!("{}\n", output);
402
403 println!("📊 Goal Progress: {}%", goal.get_progress());
404 println!("\n✅ Example 4 completed!\n");
405}
406
407// ============================================
408// Example 5: Django Web Application
409// ============================================
410
411async fn example_5_django_web_app() {
412 println!("\n=== Example 5: Generate Django Web Application ===\n");
413
414 let mut agent = Agent::new("DjangoGenerator", "ollama::gemma3:latest");
415
416 let mut goal = Goal::new(
417 "Generate a complete Django web application with admin and authentication".to_string()
418 );
419
420 goal.add_criterion("Django project structure with multiple apps".to_string());
421 goal.add_criterion("Custom user model implementation".to_string());
422 goal.add_criterion("Database models for core features".to_string());
423 goal.add_criterion("Admin interface customization".to_string());
424 goal.add_criterion("Views and URL routing".to_string());
425 goal.add_criterion("Templates with Bootstrap styling".to_string());
426 goal.add_criterion("Authentication and permissions".to_string());
427 goal.add_criterion("Database migrations".to_string());
428 goal.add_criterion("Django REST Framework API".to_string());
429
430 goal.add_sub_goal("Create Django project and app structure".to_string(), 0);
431 goal.add_sub_goal("Design and implement custom user model".to_string(), 1);
432 goal.add_sub_goal("Create models for core features".to_string(), 2);
433 goal.add_sub_goal("Configure admin interface".to_string(), 3);
434 goal.add_sub_goal("Create views and templates".to_string(), 4);
435 goal.add_sub_goal("Set up URL routing".to_string(), 5);
436 goal.add_sub_goal("Implement authentication views".to_string(), 6);
437 goal.add_sub_goal("Create Django REST Framework serializers".to_string(), 7);
438 goal.add_sub_goal("Set up static files and media handling".to_string(), 8);
439
440 goal.status = GoalStatus::InProgress;
441 agent.set_goal(goal.clone());
442
443 let task = TaskRequest::new(
444 "Generate a full-featured Django web application with:\n\
445 1. Django project structure with multiple apps\n\
446 2. Custom user model extending AbstractBaseUser\n\
447 3. Models for main features (e.g., Blog posts, Comments, Categories)\n\
448 4. Django ORM relationships (ForeignKey, ManyToMany)\n\
449 5. Admin interface with custom actions\n\
450 6. Class-based views (ListView, DetailView, CreateView)\n\
451 7. Django templates with template inheritance\n\
452 8. Bootstrap styling integration\n\
453 9. Authentication and login required decorators\n\
454 10. Permission-based access control\n\
455 11. Database migrations\n\
456 12. Forms with validation\n\
457 13. Django REST Framework setup\n\
458 14. API serializers and viewsets\n\
459 15. Pagination and filtering\n\
460 16. Settings for dev and production\n\
461 17. Environment variable configuration\n\
462 18. Logging configuration\n\
463 19. Tests with Django TestCase\n\
464 20. Static files and media management\n\
465 21. Docker setup\n\
466 22. Requirements.txt\n\
467 Include examples and docstrings following Django conventions."
468 );
469
470 println!("📝 Task: Generate Django Web Application\n");
471 println!("🎯 Django Features:");
472 for criterion in &goal.success_criteria {
473 println!(" ✓ {}", criterion.description);
474 }
475
476 println!("\n⏳ Agent is generating Django app...\n");
477 let response = agent.run(task).await;
478
479 let output = extract_output_text(&response.result());
480 println!("📄 Generated Output:\n");
481 println!("{}\n", output);
482
483 println!("📊 Goal Progress: {}%", goal.get_progress());
484 println!("\n✅ Example 5 completed!\n");
485}Sourcepub fn get_summary(&self) -> String
pub fn get_summary(&self) -> String
Returns a formatted summary of the goal’s current state.
§Returns
A multi-line string showing the goal, status, progress, criteria, and sub-goals
Examples found in repository?
22async fn example_1_manual_goal() {
23 println!("=== Example 1: Manual Goal Creation ===\n");
24
25 // Create an agent
26 let mut agent = Agent::new("MealPlanner", "ollama::gemma3:latest");
27
28 // Create a goal manually for a complex task
29 let mut goal = Goal::new(
30 "Plan a healthy meal prep for the week".to_string()
31 );
32
33 // Define what success looks like
34 println!("📋 Setting success criteria...");
35 goal.add_criterion("7 breakfast recipes selected".to_string());
36 goal.add_criterion("7 lunch recipes selected".to_string());
37 goal.add_criterion("7 dinner recipes selected".to_string());
38 goal.add_criterion("Shopping list created".to_string());
39 goal.add_criterion("Prep schedule created".to_string());
40
41 // Break down into steps (sub-goals)
42 println!("🎯 Breaking down into sub-goals...\n");
43 goal.add_sub_goal("Ask user about dietary preferences".to_string(), 0);
44 goal.add_sub_goal("Ask about time available for prep".to_string(), 1);
45 goal.add_sub_goal("Suggest breakfast options".to_string(), 2);
46 goal.add_sub_goal("Suggest lunch options".to_string(), 3);
47 goal.add_sub_goal("Suggest dinner options".to_string(), 4);
48 goal.add_sub_goal("Create shopping list".to_string(), 5);
49 goal.add_sub_goal("Create prep schedule".to_string(), 6);
50
51 // Start working on the goal
52 goal.status = GoalStatus::InProgress;
53
54 // Set the goal on the agent
55 agent.set_goal(goal.clone());
56
57 // Create a task aligned with the goal
58 let task = TaskRequest::new("I need help with meal planning");
59
60 // Run the agent
61 println!("⏳ Agent is working on the meal planning task...\n");
62 let _response = agent.run(task).await;
63
64 // Show the goal summary
65 println!("\n📊 Goal Summary:");
66 println!("{}", goal.get_summary());
67
68 println!("\n✅ Example 1 completed!\n");
69}
70
71// ============================================
72// Example 2: Goal Progress Tracking
73// ============================================
74
75async fn example_2_goal_progress_tracking() {
76 println!("\n=== Example 2: Goal Progress Tracking ===\n");
77
78 // Create a goal for a project
79 let mut goal = Goal::new(
80 "Create a project plan for building a mobile app".to_string()
81 );
82
83 // Add success criteria
84 goal.add_criterion("Project requirements documented".to_string());
85 goal.add_criterion("Timeline created with milestones".to_string());
86 goal.add_criterion("Resource allocation plan completed".to_string());
87 goal.add_criterion("Risk assessment performed".to_string());
88
89 // Add sub-goals
90 goal.add_sub_goal("Gather stakeholder requirements".to_string(), 0);
91 goal.add_sub_goal("Define project scope".to_string(), 1);
92 goal.add_sub_goal("Create development timeline".to_string(), 2);
93 goal.add_sub_goal("Allocate resources".to_string(), 3);
94 goal.add_sub_goal("Identify risks and mitigation strategies".to_string(), 4);
95
96 goal.status = GoalStatus::InProgress;
97
98 // Simulate progress through the goal
99 println!("📈 Tracking goal progress...\n");
100
101 // Complete first sub-goal
102 println!("Step 1: Gathering requirements");
103 goal.complete_sub_goal(0, Some("Interviewed 5 stakeholders".to_string()));
104 goal.mark_criterion_met(0, "Requirements documented".to_string());
105 println!(" Progress: {}%\n", goal.get_progress());
106
107 // Complete second sub-goal
108 println!("Step 2: Defining scope");
109 goal.complete_sub_goal(1, Some("Scope document created".to_string()));
110 println!(" Progress: {}%\n", goal.get_progress());
111
112 // Complete third sub-goal
113 println!("Step 3: Creating timeline");
114 goal.complete_sub_goal(2, Some("12-month timeline with milestones".to_string()));
115 goal.mark_criterion_met(1, "Timeline created".to_string());
116 println!(" Progress: {}%\n", goal.get_progress());
117
118 // Complete fourth sub-goal
119 println!("Step 4: Allocating resources");
120 goal.complete_sub_goal(3, Some("Resource allocation table created".to_string()));
121 goal.mark_criterion_met(2, "Resources allocated".to_string());
122 println!(" Progress: {}%\n", goal.get_progress());
123
124 // Complete fifth sub-goal
125 println!("Step 5: Assessing risks");
126 goal.complete_sub_goal(4, Some("Risk register created with 8 identified risks".to_string()));
127 goal.mark_criterion_met(3, "Risks identified".to_string());
128 println!(" Progress: {}%\n", goal.get_progress());
129
130 // Show final status
131 println!("\n📊 Final Goal Status:");
132 println!("{}", goal.get_summary());
133
134 println!("\n✅ Example 2 completed!\n");
135}
136
137// ============================================
138// Example 3: Job Interview Preparation Goal
139// ============================================
140
141async fn example_3_interview_preparation() {
142 println!("\n=== Example 3: Job Interview Preparation Goal ===\n");
143
144 let mut agent = Agent::new("InterviewCoach", "ollama::gemma3:latest");
145
146 // Create a structured goal for interview prep
147 let mut goal = Goal::new(
148 "Prepare for a senior software engineer interview at a tech company".to_string()
149 );
150
151 // Define success criteria
152 println!("🎯 Success criteria:");
153 goal.add_criterion("Technical topics reviewed (algorithms, data structures, system design)".to_string());
154 goal.add_criterion("Behavioral questions prepared with STAR method examples".to_string());
155 goal.add_criterion("Company research completed".to_string());
156 goal.add_criterion("Practice mock interview conducted".to_string());
157 goal.add_criterion("Questions to ask the interviewer prepared".to_string());
158
159 for criterion in &goal.success_criteria {
160 println!(" • {}", criterion.description);
161 }
162
163 // Define steps
164 println!("\n📋 Steps to take:");
165 goal.add_sub_goal("Review core algorithms and data structures".to_string(), 0);
166 goal.add_sub_goal("Study system design patterns".to_string(), 1);
167 goal.add_sub_goal("Prepare STAR method stories from past projects".to_string(), 2);
168 goal.add_sub_goal("Research company background and culture".to_string(), 3);
169 goal.add_sub_goal("Practice mock interview with a friend".to_string(), 4);
170 goal.add_sub_goal("Prepare thoughtful questions about the role".to_string(), 5);
171
172 for sub_goal in &goal.sub_goals {
173 println!(" {}. {}", sub_goal.priority + 1, sub_goal.description);
174 }
175
176 goal.status = GoalStatus::InProgress;
177
178 // Set goal on agent
179 agent.set_goal(goal.clone());
180
181 // Create related task
182 let task = TaskRequest::new("Help me prepare for my senior engineer interview");
183
184 println!("\n⏳ Agent is creating interview preparation plan...\n");
185 let _response = agent.run(task).await;
186
187 println!("\n📊 Goal Summary:");
188 println!("{}", goal.get_summary());
189
190 println!("\n✅ Example 3 completed!\n");
191}
192
193// ============================================
194// Example 4: Goal Analysis from Task Description
195// ============================================
196
197fn example_4_goal_analysis() {
198 println!("\n=== Example 4: Goal Analysis from Task Description ===\n");
199
200 // Simulate LLM analyzing a task and breaking it down into a goal
201 let task_description = "Help me learn Python programming";
202
203 println!("📝 Original task: \"{}\"", task_description);
204 println!("\n🔍 LLM analyzing task...\n");
205
206 // This is what the LLM would return
207 let analysis = GoalAnalysis {
208 main_goal: "Help user learn Python programming from basics to practical skills".to_string(),
209 success_criteria: vec![
210 "User's current skill level identified".to_string(),
211 "Learning path created based on skill level".to_string(),
212 "Resources (tutorials, books) provided".to_string(),
213 "Practice exercises suggested".to_string(),
214 "Study schedule created".to_string(),
215 ],
216 sub_goals: vec![
217 "Ask about current programming experience".to_string(),
218 "Identify learning goals (web dev, data science, etc)".to_string(),
219 "Create structured learning path".to_string(),
220 "Recommend learning resources".to_string(),
221 "Suggest practice projects".to_string(),
222 "Create study timeline".to_string(),
223 ],
224 };
225
226 // Convert analysis to a Goal
227 let goal = analysis.to_goal();
228
229 println!("✅ Goal created from analysis:\n");
230 println!("{}", goal.get_summary());
231
232 println!("\n✅ Example 4 completed!\n");
233}
234
235// ============================================
236// Example 5: Goal Completion Verification
237// ============================================
238
239async fn example_5_goal_completion() {
240 println!("\n=== Example 5: Goal Completion Verification ===\n");
241
242 let mut goal = Goal::new("Plan a birthday party".to_string());
243
244 // Set up success criteria
245 goal.add_criterion("Guest list created".to_string());
246 goal.add_criterion("Venue booked".to_string());
247 goal.add_criterion("Food ordered".to_string());
248 goal.add_criterion("Decorations purchased".to_string());
249
250 // Set up sub-goals
251 goal.add_sub_goal("Ask about guests".to_string(), 0);
252 goal.add_sub_goal("Choose and book venue".to_string(), 1);
253 goal.add_sub_goal("Order food".to_string(), 2);
254 goal.add_sub_goal("Purchase decorations".to_string(), 3);
255
256 goal.status = GoalStatus::InProgress;
257
258 println!("🎉 Birthday party planning task started\n");
259 println!("Initial progress: {}%\n", goal.get_progress());
260
261 // Simulate completing tasks
262 println!("Working through sub-goals:\n");
263
264 // Task 1
265 println!("✓ Contacted 15 friends and family members");
266 goal.complete_sub_goal(0, Some("Got 15 confirmations".to_string()));
267 goal.mark_criterion_met(0, "List of 15 guests confirmed".to_string());
268 println!(" Progress: {}%", goal.get_progress());
269
270 // Task 2
271 println!("✓ Booked the community center for Saturday");
272 goal.complete_sub_goal(1, Some("Community center reserved for 6pm".to_string()));
273 goal.mark_criterion_met(1, "Community center booking confirmed".to_string());
274 println!(" Progress: {}%", goal.get_progress());
275
276 // Task 3
277 println!("✓ Ordered pizza and drinks for 15 people");
278 goal.complete_sub_goal(2, Some("Pizza and drinks ordered".to_string()));
279 goal.mark_criterion_met(2, "Food catering arranged".to_string());
280 println!(" Progress: {}%", goal.get_progress());
281
282 // Task 4
283 println!("✓ Bought balloons, streamers, and table decorations");
284 goal.complete_sub_goal(3, Some("All decorations purchased".to_string()));
285 goal.mark_criterion_met(3, "Decorations ready".to_string());
286 println!(" Progress: {}%\n", goal.get_progress());
287
288 // Check completion
289 if goal.is_successful() {
290 println!("🎊 All success criteria met!");
291 goal.status = GoalStatus::Completed;
292 }
293
294 if goal.all_sub_goals_complete() {
295 println!("✅ All sub-goals completed!");
296 }
297
298 println!("\nFinal Status:");
299 println!(" Status: {:?}", goal.status);
300 println!(" All criteria met: {}", goal.is_successful());
301 println!(" Progress: {}%\n", goal.get_progress());
302
303 println!("📊 Final Summary:");
304 println!("{}", goal.get_summary());
305
306 println!("\n✅ Example 5 completed!\n");
307}
308
309// ============================================
310// Example 6: Complex Multi-Step Project
311// ============================================
312
313async fn example_6_complex_project() {
314 println!("\n=== Example 6: Complex Multi-Step Project Goal ===\n");
315
316 let mut goal = Goal::new(
317 "Launch a new web application product".to_string()
318 );
319
320 // Success criteria
321 goal.add_criterion("Technical architecture designed and documented".to_string());
322 goal.add_criterion("Frontend and backend development completed".to_string());
323 goal.add_criterion("Testing completed (unit, integration, E2E)".to_string());
324 goal.add_criterion("Deployment pipeline set up".to_string());
325 goal.add_criterion("Marketing materials prepared".to_string());
326 goal.add_criterion("Team trained on deployment and support".to_string());
327
328 // Sub-goals in order
329 goal.add_sub_goal("Define technical requirements and architecture".to_string(), 0);
330 goal.add_sub_goal("Set up development environment and CI/CD".to_string(), 1);
331 goal.add_sub_goal("Develop backend API endpoints".to_string(), 2);
332 goal.add_sub_goal("Build frontend user interface".to_string(), 3);
333 goal.add_sub_goal("Write comprehensive test suite".to_string(), 4);
334 goal.add_sub_goal("Conduct security audit".to_string(), 5);
335 goal.add_sub_goal("Set up monitoring and logging".to_string(), 6);
336 goal.add_sub_goal("Deploy to staging environment".to_string(), 7);
337 goal.add_sub_goal("Perform final testing and QA".to_string(), 8);
338 goal.add_sub_goal("Create deployment documentation".to_string(), 9);
339 goal.add_sub_goal("Train support team".to_string(), 10);
340 goal.add_sub_goal("Deploy to production".to_string(), 11);
341
342 goal.status = GoalStatus::InProgress;
343
344 println!("🚀 Web Application Product Launch Plan\n");
345 println!("Total steps: {}\n", goal.sub_goals.len());
346
347 // Simulate progress
348 let completed_steps = vec![
349 (0, "Architecture documented with diagrams"),
350 (1, "GitHub Actions CI/CD configured"),
351 (2, "All 15 API endpoints implemented and tested"),
352 (3, "React frontend with all pages completed"),
353 (4, "Jest test suite with 85% coverage"),
354 (5, "No critical vulnerabilities found"),
355 (6, "Prometheus and ELK stack configured"),
356 (7, "Successfully deployed to staging"),
357 (8, "UAT passed with stakeholders"),
358 (9, "Deployment runbook created"),
359 (10, "Support team completed training"),
360 ];
361
362 for (index, notes) in completed_steps {
363 goal.complete_sub_goal(index, Some(notes.to_string()));
364 }
365
366 // Mark success criteria as met
367 goal.mark_criterion_met(0, "System design document completed".to_string());
368 goal.mark_criterion_met(1, "All features implemented and tested".to_string());
369 goal.mark_criterion_met(2, "85% test coverage achieved".to_string());
370 goal.mark_criterion_met(3, "GitHub Actions and monitoring configured".to_string());
371 goal.mark_criterion_met(4, "Marketing deck prepared".to_string());
372 goal.mark_criterion_met(5, "Team completed deployment training".to_string());
373
374 println!("📈 Project Progress:\n");
375 println!("Overall Progress: {}%\n", goal.get_progress());
376
377 println!("Remaining tasks:");
378 if let Some(next) = goal.get_next_sub_goal() {
379 println!(" • {}", next.description);
380 }
381
382 println!("\n📊 Status Summary:");
383 println!("{}", goal.get_summary());
384
385 if goal.get_progress() == 100 {
386 println!("\n✅ All sub-goals completed!");
387 if goal.is_successful() {
388 println!("🎉 All success criteria met!");
389 println!("Ready to mark goal as Completed!");
390 }
391 }
392
393 println!("\n✅ Example 6 completed!\n");
394}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Goal
impl<'de> Deserialize<'de> for Goal
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Goal
impl RefUnwindSafe for Goal
impl Send for Goal
impl Sync for Goal
impl Unpin for Goal
impl UnwindSafe for Goal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more