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: Add Citations and Attributions to Agent Node (#18558)
Chieh Wang30aa052a57eb
diff --git a/api/core/agent/plugin_entities.py b/api/core/agent/plugin_entities.pyindex 3b482887100..a3438fc2c74 100644--- a/api/core/agent/plugin_entities.py+++ b/api/core/agent/plugin_entities.py@@ -41,6 +41,7 @@ class AgentStrategyParameter(PluginParameter):APP_SELECTOR = CommonParameterType.APP_SELECTOR.valueMODEL_SELECTOR = CommonParameterType.MODEL_SELECTOR.valueTOOLS_SELECTOR = CommonParameterType.TOOLS_SELECTOR.value+ ANY = CommonParameterType.ANY.value# deprecated, should not use.SYSTEM_FILES = CommonParameterType.SYSTEM_FILES.valuediff --git a/api/core/entities/parameter_entities.py b/api/core/entities/parameter_entities.pyindex 2fa347c2042..fbd62437e60 100644--- a/api/core/entities/parameter_entities.py+++ b/api/core/entities/parameter_entities.py@@ -14,6 +14,7 @@ class CommonParameterType(StrEnum):APP_SELECTOR = "app-selector"MODEL_SELECTOR = "model-selector"TOOLS_SELECTOR = "array[tools]"+ ANY = "any"# Dynamic select parameter# Once you are not sure about the available options until authorization is donediff --git a/api/core/plugin/entities/parameters.py b/api/core/plugin/entities/parameters.pyindex 2be65d67a00..47290ee613f 100644--- a/api/core/plugin/entities/parameters.py+++ b/api/core/plugin/entities/parameters.py@@ -5,6 +5,7 @@ from pydantic import BaseModel, Field, field_validatorfrom core.entities.parameter_entities import CommonParameterTypefrom core.tools.entities.common_entities import I18nObject+from core.workflow.nodes.base.entities import NumberTypeclass PluginParameterOption(BaseModel):@@ -38,6 +39,7 @@ class PluginParameterType(enum.StrEnum):APP_SELECTOR = CommonParameterType.APP_SELECTOR.valueMODEL_SELECTOR = CommonParameterType.MODEL_SELECTOR.valueTOOLS_SELECTOR = CommonParameterType.TOOLS_SELECTOR.value+ ANY = CommonParameterType.ANY.valueDYNAMIC_SELECT = CommonParameterType.DYNAMIC_SELECT.value# deprecated, should not use.@@ -151,6 +153,10 @@ def cast_parameter_value(typ: enum.StrEnum, value: Any, /):if value and not isinstance(value, list):raise ValueError("The tools selector must be a list.")return value+ case PluginParameterType.ANY:+ if value and not isinstance(value, str | dict | list | NumberType):+ raise ValueError("The var selector must be a string, dictionary, list or number.")+ return valuecase PluginParameterType.ARRAY:if not isinstance(value, list):# Try to parse JSON string for arraysdiff --git a/api/core/tools/entities/tool_entities.py b/api/core/tools/entities/tool_entities.pyindex b5148e245f0..64568a8eda6 100644--- a/api/core/tools/entities/tool_entities.py+++ b/api/core/tools/entities/tool_entities.py@@ -16,6 +16,7 @@ from core.plugin.entities.parameters import (cast_parameter_value,init_frontend_parameter,)+from core.rag.entities.citation_metadata import RetrievalSourceMetadatafrom core.tools.entities.common_entities import I18nObjectfrom core.tools.entities.constants import TOOL_SELECTOR_MODEL_IDENTITY@@ -179,6 +180,10 @@ class ToolInvokeMessage(BaseModel):data: Mapping[str, Any] = Field(..., description="Detailed log data")metadata: Optional[Mapping[str, Any]] = Field(default=None, description="The metadata of the log")+ class RetrieverResourceMessage(BaseModel):+ retriever_resources: list[RetrievalSourceMetadata] = Field(..., description="retriever resources")+ context: str = Field(..., description="context")+class MessageType(Enum):TEXT = "text"IMAGE = "image"@@ -191,13 +196,22 @@ class ToolInvokeMessage(BaseModel):FILE = "file"LOG = "log"BLOB_CHUNK = "blob_chunk"+ RETRIEVER_RESOURCES = "retriever_resources"type: MessageType = MessageType.TEXT"""plain text, image url or link url"""message: (- JsonMessage | TextMessage | BlobChunkMessage | BlobMessage | LogMessage | FileMessage | None | VariableMessage+ JsonMessage+ | TextMessage+ | BlobChunkMessage+ | BlobMessage+ | LogMessage+ | FileMessage+ | None+ | VariableMessage+ | RetrieverResourceMessage)meta: dict[str, Any] | None = None@@ -243,6 +257,7 @@ class ToolParameter(PluginParameter):FILES = PluginParameterType.FILES.valueAPP_SELECTOR = PluginParameterType.APP_SELECTOR.valueMODEL_SELECTOR = PluginParameterType.MODEL_SELECTOR.value+ ANY = PluginParameterType.ANY.valueDYNAMIC_SELECT = PluginParameterType.DYNAMIC_SELECT.value# MCP object and array type parametersdiff --git a/api/core/workflow/nodes/tool/tool_node.py b/api/core/workflow/nodes/tool/tool_node.pyindex 48627a229df..3853a5d9205 100644--- a/api/core/workflow/nodes/tool/tool_node.py+++ b/api/core/workflow/nodes/tool/tool_node.py@@ -22,7 +22,7 @@ from core.workflow.enums import SystemVariableKeyfrom core.workflow.graph_engine.entities.event import AgentLogEventfrom core.workflow.nodes.base import BaseNodefrom core.workflow.nodes.enums import NodeType-from core.workflow.nodes.event import RunCompletedEvent, RunStreamChunkEvent+from core.workflow.nodes.event import RunCompletedEvent, RunRetrieverResourceEvent, RunStreamChunkEventfrom core.workflow.utils.variable_template_parser import VariableTemplateParserfrom extensions.ext_database import dbfrom factories import file_factory@@ -373,6 +373,12 @@ class ToolNode(BaseNode[ToolNodeData]):agent_logs.append(agent_log)yield agent_log+ elif message.type == ToolInvokeMessage.MessageType.RETRIEVER_RESOURCES:+ assert isinstance(message.message, ToolInvokeMessage.RetrieverResourceMessage)+ yield RunRetrieverResourceEvent(+ retriever_resources=message.message.retriever_resources,+ context=message.message.context,+ )# Add agent_logs to outputs['json'] to ensure frontend can access thinking processjson_output: list[dict[str, Any]] = []diff --git a/web/app/components/base/chat/chat/question.tsx b/web/app/components/base/chat/chat/question.tsxindex 666a869a32e..6630d9bb9d6 100644--- a/web/app/components/base/chat/chat/question.tsx+++ b/web/app/components/base/chat/chat/question.tsx@@ -117,7 +117,7 @@ const Question: FC<QuestionProps> = ({</div><divref={contentRef}- className='bg-background-gradient-bg-fill-chat-bubble-bg-3 w-full rounded-2xl px-4 py-3 text-sm text-text-primary'+ className='w-full rounded-2xl bg-background-gradient-bg-fill-chat-bubble-bg-3 px-4 py-3 text-sm text-text-primary'style={theme?.chatBubbleColorStyle ? CssTransform(theme.chatBubbleColorStyle) : {}}>{diff --git a/web/app/components/header/account-setting/model-provider-page/declarations.ts b/web/app/components/header/account-setting/model-provider-page/declarations.tsindex 2ae0e74ccc5..1f5ced612c2 100644--- a/web/app/components/header/account-setting/model-provider-page/declarations.ts+++ b/web/app/components/header/account-setting/model-provider-page/declarations.ts@@ -21,6 +21,7 @@ export enum FormTypeEnum {toolSelector = 'tool-selector',multiToolSelector = 'array[tools]',appSelector = 'app-selector',+ any = 'any',object = 'object',array = 'array',dynamicSelect = 'dynamic-select',diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsxindex f1e3595d1e6..3b3527a9fdc 100644--- a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx+++ b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx@@ -21,6 +21,7 @@ import ModelParameterModal from '@/app/components/plugins/plugin-detail-panel/moimport ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector'import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector'import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector'+import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'import RadioE from '@/app/components/base/radio/ui'import type {NodeOutPutVar,@@ -412,6 +413,38 @@ function Form<)}+ if (formSchema.type === FormTypeEnum.any) {+ const {+ variable, label, required, scope,+ } = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput)++ return (+ <div key={variable} className={cn(itemClassName, 'py-3')}>+ <div className={cn(fieldLabelClassName, 'system-sm-semibold flex items-center py-2 text-text-secondary')}>+ {label[language] || label.en_US}+ {required && (+ <span className='ml-1 text-red-500'>*</span>+ )}+ {tooltipContent}+ </div>+ <VarReferencePicker+ zIndex={1001}+ readonly={false}+ isShowNodeName+ nodeId={nodeId || ''}+ value={value[variable] || []}+ onChange={item => handleFormChange(variable, item as any)}+ filterVar={(varPayload) => {+ if (!scope) return true+ return scope.split('&').includes(varPayload.type)+ }}+ />+ {fieldMoreInfo?.(formSchema)}+ {validating && changeKey === variable && <ValidatingTip />}+ </div>+ )+ }+// @ts-expect-error it workif (!Object.values(FormTypeEnum).includes(formSchema.type))return customRenderField?.(formSchema as CustomFormSchema, filteredProps)diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list-item.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list-item.tsxindex 5439da669eb..8908d9a039f 100644--- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list-item.tsx+++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list-item.tsx@@ -48,7 +48,7 @@ const ModelListItem = ({ model, provider, isConfigurable, onConfig, onModifyLoad<divkey={model.model}className={classNames(- 'group flex items-center pl-2 pr-2.5 h-8 rounded-lg',+ 'group flex h-8 items-center rounded-lg pl-2 pr-2.5',isConfigurable && 'hover:bg-components-panel-on-panel-item-bg-hover',model.deprecated && 'opacity-60',)}diff --git a/web/app/components/workflow/nodes/agent/use-config.ts b/web/app/components/workflow/nodes/agent/use-config.tsindex 50faf030402..a8b80c0348c 100644--- a/web/app/components/workflow/nodes/agent/use-config.ts+++ b/web/app/components/workflow/nodes/agent/use-config.ts@@ -13,8 +13,8 @@ import type { Memory, Var } from '../../types'import { VarType as VarKindType } from '../../types'import useAvailableVarList from '../_base/hooks/use-available-var-list'import produce from 'immer'-import { isSupportMCP } from '@/utils/plugin-version-feature'import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'+import { isSupportMCP } from '@/utils/plugin-version-feature'import { generateAgentToolValue, toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'export type StrategyStatus = {@@ -95,11 +95,20 @@ const useConfig = (id: string, payload: AgentNodeType) => {)return res}, [inputs.agent_parameters, currentStrategy?.parameters])++ const getParamVarType = useCallback((paramName: string) => {+ const isVariable = currentStrategy?.parameters.some(+ param => param.name === paramName && param.type === FormTypeEnum.any,+ )+ if (isVariable) return VarType.variable+ return VarType.constant+ }, [currentStrategy?.parameters])+const onFormChange = (value: Record<string, any>) => {const res: ToolVarInputs = {}Object.entries(value).forEach(([key, val]) => {res[key] = {- type: VarType.constant,+ type: getParamVarType(key),value: val,}})