Spaces:
Sleeping
Sleeping
Update definitions.py
Browse files- definitions.py +33 -34
definitions.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
import platform
|
3 |
import psutil
|
4 |
from typing import List, Dict, Optional, Any, Tuple
|
@@ -27,12 +26,14 @@ from typing import Dict, Any
|
|
27 |
from datetime import datetime
|
28 |
from pathlib import Path
|
29 |
|
|
|
|
|
30 |
|
31 |
class AutonomousAgentApp:
|
32 |
"""Main application class for the Autonomous Agent System"""
|
33 |
|
34 |
def __init__(self):
|
35 |
-
self.workspace_manager = self.WorkspaceManager(workspace_dir='workspace') # Use self.WorkspaceManager
|
36 |
self.pipeline = self._initialize_pipeline()
|
37 |
self.refinement_loop = self.RefinementLoop(pipeline=self.pipeline) # Use self.RefinementLoop
|
38 |
self.interface = self.StreamlitInterface(self) # Use self.StreamlitInterface
|
@@ -137,8 +138,11 @@ class AutonomousAgentApp:
|
|
137 |
async def default_task(self):
|
138 |
"""Perform the default task of analyzing and generating tools/agents."""
|
139 |
logging.info("Running default task...")
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
142 |
|
143 |
async def pause(self):
|
144 |
"""Pause the current operation to accept user input."""
|
@@ -151,37 +155,34 @@ class AutonomousAgentApp:
|
|
151 |
commands = self.extract_commands(user_input)
|
152 |
|
153 |
for command in commands:
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
159 |
|
160 |
def extract_commands(self, user_input: str) -> List[str]:
|
161 |
"""Extract commands from user input."""
|
162 |
-
# Simple command extraction logic (can be improved with NLP)
|
163 |
return user_input.split(';') # Assume commands are separated by semicolons
|
164 |
|
165 |
async def run_refinement_cycle(self, task: str) -> Dict[str, Any]:
|
166 |
"""Run a refinement cycle for the given task."""
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
# Step 3: Build tools/agents based on the task
|
174 |
-
tools_built = await self._build_tools(task_analysis, search_results)
|
175 |
-
|
176 |
-
# Step 4: Execute the tools/agents
|
177 |
-
execution_results = await self._execute_tools(tools_built)
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
|
|
185 |
|
186 |
async def _analyze_task(self, task: str) -> Dict[str, Any]:
|
187 |
"""Analyze the task to determine requirements."""
|
@@ -220,7 +221,7 @@ class AutonomousAgentApp:
|
|
220 |
"""Perform a web search for relevant approaches/methods."""
|
221 |
try:
|
222 |
response = requests.get(
|
223 |
-
|
224 |
params={"q": query, "limit": 5}
|
225 |
)
|
226 |
response.raise_for_status()
|
@@ -549,8 +550,6 @@ if __name__ == "__main__":
|
|
549 |
return {
|
550 |
"test_cases": test_generation["result"],
|
551 |
"test_results": test_results["result"],
|
552 |
-
"coverage_report": coverage_report["result"]
|
553 |
-
}
|
554 |
except Exception as e:
|
555 |
raise Exception(f"Testing stage failed: {str(e)}")
|
556 |
|
@@ -847,10 +846,10 @@ if __name__ == "__main__":
|
|
847 |
test_coverage: float = 0.0
|
848 |
security_score: str = "unknown"
|
849 |
performance_score: float = 0.0
|
850 |
-
metrics_analyzer: CodeMetricsAnalyzer = None
|
851 |
-
|
852 |
def __post_init__(self):
|
853 |
-
self.metrics_analyzer = CodeMetricsAnalyzer()
|
854 |
self.history = []
|
855 |
self.thresholds = {
|
856 |
"code_quality": 0.85,
|
@@ -1260,4 +1259,4 @@ if __name__ == "__main__":
|
|
1260 |
|
1261 |
if __name__ == "__main__":
|
1262 |
import streamlit as st
|
1263 |
-
main()
|
|
|
|
|
1 |
import platform
|
2 |
import psutil
|
3 |
from typing import List, Dict, Optional, Any, Tuple
|
|
|
26 |
from datetime import datetime
|
27 |
from pathlib import Path
|
28 |
|
29 |
+
# Set logging level from environment variable
|
30 |
+
logging.basicConfig(level=os.getenv('LOG_LEVEL', 'INFO'))
|
31 |
|
32 |
class AutonomousAgentApp:
|
33 |
"""Main application class for the Autonomous Agent System"""
|
34 |
|
35 |
def __init__(self):
|
36 |
+
self.workspace_manager = self.WorkspaceManager(workspace_dir=os.getenv('WORKSPACE_DIR', 'workspace')) # Use self.WorkspaceManager
|
37 |
self.pipeline = self._initialize_pipeline()
|
38 |
self.refinement_loop = self.RefinementLoop(pipeline=self.pipeline) # Use self.RefinementLoop
|
39 |
self.interface = self.StreamlitInterface(self) # Use self.StreamlitInterface
|
|
|
138 |
async def default_task(self):
|
139 |
"""Perform the default task of analyzing and generating tools/agents."""
|
140 |
logging.info("Running default task...")
|
141 |
+
try:
|
142 |
+
# Simulate task processing
|
143 |
+
await asyncio.sleep(2) # Simulate time taken for the task
|
144 |
+
except Exception as e:
|
145 |
+
logging.error(f"Error during default task: {str(e)}")
|
146 |
|
147 |
async def pause(self):
|
148 |
"""Pause the current operation to accept user input."""
|
|
|
155 |
commands = self.extract_commands(user_input)
|
156 |
|
157 |
for command in commands:
|
158 |
+
try:
|
159 |
+
if command.startswith("generate tool"):
|
160 |
+
await self.generate_tool(command)
|
161 |
+
elif command.startswith("generate agent"):
|
162 |
+
await self.generate_agent(command)
|
163 |
+
except Exception as e:
|
164 |
+
logging.error(f"Error processing command '{command}': {str(e)}")
|
165 |
|
166 |
def extract_commands(self, user_input: str) -> List[str]:
|
167 |
"""Extract commands from user input."""
|
|
|
168 |
return user_input.split(';') # Assume commands are separated by semicolons
|
169 |
|
170 |
async def run_refinement_cycle(self, task: str) -> Dict[str, Any]:
|
171 |
"""Run a refinement cycle for the given task."""
|
172 |
+
try:
|
173 |
+
task_analysis = await self._analyze_task(task)
|
174 |
+
search_results = await self._web_search(task)
|
175 |
+
tools_built = await self._build_tools(task_analysis, search_results)
|
176 |
+
execution_results = await self._execute_tools(tools_built)
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
+
return {
|
179 |
+
"task_analysis": task_analysis,
|
180 |
+
"search_results": search_results,
|
181 |
+
"tools_built": tools_built,
|
182 |
+
"execution_results": execution_results,
|
183 |
+
}
|
184 |
+
except Exception as e:
|
185 |
+
logging.error(f"Error during refinement cycle: {str(e)}")
|
186 |
|
187 |
async def _analyze_task(self, task: str) -> Dict[str, Any]:
|
188 |
"""Analyze the task to determine requirements."""
|
|
|
221 |
"""Perform a web search for relevant approaches/methods."""
|
222 |
try:
|
223 |
response = requests.get(
|
224 |
+
os.getenv('API_URL', 'https://api.example.com/search'),
|
225 |
params={"q": query, "limit": 5}
|
226 |
)
|
227 |
response.raise_for_status()
|
|
|
550 |
return {
|
551 |
"test_cases": test_generation["result"],
|
552 |
"test_results": test_results["result"],
|
|
|
|
|
553 |
except Exception as e:
|
554 |
raise Exception(f"Testing stage failed: {str(e)}")
|
555 |
|
|
|
846 |
test_coverage: float = 0.0
|
847 |
security_score: str = "unknown"
|
848 |
performance_score: float = 0.0
|
849 |
+
metrics_analyzer: CodeMetricsAnalyzer = None
|
850 |
+
|
851 |
def __post_init__(self):
|
852 |
+
self.metrics_analyzer = CodeMetricsAnalyzer()
|
853 |
self.history = []
|
854 |
self.thresholds = {
|
855 |
"code_quality": 0.85,
|
|
|
1259 |
|
1260 |
if __name__ == "__main__":
|
1261 |
import streamlit as st
|
1262 |
+
main()
|