Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: output the execution results of tool should only in debug mode (#9104)
zhuhao5fcd61418621
diff --git a/api/core/callback_handler/agent_tool_callback_handler.py b/api/core/callback_handler/agent_tool_callback_handler.pyindex 99e992fd890..d826edf6a0f 100644--- a/api/core/callback_handler/agent_tool_callback_handler.py+++ b/api/core/callback_handler/agent_tool_callback_handler.py@@ -1,9 +1,9 @@-import osfrom collections.abc import Mapping, Sequencefrom typing import Any, Optional, TextIO, Unionfrom pydantic import BaseModel+from configs import dify_configfrom core.ops.entities.trace_entity import TraceTaskNamefrom core.ops.ops_trace_manager import TraceQueueManager, TraceTaskfrom core.tools.entities.tool_entities import ToolInvokeMessage@@ -50,7 +50,8 @@ class DifyAgentCallbackHandler(BaseModel):tool_inputs: Mapping[str, Any],) -> None:"""Do nothing."""- print_text("\n[on_tool_start] ToolCall:" + tool_name + "\n" + str(tool_inputs) + "\n", color=self.color)+ if dify_config.DEBUG:+ print_text("\n[on_tool_start] ToolCall:" + tool_name + "\n" + str(tool_inputs) + "\n", color=self.color)def on_tool_end(self,@@ -62,11 +63,12 @@ class DifyAgentCallbackHandler(BaseModel):trace_manager: Optional[TraceQueueManager] = None,) -> None:"""If not the final action, print out observation."""- print_text("\n[on_tool_end]\n", color=self.color)- print_text("Tool: " + tool_name + "\n", color=self.color)- print_text("Inputs: " + str(tool_inputs) + "\n", color=self.color)- print_text("Outputs: " + str(tool_outputs)[:1000] + "\n", color=self.color)- print_text("\n")+ if dify_config.DEBUG:+ print_text("\n[on_tool_end]\n", color=self.color)+ print_text("Tool: " + tool_name + "\n", color=self.color)+ print_text("Inputs: " + str(tool_inputs) + "\n", color=self.color)+ print_text("Outputs: " + str(tool_outputs)[:1000] + "\n", color=self.color)+ print_text("\n")if trace_manager:trace_manager.add_trace_task(@@ -82,30 +84,33 @@ class DifyAgentCallbackHandler(BaseModel):def on_tool_error(self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any) -> None:"""Do nothing."""- print_text("\n[on_tool_error] Error: " + str(error) + "\n", color="red")+ if dify_config.DEBUG:+ print_text("\n[on_tool_error] Error: " + str(error) + "\n", color="red")def on_agent_start(self, thought: str) -> None:"""Run on agent start."""- if thought:- print_text(- "\n[on_agent_start] \nCurrent Loop: " + str(self.current_loop) + "\nThought: " + thought + "\n",- color=self.color,- )- else:- print_text("\n[on_agent_start] \nCurrent Loop: " + str(self.current_loop) + "\n", color=self.color)+ if dify_config.DEBUG:+ if thought:+ print_text(+ "\n[on_agent_start] \nCurrent Loop: " + str(self.current_loop) + "\nThought: " + thought + "\n",+ color=self.color,+ )+ else:+ print_text("\n[on_agent_start] \nCurrent Loop: " + str(self.current_loop) + "\n", color=self.color)def on_agent_finish(self, color: Optional[str] = None, **kwargs: Any) -> None:"""Run on agent end."""- print_text("\n[on_agent_finish]\n Loop: " + str(self.current_loop) + "\n", color=self.color)+ if dify_config.DEBUG:+ print_text("\n[on_agent_finish]\n Loop: " + str(self.current_loop) + "\n", color=self.color)self.current_loop += 1@propertydef ignore_agent(self) -> bool:"""Whether to ignore agent callbacks."""- return not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != "true"+ return not dify_config.DEBUG@propertydef ignore_chat_model(self) -> bool:"""Whether to ignore chat model callbacks."""- return not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != "true"+ return not dify_config.DEBUG