Skip to content

Commit bcf461a

Browse files
committed
feat: fixed error checking logic for json
1 parent 354b65a commit bcf461a

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

agentic_rag/gradio_app.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def test_a2a_health() -> str:
343343
"""Test A2A health check"""
344344
try:
345345
response = a2a_client.health_check()
346-
if "error" in response:
346+
if response.get("error"):
347347
return f"❌ Health Check Failed: {response['error']}"
348348
else:
349349
return f"✅ Health Check Passed: {json.dumps(response, indent=2)}"
@@ -354,7 +354,7 @@ def test_a2a_agent_card() -> str:
354354
"""Test A2A agent card retrieval"""
355355
try:
356356
response = a2a_client.get_agent_card()
357-
if "error" in response:
357+
if response.get("error"):
358358
return f"❌ Agent Card Failed: {response['error']}"
359359
else:
360360
return f"✅ Agent Card Retrieved: {json.dumps(response, indent=2)}"
@@ -384,7 +384,7 @@ def test_a2a_document_query(query: str, collection: str, use_cot: bool) -> str:
384384
f"query-{int(time.time())}"
385385
)
386386

387-
if "error" in response:
387+
if response.get("error"):
388388
return f"❌ Document Query Failed: {json.dumps(response['error'], indent=2)}"
389389
else:
390390
result = response.get("result", {})
@@ -430,7 +430,7 @@ def test_a2a_task_create(task_type: str, task_params: str) -> str:
430430
task_id
431431
)
432432

433-
if "error" in response:
433+
if response.get("error"):
434434
return f"❌ Task Creation Failed: {json.dumps(response['error'], indent=2)}"
435435
else:
436436
result = response.get("result", {})
@@ -458,7 +458,7 @@ def test_a2a_task_status(task_id: str) -> str:
458458
f"status-{int(time.time())}"
459459
)
460460

461-
if "error" in response:
461+
if response.get("error"):
462462
return f"❌ Task Status Failed: {json.dumps(response['error'], indent=2)}"
463463
else:
464464
result = response.get("result", {})
@@ -475,7 +475,7 @@ def test_a2a_agent_discover(capability: str) -> str:
475475
f"discover-{int(time.time())}"
476476
)
477477

478-
if "error" in response:
478+
if response.get("error"):
479479
return f"❌ Agent Discovery Failed: {json.dumps(response['error'], indent=2)}"
480480
else:
481481
result = response.get("result", {})
@@ -522,7 +522,7 @@ def refresh_a2a_tasks() -> str:
522522
f"refresh-{int(time.time())}"
523523
)
524524

525-
if "error" not in status_response:
525+
if not status_response.get("error"):
526526
result = status_response.get("result", {})
527527
a2a_tasks[task_id]["status"] = result.get("status", "unknown")
528528
response_text += f"✅ {task_id}: {result.get('status', 'unknown')}\n"
@@ -584,9 +584,16 @@ def a2a_chat(message: str, history: List[List[str]], agent_type: str, use_cot: b
584584
f"chat-{int(time.time())}"
585585
)
586586

587-
if "error" in response:
587+
# Print full response for debugging
588+
print("\n📥 A2A Response Received:")
589+
print("-" * 50)
590+
print(json.dumps(response, indent=2))
591+
print("-" * 50 + "\n")
592+
593+
# Check if there's an actual error (not just null/None)
594+
if response.get("error"):
588595
error_msg = f"A2A Error: {json.dumps(response['error'], indent=2)}"
589-
print(f"A2A Error: {error_msg}")
596+
print(f"A2A Error detected: {error_msg}")
590597
history.append([message, error_msg])
591598
return history
592599

@@ -597,6 +604,13 @@ def a2a_chat(message: str, history: List[List[str]], agent_type: str, use_cot: b
597604
reasoning_steps = result.get("reasoning_steps", [])
598605
context = result.get("context", [])
599606

607+
print("📊 Extracted Response Data:")
608+
print(f" - Answer length: {len(answer)} chars")
609+
print(f" - Sources count: {len(sources)}")
610+
print(f" - Reasoning steps: {len(reasoning_steps)}")
611+
print(f" - Context chunks: {len(context)}")
612+
print()
613+
600614
# Format response similar to standard chat interface
601615
if use_cot and reasoning_steps:
602616
formatted_response = "🤔 Let me think about this step by step:\n\n"
@@ -663,7 +677,8 @@ def a2a_chat(message: str, history: List[List[str]], agent_type: str, use_cot: b
663677
history.append([message, formatted_response])
664678

665679
print("\n" + "="*50)
666-
print("A2A Response complete")
680+
print("✅ A2A Response complete")
681+
print(f"📝 Added to history - Response length: {len(formatted_response)} chars")
667682
print("="*50 + "\n")
668683

669684
return history

0 commit comments

Comments
 (0)