I am using Run Function to execute a prepared query on a remote database (MySQL). I am running it in the Virtual Machine since I must import the mysql2 package. The function successfully retrieves the data but when I assign an extracted string to a variable ( ai.vars.rawtext) it is not available in subsequent blocks through {{rawtext}}. The console.log statements inside the function show that ai.vars.rawtext is updated with the extracted string. But a display to user block shows {{rawtext}} to be its original value (from before the Run Function block). Is this a bug?
I see this is related to a different post https://community.mindstudio.ai/t/cloudrunner-not-persisting-returned-variables-between-function-and-display-blocks/1782. I have two run functions in my workflow, one to fetch input from the database and a second to save the output to the database. So, if ai.vars is cleared every time there is a run function block that might explain the lack of persistence.
Hi @pj16,
That’s correct, the values are cleared, although you can pass values back into the workflow by assigning them to Output variables that you define in the block configuration.
Here’s a remix link to a sample Agent that uses two Custom Functions:
https://app.mindstudio.ai/agents/rdearmas–sample-agent-with-two-custom-functions-102f3d3e/remix
Let me know if you have any questions!
Alex, Thank you for this response. It is good to see that there is a method for passing variables back to the workflow in this situation. Thanks for the link to the detailed solution. I found another workaround by passing in my data as part of webhookParams so I will stick with that for now. I appreciate the fast helpful response. My MindStudio project is a success.
Peter