Skip to content

Commit 478d88d

Browse files
authored
Merge pull request #36 from vaisu-bhut/dd_agent
GenAi error fixed, AgentCore is ready
2 parents 78efbbb + 4558cf6 commit 478d88d

2 files changed

Lines changed: 7 additions & 48 deletions

File tree

services/security-agent/app/agents/nodes/security.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -276,48 +276,22 @@ async def security_check(state: AgentState) -> Dict[str, Any]:
276276
# Step 4: LLM Security Analysis (if enabled)
277277
llm_result = {}
278278
if settings.SECURITY_LLM_CHECK_ENABLED:
279-
logger.info("CRASH_DEBUG: Starting LLM Security Check setup")
280-
281279
# Reconstruct the chain manually as before
282280
try:
283-
logger.info("CRASH_DEBUG: About to import ChatPromptTemplate")
284281
from langchain_core.prompts import ChatPromptTemplate
285-
286-
logger.info("CRASH_DEBUG: ChatPromptTemplate imported successfully")
287-
288-
logger.info("CRASH_DEBUG: About to import JsonOutputParser")
289282
from langchain_core.output_parsers import JsonOutputParser
290283

291-
logger.info("CRASH_DEBUG: JsonOutputParser imported successfully")
292-
293-
logger.info("CRASH_DEBUG: About to create prompt template")
294284
prompt = ChatPromptTemplate.from_template(SECURITY_PROMPT)
295-
logger.info("CRASH_DEBUG: Prompt template created successfully")
296-
297-
logger.info("CRASH_DEBUG: About to call get_llm()")
298285
llm = get_llm()
299-
logger.info("CRASH_DEBUG: get_llm() returned successfully")
300-
301-
logger.info("CRASH_DEBUG: About to create output parser")
302286
parser = JsonOutputParser()
303-
logger.info("CRASH_DEBUG: Output parser created successfully")
304287

305-
logger.info("CRASH_DEBUG: About to create chain with pipe operator")
306288
chain = prompt | llm | parser
307-
logger.info("CRASH_DEBUG: LLM chain initialized successfully")
308289
except Exception as e:
309-
logger.error(f"CRASH_DEBUG: Failed to initialize LLM chain: {e}")
290+
logger.error(f"Failed to initialize LLM chain: {e}")
310291
raise
311292

312-
logger.info(
313-
"CRASH_DEBUG: Preparing LLM input",
314-
input_length=len(user_input),
315-
threshold=settings.SECURITY_LLM_CHECK_THRESHOLD,
316-
)
317-
318293
# Using current time for detailed timing
319294
llm_start = time.perf_counter()
320-
logger.info(f"CRASH_DEBUG: Invoking LLM chain... (Time: {llm_start})")
321295

322296
try:
323297
# Add a timeout to the LLM call if possible or just log around it
@@ -327,18 +301,13 @@ async def security_check(state: AgentState) -> Dict[str, Any]:
327301
"threshold": settings.SECURITY_LLM_CHECK_THRESHOLD,
328302
}
329303
)
330-
logger.info("CRASH_DEBUG: LLM chain returned successfully")
331304
except Exception as llm_exc:
332-
logger.error(f"CRASH_DEBUG: LLM chain raised exception: {llm_exc}")
305+
logger.error(f"LLM chain raised exception: {llm_exc}")
333306
# Depending on policy, you might want to block here or set a default score
334307
# For now, re-raise to be caught by the outer try/except
335308
raise
336309

337310
check_time_ms = (time.perf_counter() - llm_start) * 1000
338-
339-
logger.info(
340-
f"CRASH_DEBUG: LLM Security Check completed in {check_time_ms:.2f}ms"
341-
)
342311
metrics.record_stage_latency("llm_check", check_time_ms)
343312
metrics_builder.add_latency("llm_check", check_time_ms)
344313

services/security-agent/app/main.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,26 @@ async def lifespan(app: FastAPI):
1818

1919
app = FastAPI(title=settings.PROJECT_NAME, version=settings.VERSION, lifespan=lifespan)
2020

21-
print("DEBUG: Setting up telemetry...", flush=True)
2221
# Setup telemetry IMMEDIATELY
2322
setup_telemetry(app)
24-
print("DEBUG: Telemetry setup complete", flush=True)
2523

2624
# Initialize global logger after telemetry
27-
print("DEBUG: Initializing structlog...", flush=True)
25+
# Initialize global logger after telemetry
2826
logger = structlog.get_logger()
29-
print("DEBUG: Structlog initialized", flush=True)
3027

3128
# Import modules AFTER logging is configured
32-
print("DEBUG: Importing app.agents.graph...", flush=True)
29+
# Import modules AFTER logging is configured
3330
try:
3431
from app.agents.graph import agent_graph
35-
36-
print("DEBUG: Imported app.agents.graph successfully", flush=True)
3732
except Exception as e:
38-
print(f"DEBUG: Failed to import app.agents.graph: {e}", flush=True)
3933
import traceback
4034

4135
traceback.print_exc()
4236
raise
4337

44-
print("DEBUG: Importing schemas and metrics...", flush=True)
4538
from app.schemas.security import ChatRequest, ChatResponse
4639
from app.core.metrics import get_security_metrics
4740

48-
print("DEBUG: Imports completed successfully", flush=True)
49-
5041

5142
@app.get("/health")
5243
async def health_check():
@@ -65,7 +56,8 @@ async def chat(request: ChatRequest):
6556
"""
6657
import time
6758

68-
print(f"CRASH_DEBUG: Chat request endpoint entered at {time.time()}", flush=True)
59+
import time
60+
6961
logger.info(
7062
"Chat request received",
7163
client_ip=request.client_ip,
@@ -83,12 +75,10 @@ async def chat(request: ChatRequest):
8375
"metrics_data": None,
8476
}
8577

86-
print("CRASH_DEBUG: Invoking agent graph...", flush=True)
8778
try:
8879
result = await agent_graph.ainvoke(initial_state)
89-
print("CRASH_DEBUG: Agent graph returned successfully", flush=True)
9080
except Exception as e:
91-
print(f"CRASH_DEBUG: Agent graph failed: {e}", flush=True)
81+
logger.error(f"Agent graph execution failed: {e}")
9282
raise
9383

9484
if result.get("is_blocked"):

0 commit comments

Comments
 (0)