Abid Ali Awan commited on
Commit
23ecbc0
ยท
1 Parent(s): 049b708

Refactor UIHandler to enhance collapsible message formatting and improve clarity in tool execution and parameter extraction updates. Update RegRadarAgent report sections for better organization and remove unnecessary markdown artifacts.

Browse files
Files changed (3) hide show
  1. agents/reg_radar.py +4 -12
  2. agents/ui_handler.py +53 -48
  3. images/avatar.png +2 -2
agents/reg_radar.py CHANGED
@@ -178,26 +178,18 @@ class RegRadarAgent:
178
 
179
  ## ๐Ÿ›๏ธ Executive Summary
180
  (2-3 sentences overview)
181
-
182
- ---
183
-
184
  ## ๐Ÿ” Key Findings
185
  โ€ข Finding 1
186
  โ€ข Finding 2
187
  โ€ข Finding 3
188
-
189
- ---
190
-
191
  ## ๐Ÿ›ก๏ธ Compliance Requirements
192
  - List main requirements with priorities
193
-
194
- ---
195
-
196
  ## โœ… Action Items
197
  - Specific actions with suggested timelines
198
-
199
- ---
200
-
201
  ## ๐Ÿ“š Resources
202
  - Links and references
203
 
 
178
 
179
  ## ๐Ÿ›๏ธ Executive Summary
180
  (2-3 sentences overview)
181
+
 
 
182
  ## ๐Ÿ” Key Findings
183
  โ€ข Finding 1
184
  โ€ข Finding 2
185
  โ€ข Finding 3
186
+
 
 
187
  ## ๐Ÿ›ก๏ธ Compliance Requirements
188
  - List main requirements with priorities
189
+
 
 
190
  ## โœ… Action Items
191
  - Specific actions with suggested timelines
192
+
 
 
193
  ## ๐Ÿ“š Resources
194
  - Links and references
195
 
agents/ui_handler.py CHANGED
@@ -70,31 +70,46 @@ class UIHandler:
70
  # Show tool detection
71
  tool_key, tool_name = self.agent.determine_intended_tool(message)
72
 
73
- # Initial processing message with tool info
74
- status_msg = f"๐Ÿ” Using **{tool_name}** to analyze your query (estimated 10-20 seconds)..."
75
- history.append(ChatMessage(role="assistant", content=status_msg))
 
 
 
 
 
 
 
 
76
  yield history, "", gr.update(interactive=False), user_id_state
77
 
78
  # Extract parameters and process query
79
  params = self.agent.extract_parameters(message)
80
 
81
- # Clear status and show parameter extraction
82
  history.pop()
 
 
 
 
 
 
 
 
 
83
 
84
- # Show tool execution steps
85
  tool_status = f"""
86
- ๐Ÿ› ๏ธ **Tool Execution Status**
87
-
88
- ๐Ÿ“ **Parameters Extracted:**
89
- - Industry: {params["industry"]}
90
- - Region: {params["region"]}
91
- - Keywords: {params["keywords"]}
92
-
93
- ๐Ÿ”„ **Executing {tool_name}...**
94
-
95
  โณ _This process may take 40-90 seconds depending on the number of webpages being crawled._
96
  """
97
- history.append(ChatMessage(role="assistant", content=tool_status))
 
 
 
 
 
 
98
  yield history, "", gr.update(interactive=False), user_id_state
99
 
100
  # Process the regulatory query
@@ -102,27 +117,31 @@ class UIHandler:
102
  crawl_results = results["crawl_results"]
103
  memory_results = results["memory_results"]
104
 
105
- # Update with results count
106
- history[-1] = ChatMessage(
107
- role="assistant",
108
- content=tool_status
109
- + f"\n\nโœ… **Found {crawl_results['total_found']} regulatory updates**",
110
- )
111
- yield history, "", gr.update(interactive=False), user_id_state
112
-
113
  # Show collapsible raw results
114
  if crawl_results["results"]:
115
  collapsible_results = self._format_crawl_results(crawl_results["results"])
116
- history.append(ChatMessage(role="assistant", content=collapsible_results))
 
 
 
 
 
 
117
  yield history, "", gr.update(interactive=False), user_id_state
118
 
119
  # Display memory results if available
120
  if memory_results:
121
  memory_msg = self._format_memory_results(memory_results)
122
- history.append(ChatMessage(role="assistant", content=memory_msg))
 
 
 
 
 
 
123
  yield history, "", gr.update(interactive=False), user_id_state
124
 
125
- # Generate final analysis
126
  history.append(
127
  ChatMessage(
128
  role="assistant", content="๐Ÿ“ **Generating Compliance Report...**"
@@ -141,12 +160,11 @@ class UIHandler:
141
  history[-1] = ChatMessage(role="assistant", content=streaming_content)
142
  yield history, "", gr.update(interactive=False), user_id_state
143
 
144
- # Show completion time (before saving to memory)
145
  elapsed = time.time() - start_time
146
- history.append(
147
- ChatMessage(
148
- role="assistant", content=f"โœจ **Analysis complete** ({elapsed:.1f}s)"
149
- )
150
  )
151
  # Re-enable input box at the end
152
  yield history, "", gr.update(interactive=True), user_id_state
@@ -176,16 +194,10 @@ class UIHandler:
176
  - URL: {url}
177
  """)
178
  if results_display:
179
- collapsible_results = f"""
180
- <details>
181
- <summary><strong>๐Ÿ—ƒ๏ธ Raw Regulatory Data</strong> - Click to expand</summary>
182
-
183
- {"".join(results_display)}
184
-
185
- </details>
186
- """
187
  else:
188
- collapsible_results = "<details><summary><strong>๐Ÿ—ƒ๏ธ Raw Regulatory Data</strong> - Click to expand</summary>\nNo unique regulatory updates found.\n</details>"
189
  return collapsible_results
190
 
191
  def _format_memory_results(self, memory_results):
@@ -195,14 +207,7 @@ class UIHandler:
195
  for i, mem in enumerate(top_memories, 1):
196
  memory_text = mem.get("memory", "N/A")
197
  memory_details += f"\n**{i}. Memory:** {memory_text[:300]}...\n"
198
- memory_msg = f"""
199
- <details>
200
- <summary><strong>๐Ÿ’พ Related Past Queries</strong> - Click to expand</summary>
201
-
202
- Found {len(memory_results)} similar past queries in memory. Top 3 shown below:
203
- {memory_details}
204
- </details>
205
- """
206
  return memory_msg
207
 
208
  def delayed_clear(self, user_id_state):
 
70
  # Show tool detection
71
  tool_key, tool_name = self.agent.determine_intended_tool(message)
72
 
73
+ # Initial processing message with tool info (collapsible)
74
+ status_msg = (
75
+ f"Using **{tool_name}** to analyze your query (estimated 10-20 seconds)..."
76
+ )
77
+ history.append(
78
+ ChatMessage(
79
+ role="assistant",
80
+ content=status_msg,
81
+ metadata={"title": f"๐Ÿ› ๏ธ Tool Selected: {tool_name}"},
82
+ )
83
+ )
84
  yield history, "", gr.update(interactive=False), user_id_state
85
 
86
  # Extract parameters and process query
87
  params = self.agent.extract_parameters(message)
88
 
89
+ # Clear status and show parameter extraction (collapsible)
90
  history.pop()
91
+ param_msg = f"- Industry: {params['industry']}\n- Region: {params['region']}\n- Keywords: {params['keywords']}"
92
+ history.append(
93
+ ChatMessage(
94
+ role="assistant",
95
+ content=param_msg,
96
+ metadata={"title": "๐Ÿ“Parameter Extraction"},
97
+ )
98
+ )
99
+ yield history, "", gr.update(interactive=False), user_id_state
100
 
101
+ # Show tool execution steps (collapsible)
102
  tool_status = f"""
103
+ **Executing {tool_name}...**
 
 
 
 
 
 
 
 
104
  โณ _This process may take 40-90 seconds depending on the number of webpages being crawled._
105
  """
106
+ history.append(
107
+ ChatMessage(
108
+ role="assistant",
109
+ content=tool_status,
110
+ metadata={"title": "๐Ÿ“ข Tool Execution Status"},
111
+ )
112
+ )
113
  yield history, "", gr.update(interactive=False), user_id_state
114
 
115
  # Process the regulatory query
 
117
  crawl_results = results["crawl_results"]
118
  memory_results = results["memory_results"]
119
 
 
 
 
 
 
 
 
 
120
  # Show collapsible raw results
121
  if crawl_results["results"]:
122
  collapsible_results = self._format_crawl_results(crawl_results["results"])
123
+ history.append(
124
+ ChatMessage(
125
+ role="assistant",
126
+ content=collapsible_results,
127
+ metadata={"title": "๐ŸŒ Raw Regulatory Data", "status": "done"},
128
+ )
129
+ )
130
  yield history, "", gr.update(interactive=False), user_id_state
131
 
132
  # Display memory results if available
133
  if memory_results:
134
  memory_msg = self._format_memory_results(memory_results)
135
+ history.append(
136
+ ChatMessage(
137
+ role="assistant",
138
+ content=memory_msg,
139
+ metadata={"title": "๐Ÿ’พ Past Memories", "status": "done"},
140
+ )
141
+ )
142
  yield history, "", gr.update(interactive=False), user_id_state
143
 
144
+ # Generate final analysis (no metadata, standard message)
145
  history.append(
146
  ChatMessage(
147
  role="assistant", content="๐Ÿ“ **Generating Compliance Report...**"
 
160
  history[-1] = ChatMessage(role="assistant", content=streaming_content)
161
  yield history, "", gr.update(interactive=False), user_id_state
162
 
163
+ # Show completion time appended to the final report (no metadata)
164
  elapsed = time.time() - start_time
165
+ history[-1] = ChatMessage(
166
+ role="assistant",
167
+ content=streaming_content + f"\n\nโœจ Analysis complete ({elapsed:.1f}s).",
 
168
  )
169
  # Re-enable input box at the end
170
  yield history, "", gr.update(interactive=True), user_id_state
 
194
  - URL: {url}
195
  """)
196
  if results_display:
197
+ # Only return the content, let Gradio's metadata title handle the dropdown
198
+ collapsible_results = "\n".join(results_display)
 
 
 
 
 
 
199
  else:
200
+ collapsible_results = "No unique regulatory updates found."
201
  return collapsible_results
202
 
203
  def _format_memory_results(self, memory_results):
 
207
  for i, mem in enumerate(top_memories, 1):
208
  memory_text = mem.get("memory", "N/A")
209
  memory_details += f"\n**{i}. Memory:** {memory_text[:300]}...\n"
210
+ memory_msg = f"Found {len(memory_results)} similar past queries in memory. \nTop 3 shown below:\n{memory_details}"
 
 
 
 
 
 
 
211
  return memory_msg
212
 
213
  def delayed_clear(self, user_id_state):
images/avatar.png CHANGED

Git LFS Details

  • SHA256: ec24e81cfa3923766cca612d15d201b350f1325a68e046920db74fb6953dfa60
  • Pointer size: 131 Bytes
  • Size of remote file: 205 kB

Git LFS Details

  • SHA256: 5ac956ea6737a7113f497587fa1bf878fb8d8f253e0750915b9bfb3555fae6c6
  • Pointer size: 130 Bytes
  • Size of remote file: 23.5 kB