feat: Preserve object return type in Agentflow Custom Function#5895
feat: Preserve object return type in Agentflow Custom Function#5895beliga44 wants to merge 2 commits intoFlowiseAI:mainfrom
Conversation
…ectly Previously, object return values were automatically stringified before being passed downstream. Now objects are returned as-is, with stringification only applied when updating flow state template variables. Also adds freeSolo support for the state key field and updates the example comment accordingly. Co-Authored-By: beliga44 <beliga44@users.noreply.github.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the flexibility of Agentflow Custom Functions by enabling them to return structured JavaScript objects directly, rather than forcing a string conversion. This change streamlines data handling for subsequent operations and external consumers, improving the overall efficiency and usability of the Agentflow system. It ensures that while structured data is preserved for direct output, state updates continue to receive stringified representations where necessary, maintaining backward compatibility for internal processes. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the issue of preserving object return types from Custom Functions in Agentflow. The implementation is clean, removing the unconditional stringification for the node's output while ensuring that dependent logic like state processing continues to function correctly by providing it with a stringified version. I've identified one minor edge case regarding null return values that introduces a subtle change in behavior and have provided a suggestion to align it with the previous implementation. Overall, this is a great enhancement that improves the flexibility of Custom Functions.
packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Closes #4811
Problem
Custom Function nodes in Agentflow V2 always coerce object returns
to strings via
JSON.stringify(). This forces API consumers toJSON.parse()the response and prevents downstream Custom Functionsfrom receiving structured data.
Solution
Remove the automatic
JSON.stringify()on object returns. When usercode returns a JavaScript object,
output.contentnow preserves theoriginal object. String returns remain unchanged.
Changes
packages/components/nodes/agentflow/CustomFunction/CustomFunction.tsif (typeof response === 'object') { finalOutput = JSON.stringify(...) }processTemplateVariables(state processing)Backward Compatibility
return JSON.stringify(obj)explicitly → unchanged (string in, string out)return obj→ now get object instead of string (the fix)processTemplateVariablesstill receives string for state updates