dify icon indicating copy to clipboard operation
dify copied to clipboard

In a round of session, the same tool is called many times, and the tracing information is incorrect

Open HeyDorvin opened this issue 1 year ago • 1 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. call the same tool twice in a session image
  2. The input for two calls is the same image image 3.The actual call is different: image image

✔️ Expected Behavior

Output correct call information.

❌ Actual Behavior

Output incorrect call information.

HeyDorvin avatar Sep 10 '24 08:09 HeyDorvin

The tracing information is incorrect when the same tool is called multiple times in a session in Dify version 0.7.2 because the trace_manager is not consistently updated or managed across multiple invocations. Specifically, the trace_manager is only passed to the agent_tool_callback.on_tool_end method but not updated or reset between calls, leading to potential inconsistencies in the tracing data [1].

To address this issue, you can ensure that the trace_manager is properly updated or reset between tool calls. This can be done by adding a new trace task in the on_tool_end method of the DifyAgentCallbackHandler class, which already has a mechanism to update the trace_manager:

def on_tool_end(
    self,
    tool_name: str,
    tool_inputs: Mapping[str, Any],
    tool_outputs: str,
    message_id: Optional[str] = None,
    timer: Optional[Any] = None,
    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: " + tool_outputs[:1000] + "\n", color=self.color)
    print_text("\n")

    if trace_manager:
        trace_manager.add_trace_task(
            TraceTask(
                TraceTaskName.TOOL_TRACE,
                message_id=message_id,
                tool_name=tool_name,
                tool_inputs=tool_inputs,
                tool_outputs=tool_outputs,
                timer=timer,
            )
        )

This ensures that each tool call is properly logged and traced, maintaining accurate tracing information across multiple invocations [2].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Sep 10 '24 08:09 dosubot[bot]