This commit is contained in:
Obada Khalili 2025-03-21 13:44:59 +08:00 committed by GitHub
commit 0c27d9996c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 7 deletions

View File

@ -131,6 +131,7 @@ class BaseAgentRunner(AppRunner):
tenant_id=self.tenant_id,
app_id=self.app_config.app_id,
agent_tool=tool,
variables_inputs=self.application_generate_entity.inputs,
invoke_from=self.application_generate_entity.invoke_from,
)
assert tool_entity.entity.description

View File

@ -1,10 +1,10 @@
import json
import logging
import mimetypes
from collections.abc import Generator
from collections.abc import Generator, Mapping
from os import listdir, path
from threading import Lock
from typing import TYPE_CHECKING, Any, Union, cast
from typing import TYPE_CHECKING, Any, Optional, Union, cast
from yarl import URL
@ -298,6 +298,7 @@ class ToolManager:
tenant_id: str,
app_id: str,
agent_tool: AgentToolEntity,
variables_inputs: Optional[Mapping[str, Any]] = None,
invoke_from: InvokeFrom = InvokeFrom.DEBUGGER,
) -> Tool:
"""
@ -327,6 +328,11 @@ class ToolManager:
raise ValueError(f"file type parameter {parameter.name} not supported in agent")
if parameter.form == ToolParameter.ToolParameterForm.FORM:
if variables_inputs:
for key, value in variables_inputs.items():
agent_tool.tool_parameters[parameter.name] = agent_tool.tool_parameters[parameter.name].replace(
f"{{{{{key}}}}}", str(value)
)
# save tool parameter to tool entity memory
value = parameter.init_frontend_parameter(agent_tool.tool_parameters.get(parameter.name))
runtime_parameters[parameter.name] = value

View File

@ -202,7 +202,7 @@ class AgentNode(ToolNode):
extra = tool.get("extra", {})
tool_runtime = ToolManager.get_agent_tool_runtime(
self.tenant_id, self.app_id, entity, self.invoke_from
self.tenant_id, self.app_id, entity, invoke_from=self.invoke_from
)
if tool_runtime.entity.description:
tool_runtime.entity.description.llm = (

View File

@ -23,6 +23,7 @@ import { CollectionType } from '@/app/components/tools/types'
import { fetchBuiltInToolList, fetchCustomToolList, fetchModelToolList, fetchWorkflowToolList } from '@/service/tools'
import I18n from '@/context/i18n'
import { getLanguage } from '@/i18n/language'
import ConfigContext from '@/context/debug-configuration'
import cn from '@/utils/classnames'
type Props = {
@ -48,6 +49,8 @@ const SettingBuiltInTool: FC<Props> = ({
onHide,
onSave,
}) => {
const { modelConfig } = useContext(ConfigContext)
const { locale } = useContext(I18n)
const language = getLanguage(locale)
const { t } = useTranslation()
@ -57,7 +60,15 @@ const SettingBuiltInTool: FC<Props> = ({
const currTool = tools.find(tool => tool.name === toolName)
const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : []
const infoSchemas = formSchemas.filter((item: any) => item.form === 'llm')
const settingSchemas = formSchemas.filter((item: any) => item.form !== 'llm')
const settingSchemas = formSchemas
.filter((item: any) => item.form !== 'llm')
.map((item: any) => ({
...item,
inputs: modelConfig.configs.prompt_variables.map(variable => ({
name: variable.key,
value: variable.key,
})),
}))
const hasSetting = settingSchemas.length > 0
const [tempSetting, setTempSetting] = useState(setting)
const [currType, setCurrType] = useState('info')

View File

@ -106,6 +106,7 @@ export type FormShowOnObject = {
export type CredentialFormSchemaBase = {
variable: string
inputs?: Array<{ name: string; value: string }>
label: TypeWithI18N
type: FormTypeEnum
required: boolean

View File

@ -22,6 +22,7 @@ import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-sele
import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector'
import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector'
import RadioE from '@/app/components/base/radio/ui'
import PromptEditor from '@/app/components/base/prompt-editor'
import type {
NodeOutPutVar,
} from '@/app/components/workflow/types'
@ -144,13 +145,19 @@ function Form<
if (formSchema.type === FormTypeEnum.textInput || formSchema.type === FormTypeEnum.secretInput || formSchema.type === FormTypeEnum.textNumber) {
const {
variable, label, placeholder, required, show_on,
variable,
inputs = [],
label,
placeholder,
required,
show_on,
} = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput)
if (show_on.length && !show_on.every(showOnItem => value[showOnItem.variable] === showOnItem.value))
return null
const disabled = readonly || (isEditMode && (variable === '__model_type' || variable === '__model_name'))
const fieldValue = (isShowDefaultValue && ((value[variable] as string) === '' || value[variable] === undefined || value[variable] === null)) ? formSchema.default : value[variable]
return (
<div key={variable} className={cn(itemClassName, 'py-3')}>
<div className={cn(fieldLabelClassName, 'flex items-center py-2 system-sm-semibold text-text-secondary')}>
@ -160,7 +167,21 @@ function Form<
)}
{tooltipContent}
</div>
<Input
{inputs.length
? <div className={'rounded-lg border border-transparent bg-gray-50 px-3 py-[6px] hover:border-[rgba(0,0,0,0.08)]'}>
<PromptEditor
value={fieldValue}
onChange={val => handleFormChange(variable, val)}
placeholder={placeholder?.[language] || placeholder?.en_US || 'enter \'/\' to reference a variable'}
variableBlock={{
show: true,
variables: inputs,
}}
compact
editable
/>
</div>
: <Input
className={cn(inputClassName, `${disabled && 'cursor-not-allowed opacity-60'}`)}
value={(isShowDefaultValue && ((value[variable] as string) === '' || value[variable] === undefined || value[variable] === null)) ? formSchema.default : value[variable]}
onChange={val => handleFormChange(variable, val)}
@ -168,7 +189,7 @@ function Form<
placeholder={placeholder?.[language] || placeholder?.en_US}
disabled={disabled}
type={formSchema.type === FormTypeEnum.textNumber ? 'number' : 'text'}
{...(formSchema.type === FormTypeEnum.textNumber ? { min: (formSchema as CredentialFormSchemaNumberInput).min, max: (formSchema as CredentialFormSchemaNumberInput).max } : {})} />
{...(formSchema.type === FormTypeEnum.textNumber ? { min: (formSchema as CredentialFormSchemaNumberInput).min, max: (formSchema as CredentialFormSchemaNumberInput).max } : {})} />}
{fieldMoreInfo?.(formSchema)}
{validating && changeKey === variable && <ValidatingTip />}
</div>