Enhance conversation history and runtime variable management
- Update ConversationRecorder to include source and nodeId metadata in transcripts for better context tracking. - Introduce optional variable handling in DynamicVariableStore, allowing for unset variables to be rendered as empty without raising errors. - Refactor WorkflowBrain to apply turn configurations and manage interaction policies dynamically, improving agent responsiveness. - Implement tests to ensure proper handling of updated session variables and workflow metadata in various scenarios.
This commit is contained in:
@@ -78,6 +78,7 @@ import {
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import type { KnowledgeRetrievalConfig, TurnConfig } from "@/lib/api";
|
||||
import { TurnConfigEditor } from "@/components/turn-config-editor";
|
||||
import { normalizeTurnConfig } from "@/lib/turn-config";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Tooltip,
|
||||
@@ -195,6 +196,8 @@ function fromFlow(nodes: Node[], edges: Edge[]): WorkflowGraph {
|
||||
knowledgeMode: "automatic",
|
||||
knowledgeTopN: 5,
|
||||
knowledgeScoreThreshold: 0,
|
||||
enableInterrupt: true,
|
||||
turnConfig: defaultGraph().settings.turnConfig,
|
||||
},
|
||||
nodes: nodes.map((n) => ({
|
||||
id: n.id,
|
||||
@@ -261,6 +264,8 @@ function Canvas({
|
||||
knowledgeTopN: settings.knowledgeRetrievalConfig.topN,
|
||||
knowledgeScoreThreshold:
|
||||
settings.knowledgeRetrievalConfig.scoreThreshold,
|
||||
enableInterrupt: settings.allowInterrupt,
|
||||
turnConfig: settings.turnConfig,
|
||||
};
|
||||
onChangeRef.current?.(graph);
|
||||
}, [
|
||||
@@ -273,6 +278,8 @@ function Canvas({
|
||||
settings.toolIds,
|
||||
settings.knowledgeBaseId,
|
||||
settings.knowledgeRetrievalConfig,
|
||||
settings.allowInterrupt,
|
||||
settings.turnConfig,
|
||||
]);
|
||||
|
||||
const onConnect = useCallback(
|
||||
@@ -1519,6 +1526,9 @@ function AgentPanelForm({
|
||||
topN: Number(draft.knowledgeTopN ?? 5),
|
||||
scoreThreshold: Number(draft.knowledgeScoreThreshold ?? 0),
|
||||
};
|
||||
const agentTurnConfig = normalizeTurnConfig(
|
||||
draft.turnConfig ?? workflowSettings.turnConfig,
|
||||
);
|
||||
|
||||
const setInheritance = (inheritGlobalConfig: boolean) => {
|
||||
if (inheritGlobalConfig) {
|
||||
@@ -1550,6 +1560,9 @@ function AgentPanelForm({
|
||||
knowledgeScoreThreshold:
|
||||
draft.knowledgeScoreThreshold ??
|
||||
workflowSettings.knowledgeRetrievalConfig.scoreThreshold,
|
||||
enableInterrupt:
|
||||
draft.enableInterrupt ?? workflowSettings.allowInterrupt,
|
||||
turnConfig: agentTurnConfig,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1592,10 +1605,10 @@ function AgentPanelForm({
|
||||
|
||||
<SectionCard
|
||||
icon={<MessageSquareText size={15} />}
|
||||
title="提示词"
|
||||
title={inheritsGlobal ? "任务" : "提示词"}
|
||||
description={
|
||||
inheritsGlobal
|
||||
? "描述当前阶段任务,并与工作流全局提示词合并"
|
||||
? "描述当前阶段要完成的目标;角色、能力和通用规则继承工作流全局配置"
|
||||
: "描述当前独立助手的角色、能力和回答要求"
|
||||
}
|
||||
>
|
||||
@@ -1603,7 +1616,11 @@ function AgentPanelForm({
|
||||
rows={8}
|
||||
value={draft.prompt ?? ""}
|
||||
onChange={(event) => set("prompt", event.target.value)}
|
||||
placeholder="请输入提示词,描述助手的角色、能力和回答要求"
|
||||
placeholder={
|
||||
inheritsGlobal
|
||||
? "例如:确认用户身份,并收集需要查询的订单编号"
|
||||
: "请输入提示词,描述助手的角色、能力和回答要求"
|
||||
}
|
||||
className="field-sizing-fixed min-h-28 resize-y border-hairline-strong bg-background text-sm text-foreground placeholder:text-muted-soft"
|
||||
/>
|
||||
</SectionCard>
|
||||
@@ -1714,6 +1731,23 @@ function AgentPanelForm({
|
||||
onChange={(toolIds) => set("toolIds", toolIds)}
|
||||
/>
|
||||
</SectionCard>
|
||||
|
||||
<SectionCard
|
||||
icon={<Sparkles size={15} />}
|
||||
title="交互策略"
|
||||
description="配置当前 Agent 独立使用的打断和轮次检测策略"
|
||||
>
|
||||
<TurnConfigEditor
|
||||
enabled={
|
||||
draft.enableInterrupt ?? workflowSettings.allowInterrupt
|
||||
}
|
||||
config={agentTurnConfig}
|
||||
onEnabledChange={(enableInterrupt) =>
|
||||
set("enableInterrupt", enableInterrupt)
|
||||
}
|
||||
onConfigChange={(turnConfig) => set("turnConfig", turnConfig)}
|
||||
/>
|
||||
</SectionCard>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user