From e9f7e7ec8956592a1c65144f4a3a5fbb7344fb22 Mon Sep 17 00:00:00 2001
From: retoor <retoor@molodetz.nl>
Date: Wed, 12 Mar 2025 18:28:28 +0100
Subject: [PATCH] Error handling.

---
 src/ragent/__init__.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ragent/__init__.py b/src/ragent/__init__.py
index 9a1af7c..ceacc95 100644
--- a/src/ragent/__init__.py
+++ b/src/ragent/__init__.py
@@ -185,7 +185,12 @@ class EventHandler(AssistantEventHandler):
         for tool in data.required_action.submit_tool_outputs.tool_calls:
             for function in self.agent.tools:
                 if function.__name__ == tool.function.name:
-                    tool_outputs.append({"tool_call_id": tool.id, "output": str(function(**json.loads(tool.function.arguments)))})
+                    result = None
+                    try:
+                        result = function(**json.loads(tool.function.arguments))
+                    except Exception as ex:
+                        result = str(ex)
+                    tool_outputs.append({"tool_call_id": tool.id, "output": str(result)})
 
         self.submit_tool_outputs(tool_outputs, run_id)