Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/src/workflow-canvas/WORKFLOW_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ AI 生成的 validate 工具复用同一入口(`collectWorkflowValidationError
当前用于应用、知识库、工具三类工作流及其循环体,根据用户需求规划、创建节点、连线与配置字段。
页面通过 WorkflowCanvas.getLogicFlow() 提供画布,生成结果只改图,不自动保存。
模型选择支持参数设置,不提供添加模型入口;优先沿用默认 LLM 的参数,切换模型加载对应默认参数。
首轮生成时固定模型及参数,父 agent 和委派的子 agent 共用,并通过 `model_params_setting` 传入补全请求;新建会话后可重新配置。
模型及参数经 `AgentBindings.getModel` 在每轮补全前读取,父 agent 和委派的子 agent 共用,并通过 `model_params_setting` 传入补全请求;
会话中切换模型保留上下文,下一轮补全即生效;生成运行中模型选择禁用。
面板从 `resourceWorkspaceId` 注入读取资源所属空间,以 `AgentBindings.getResourceWorkspaceId` 传给节点 agent,
资源查询经 `useWorkflowStore(resourceScope, getResourceWorkspaceId)` 与节点回显、选择弹窗保持同一查询范围。

Expand Down
3 changes: 1 addition & 2 deletions ui/src/workflow-canvas/ai-generate/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export function useAgentConfig(config: AgentConfig, bindings: AgentBindings): Ru
prompt,
messages,
tools: config.tools,
modelId: bindings.modelId,
modelParams: bindings.modelParams,
getModel: bindings.getModel,
resourceScope: bindings.resourceScope,
call: bindings.call,
position: bindings.position ?? [],
Expand Down
13 changes: 7 additions & 6 deletions ui/src/workflow-canvas/ai-generate/create-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ToolResult } from './tools/result'
import type {
AgentHandle,
AgentMessage,
AgentModel,
AgentPayload,
AgentResult,
AgentTool,
Expand Down Expand Up @@ -44,7 +45,7 @@ function toExecutor(value: unknown): Executor {
* 某工具返回 AgentSuccessResult / AgentErrorResult 结束、被停止或超过轮次。工具返回 ErrorResult 或抛错时把错误回喂模型自愈。
*/
export function createAgent(agent: RunnableAgent): AgentHandle {
const { tools, modelId, modelParams, resourceScope, call, position, maxIterations } = agent
const { tools, getModel, resourceScope, call, position, maxIterations } = agent
const controller = new AbortController()
const stopCallbacks: Array<() => void> = []
const messages: AgentMessage[] = agent.messages
Expand All @@ -65,7 +66,7 @@ export function createAgent(agent: RunnableAgent): AgentHandle {
}

async function run(requirement: string): Promise<AgentResult> {
if (!modelId) return finish({ status: 'error', data: t('workflow.aiGeneration.errors.modelRequired') })
if (!getModel().modelId) return finish({ status: 'error', data: t('workflow.aiGeneration.errors.modelRequired') })
logDebug({ kind: 'run', pos: position, requirement: clipForLog(requirement, 800) })
messages.push({ role: 'user', content: requirement })

Expand All @@ -75,7 +76,8 @@ export function createAgent(agent: RunnableAgent): AgentHandle {
if (iteration > maxIterations)
return finish({ status: 'error', data: t('workflow.aiGeneration.errors.iterationLimit', { max: maxIterations }) })

const response = await runTurn(resourceScope, modelId, modelParams, messages, tools, emit, controller.signal)
// 每轮读取当前选中的模型:会话中切换模型后,下一轮补全即生效
const response = await runTurn(resourceScope, getModel(), messages, tools, emit, controller.signal)
const toolCalls = response.toolCalls ?? []
const assistantMessage: AgentMessage = { role: 'assistant', content: response.content || '' }
// thinking 模型要求思考内容按原字段名回传,否则下一轮请求会被拒绝
Expand Down Expand Up @@ -126,8 +128,7 @@ export function createAgent(agent: RunnableAgent): AgentHandle {
/** 跑一轮补全:把流式条目翻成事件下发,并返回本轮完整结果。 */
function runTurn(
resourceScope: string,
modelId: string,
modelParams: Record<string, unknown> | undefined,
model: AgentModel,
messages: AgentMessage[],
tools: AgentTool[],
emit: (payload: AgentPayload) => void,
Expand Down Expand Up @@ -158,7 +159,7 @@ function runTurn(
else reject(new Error(t('workflow.aiGeneration.errors.incompleteTurn')))
},
}
chatCompletion(resourceScope, modelId, { messages, tools: toToolSchemas(tools), model_params_setting: modelParams }, sink, signal)
chatCompletion(resourceScope, model.modelId, { messages, tools: toToolSchemas(tools), model_params_setting: model.modelParams }, sink, signal)
})
}

Expand Down
5 changes: 2 additions & 3 deletions ui/src/workflow-canvas/ai-generate/panel/AiGeneratePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function resourceIdOf(): string | undefined {
return typeof route.params[key] === 'string' ? (route.params[key] as string) : undefined
}

/** 首轮装配父 agent,后续续聊复用同一实例以保留上下文 */
/** 首轮装配父 agent,后续续聊复用同一实例以保留上下文;模型每轮补全前读取,切换后下一轮即生效 */
async function run(text: string) {
const lf = props.getLogicFlow()
if (!lf) return
Expand All @@ -148,8 +148,7 @@ async function run(text: string) {
agent = createAgent(
useAgent(props.workflowMode, {
rootLf: lf,
modelId: modelId.value,
modelParams: cloneDeep(modelParams.value),
getModel: () => ({ modelId: modelId.value, modelParams: cloneDeep(modelParams.value) }),
call: { onNext: onEvent },
workflowMode: props.workflowMode,
resourceScope,
Expand Down
18 changes: 11 additions & 7 deletions ui/src/workflow-canvas/ai-generate/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,19 @@ export interface AgentTool {
resultLimit?: number
}

/** 补全使用的模型及参数 */
export interface AgentModel {
modelId: string
/** 补全请求的 model_params_setting */
modelParams?: Record<string, unknown>
}

/** 构造期绑定:装配 agent 与建工具时使用的上下文。 */
export interface AgentBindings {
/** 主画布 LogicFlow 实例;循环体画布经 lf_id 从主画布展开 */
rootLf: LogicFlow
/** 模型 id(委派的子 agent 复用同一模型) */
modelId: string
/** 生成及委派补全共用的模型参数 */
modelParams?: Record<string, unknown>
/** 读取当前选中的模型及参数;每轮补全前读取,委派的子 agent 共用 */
getModel: () => AgentModel
/** 对外事件出口 */
call: Call<AgentEvent>
/** 主画布模式 */
Expand Down Expand Up @@ -137,9 +142,8 @@ export interface RunnableAgent {
prompt: string
messages: AgentMessage[]
tools: AgentTool[]
modelId: string
/** 生成及委派补全共用的模型参数 */
modelParams?: Record<string, unknown>
/** 读取当前选中的模型及参数,每轮补全前读取 */
getModel: () => AgentModel
/** 画布资源范围,补全请求经 useWorkflowStore(resourceScope) 发起 */
resourceScope: string
call: Call<AgentEvent>
Expand Down
Loading