Skip to content

Commit f73934a

Browse files
committed
refactor: rename misleading LangGraphValidationAgent to AnsibleLintValidator
- Rename class from LangGraphValidationAgent to AnsibleLintValidator - Rename file from lg_validation_agent.py to ansible_lint_validator.py - Remove misleading 'agent' terminology from CLI tool wrapper - Update all imports and references to use honest naming - Remove unused traceback import - Change 'agentic' to 'tool_based' in metadata - Update log messages to reflect CLI tool wrapper nature - Ensure naming accurately reflects simple subprocess-based validation
1 parent 2339628 commit f73934a

3 files changed

Lines changed: 63 additions & 64 deletions

File tree

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import os
22
import tempfile
33
import subprocess
4-
import traceback
54
import json
65
import logging
76
import time
87
import uuid
98
from typing import Optional, Dict, Any, Generator, List
109
import asyncio
1110

12-
logger = logging.getLogger("LangGraphValidationAgent")
11+
logger = logging.getLogger("AnsibleLintValidator")
1312

14-
class LangGraphValidationAgent:
13+
class AnsibleLintValidator:
1514
"""
16-
Simplified LangGraph-based ValidationAgent that provides the same interface as ValidationAgent.
15+
Simple CLI-based validator that wraps ansible-lint tool.
1716
18-
This wraps the lg.py functionality and integrates it into the main app's agent registry.
19-
Uses a simplified approach to avoid complex import issues.
17+
This provides the same interface as ValidationAgent but uses direct subprocess calls
18+
to ansible-lint CLI tool instead of AI agent calls.
2019
"""
2120

2221
def __init__(
@@ -38,8 +37,8 @@ def __init__(
3837
self.timeout = timeout
3938
self.default_profile = "basic"
4039

41-
logger.info(f"🔧 LangGraphValidationAgent initialized")
42-
logger.info(f"🔧 Agent ID: {agent_id}")
40+
logger.info(f"🔧 AnsibleLintValidator initialized")
41+
logger.info(f"🔧 Validator ID: {agent_id}")
4342
logger.info(f"🔧 Session ID: {session_id}")
4443

4544
def _run_ansible_lint_subprocess(self, playbook_code: str) -> dict:
@@ -155,16 +154,16 @@ async def validate_playbook(
155154
correlation_id: Optional[str] = None
156155
) -> Dict[str, Any]:
157156
"""
158-
Validate an Ansible playbook using simplified LangGraph approach.
157+
Validate an Ansible playbook using direct ansible-lint CLI calls.
159158
"""
160-
correlation_id = correlation_id or f"lg-val-{uuid.uuid4().hex[:8]}"
159+
correlation_id = correlation_id or f"ansible-lint-val-{uuid.uuid4().hex[:8]}"
161160
start_time = time.monotonic()
162161
profile = profile or self.default_profile
163162

164-
logger.info(f"[{correlation_id}] Starting LangGraph playbook validation with profile: {profile}")
163+
logger.info(f"[{correlation_id}] Starting ansible-lint CLI validation with profile: {profile}")
165164

166165
try:
167-
# Run the validation (simplified LangGraph approach)
166+
# Run the validation using direct ansible-lint CLI
168167
lint_result = self._run_ansible_lint_subprocess(playbook_content)
169168

170169
total_time = time.monotonic() - start_time
@@ -193,7 +192,7 @@ async def validate_playbook(
193192
"tool_execution_steps": 1,
194193
"agent_steps": 1,
195194
"events_processed": 1,
196-
"agent_pattern": "langgraph_with_ansible_lint",
195+
"validator_pattern": "cli_tool_wrapper",
197196
"json_extracted": True,
198197
"tool_names_called": ["ansible_lint_tool"],
199198
"detailed_analysis": "LangGraph execution",
@@ -203,7 +202,7 @@ async def validate_playbook(
203202
"agent_id": self.agent_id,
204203
"session_id": self.session_id,
205204
"correlation_id": correlation_id,
206-
"method_used": "langgraph_validation",
205+
"method_used": "cli_validation",
207206
"analysis_time_seconds": round(total_time, 3),
208207
"registry_agent_id": self.agent_id,
209208
"registry_session_id": self.session_id
@@ -213,35 +212,35 @@ async def validate_playbook(
213212
"elapsed_time": round(total_time, 3)
214213
}
215214

216-
logger.info(f" LangGraph validation completed successfully in {total_time:.3f}s")
215+
logger.info(f" Ansible-lint CLI validation completed successfully in {total_time:.3f}s")
217216
return result
218217

219218
except Exception as e:
220-
logger.error(f"❌ LangGraph validation error: {e}")
221-
return self._create_error_response(f"LangGraph validation failed: {str(e)}")
219+
logger.error(f"❌ Ansible-lint CLI validation error: {e}")
220+
return self._create_error_response(f"Ansible-lint CLI validation failed: {str(e)}")
222221

223222
def validate_playbook_stream(
224223
self, playbook_content: str, profile: Optional[str] = None
225224
) -> Generator[str, None, None]:
226225
"""
227226
Streams playbook validation results as SSE (Server-Sent Events).
228-
Uses LangGraph validation.
227+
Uses direct ansible-lint CLI calls.
229228
"""
230229
t0 = time.monotonic()
231230
profile = profile or self.default_profile
232-
correlation_id = f"lg-stream-{uuid.uuid4().hex[:8]}"
231+
correlation_id = f"ansible-lint-stream-{uuid.uuid4().hex[:8]}"
233232

234-
logger.info(f"[{correlation_id}] Starting LangGraph streaming validation with profile: {profile}")
233+
logger.info(f"[{correlation_id}] Starting ansible-lint CLI streaming validation with profile: {profile}")
235234

236235
try:
237-
# Run the LangGraph validation
236+
# Run the ansible-lint CLI validation
238237
result = asyncio.run(self.validate_playbook(playbook_content, profile, correlation_id))
239238

240239
# Stream the result
241240
yield f"data: {json.dumps({'type': 'result', 'data': result, 'elapsed_time': round(time.monotonic() - t0, 2)})}\n\n"
242241

243242
except Exception as e:
244-
logger.error(f"[{correlation_id}] LangGraph streaming validation error: {e}")
243+
logger.error(f"[{correlation_id}] Ansible-lint CLI streaming validation error: {e}")
245244
yield f"data: {json.dumps({'type': 'error', 'error': str(e), 'elapsed_time': round(time.monotonic() - t0, 2)})}\n\n"
246245

247246
# End event
@@ -254,13 +253,13 @@ async def validate_multiple_files(
254253
correlation_id: Optional[str] = None
255254
) -> Dict[str, Any]:
256255
"""
257-
Validate multiple Ansible playbook files using LangGraph approach.
256+
Validate multiple Ansible playbook files using direct ansible-lint CLI calls.
258257
"""
259-
correlation_id = correlation_id or f"lg-multi-{uuid.uuid4().hex[:8]}"
258+
correlation_id = correlation_id or f"ansible-lint-multi-{uuid.uuid4().hex[:8]}"
260259
start_time = time.monotonic()
261260
profile = profile or self.default_profile
262261

263-
logger.info(f"[{correlation_id}] Starting LangGraph multiple file validation with profile: {profile}")
262+
logger.info(f"[{correlation_id}] Starting ansible-lint CLI multiple file validation with profile: {profile}")
264263

265264
results = {}
266265
total_issues = 0
@@ -294,10 +293,10 @@ async def validate_multiple_files(
294293
"correlation_id": correlation_id,
295294
"elapsed_time": round(time.monotonic() - start_time, 2),
296295
"profile": profile,
297-
"agentic": True,
296+
"tool_based": True,
298297
}
299298

300-
logger.info(f"[{correlation_id}] LangGraph multiple file validation completed: {total_passed}/{len(files)} files passed")
299+
logger.info(f"[{correlation_id}] Ansible-lint CLI multiple file validation completed: {total_passed}/{len(files)} files passed")
301300
return overall_result
302301

303302
async def validate_syntax(
@@ -306,12 +305,12 @@ async def validate_syntax(
306305
correlation_id: Optional[str] = None
307306
) -> Dict[str, Any]:
308307
"""
309-
Quick syntax validation of an Ansible playbook using LangGraph.
308+
Quick syntax validation of an Ansible playbook using direct ansible-lint CLI calls.
310309
"""
311-
correlation_id = correlation_id or f"lg-syntax-{uuid.uuid4().hex[:8]}"
310+
correlation_id = correlation_id or f"ansible-lint-syntax-{uuid.uuid4().hex[:8]}"
312311
start_time = time.monotonic()
313312

314-
logger.info(f"[{correlation_id}] Starting LangGraph syntax validation")
313+
logger.info(f"[{correlation_id}] Starting ansible-lint CLI syntax validation")
315314

316315
try:
317316
# Use the same validation logic but with basic profile
@@ -327,16 +326,16 @@ async def validate_syntax(
327326
"session_id": self.session_id,
328327
"correlation_id": correlation_id,
329328
"elapsed_time": round(time.monotonic() - start_time, 3),
330-
"agentic": True,
329+
"tool_based": True,
331330
"tool_called": True,
332-
"method_used": "langgraph_validation"
331+
"method_used": "cli_validation"
333332
}
334333

335-
logger.info(f" LangGraph syntax validation completed: {'valid' if syntax_result['syntax_valid'] else 'invalid'}")
334+
logger.info(f" Ansible-lint CLI syntax validation completed: {'valid' if syntax_result['syntax_valid'] else 'invalid'}")
336335
return syntax_result
337336

338337
except Exception as e:
339-
logger.error(f"[{correlation_id}] LangGraph syntax validation failed: {e}")
338+
logger.error(f"[{correlation_id}] Ansible-lint CLI syntax validation failed: {e}")
340339
return {
341340
"syntax_valid": False,
342341
"issues": [],
@@ -346,7 +345,7 @@ async def validate_syntax(
346345
"session_id": self.session_id,
347346
"correlation_id": correlation_id,
348347
"elapsed_time": round(time.monotonic() - start_time, 3),
349-
"agentic": True,
348+
"tool_based": True,
350349
"error": str(e),
351350
}
352351

@@ -356,12 +355,12 @@ async def production_validate(
356355
correlation_id: Optional[str] = None
357356
) -> Dict[str, Any]:
358357
"""
359-
Production-ready validation with strict profile using LangGraph approach.
358+
Production-ready validation with strict profile using direct ansible-lint CLI calls.
360359
"""
361-
correlation_id = correlation_id or f"lg-prod-{uuid.uuid4().hex[:8]}"
360+
correlation_id = correlation_id or f"ansible-lint-prod-{uuid.uuid4().hex[:8]}"
362361
start_time = time.monotonic()
363362

364-
logger.info(f"[{correlation_id}] Starting LangGraph production validation")
363+
logger.info(f"[{correlation_id}] Starting ansible-lint CLI production validation")
365364

366365
try:
367366
# Use the same validation logic but with production profile
@@ -371,15 +370,15 @@ async def production_validate(
371370
result.update({
372371
"production_ready": result.get("validation_passed", False),
373372
"validation_level": "production",
374-
"agentic": True,
373+
"tool_based": True,
375374
"tool_called": True,
376375
})
377376

378-
logger.info(f"[{correlation_id}] LangGraph production validation completed: {'ready' if result['production_ready'] else 'not ready'}")
377+
logger.info(f"[{correlation_id}] Ansible-lint CLI production validation completed: {'ready' if result['production_ready'] else 'not ready'}")
379378
return result
380379

381380
except Exception as e:
382-
logger.error(f"[{correlation_id}] LangGraph production validation failed: {e}")
381+
logger.error(f"[{correlation_id}] Ansible-lint CLI production validation failed: {e}")
383382
return {
384383
"production_ready": False,
385384
"validation_level": "production",
@@ -391,7 +390,7 @@ async def production_validate(
391390
"validation_passed": False,
392391
"issues": [],
393392
"issues_count": 0,
394-
"agentic": True,
393+
"tool_based": True,
395394
"error": str(e),
396395
}
397396

@@ -401,7 +400,7 @@ def get_supported_profiles(self) -> List[str]:
401400

402401
async def health_check(self) -> bool:
403402
"""
404-
Perform a basic health check using LangGraph validation.
403+
Perform a basic health check using ansible-lint CLI validation.
405404
"""
406405
try:
407406
test_playbook = """---
@@ -416,36 +415,36 @@ async def health_check(self) -> bool:
416415
result = await self.validate_playbook(test_playbook, "basic", "health-check")
417416

418417
# If we get here, the validation worked
419-
logger.info(" LangGraph health check completed successfully")
418+
logger.info(" Ansible-lint CLI health check completed successfully")
420419
return True
421420

422421
except Exception as e:
423-
logger.error(f" LangGraph health check failed: {e}")
422+
logger.error(f" Ansible-lint CLI health check failed: {e}")
424423
return False
425424

426425
def get_status(self) -> Dict[str, Any]:
427426
"""Get agent status information."""
428427
return {
429-
"agent_id": self.agent_id,
428+
"validator_id": self.agent_id,
430429
"session_id": self.session_id,
431-
"client_base_url": "langgraph-local",
430+
"client_base_url": "cli-local",
432431
"timeout": self.timeout,
433432
"status": "ready",
434-
"approach": "langgraph_validation",
435-
"methods_available": ["langgraph_validation"],
433+
"approach": "cli_tool_wrapper",
434+
"methods_available": ["cli_validation"],
436435
"capabilities": [
437-
"langgraph_tool_calling",
436+
"cli_tool_calling",
438437
"json_response_parsing",
439438
"streaming_validation",
440439
"ansible_lint_integration"
441440
],
442441
"tools_registered": [
443442
"ansible_lint_tool"
444443
],
445-
"agent_pattern": "langgraph_with_ansible_lint",
446-
"registry_agent_id": self.agent_id,
444+
"validator_pattern": "cli_tool_wrapper",
445+
"registry_validator_id": self.agent_id,
447446
"registry_session_id": self.session_id,
448-
"langgraph_managed": True
447+
"cli_managed": True
449448
}
450449

451450
def _create_error_response(self, message: str) -> Dict[str, Any]:

main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from agents.context_agent.context_agent import ContextAgent
1919
from agents.code_generator.code_generator_agent import CodeGeneratorAgent
2020
from agents.validate.validate_agent import ValidationAgent
21-
from agents.validate.lg_validation_agent import LangGraphValidationAgent
21+
from agents.validate.ansible_lint_validator import AnsibleLintValidator
2222
from routes.files import set_upload_dir
2323
from routes.vector_db import set_vector_db_client
2424

@@ -403,8 +403,8 @@ async def lifespan(app: FastAPI):
403403
else:
404404
logger.warning("generate agent not found in config!")
405405

406-
# --- LangGraph Validation Agent Setup (Default) ---
407-
logger.info("Setting up LangGraph Validation Agent as default...")
406+
# --- Ansible-lint CLI Validation Agent Setup (Default) ---
407+
logger.info("Setting up Ansible-lint CLI Validation Agent as default...")
408408

409409
# Get validation instructions from config if available
410410
validation_instructions = "Validate Ansible playbooks using ansible-lint"
@@ -418,20 +418,20 @@ async def lifespan(app: FastAPI):
418418
logger.warning(f"Could not get validation instructions from config: {e}")
419419

420420
try:
421-
# Create LangGraph validation agent as default
422-
app.state.validation_agent = LangGraphValidationAgent(
421+
# Create Ansible-lint CLI validator as default
422+
app.state.validation_agent = AnsibleLintValidator(
423423
client=client,
424-
agent_id="langgraph-validation",
425-
session_id="langgraph-session",
424+
agent_id="ansible-lint-validation",
425+
session_id="ansible-lint-session",
426426
instruction=validation_instructions,
427427
config_loader=config_loader,
428428
verbose_logging=True,
429429
timeout=120
430430
)
431-
logger.info("LangGraph Validation Agent ready (default)")
431+
logger.info("Ansible-lint CLI Validator ready (default)")
432432
except Exception as e:
433-
logger.error(f"Failed to initialize LangGraph Validation Agent: {e}")
434-
# Fallback to original ValidationAgent if LangGraph fails
433+
logger.error(f"Failed to initialize Ansible-lint CLI Validator: {e}")
434+
# Fallback to original ValidationAgent if CLI agent fails
435435
logger.warning("Falling back to original ValidationAgent...")
436436
try:
437437
if "validate" in registered_agents:

routes/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import datetime
99

1010
from agents.validate.validate_agent import ValidationAgent
11-
from agents.validate.lg_validation_agent import LangGraphValidationAgent
11+
from agents.validate.ansible_lint_validator import AnsibleLintValidator
1212

1313
router = APIRouter(prefix="/validate", tags=["validation"])
1414
logger = logging.getLogger("validation_routes")

0 commit comments

Comments
 (0)