|
275 | 275 | " # Find and execute the tool\n", |
276 | 276 | " tool = next((t for t in memory_tools if t.name == tool_call['name']), None)\n", |
277 | 277 | " if tool:\n", |
278 | | - " result = await tool.ainvoke(tool_call['args'])\n", |
279 | | - " print(f\" Result: {result}\")\n", |
| 278 | + " try:\n", |
| 279 | + " result = await tool.ainvoke(tool_call['args'])\n", |
| 280 | + " print(f\" Result: {result}\")\n", |
| 281 | + " result_content = str(result)\n", |
| 282 | + " except Exception as e:\n", |
| 283 | + " print(f\" Error: {e}\")\n", |
| 284 | + " result_content = f\"Error: {str(e)}\"\n", |
280 | 285 | " \n", |
281 | 286 | " # Add tool result to messages\n", |
282 | 287 | " messages.append(response)\n", |
283 | 288 | " messages.append(ToolMessage(\n", |
284 | | - " content=str(result),\n", |
| 289 | + " content=result_content,\n", |
285 | 290 | " tool_call_id=tool_call['id']\n", |
286 | 291 | " ))\n", |
287 | 292 | " \n", |
|
336 | 341 | " # Find and execute the tool\n", |
337 | 342 | " tool = next((t for t in memory_tools if t.name == tool_call['name']), None)\n", |
338 | 343 | " if tool:\n", |
339 | | - " result = await tool.ainvoke(tool_call['args'])\n", |
340 | | - " print(f\"\\n Retrieved memories:\")\n", |
341 | | - " print(f\" {result}\")\n", |
| 344 | + " try:\n", |
| 345 | + " result = await tool.ainvoke(tool_call['args'])\n", |
| 346 | + " print(f\"\\n Retrieved memories:\")\n", |
| 347 | + " print(f\" {result}\")\n", |
| 348 | + " result_content = str(result)\n", |
| 349 | + " except Exception as e:\n", |
| 350 | + " print(f\"\\n Error: {e}\")\n", |
| 351 | + " result_content = f\"Error: {str(e)}\"\n", |
342 | 352 | " \n", |
343 | 353 | " # Add tool result to messages\n", |
344 | 354 | " messages.append(response)\n", |
345 | 355 | " messages.append(ToolMessage(\n", |
346 | | - " content=str(result),\n", |
| 356 | + " content=result_content,\n", |
347 | 357 | " tool_call_id=tool_call['id']\n", |
348 | 358 | " ))\n", |
349 | 359 | " \n", |
|
0 commit comments