Kackle commited on
Commit
788978f
·
verified ·
1 Parent(s): e63ee7b
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -132,10 +132,10 @@ class SlpMultiAgent:
132
  temperature=0.0,
133
  max_tokens=500
134
  ),
135
- tools=[KnowledgeBaseTool()], # Remove Wikipedia to avoid timeouts
136
  managed_agents=[research_agent, solver_agent], # Only 2 agents
137
  name="ManagerAgent",
138
- description="Efficient manager for quick problem solving.",
139
  additional_authorized_imports=["re", "math"],
140
  planning_interval=1, # Faster planning
141
  verbosity_level=0, # Reduce verbosity
@@ -188,20 +188,36 @@ class SlpMultiAgent:
188
 
189
  # Extract clean answer from result
190
  if result and isinstance(result, str):
191
- # Look for final_answer pattern
192
  import re
193
- final_answer_match = re.search(r'final_answer\(["\']([^"\']*)["\'\)]', result) # Fixed regex
 
194
  if final_answer_match:
195
- clean_answer = final_answer_match.group(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  return clean_answer
197
-
198
  # If no final_answer found, try to extract the last meaningful line
199
  lines = result.strip().split('\n')
200
  for line in reversed(lines):
201
- line = line.strip()
202
  if line and not line.startswith('#') and not line.startswith('###') and len(line) < 200:
 
 
 
 
203
  return line
204
-
205
  # Return the result from the agent
206
  return result if result else "Unable to determine answer."
207
 
 
132
  temperature=0.0,
133
  max_tokens=500
134
  ),
135
+ tools=[KnowledgeBaseTool(), WikipediaSearchTool(), DuckDuckGoSearchTool()], # Pass all retrieval tools
136
  managed_agents=[research_agent, solver_agent], # Only 2 agents
137
  name="ManagerAgent",
138
+ description="Efficient manager for quick problem solving. Uses Wikipedia and DuckDuckGo for factual questions.",
139
  additional_authorized_imports=["re", "math"],
140
  planning_interval=1, # Faster planning
141
  verbosity_level=0, # Reduce verbosity
 
188
 
189
  # Extract clean answer from result
190
  if result and isinstance(result, str):
 
191
  import re
192
+ # Look for final_answer pattern
193
+ final_answer_match = re.search(r'final_answer\(["\']([^"\']*)["\']\)', result)
194
  if final_answer_match:
195
+ clean_answer = final_answer_match.group(1).strip()
196
+ # Post-process: remove code blocks, explanations, and keep only the direct answer
197
+ clean_answer = clean_answer.strip('`').strip()
198
+ # Remove common prefixes
199
+ for prefix in ["The answer is", "Based on", "According to", "Answer:"]:
200
+ if clean_answer.lower().startswith(prefix.lower()):
201
+ clean_answer = clean_answer[len(prefix):].strip(' :,.')
202
+ # If answer is a list, keep it comma separated and clean
203
+ if '\n' in clean_answer and ',' not in clean_answer:
204
+ items = [x.strip() for x in clean_answer.split('\n') if x.strip()]
205
+ clean_answer = ', '.join(items)
206
+ # If answer is a code block, extract the value
207
+ code_match = re.search(r'([A-Za-z0-9 ,.+-]+)', clean_answer)
208
+ if code_match:
209
+ clean_answer = code_match.group(1).strip()
210
  return clean_answer
 
211
  # If no final_answer found, try to extract the last meaningful line
212
  lines = result.strip().split('\n')
213
  for line in reversed(lines):
214
+ line = line.strip('`').strip()
215
  if line and not line.startswith('#') and not line.startswith('###') and len(line) < 200:
216
+ # Remove common prefixes
217
+ for prefix in ["The answer is", "Based on", "According to", "Answer:"]:
218
+ if line.lower().startswith(prefix.lower()):
219
+ line = line[len(prefix):].strip(' :,.')
220
  return line
 
221
  # Return the result from the agent
222
  return result if result else "Unable to determine answer."
223