acecalisto3 commited on
Commit
cd3d673
·
verified ·
1 Parent(s): 298ec11

Update definitions.py

Browse files
Files changed (1) hide show
  1. definitions.py +92 -0
definitions.py CHANGED
@@ -410,6 +410,98 @@ class AutonomousAgent:
410
  if st.button("Send", key="send_message"):
411
  self.process_user_input(user_input)
412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  class AutonomousAgentApp:
414
  """Main application class for the Autonomous Agent System."""
415
  def __init__(self):
 
410
  if st.button("Send", key="send_message"):
411
  self.process_user_input(user_input)
412
 
413
+ class RefinementLoop:
414
+ """Manages the iterative refinement process."""
415
+ def __init__(self, pipeline):
416
+ self.pipeline = pipeline
417
+ self.max_iterations = 10
418
+ self.quality_metrics = QualityMetrics()
419
+ self.logger = logging.getLogger(__name__)
420
+ self.current_iteration = 0
421
+ self.history = []
422
+
423
+ async def run_refinement_cycle(self, task: str) -> Dict[str, Any]:
424
+ """Run a complete refinement cycle for the given task."""
425
+ self.logger.info(f"Starting refinement cycle for task: {task}")
426
+ self.current_iteration = 0
427
+
428
+ try:
429
+ while self.current_iteration < self.max_iterations:
430
+ self.logger.info(f"Starting iteration {self.current_iteration + 1}")
431
+
432
+ # Execute pipeline stages
433
+ planning_result = await self.pipeline.execute_stage(
434
+ self.pipeline.PipelineStage.PLANNING,
435
+ {"task": task}
436
+ )
437
+
438
+ development_result = await self.pipeline.execute_stage(
439
+ self.pipeline.PipelineStage.DEVELOPMENT,
440
+ planning_result["result"]
441
+ )
442
+
443
+ testing_result = await self.pipeline.execute_stage(
444
+ self.pipeline.PipelineStage.TESTING,
445
+ development_result["result"]
446
+ )
447
+
448
+ # Analyze results
449
+ quality_analysis = self._analyze_quality(testing_result["result"])
450
+
451
+ # Record iteration history
452
+ self.history.append({
453
+ "iteration": self.current_iteration,
454
+ "quality_metrics": quality_analysis,
455
+ "timestamp": datetime.now()
456
+ })
457
+
458
+ # Check if quality requirements are met
459
+ if self._meets_quality_requirements(quality_analysis):
460
+ self.logger.info("Quality requirements met. Refinement cycle complete.")
461
+ return self._prepare_final_result(quality_analysis)
462
+
463
+ self.current_iteration += 1
464
+
465
+ return {
466
+ "status": "max_iterations_reached",
467
+ "iterations_completed": self.current_iteration,
468
+ "final_quality": quality_analysis
469
+ }
470
+
471
+ except Exception as e:
472
+ self.logger.error(f"Error in refinement cycle: {str(e)}")
473
+ return {"status": "error", "error": str(e)}
474
+
475
+ def _analyze_quality(self, result: Dict[str, Any]) -> Dict[str, float]:
476
+ """Analyze the quality metrics of the current iteration."""
477
+ return {
478
+ "code_quality": self.quality_metrics.code_quality_score,
479
+ "test_coverage": self.quality_metrics.test_coverage,
480
+ "security_score": float(self.quality_metrics.security_score)
481
+ }
482
+
483
+ def _meets_quality_requirements(self, quality_analysis: Dict[str, float]) -> bool:
484
+ """Check if the current quality metrics meet the requirements."""
485
+ thresholds = self.quality_metrics.thresholds
486
+ return (
487
+ quality_analysis["code_quality"] >= thresholds["code_quality"] and
488
+ quality_analysis["test_coverage"] >= thresholds["test_coverage"] and
489
+ quality_analysis["security_score"] >= thresholds["security"]
490
+ )
491
+
492
+ def _prepare_final_result(self, quality_analysis: Dict[str, float]) -> Dict[str, Any]:
493
+ """Prepare the final result of the refinement cycle."""
494
+ return {
495
+ "status": "success",
496
+ "iterations_completed": self.current_iteration,
497
+ "final_quality": quality_analysis,
498
+ "history": self.history
499
+ }
500
+
501
+ def get_refinement_history(self) -> List[Dict[str, Any]]:
502
+ """Get the history of refinement iterations."""
503
+ return self.history
504
+
505
  class AutonomousAgentApp:
506
  """Main application class for the Autonomous Agent System."""
507
  def __init__(self):