Bugfix/AgentflowV2 State (#4512)

* add persistence state, http node variables, custom function flow state

* update marketplace templates
This commit is contained in:
Henry Heng
2025-05-27 18:01:39 +01:00
committed by GitHub
parent 572fb31a1c
commit 01dab4365a
15 changed files with 177 additions and 16 deletions
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -157,6 +157,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -157,6 +157,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -160,6 +160,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -157,6 +157,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -157,6 +157,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -157,6 +157,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -157,6 +157,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -12,7 +12,7 @@
"data": {
"id": "startAgentflow_0",
"label": "Start",
"version": 1,
"version": 1.1,
"name": "startAgentflow",
"type": "Start",
"color": "#7EE787",
@@ -157,6 +157,15 @@
],
"id": "startAgentflow_0-input-startState-array",
"display": true
},
{
"label": "Persist State",
"name": "startPersistState",
"type": "boolean",
"description": "Persist the state in the same session",
"optional": true,
"id": "startAgentflow_0-input-startPersistState-boolean",
"display": true
}
],
"inputAnchors": [],
@@ -1324,6 +1324,24 @@ export const executeAgentFlow = async ({
}
}
// If the state is persistent, get the state from the previous execution
const startPersistState = nodes.find((node) => node.data.name === 'startAgentflow')?.data.inputs?.startPersistState
if (startPersistState === true && previousExecution) {
const previousExecutionData = (JSON.parse(previousExecution.executionData) as IAgentflowExecutedData[]) ?? []
let previousState = {}
if (Array.isArray(previousExecutionData) && previousExecutionData.length) {
for (const execData of previousExecutionData.reverse()) {
if (execData.data.state) {
previousState = execData.data.state
break
}
}
}
agentflowRuntime.state = previousState
}
// If the start input type is form input, get the form values from the previous execution (form values are persisted in the same session)
if (startInputType === 'formInput' && previousExecution) {
const previousExecutionData = (JSON.parse(previousExecution.executionData) as IAgentflowExecutedData[]) ?? []