dify icon indicating copy to clipboard operation
dify copied to clipboard

Add Citations and Attributions to Agent Node

Open chiehw opened this issue 8 months ago • 6 comments

Self Checks

  • [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.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

Are there any plans for this feature?

Image

2. Additional context or comments

No response

3. Can you help us with this feature?

  • [x] I am interested in contributing to this feature.

chiehw avatar Apr 14 '25 06:04 chiehw

@Nov1c444 Have any plan about this?

chiehw avatar Apr 15 '25 09:04 chiehw

Thank you for your valuable suggestion. We appreciate your input and agree it would be effective, however we don't currently have plans to implement this feature in the short term.

Nov1c444 avatar Apr 16 '25 00:04 Nov1c444

Can you assign this issue to me? I will implement this feature.

chiehw avatar Apr 16 '25 02:04 chiehw

I plan to support Array[Object] type parameters for the tool plugin. Andd add retriever_resource type in MessageType. Or Any type(refer to context parameters of LLM node)

I refer to the log type. The log message returned by the tool plugin is converted into AgentLogEvent type in dify-api. the retriever_resource message returned by the plugin will be converted into AgentRetrieverResourceEvent type.

class MessageType(Enum):
      TEXT = "text"
      FILE = "file"
      BLOB = "blob"
      JSON = "json"
      LINK = "link"
      IMAGE = "image"
      IMAGE_LINK = "image_link"
      VARIABLE = "variable"
      BLOB_CHUNK = "blob_chunk"
      LOG = "log"
      RETRIEVER_RESOURCES = "retriever_resources "

@Nov1c444 What do you think?

chiehw avatar Apr 21 '25 02:04 chiehw

Solution

Image

Action 2.1 Detailed steps:

Add two new features to the Agent strategy

  1. features[n] = context
  2. parameters[n].XXX.context.enabled = true

Example (using the official Agent strategy plugin) Image

  • For the feature features[n] = context, the dify-web frontend renders a context selection box based on the parameter information.

Image

  • For the parameters[n].XXX.context.enabled = true feature, support for selecting context variables in the field (see LLM node)

Image

Action 2.2 Detailed steps:

  • The dify-api backend obtains the context and prompt word parameters. If the prompt word contains context variables, the context is converted into text and filled into the parameters.

  • Pass the parameters to the plugin.

Action 2.3 Detailed steps:

  • If the Agent Node specifies the context, push the reference and attribution on the Agent node (dify-api).

chiehw avatar Apr 28 '25 06:04 chiehw

Thank you for your contribution. I will review it this week. If you'd like to discuss some details with me afterwards, you can add my WeChat: No1v444

Nov1c444 avatar Apr 28 '25 07:04 Nov1c444

When is this feature expected to go online? I noticed that the dify-plugin has added the create_retriever_resource_message method, but dify itself does not yet support this message type.

zhudongwork avatar Jul 15 '25 02:07 zhudongwork

It will be merged in this week.

Nov1c444 avatar Jul 15 '25 05:07 Nov1c444