diff --git a/src/ragent/__init__.py b/src/ragent/__init__.py index ceacc95..bac5a43 100644 --- a/src/ragent/__init__.py +++ b/src/ragent/__init__.py @@ -191,11 +191,14 @@ class EventHandler(AssistantEventHandler): 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) + try: + self.submit_tool_outputs(tool_outputs, run_id) + except Exception as ex: + log.exception(ex) def submit_tool_outputs(self, tool_outputs, run_id): event_handler = EventHandler(self.agent) + log.debug(f"Submitting tool outputs {tool_outputs} for run {run_id}.") with self.agent.client.beta.threads.runs.submit_tool_outputs_stream( thread_id=self.current_run.thread_id, run_id=self.current_run.id, @@ -227,7 +230,12 @@ class Agent: self.thread = self.client.beta.threads.create() log.debug(f"Created thread with name {self.thread.id} for assistant {self.assistant.id}.") - + + def reset(self): + self.assistant = self._get_assistant() + self.thread = self.client.beta.threads.create() + log.debug(f"Resetted and created thread with name {self.thread.id} for assistant {self.assistant.id}.") + def get_file_by_name(self, name: str): for file in self.client.files.list().data: if file.filename == str(name): @@ -408,6 +416,7 @@ class Agent: ) as stream: stream.until_done() response = event_handler.message + log.debug(f"Event handler: {event_handler}") log.debug(f"Received response: {response} from assistant {self.assistant.id} in thread {self.thread.id}.") log.debug(f"Result of communicate (last returned message): {response} from assistant {self.assistant.id} in thread {self.thread.id}.") self.transcript.append(dict(role="assistant", content=response))