Spaces:
Running
Running
Update agent.py
Browse files
agent.py
CHANGED
@@ -275,41 +275,40 @@ class MagAgent:
|
|
275 |
ExcelReaderTool()
|
276 |
# LocalFileAudioTool()
|
277 |
],
|
278 |
-
verbosity_level=
|
279 |
add_base_tools=True,
|
280 |
max_steps=20
|
281 |
)
|
282 |
print("MagAgent initialized.")
|
283 |
|
284 |
-
async def __call__(self, question: str,
|
285 |
"""Process a question asynchronously using the MagAgent."""
|
286 |
print(f"MagAgent received question (first 50 chars): {question[:50]}... Task ID: {task_id}")
|
287 |
-
|
288 |
try:
|
289 |
if self.rate_limiter:
|
290 |
while not self.rate_limiter.consume(1):
|
291 |
-
|
292 |
-
|
|
|
293 |
task = (
|
294 |
f"Answer the following question accurately and concisely: {question}\n"
|
295 |
f"If the question references an attachment, use the download_file tool with task_id: {task_id}\n"
|
296 |
f"Return the answer as a string."
|
297 |
)
|
|
|
298 |
response = await asyncio.to_thread(
|
299 |
self.agent.run,
|
300 |
task=task
|
301 |
)
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
print(f"MagAgent response: {response[:50]}...")
|
309 |
return response
|
310 |
-
|
311 |
except Exception as e:
|
312 |
-
error_msg = f"Error processing question: {str(e)}. Check API key or network connectivity."
|
313 |
print(error_msg)
|
314 |
return error_msg
|
315 |
|
|
|
275 |
ExcelReaderTool()
|
276 |
# LocalFileAudioTool()
|
277 |
],
|
278 |
+
verbosity_level=3,
|
279 |
add_base_tools=True,
|
280 |
max_steps=20
|
281 |
)
|
282 |
print("MagAgent initialized.")
|
283 |
|
284 |
+
async def __call__(self, question: str, task_id: str) -> str:
|
285 |
"""Process a question asynchronously using the MagAgent."""
|
286 |
print(f"MagAgent received question (first 50 chars): {question[:50]}... Task ID: {task_id}")
|
|
|
287 |
try:
|
288 |
if self.rate_limiter:
|
289 |
while not self.rate_limiter.consume(1):
|
290 |
+
print(f"Rate limit reached for task {task_id}. Waiting...")
|
291 |
+
await asyncio.sleep(60 / 15) # Assuming 15 RPM
|
292 |
+
# Include task_id in the task prompt to guide the agent
|
293 |
task = (
|
294 |
f"Answer the following question accurately and concisely: {question}\n"
|
295 |
f"If the question references an attachment, use the download_file tool with task_id: {task_id}\n"
|
296 |
f"Return the answer as a string."
|
297 |
)
|
298 |
+
print(f"Calling agent.run for task {task_id}...")
|
299 |
response = await asyncio.to_thread(
|
300 |
self.agent.run,
|
301 |
task=task
|
302 |
)
|
303 |
+
print(f"Agent.run completed for task {task_id}.")
|
304 |
+
response = str(response)
|
305 |
+
if not response:
|
306 |
+
print(f"No answer found for task {task_id}.")
|
307 |
+
response = "No answer found."
|
|
|
308 |
print(f"MagAgent response: {response[:50]}...")
|
309 |
return response
|
|
|
310 |
except Exception as e:
|
311 |
+
error_msg = f"Error processing question for task {task_id}: {str(e)}. Check API key or network connectivity."
|
312 |
print(error_msg)
|
313 |
return error_msg
|
314 |
|