devsu commited on
Commit
ffbefb9
·
1 Parent(s): 877bedf

Add debugging statements to app.py and tools.py for enhanced output tracking

Browse files

- Added detailed debug prints in process_email_interface to log HTML formatting and response details.
- Enhanced output logging in process_email_with_handoff_agent to track raw output, parsing steps, and final results.
- Improved reply content collection and formatting with additional debug information.

Files changed (2) hide show
  1. app.py +19 -0
  2. tools.py +55 -4
app.py CHANGED
@@ -100,9 +100,22 @@ def process_email_interface(api_key: str, email_text: str) -> str:
100
 
101
  # Format the reply text for HTML display
102
  formatted_reply = result['reply']
 
 
 
 
 
 
 
103
  if formatted_reply:
104
  # Convert \n to HTML line breaks for proper rendering in Gradio
105
  formatted_reply = formatted_reply.replace('\n', '<br>')
 
 
 
 
 
 
106
 
107
  # Format the successful response
108
  response = f"""
@@ -120,6 +133,12 @@ def process_email_interface(api_key: str, email_text: str) -> str:
120
  *Generated by Email Assistant Agent using OpenAI Agents SDK*
121
  """
122
 
 
 
 
 
 
 
123
  return response
124
 
125
 
 
100
 
101
  # Format the reply text for HTML display
102
  formatted_reply = result['reply']
103
+
104
+ print("=" * 80)
105
+ print("DEBUG: HTML FORMATTING IN APP.PY")
106
+ print("=" * 80)
107
+ print(f"Original reply from result: '{result['reply']}'")
108
+ print(f"Reply length: {len(result['reply'])} characters")
109
+
110
  if formatted_reply:
111
  # Convert \n to HTML line breaks for proper rendering in Gradio
112
  formatted_reply = formatted_reply.replace('\n', '<br>')
113
+ print(f"After HTML formatting: '{formatted_reply}'")
114
+ print(f"Formatted reply length: {len(formatted_reply)} characters")
115
+ else:
116
+ print("WARNING: Reply is empty or None!")
117
+
118
+ print("=" * 80)
119
 
120
  # Format the successful response
121
  response = f"""
 
133
  *Generated by Email Assistant Agent using OpenAI Agents SDK*
134
  """
135
 
136
+ print("DEBUG: FINAL RESPONSE FOR GRADIO")
137
+ print("=" * 80)
138
+ print(f"Final response length: {len(response)} characters")
139
+ print(f"Final response content:\n{response}")
140
+ print("=" * 80)
141
+
142
  return response
143
 
144
 
tools.py CHANGED
@@ -275,37 +275,88 @@ def process_email_with_handoff_agent(email_text: str, api_key: str) -> Dict[str,
275
  # The orchestrator agent will coordinate the workflow using tools and handoffs
276
  result = run_agent_in_thread(orchestrator_agent, email_text)
277
 
278
- print(f"Orchestrator agent raw output: {result}")
 
 
 
 
 
279
 
280
  # Parse the orchestrator agent's structured response
281
  lines = result.strip().split('\n')
282
 
 
 
 
 
 
 
 
283
  category = "Other"
284
  summary = "Unable to generate summary"
285
  reply = "Unable to generate reply"
286
 
287
  # Parse the orchestrator agent's structured response
288
- for line in lines:
 
 
 
289
  line = line.strip()
290
  if not line:
 
 
291
  continue
292
 
293
  # Look for structured output from orchestrator agent
294
  if line.startswith("Category:"):
295
  category = line.replace("Category:", "").strip()
 
 
296
  elif line.startswith("Summary:"):
297
  summary = line.replace("Summary:", "").strip()
 
 
298
  elif line.startswith("Reply:"):
299
- reply = line.replace("Reply:", "").strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
  # Format the reply text to render \n characters as actual line breaks
302
  if reply and reply != "Unable to generate reply":
 
 
 
 
303
  # Replace literal \n with actual line breaks
304
  reply = reply.replace('\\n', '\n')
 
 
305
  # Clean up any double line breaks and format properly
306
  reply = '\n'.join(line.rstrip() for line in reply.split('\n'))
 
 
307
 
308
- print(f"Parsed results - Category: {category}, Summary: {summary}, Reply: {reply}")
309
 
310
  return {
311
  'success': True,
 
275
  # The orchestrator agent will coordinate the workflow using tools and handoffs
276
  result = run_agent_in_thread(orchestrator_agent, email_text)
277
 
278
+ print("=" * 80)
279
+ print("DEBUG: RAW OUTPUT FROM ORCHESTRATOR AGENT")
280
+ print("=" * 80)
281
+ print(f"Raw output length: {len(result)} characters")
282
+ print(f"Raw output content:\n{result}")
283
+ print("=" * 80)
284
 
285
  # Parse the orchestrator agent's structured response
286
  lines = result.strip().split('\n')
287
 
288
+ print("DEBUG: PARSING STRUCTURED RESPONSE")
289
+ print("=" * 80)
290
+ print(f"Number of lines to parse: {len(lines)}")
291
+ for i, line in enumerate(lines):
292
+ print(f"Line {i+1}: '{line}'")
293
+ print("=" * 80)
294
+
295
  category = "Other"
296
  summary = "Unable to generate summary"
297
  reply = "Unable to generate reply"
298
 
299
  # Parse the orchestrator agent's structured response
300
+ current_field = None
301
+ reply_lines = []
302
+
303
+ for i, line in enumerate(lines):
304
  line = line.strip()
305
  if not line:
306
+ if current_field == "reply":
307
+ reply_lines.append("") # Preserve empty lines in reply
308
  continue
309
 
310
  # Look for structured output from orchestrator agent
311
  if line.startswith("Category:"):
312
  category = line.replace("Category:", "").strip()
313
+ print(f"DEBUG: Found Category: '{category}'")
314
+ current_field = "category"
315
  elif line.startswith("Summary:"):
316
  summary = line.replace("Summary:", "").strip()
317
+ print(f"DEBUG: Found Summary: '{summary}'")
318
+ current_field = "summary"
319
  elif line.startswith("Reply:"):
320
+ # Start collecting reply content
321
+ reply_content = line.replace("Reply:", "").strip()
322
+ reply_lines = [reply_content] if reply_content else []
323
+ current_field = "reply"
324
+ print(f"DEBUG: Started collecting Reply: '{reply_content}'")
325
+ elif current_field == "reply":
326
+ # Continue collecting reply content
327
+ reply_lines.append(line)
328
+ print(f"DEBUG: Added to Reply: '{line}'")
329
+
330
+ # Join all reply lines
331
+ if reply_lines:
332
+ reply = '\n'.join(reply_lines)
333
+ print(f"DEBUG: Final Reply assembled: '{reply}'")
334
+ else:
335
+ reply = "Unable to generate reply"
336
+
337
+ print("DEBUG: PARSING RESULTS")
338
+ print("=" * 80)
339
+ print(f"Category: '{category}' (length: {len(category)})")
340
+ print(f"Summary: '{summary}' (length: {len(summary)})")
341
+ print(f"Reply: '{reply}' (length: {len(reply)})")
342
+ print("=" * 80)
343
 
344
  # Format the reply text to render \n characters as actual line breaks
345
  if reply and reply != "Unable to generate reply":
346
+ print("DEBUG: FORMATTING REPLY TEXT")
347
+ print("=" * 80)
348
+ print(f"Original reply: '{reply}'")
349
+
350
  # Replace literal \n with actual line breaks
351
  reply = reply.replace('\\n', '\n')
352
+ print(f"After \\n replacement: '{reply}'")
353
+
354
  # Clean up any double line breaks and format properly
355
  reply = '\n'.join(line.rstrip() for line in reply.split('\n'))
356
+ print(f"After formatting: '{reply}'")
357
+ print("=" * 80)
358
 
359
+ print(f"Final parsed results - Category: {category}, Summary: {summary}, Reply: {reply}")
360
 
361
  return {
362
  'success': True,