diff --git a/agent/canvas.py b/agent/canvas.py index bc7a45e3e..58f2cdd86 100644 --- a/agent/canvas.py +++ b/agent/canvas.py @@ -405,6 +405,8 @@ class Canvas(Graph): _m += m cpn_obj.set_output("content", _m) cite = re.search(r"\[ID:[ 0-9]+\]", _m) + elif isinstance(cpn_obj.output("attachment"), tuple): + yield decorate("message", {"attachment": cpn_obj.output("attachment")}) else: yield decorate("message", {"content": cpn_obj.output("content")}) cite = re.search(r"\[ID:[ 0-9]+\]", cpn_obj.output("content")) diff --git a/agent/component/message.py b/agent/component/message.py index 141f58448..dc5a83952 100644 --- a/agent/component/message.py +++ b/agent/component/message.py @@ -168,7 +168,6 @@ class Message(ComponentBase): for n, v in kwargs.items(): content = re.sub(n, v, content) - self.set_output("content", content) self._convert_content(content) def thoughts(self) -> str: @@ -222,7 +221,11 @@ class Message(ComponentBase): os.remove(tmp_name) settings.STORAGE_IMPL.put(self._canvas._tenant_id, doc_id, binary_content) + + self.set_output("attachment", (doc_id, self._param.output_format, f"{doc_id[:8]}.{self._param.output_format}")) + logging.info(f"Converted content uploaded as {doc_id} (format={self._param.output_format})") except Exception as e: - logging.error(f"Error converting content to {self._param.output_format}: {e}") \ No newline at end of file + logging.error(f"Error converting content to {self._param.output_format}: {e}") + self.set_output("attachment", None) \ No newline at end of file