Bugfix/Override State WhenStartPersistState (#5017)
- Added support for overriding startState from overrideConfig even when startPersistState is true
This commit is contained in:
parent
5930f1119c
commit
e3e4d6a904
|
|
@ -1403,6 +1403,29 @@ export const executeAgentFlow = async ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if startState has been overridden from overrideConfig.startState and is enabled
|
||||||
|
const startAgentflowNode = nodes.find((node) => node.data.name === 'startAgentflow')
|
||||||
|
const isStartStateEnabled =
|
||||||
|
nodeOverrides && startAgentflowNode
|
||||||
|
? nodeOverrides[startAgentflowNode.data.label]?.find((param: any) => param.name === 'startState')?.enabled ?? false
|
||||||
|
: false
|
||||||
|
|
||||||
|
if (isStartStateEnabled && overrideConfig?.startState) {
|
||||||
|
if (Array.isArray(overrideConfig.startState)) {
|
||||||
|
// Handle array format: [{"key": "foo", "value": "foo4"}]
|
||||||
|
const overrideStateObj: ICommonObject = {}
|
||||||
|
for (const item of overrideConfig.startState) {
|
||||||
|
if (item.key && item.value !== undefined) {
|
||||||
|
overrideStateObj[item.key] = item.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previousState = { ...previousState, ...overrideStateObj }
|
||||||
|
} else if (typeof overrideConfig.startState === 'object') {
|
||||||
|
// Object override: "startState": {...}
|
||||||
|
previousState = { ...previousState, ...overrideConfig.startState }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
agentflowRuntime.state = previousState
|
agentflowRuntime.state = previousState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1584,12 +1607,44 @@ export const executeAgentFlow = async ({
|
||||||
role: message.role === 'userMessage' ? 'user' : 'assistant'
|
role: message.role === 'userMessage' ? 'user' : 'assistant'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only add additional_kwargs when fileUploads or artifacts exists and is not empty
|
const hasFileUploads = message.fileUploads && message.fileUploads !== ''
|
||||||
if ((message.fileUploads && message.fileUploads !== '') || (message.artifacts && message.artifacts !== '')) {
|
const hasArtifacts = message.artifacts && message.artifacts !== ''
|
||||||
|
const hasFileAnnotations = message.fileAnnotations && message.fileAnnotations !== ''
|
||||||
|
const hasUsedTools = message.usedTools && message.usedTools !== ''
|
||||||
|
|
||||||
|
if (hasFileUploads || hasArtifacts || hasFileAnnotations || hasUsedTools) {
|
||||||
mappedMessage.additional_kwargs = {}
|
mappedMessage.additional_kwargs = {}
|
||||||
|
|
||||||
if (message.fileUploads && message.fileUploads !== '') {
|
if (hasFileUploads) {
|
||||||
mappedMessage.additional_kwargs.fileUploads = message.fileUploads
|
try {
|
||||||
|
mappedMessage.additional_kwargs.fileUploads = JSON.parse(message.fileUploads!)
|
||||||
|
} catch {
|
||||||
|
mappedMessage.additional_kwargs.fileUploads = message.fileUploads
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasArtifacts) {
|
||||||
|
try {
|
||||||
|
mappedMessage.additional_kwargs.artifacts = JSON.parse(message.artifacts!)
|
||||||
|
} catch {
|
||||||
|
mappedMessage.additional_kwargs.artifacts = message.artifacts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasFileAnnotations) {
|
||||||
|
try {
|
||||||
|
mappedMessage.additional_kwargs.fileAnnotations = JSON.parse(message.fileAnnotations!)
|
||||||
|
} catch {
|
||||||
|
mappedMessage.additional_kwargs.fileAnnotations = message.fileAnnotations
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasUsedTools) {
|
||||||
|
try {
|
||||||
|
mappedMessage.additional_kwargs.usedTools = JSON.parse(message.usedTools!)
|
||||||
|
} catch {
|
||||||
|
mappedMessage.additional_kwargs.usedTools = message.usedTools
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue