cryogenic22 commited on
Commit
4c2ee17
Β·
verified Β·
1 Parent(s): e2eb9f2

Update diagnostics.py

Browse files
Files changed (1) hide show
  1. diagnostics.py +39 -14
diagnostics.py CHANGED
@@ -1,6 +1,6 @@
1
  """
2
- Diagnostics module for the Pharmaceutical Analytics application.
3
- Contains functions to test LLM connectivity and agent functionality.
4
  """
5
 
6
  import streamlit as st
@@ -50,10 +50,9 @@ def test_claude_connectivity() -> Tuple[bool, str]:
50
  error_msg = f"Error testing Claude API: {str(e)}\n\n{traceback.format_exc()}"
51
  return False, error_msg
52
 
53
- def test_agent_functionality() -> Tuple[bool, Dict[str, Any]]:
54
  """
55
- Test basic agent functionality by initializing the Planning Agent
56
- and generating a simple analysis plan
57
 
58
  Returns:
59
  Tuple of (success_flag, results_dict)
@@ -68,10 +67,10 @@ def test_agent_functionality() -> Tuple[bool, Dict[str, Any]]:
68
  # Test Planning Agent import
69
  results["steps"].append({"step": "import", "status": "started"})
70
  try:
71
- from agents.planning_agent import PlanningAgent
72
  results["steps"].append({"step": "import", "status": "success"})
73
  except Exception as import_error:
74
- error_msg = f"Error importing PlanningAgent: {str(import_error)}\n\n{traceback.format_exc()}"
75
  results["errors"].append({"phase": "import", "error": error_msg})
76
  return False, results
77
 
@@ -158,20 +157,36 @@ def render_diagnostics_tab():
158
  st.error("❌ Claude API test failed")
159
  st.expander("Error Details", expanded=True).error(response)
160
 
161
- # Agent functionality test
162
- st.subheader("Agent Functionality Test")
163
- if st.button("Test Planning Agent"):
164
- with st.spinner("Testing Planning Agent..."):
165
- success, results = test_agent_functionality()
166
 
167
  if success:
168
- st.success("βœ… Planning Agent is working properly!")
169
  st.json(results["plan"])
170
  else:
171
- st.error("❌ Planning Agent test failed")
172
  for error in results["errors"]:
173
  st.expander(f"Error in {error['phase']} phase", expanded=True).error(error["error"])
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  # Database Connectivity
176
  st.subheader("Database Connectivity")
177
  if st.button("Test Database Connection"):
@@ -199,6 +214,16 @@ def render_diagnostics_tab():
199
  # Add guidance
200
  st.markdown("---")
201
  st.markdown("""
 
 
 
 
 
 
 
 
 
 
202
  ### Troubleshooting Tips
203
 
204
  1. If Claude test fails:
 
1
  """
2
+ Updated diagnostics module for the Pharmaceutical Analytics application.
3
+ Uses the simplified Planning Agent implementation.
4
  """
5
 
6
  import streamlit as st
 
50
  error_msg = f"Error testing Claude API: {str(e)}\n\n{traceback.format_exc()}"
51
  return False, error_msg
52
 
53
+ def test_simplified_agent() -> Tuple[bool, Dict[str, Any]]:
54
  """
55
+ Test the simplified Planning Agent functionality
 
56
 
57
  Returns:
58
  Tuple of (success_flag, results_dict)
 
67
  # Test Planning Agent import
68
  results["steps"].append({"step": "import", "status": "started"})
69
  try:
70
+ from simplified_planning_agent import PlanningAgent
71
  results["steps"].append({"step": "import", "status": "success"})
72
  except Exception as import_error:
73
+ error_msg = f"Error importing simplified PlanningAgent: {str(import_error)}\n\n{traceback.format_exc()}"
74
  results["errors"].append({"phase": "import", "error": error_msg})
75
  return False, results
76
 
 
157
  st.error("❌ Claude API test failed")
158
  st.expander("Error Details", expanded=True).error(response)
159
 
160
+ # Simplified Agent functionality test
161
+ st.subheader("Simplified Planning Agent Test")
162
+ if st.button("Test Simplified Planning Agent"):
163
+ with st.spinner("Testing Simplified Planning Agent..."):
164
+ success, results = test_simplified_agent()
165
 
166
  if success:
167
+ st.success("βœ… Simplified Planning Agent is working properly!")
168
  st.json(results["plan"])
169
  else:
170
+ st.error("❌ Simplified Planning Agent test failed")
171
  for error in results["errors"]:
172
  st.expander(f"Error in {error['phase']} phase", expanded=True).error(error["error"])
173
 
174
+ # Original Agent functionality test
175
+ st.subheader("Original Planning Agent Test (Likely to Fail)")
176
+ if st.button("Test Original Planning Agent"):
177
+ with st.spinner("Testing Original Planning Agent..."):
178
+ try:
179
+ from agents.planning_agent import PlanningAgent
180
+ planning_agent = PlanningAgent()
181
+ test_alert = "Sales of DrugX down 15% in Northeast region over past 30 days."
182
+ analysis_plan, plan_dict = planning_agent.create_analysis_plan(test_alert)
183
+
184
+ st.success("βœ… Original Planning Agent is working!")
185
+ st.json(plan_dict)
186
+ except Exception as e:
187
+ st.error("❌ Original Planning Agent test failed")
188
+ st.expander("Error Details", expanded=True).error(f"{str(e)}\n\n{traceback.format_exc()}")
189
+
190
  # Database Connectivity
191
  st.subheader("Database Connectivity")
192
  if st.button("Test Database Connection"):
 
214
  # Add guidance
215
  st.markdown("---")
216
  st.markdown("""
217
+ ### Using the Simplified Agent
218
+
219
+ The original Planning Agent implementation has issues with the LangChain prompt templates.
220
+ We've created a simplified version that uses direct API calls to Claude.
221
+
222
+ To use the simplified agent:
223
+
224
+ 1. Copy the `simplified_planning_agent.py` file to your project
225
+ 2. Update your workflow to import from `simplified_planning_agent` instead of `agents.planning_agent`
226
+
227
  ### Troubleshooting Tips
228
 
229
  1. If Claude test fails: