mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 10:25:52 +08:00
feat: output the execution results of tool should only in debug mode (#9104)
This commit is contained in:
parent
4be1aa516c
commit
5fcd614186
@ -1,9 +1,9 @@
|
|||||||
import os
|
|
||||||
from collections.abc import Mapping, Sequence
|
from collections.abc import Mapping, Sequence
|
||||||
from typing import Any, Optional, TextIO, Union
|
from typing import Any, Optional, TextIO, Union
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from configs import dify_config
|
||||||
from core.ops.entities.trace_entity import TraceTaskName
|
from core.ops.entities.trace_entity import TraceTaskName
|
||||||
from core.ops.ops_trace_manager import TraceQueueManager, TraceTask
|
from core.ops.ops_trace_manager import TraceQueueManager, TraceTask
|
||||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||||
@ -50,6 +50,7 @@ class DifyAgentCallbackHandler(BaseModel):
|
|||||||
tool_inputs: Mapping[str, Any],
|
tool_inputs: Mapping[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Do nothing."""
|
"""Do nothing."""
|
||||||
|
if dify_config.DEBUG:
|
||||||
print_text("\n[on_tool_start] ToolCall:" + tool_name + "\n" + str(tool_inputs) + "\n", color=self.color)
|
print_text("\n[on_tool_start] ToolCall:" + tool_name + "\n" + str(tool_inputs) + "\n", color=self.color)
|
||||||
|
|
||||||
def on_tool_end(
|
def on_tool_end(
|
||||||
@ -62,6 +63,7 @@ class DifyAgentCallbackHandler(BaseModel):
|
|||||||
trace_manager: Optional[TraceQueueManager] = None,
|
trace_manager: Optional[TraceQueueManager] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""If not the final action, print out observation."""
|
"""If not the final action, print out observation."""
|
||||||
|
if dify_config.DEBUG:
|
||||||
print_text("\n[on_tool_end]\n", color=self.color)
|
print_text("\n[on_tool_end]\n", color=self.color)
|
||||||
print_text("Tool: " + tool_name + "\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("Inputs: " + str(tool_inputs) + "\n", color=self.color)
|
||||||
@ -82,10 +84,12 @@ class DifyAgentCallbackHandler(BaseModel):
|
|||||||
|
|
||||||
def on_tool_error(self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any) -> None:
|
def on_tool_error(self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any) -> None:
|
||||||
"""Do nothing."""
|
"""Do nothing."""
|
||||||
|
if dify_config.DEBUG:
|
||||||
print_text("\n[on_tool_error] Error: " + str(error) + "\n", color="red")
|
print_text("\n[on_tool_error] Error: " + str(error) + "\n", color="red")
|
||||||
|
|
||||||
def on_agent_start(self, thought: str) -> None:
|
def on_agent_start(self, thought: str) -> None:
|
||||||
"""Run on agent start."""
|
"""Run on agent start."""
|
||||||
|
if dify_config.DEBUG:
|
||||||
if thought:
|
if thought:
|
||||||
print_text(
|
print_text(
|
||||||
"\n[on_agent_start] \nCurrent Loop: " + str(self.current_loop) + "\nThought: " + thought + "\n",
|
"\n[on_agent_start] \nCurrent Loop: " + str(self.current_loop) + "\nThought: " + thought + "\n",
|
||||||
@ -96,6 +100,7 @@ class DifyAgentCallbackHandler(BaseModel):
|
|||||||
|
|
||||||
def on_agent_finish(self, color: Optional[str] = None, **kwargs: Any) -> None:
|
def on_agent_finish(self, color: Optional[str] = None, **kwargs: Any) -> None:
|
||||||
"""Run on agent end."""
|
"""Run on agent end."""
|
||||||
|
if dify_config.DEBUG:
|
||||||
print_text("\n[on_agent_finish]\n Loop: " + str(self.current_loop) + "\n", color=self.color)
|
print_text("\n[on_agent_finish]\n Loop: " + str(self.current_loop) + "\n", color=self.color)
|
||||||
|
|
||||||
self.current_loop += 1
|
self.current_loop += 1
|
||||||
@ -103,9 +108,9 @@ class DifyAgentCallbackHandler(BaseModel):
|
|||||||
@property
|
@property
|
||||||
def ignore_agent(self) -> bool:
|
def ignore_agent(self) -> bool:
|
||||||
"""Whether to ignore agent callbacks."""
|
"""Whether to ignore agent callbacks."""
|
||||||
return not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != "true"
|
return not dify_config.DEBUG
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ignore_chat_model(self) -> bool:
|
def ignore_chat_model(self) -> bool:
|
||||||
"""Whether to ignore chat model callbacks."""
|
"""Whether to ignore chat model callbacks."""
|
||||||
return not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != "true"
|
return not dify_config.DEBUG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user