claude-mpm 4.1.4__py3-none-any.whl → 4.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- claude_mpm/VERSION +1 -1
- claude_mpm/cli/commands/tickets.py +365 -784
- claude_mpm/core/output_style_manager.py +24 -0
- claude_mpm/core/unified_agent_registry.py +46 -15
- claude_mpm/services/agents/deployment/agent_discovery_service.py +12 -3
- claude_mpm/services/agents/deployment/agent_lifecycle_manager.py +172 -233
- claude_mpm/services/agents/deployment/agent_lifecycle_manager_refactored.py +575 -0
- claude_mpm/services/agents/deployment/agent_operation_service.py +573 -0
- claude_mpm/services/agents/deployment/agent_record_service.py +419 -0
- claude_mpm/services/agents/deployment/agent_state_service.py +381 -0
- claude_mpm/services/agents/deployment/multi_source_deployment_service.py +4 -2
- claude_mpm/services/infrastructure/__init__.py +31 -5
- claude_mpm/services/infrastructure/monitoring/__init__.py +43 -0
- claude_mpm/services/infrastructure/monitoring/aggregator.py +437 -0
- claude_mpm/services/infrastructure/monitoring/base.py +130 -0
- claude_mpm/services/infrastructure/monitoring/legacy.py +203 -0
- claude_mpm/services/infrastructure/monitoring/network.py +218 -0
- claude_mpm/services/infrastructure/monitoring/process.py +342 -0
- claude_mpm/services/infrastructure/monitoring/resources.py +243 -0
- claude_mpm/services/infrastructure/monitoring/service.py +367 -0
- claude_mpm/services/infrastructure/monitoring.py +67 -1030
- claude_mpm/services/project/analyzer.py +13 -4
- claude_mpm/services/project/analyzer_refactored.py +450 -0
- claude_mpm/services/project/analyzer_v2.py +566 -0
- claude_mpm/services/project/architecture_analyzer.py +461 -0
- claude_mpm/services/project/dependency_analyzer.py +462 -0
- claude_mpm/services/project/language_analyzer.py +265 -0
- claude_mpm/services/project/metrics_collector.py +410 -0
- claude_mpm/services/ticket_manager.py +5 -1
- claude_mpm/services/ticket_services/__init__.py +26 -0
- claude_mpm/services/ticket_services/crud_service.py +328 -0
- claude_mpm/services/ticket_services/formatter_service.py +290 -0
- claude_mpm/services/ticket_services/search_service.py +324 -0
- claude_mpm/services/ticket_services/validation_service.py +303 -0
- claude_mpm/services/ticket_services/workflow_service.py +244 -0
- {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.5.dist-info}/METADATA +1 -1
- {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.5.dist-info}/RECORD +41 -17
- {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.5.dist-info}/WHEEL +0 -0
- {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.5.dist-info}/entry_points.txt +0 -0
- {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.5.dist-info}/licenses/LICENSE +0 -0
- {claude_mpm-4.1.4.dist-info → claude_mpm-4.1.5.dist-info}/top_level.txt +0 -0
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
|
|
3
1
|
#!/usr/bin/env python3
|
|
4
2
|
"""
|
|
5
|
-
Agent Lifecycle Manager - ISS-0118 Integration Service
|
|
6
|
-
|
|
3
|
+
Agent Lifecycle Manager - ISS-0118 Integration Service (Refactored)
|
|
4
|
+
===================================================================
|
|
7
5
|
|
|
8
6
|
Comprehensive agent lifecycle management integrating modification tracking,
|
|
9
7
|
persistence, and registry services for complete agent management across
|
|
10
8
|
the three-tier hierarchy.
|
|
11
9
|
|
|
10
|
+
This refactored version delegates responsibilities to specialized services:
|
|
11
|
+
- AgentStateService: State tracking and transitions
|
|
12
|
+
- AgentOperationService: CRUD operations
|
|
13
|
+
- AgentRecordService: Persistence and history
|
|
14
|
+
- LifecycleHealthChecker: Health monitoring
|
|
15
|
+
|
|
12
16
|
Key Features:
|
|
13
17
|
- Unified agent lifecycle management (create, modify, delete, restore)
|
|
14
18
|
- Integrated modification tracking and persistence
|
|
@@ -28,13 +32,10 @@ Created for ISS-0118: Agent Registry and Hierarchical Discovery System
|
|
|
28
32
|
|
|
29
33
|
import asyncio
|
|
30
34
|
import time
|
|
31
|
-
from
|
|
32
|
-
from datetime import datetime
|
|
33
|
-
from enum import Enum
|
|
35
|
+
from pathlib import Path
|
|
34
36
|
from typing import Any, Dict, List, Optional
|
|
35
37
|
|
|
36
38
|
from claude_mpm.core.base_service import BaseService
|
|
37
|
-
from claude_mpm.core.unified_paths import get_path_manager
|
|
38
39
|
from claude_mpm.models.agent_definition import AgentDefinition
|
|
39
40
|
from claude_mpm.services.agents.management import AgentManager
|
|
40
41
|
from claude_mpm.services.agents.memory import (
|
|
@@ -51,82 +52,41 @@ from claude_mpm.services.agents.registry.modification_tracker import (
|
|
|
51
52
|
ModificationType,
|
|
52
53
|
)
|
|
53
54
|
from claude_mpm.services.memory.cache.shared_prompt_cache import SharedPromptCache
|
|
54
|
-
from claude_mpm.utils.config_manager import ConfigurationManager
|
|
55
55
|
from claude_mpm.utils.path_operations import path_ops
|
|
56
56
|
|
|
57
|
+
# Import extracted services
|
|
58
|
+
from .agent_operation_service import (
|
|
59
|
+
AgentOperationService,
|
|
60
|
+
LifecycleOperation,
|
|
61
|
+
LifecycleOperationResult,
|
|
62
|
+
)
|
|
63
|
+
from .agent_record_service import AgentRecordService
|
|
64
|
+
from .agent_state_service import (
|
|
65
|
+
AgentLifecycleRecord,
|
|
66
|
+
AgentStateService,
|
|
67
|
+
LifecycleState,
|
|
68
|
+
)
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
REPLICATE = "replicate"
|
|
67
|
-
VALIDATE = "validate"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
class LifecycleState(Enum):
|
|
71
|
-
"""Agent lifecycle states."""
|
|
72
|
-
|
|
73
|
-
ACTIVE = "active"
|
|
74
|
-
MODIFIED = "modified"
|
|
75
|
-
DELETED = "deleted"
|
|
76
|
-
CONFLICTED = "conflicted"
|
|
77
|
-
MIGRATING = "migrating"
|
|
78
|
-
VALIDATING = "validating"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@dataclass
|
|
82
|
-
class AgentLifecycleRecord:
|
|
83
|
-
"""Complete lifecycle record for an agent."""
|
|
84
|
-
|
|
85
|
-
agent_name: str
|
|
86
|
-
current_state: LifecycleState
|
|
87
|
-
tier: ModificationTier
|
|
88
|
-
file_path: str
|
|
89
|
-
created_at: float
|
|
90
|
-
last_modified: float
|
|
91
|
-
version: str
|
|
92
|
-
modifications: List[str] = field(default_factory=list) # Modification IDs
|
|
93
|
-
persistence_operations: List[str] = field(default_factory=list) # Operation IDs
|
|
94
|
-
backup_paths: List[str] = field(default_factory=list)
|
|
95
|
-
validation_status: str = "valid"
|
|
96
|
-
validation_errors: List[str] = field(default_factory=list)
|
|
97
|
-
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
98
|
-
|
|
99
|
-
@property
|
|
100
|
-
def age_days(self) -> float:
|
|
101
|
-
"""Get age in days."""
|
|
102
|
-
return (time.time() - self.created_at) / (24 * 3600)
|
|
103
|
-
|
|
104
|
-
@property
|
|
105
|
-
def last_modified_datetime(self) -> datetime:
|
|
106
|
-
"""Get last modified as datetime."""
|
|
107
|
-
return datetime.fromtimestamp(self.last_modified)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
@dataclass
|
|
111
|
-
class LifecycleOperationResult:
|
|
112
|
-
"""Result of a lifecycle operation."""
|
|
113
|
-
|
|
114
|
-
operation: LifecycleOperation
|
|
115
|
-
agent_name: str
|
|
116
|
-
success: bool
|
|
117
|
-
duration_ms: float
|
|
118
|
-
error_message: Optional[str] = None
|
|
119
|
-
modification_id: Optional[str] = None
|
|
120
|
-
persistence_id: Optional[str] = None
|
|
121
|
-
cache_invalidated: bool = False
|
|
122
|
-
registry_updated: bool = False
|
|
123
|
-
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
70
|
+
# Re-export for backward compatibility
|
|
71
|
+
__all__ = [
|
|
72
|
+
"AgentLifecycleManager",
|
|
73
|
+
"AgentLifecycleRecord",
|
|
74
|
+
"LifecycleOperation",
|
|
75
|
+
"LifecycleOperationResult",
|
|
76
|
+
"LifecycleState",
|
|
77
|
+
]
|
|
124
78
|
|
|
125
79
|
|
|
126
80
|
class AgentLifecycleManager(BaseService):
|
|
127
81
|
"""
|
|
128
82
|
Agent Lifecycle Manager - Unified agent management across hierarchy tiers.
|
|
129
83
|
|
|
84
|
+
Refactored to use specialized services following SOLID principles:
|
|
85
|
+
- AgentStateService handles state tracking
|
|
86
|
+
- AgentOperationService handles CRUD operations
|
|
87
|
+
- AgentRecordService handles persistence
|
|
88
|
+
- LifecycleHealthChecker handles health monitoring
|
|
89
|
+
|
|
130
90
|
Features:
|
|
131
91
|
- Complete agent lifecycle management (CRUD operations)
|
|
132
92
|
- Integrated modification tracking and persistence
|
|
@@ -153,17 +113,20 @@ class AgentLifecycleManager(BaseService):
|
|
|
153
113
|
)
|
|
154
114
|
)
|
|
155
115
|
|
|
156
|
-
# Core services
|
|
116
|
+
# Core external services
|
|
157
117
|
self.shared_cache: Optional[SharedPromptCache] = None
|
|
158
118
|
self.agent_registry: Optional[AgentRegistry] = None
|
|
159
119
|
self.modification_tracker: Optional[AgentModificationTracker] = None
|
|
160
120
|
self.persistence_service: Optional[AgentPersistenceService] = None
|
|
161
121
|
self.agent_manager: Optional[AgentManager] = None
|
|
162
122
|
|
|
163
|
-
#
|
|
164
|
-
self.
|
|
165
|
-
self.
|
|
166
|
-
self.
|
|
123
|
+
# Extracted internal services
|
|
124
|
+
self.state_service = AgentStateService()
|
|
125
|
+
self.operation_service = AgentOperationService()
|
|
126
|
+
self.record_service = AgentRecordService()
|
|
127
|
+
|
|
128
|
+
# Backward compatibility - expose service data through properties
|
|
129
|
+
self._operation_lock = asyncio.Lock()
|
|
167
130
|
|
|
168
131
|
# Performance metrics
|
|
169
132
|
self.performance_metrics = {
|
|
@@ -174,13 +137,7 @@ class AgentLifecycleManager(BaseService):
|
|
|
174
137
|
"cache_hit_rate": 0.0,
|
|
175
138
|
}
|
|
176
139
|
|
|
177
|
-
|
|
178
|
-
self._operation_lock = asyncio.Lock()
|
|
179
|
-
|
|
180
|
-
# Configuration manager
|
|
181
|
-
self.config_mgr = ConfigurationManager(cache_enabled=True)
|
|
182
|
-
|
|
183
|
-
self.logger.info("AgentLifecycleManager initialized")
|
|
140
|
+
self.logger.info("AgentLifecycleManager initialized (refactored)")
|
|
184
141
|
|
|
185
142
|
async def _initialize(self) -> None:
|
|
186
143
|
"""Initialize the lifecycle manager."""
|
|
@@ -189,8 +146,18 @@ class AgentLifecycleManager(BaseService):
|
|
|
189
146
|
# Initialize core services
|
|
190
147
|
await self._initialize_core_services()
|
|
191
148
|
|
|
192
|
-
#
|
|
193
|
-
await self.
|
|
149
|
+
# Initialize extracted services
|
|
150
|
+
await self.state_service.start()
|
|
151
|
+
await self.operation_service.start()
|
|
152
|
+
await self.record_service.start()
|
|
153
|
+
|
|
154
|
+
# Load existing agent records into state service
|
|
155
|
+
records = await self.record_service.load_records()
|
|
156
|
+
self.state_service.agent_records = records
|
|
157
|
+
|
|
158
|
+
# Setup operation service dependencies
|
|
159
|
+
self.operation_service.agent_manager = self.agent_manager
|
|
160
|
+
self.operation_service.set_modification_tracker(self.modification_tracker)
|
|
194
161
|
|
|
195
162
|
# Start service integrations
|
|
196
163
|
await self._setup_service_integrations()
|
|
@@ -205,8 +172,14 @@ class AgentLifecycleManager(BaseService):
|
|
|
205
172
|
"""Cleanup lifecycle manager resources."""
|
|
206
173
|
self.logger.info("Cleaning up AgentLifecycleManager...")
|
|
207
174
|
|
|
208
|
-
# Save agent records
|
|
209
|
-
await self.
|
|
175
|
+
# Save agent records through record service
|
|
176
|
+
await self.record_service.save_records(self.state_service.agent_records)
|
|
177
|
+
await self.record_service.save_history(self.operation_service.operation_history)
|
|
178
|
+
|
|
179
|
+
# Stop extracted services
|
|
180
|
+
await self.state_service.stop()
|
|
181
|
+
await self.operation_service.stop()
|
|
182
|
+
await self.record_service.stop()
|
|
210
183
|
|
|
211
184
|
# Stop core services if we own them
|
|
212
185
|
await self._cleanup_core_services()
|
|
@@ -260,26 +233,20 @@ class AgentLifecycleManager(BaseService):
|
|
|
260
233
|
except Exception as e:
|
|
261
234
|
self.logger.warning(f"Failed to setup some service integrations: {e}")
|
|
262
235
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
get_path_manager().get_tracking_dir() / "lifecycle_records.json"
|
|
268
|
-
)
|
|
269
|
-
if path_ops.validate_exists(records_file):
|
|
270
|
-
data = self.config_mgr.load_json(records_file)
|
|
271
|
-
|
|
272
|
-
for agent_name, record_data in data.items():
|
|
273
|
-
record = AgentLifecycleRecord(**record_data)
|
|
274
|
-
# Convert string enum back to enum
|
|
275
|
-
record.current_state = LifecycleState(record_data["current_state"])
|
|
276
|
-
record.tier = ModificationTier(record_data["tier"])
|
|
277
|
-
self.agent_records[agent_name] = record
|
|
236
|
+
@property
|
|
237
|
+
def agent_records(self) -> Dict[str, AgentLifecycleRecord]:
|
|
238
|
+
"""Get agent records from state service (backward compatibility)."""
|
|
239
|
+
return self.state_service.agent_records
|
|
278
240
|
|
|
279
|
-
|
|
241
|
+
@property
|
|
242
|
+
def operation_history(self) -> List[LifecycleOperationResult]:
|
|
243
|
+
"""Get operation history from operation service (backward compatibility)."""
|
|
244
|
+
return self.operation_service.operation_history
|
|
280
245
|
|
|
281
|
-
|
|
282
|
-
|
|
246
|
+
@property
|
|
247
|
+
def active_operations(self) -> Dict[str, LifecycleOperation]:
|
|
248
|
+
"""Get active operations from operation service (backward compatibility)."""
|
|
249
|
+
return self.operation_service.active_operations
|
|
283
250
|
|
|
284
251
|
async def _save_agent_records(self) -> None:
|
|
285
252
|
"""Save agent lifecycle records to disk."""
|
|
@@ -377,141 +344,113 @@ class AgentLifecycleManager(BaseService):
|
|
|
377
344
|
"""
|
|
378
345
|
start_time = time.time()
|
|
379
346
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
success=False,
|
|
390
|
-
duration_ms=(time.time() - start_time) * 1000,
|
|
391
|
-
error_message="Agent already exists",
|
|
392
|
-
)
|
|
393
|
-
|
|
394
|
-
# Create agent definition
|
|
395
|
-
agent_def = await self._create_agent_definition(
|
|
396
|
-
agent_name, agent_content, tier, agent_type, **kwargs
|
|
397
|
-
)
|
|
398
|
-
|
|
399
|
-
# Determine location based on tier
|
|
400
|
-
location = (
|
|
401
|
-
"project" if tier == ModificationTier.PROJECT else "framework"
|
|
402
|
-
)
|
|
403
|
-
|
|
404
|
-
# Create agent using AgentManager (sync call in executor)
|
|
405
|
-
try:
|
|
406
|
-
if self.agent_manager:
|
|
407
|
-
file_path = await self._run_sync_in_executor(
|
|
408
|
-
self.agent_manager.create_agent,
|
|
409
|
-
agent_name,
|
|
410
|
-
agent_def,
|
|
411
|
-
location,
|
|
412
|
-
)
|
|
413
|
-
else:
|
|
414
|
-
# Fallback to direct file creation if AgentManager not available
|
|
415
|
-
file_path = await self._determine_agent_file_path(
|
|
416
|
-
agent_name, tier
|
|
417
|
-
)
|
|
418
|
-
path_ops.ensure_dir(file_path.parent)
|
|
419
|
-
path_ops.safe_write(file_path, agent_content)
|
|
420
|
-
except Exception as e:
|
|
421
|
-
self.logger.error(f"AgentManager failed to create agent: {e}")
|
|
422
|
-
# Fallback to direct file creation
|
|
423
|
-
file_path = await self._determine_agent_file_path(agent_name, tier)
|
|
424
|
-
path_ops.ensure_dir(file_path.parent)
|
|
425
|
-
path_ops.safe_write(file_path, agent_content)
|
|
426
|
-
|
|
427
|
-
# Track modification
|
|
428
|
-
modification = await self.modification_tracker.track_modification(
|
|
429
|
-
agent_name=agent_name,
|
|
430
|
-
modification_type=ModificationType.CREATE,
|
|
431
|
-
file_path=str(file_path),
|
|
432
|
-
tier=tier,
|
|
433
|
-
agent_type=agent_type,
|
|
434
|
-
**kwargs,
|
|
435
|
-
)
|
|
436
|
-
|
|
437
|
-
# Note: We don't use persistence_service for the actual write anymore
|
|
438
|
-
# since AgentManager handles that. We create a synthetic record for compatibility.
|
|
439
|
-
persistence_record = PersistenceRecord(
|
|
440
|
-
operation_id=f"create_{agent_name}_{time.time()}",
|
|
441
|
-
operation_type=PersistenceOperation.CREATE,
|
|
442
|
-
agent_name=agent_name,
|
|
443
|
-
source_tier=tier,
|
|
444
|
-
target_tier=tier,
|
|
445
|
-
strategy=self.default_persistence_strategy,
|
|
446
|
-
success=True,
|
|
447
|
-
timestamp=time.time(),
|
|
448
|
-
file_path=str(file_path),
|
|
449
|
-
)
|
|
450
|
-
|
|
451
|
-
# Create lifecycle record
|
|
452
|
-
lifecycle_record = AgentLifecycleRecord(
|
|
453
|
-
agent_name=agent_name,
|
|
454
|
-
current_state=LifecycleState.ACTIVE,
|
|
455
|
-
tier=tier,
|
|
456
|
-
file_path=str(file_path),
|
|
457
|
-
created_at=time.time(),
|
|
458
|
-
last_modified=time.time(),
|
|
459
|
-
version="1.0.0",
|
|
460
|
-
modifications=[modification.modification_id],
|
|
461
|
-
persistence_operations=[persistence_record.operation_id],
|
|
462
|
-
metadata={"agent_type": agent_type, **kwargs},
|
|
463
|
-
)
|
|
347
|
+
# Check if agent already exists
|
|
348
|
+
if self.state_service.get_record(agent_name):
|
|
349
|
+
return LifecycleOperationResult(
|
|
350
|
+
operation=LifecycleOperation.CREATE,
|
|
351
|
+
agent_name=agent_name,
|
|
352
|
+
success=False,
|
|
353
|
+
duration_ms=0,
|
|
354
|
+
error_message="Agent already exists",
|
|
355
|
+
)
|
|
464
356
|
|
|
465
|
-
|
|
357
|
+
# Create agent definition
|
|
358
|
+
agent_def = await self._create_agent_definition(
|
|
359
|
+
agent_name, agent_content, tier, agent_type, **kwargs
|
|
360
|
+
)
|
|
466
361
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
registry_updated = await self._update_registry(agent_name)
|
|
362
|
+
# Determine location based on tier
|
|
363
|
+
location = "project" if tier == ModificationTier.PROJECT else "framework"
|
|
470
364
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
cache_invalidated=cache_invalidated,
|
|
480
|
-
registry_updated=registry_updated,
|
|
481
|
-
metadata={"file_path": str(file_path)},
|
|
365
|
+
# Create agent using AgentManager (sync call in executor)
|
|
366
|
+
try:
|
|
367
|
+
if self.agent_manager:
|
|
368
|
+
file_path = await self._run_sync_in_executor(
|
|
369
|
+
self.agent_manager.create_agent,
|
|
370
|
+
agent_name,
|
|
371
|
+
agent_def,
|
|
372
|
+
location,
|
|
482
373
|
)
|
|
374
|
+
else:
|
|
375
|
+
# Fallback to direct file creation if AgentManager not available
|
|
376
|
+
file_path = await self._determine_agent_file_path(agent_name, tier)
|
|
377
|
+
path_ops.ensure_dir(file_path.parent)
|
|
378
|
+
path_ops.safe_write(file_path, agent_content)
|
|
379
|
+
except Exception as e:
|
|
380
|
+
self.logger.error(f"AgentManager failed to create agent: {e}")
|
|
381
|
+
# Fallback to direct file creation
|
|
382
|
+
file_path = await self._determine_agent_file_path(agent_name, tier)
|
|
383
|
+
path_ops.ensure_dir(file_path.parent)
|
|
384
|
+
path_ops.safe_write(file_path, agent_content)
|
|
385
|
+
|
|
386
|
+
# Track modification
|
|
387
|
+
modification = await self.modification_tracker.track_modification(
|
|
388
|
+
agent_name=agent_name,
|
|
389
|
+
modification_type=ModificationType.CREATE,
|
|
390
|
+
file_path=str(file_path),
|
|
391
|
+
tier=tier,
|
|
392
|
+
agent_type=agent_type,
|
|
393
|
+
**kwargs,
|
|
394
|
+
)
|
|
483
395
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
396
|
+
# Note: We don't use persistence_service for the actual write anymore
|
|
397
|
+
# since AgentManager handles that. We create a synthetic record for compatibility.
|
|
398
|
+
persistence_record = PersistenceRecord(
|
|
399
|
+
operation_id=f"create_{agent_name}_{time.time()}",
|
|
400
|
+
operation_type=PersistenceOperation.CREATE,
|
|
401
|
+
agent_name=agent_name,
|
|
402
|
+
source_tier=tier,
|
|
403
|
+
target_tier=tier,
|
|
404
|
+
strategy=self.default_persistence_strategy,
|
|
405
|
+
success=True,
|
|
406
|
+
timestamp=time.time(),
|
|
407
|
+
file_path=str(file_path),
|
|
408
|
+
)
|
|
490
409
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
410
|
+
# Create lifecycle record
|
|
411
|
+
lifecycle_record = AgentLifecycleRecord(
|
|
412
|
+
agent_name=agent_name,
|
|
413
|
+
current_state=LifecycleState.ACTIVE,
|
|
414
|
+
tier=tier,
|
|
415
|
+
file_path=str(file_path),
|
|
416
|
+
created_at=time.time(),
|
|
417
|
+
last_modified=time.time(),
|
|
418
|
+
version="1.0.0",
|
|
419
|
+
modifications=[modification.modification_id],
|
|
420
|
+
persistence_operations=[persistence_record.operation_id],
|
|
421
|
+
metadata={"agent_type": agent_type, **kwargs},
|
|
422
|
+
)
|
|
495
423
|
|
|
496
|
-
|
|
424
|
+
self.agent_records[agent_name] = lifecycle_record
|
|
425
|
+
|
|
426
|
+
# Invalidate cache and update registry
|
|
427
|
+
cache_invalidated = await self._invalidate_agent_cache(agent_name)
|
|
428
|
+
registry_updated = await self._update_registry(agent_name)
|
|
429
|
+
|
|
430
|
+
# Create result
|
|
431
|
+
result = LifecycleOperationResult(
|
|
432
|
+
operation=LifecycleOperation.CREATE,
|
|
433
|
+
agent_name=agent_name,
|
|
434
|
+
success=persistence_record.success,
|
|
435
|
+
duration_ms=(time.time() - start_time) * 1000,
|
|
436
|
+
modification_id=modification.modification_id,
|
|
437
|
+
persistence_id=persistence_record.operation_id,
|
|
438
|
+
cache_invalidated=cache_invalidated,
|
|
439
|
+
registry_updated=registry_updated,
|
|
440
|
+
metadata={"file_path": str(file_path)},
|
|
441
|
+
)
|
|
497
442
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
agent_name=agent_name,
|
|
502
|
-
success=False,
|
|
503
|
-
duration_ms=(time.time() - start_time) * 1000,
|
|
504
|
-
error_message=str(e),
|
|
505
|
-
)
|
|
443
|
+
if not persistence_record.success:
|
|
444
|
+
result.error_message = persistence_record.error_message
|
|
445
|
+
lifecycle_record.current_state = LifecycleState.CONFLICTED
|
|
506
446
|
|
|
507
|
-
|
|
508
|
-
|
|
447
|
+
# Update performance metrics
|
|
448
|
+
await self._update_performance_metrics(result)
|
|
509
449
|
|
|
510
|
-
|
|
511
|
-
|
|
450
|
+
self.operation_history.append(result)
|
|
451
|
+
self.logger.info(f"Created agent '{agent_name}' in {result.duration_ms:.1f}ms")
|
|
512
452
|
|
|
513
|
-
|
|
514
|
-
self.active_operations.pop(agent_name, None)
|
|
453
|
+
return result
|
|
515
454
|
|
|
516
455
|
async def update_agent(
|
|
517
456
|
self, agent_name: str, agent_content: str, **kwargs
|