Agent Zero AI framework
mistral fix, error text output
frdel53a46288f9a7
diff --git a/agent.py b/agent.pyindex c2033f349..8882b91f4 100644--- a/agent.py+++ b/agent.py@@ -392,9 +392,15 @@ class Agent:) # Re-raise the exception to cancel the loopelse:# Handling for general exceptions+ error_text = errors.error_text(exception)error_message = errors.format_error(exception)PrintStyle(font_color="red", padding=True).print(error_message)- self.context.log.log(type="error", heading="Error", content=error_message)+ self.context.log.log(+ type="error",+ heading="Error",+ content=error_message,+ kvps={"text": error_text},+ )raise HandledException(exception) # Re-raise the exception to kill the loopasync def get_system_prompt(self, loop_data: LoopData) -> list[str]:diff --git a/models.py b/models.pyindex 93ac6e297..4a7d7a557 100644--- a/models.py+++ b/models.py@@ -252,7 +252,7 @@ def get_google_embedding(# Mistral models-def get_mistral_chat(+def get_mistralai_chat(model_name: str,api_key=None,temperature=DEFAULT_TEMPERATURE,diff --git a/python/helpers/errors.py b/python/helpers/errors.pyindex 92e2ac2f7..7a9132603 100644--- a/python/helpers/errors.py+++ b/python/helpers/errors.py@@ -2,39 +2,51 @@ import reimport tracebackimport asyncio+def handle_error(e: Exception):# if asyncio.CancelledError, re-raiseif isinstance(e, asyncio.CancelledError):raise e-+++def error_text(e: Exception):+ return str(e)++def format_error(e: Exception, start_entries=6, end_entries=4):traceback_text = traceback.format_exc()# Split the traceback into lines- lines = traceback_text.split('\n')-+ lines = traceback_text.split("\n")+# Find all "File" lines- file_indices = [i for i, line in enumerate(lines) if line.strip().startswith("File ")]-+ file_indices = [+ i for i, line in enumerate(lines) if line.strip().startswith("File ")+ ]+# If we found at least one "File" line, trim the middle if there are more than start_entries+end_entries linesif len(file_indices) > start_entries + end_entries:start_index = max(0, len(file_indices) - start_entries - end_entries)- trimmed_lines = lines[:file_indices[start_index]] + [- f"\n>>> {len(file_indices) - start_entries - end_entries} stack lines skipped <<<\n"- ] + lines[file_indices[start_index + end_entries]:]+ trimmed_lines = (+ lines[: file_indices[start_index]]+ + [+ f"\n>>> {len(file_indices) - start_entries - end_entries} stack lines skipped <<<\n"+ ]+ + lines[file_indices[start_index + end_entries] :]+ )else:# If no "File" lines found, or not enough to trim, just return the original tracebacktrimmed_lines = lines-+# Find the error message at the enderror_message = ""for line in reversed(trimmed_lines):- if re.match(r'\w+Error:', line):+ if re.match(r"\w+Error:", line):error_message = linebreak-+# Combine the trimmed traceback with the error message- result = "Traceback (most recent call last):\n" + '\n'.join(trimmed_lines)+ result = "Traceback (most recent call last):\n" + "\n".join(trimmed_lines)if error_message:result += f"\n\n{error_message}"-- return result\ No newline at end of file++ return resultdiff --git a/webui/js/messages.js b/webui/js/messages.jsindex caef888ad..c9c86d85f 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -247,7 +247,7 @@ export function drawMessageCodeExe(messageContainer, id, type, heading, content,export function drawMessageAgentPlain(classes, messageContainer, id, type, heading, content, temp, kvps = null) {const messageContent = convertImageTags(content); // Convert image tags- _drawMessage(messageContainer, heading, messageContent, temp, false, null, [...classes]);+ _drawMessage(messageContainer, heading, messageContent, temp, false, kvps, [...classes]);messageContainer.classList.add('center-container');}