Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
agent.py
CHANGED
|
@@ -308,8 +308,13 @@ class CUGAAgent:
|
|
| 308 |
|
| 309 |
logger.info("Setting up CUGA agent...")
|
| 310 |
|
| 311 |
-
# Enable ActivityTracker
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
# Initialize tool provider (will load from registry)
|
| 315 |
self.tool_provider = CombinedToolProvider()
|
|
@@ -325,21 +330,16 @@ class CUGAAgent:
|
|
| 325 |
self.agent = CugaAgent(tool_provider=self.tool_provider)
|
| 326 |
logger.info("CUGA agent initialized")
|
| 327 |
|
| 328 |
-
# Load policies
|
| 329 |
if self.policies_enabled:
|
| 330 |
await self._load_policies()
|
| 331 |
else:
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
async def _load_policies(self):
|
| 335 |
-
"""Load policies from policies.json using CUGA SDK."""
|
| 336 |
-
policies_json = Path(__file__).parent / "policies" / "policies.json"
|
| 337 |
-
if not policies_json.exists():
|
| 338 |
-
logger.warning(f"policies.json not found: {policies_json}")
|
| 339 |
-
return
|
| 340 |
|
|
|
|
|
|
|
| 341 |
try:
|
| 342 |
-
# Clear any persisted policies first
|
| 343 |
existing = await self.agent.policies.list()
|
| 344 |
for policy in existing:
|
| 345 |
await self.agent.policies.delete(policy["id"])
|
|
@@ -348,6 +348,15 @@ class CUGAAgent:
|
|
| 348 |
except Exception as e:
|
| 349 |
logger.warning(f"Failed to clear policies: {e}")
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
try:
|
| 352 |
result = await self.agent.policies.load_from_json(
|
| 353 |
str(policies_json), clear_existing=True
|
|
|
|
| 308 |
|
| 309 |
logger.info("Setting up CUGA agent...")
|
| 310 |
|
| 311 |
+
# Enable ActivityTracker and set policy toggle via Dynaconf directly
|
| 312 |
+
# (env vars are only read on first import, so we must update settings at runtime)
|
| 313 |
+
settings.update({
|
| 314 |
+
"ADVANCED_FEATURES": {"TRACKER_ENABLED": True},
|
| 315 |
+
"POLICY": {"ENABLED": self.policies_enabled},
|
| 316 |
+
}, merge=True)
|
| 317 |
+
logger.info(f"Dynaconf POLICY.ENABLED set to {self.policies_enabled}")
|
| 318 |
|
| 319 |
# Initialize tool provider (will load from registry)
|
| 320 |
self.tool_provider = CombinedToolProvider()
|
|
|
|
| 330 |
self.agent = CugaAgent(tool_provider=self.tool_provider)
|
| 331 |
logger.info("CUGA agent initialized")
|
| 332 |
|
| 333 |
+
# Load or clear policies based on toggle
|
| 334 |
if self.policies_enabled:
|
| 335 |
await self._load_policies()
|
| 336 |
else:
|
| 337 |
+
await self._clear_policies()
|
| 338 |
+
logger.info("Policies disabled and cleared")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
+
async def _clear_policies(self):
|
| 341 |
+
"""Remove all persisted policies from the vector DB."""
|
| 342 |
try:
|
|
|
|
| 343 |
existing = await self.agent.policies.list()
|
| 344 |
for policy in existing:
|
| 345 |
await self.agent.policies.delete(policy["id"])
|
|
|
|
| 348 |
except Exception as e:
|
| 349 |
logger.warning(f"Failed to clear policies: {e}")
|
| 350 |
|
| 351 |
+
async def _load_policies(self):
|
| 352 |
+
"""Load policies from policies.json using CUGA SDK."""
|
| 353 |
+
policies_json = Path(__file__).parent / "policies" / "policies.json"
|
| 354 |
+
if not policies_json.exists():
|
| 355 |
+
logger.warning(f"policies.json not found: {policies_json}")
|
| 356 |
+
return
|
| 357 |
+
|
| 358 |
+
await self._clear_policies()
|
| 359 |
+
|
| 360 |
try:
|
| 361 |
result = await self.agent.policies.load_from_json(
|
| 362 |
str(policies_json), clear_existing=True
|