Fix Agent node structured output not updating flow state variables#5548
Conversation
Updated the Agent class to handle structured output by passing a JSON string instead of a markdown-wrapped response to the `processTemplateVariables` function. This change allows for proper nested property access and resolves string replacement issues with object coercion.
Summary of ChangesHello @AhmedMostafa16, 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 addresses a critical bug in the Agent node where structured output failed to correctly populate flow state template variables. The fix ensures that the underlying JSON data, rather than its markdown-formatted display version, is used for processing template variables, thereby enabling accurate replacement of placeholders like "{{output.decision}}" within the flow state. Highlights
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 addresses a bug where structured output from the Agent node was not correctly updating flow state variables. The root cause was that a markdown-formatted JSON string was being passed for template processing, which failed to parse. The fix introduces a new variable to hold the clean, non-markdown JSON string specifically for state processing, which correctly resolves the issue. The change is clear, well-targeted, and effectively fixes the bug. I have no further comments, great work!
…lowiseAI#5548) Fix Agent state processing for structured output Updated the Agent class to handle structured output by passing a JSON string instead of a markdown-wrapped response to the `processTemplateVariables` function. This change allows for proper nested property access and resolves string replacement issues with object coercion.
Description
Problem
The Agent node's structured output was not properly updating flow state template variables like
{{output.decision}}. Variables remained as literal template strings instead of being replaced with actual values.Root Cause
When structured output is enabled in Agent.ts,
finalResponseis wrapped in markdown code blocks for display:This markdown-wrapped string was passed to
processTemplateVariables(), which failed to parse it as JSON due to the markdown markers, leaving template variables unprocessed.Solution
Create a separate
outputForStateProcessingvariable that contains clean JSON (without markdown wrapping) when structured output is enabled.This ensures
processTemplateVariablesreceives valid JSON that can:{{output.decision}})"Result: {{ output }}") without[object Object]coercionChanges
packages/components/nodes/agentflow/Agent/Agent.ts: Pass clean JSON string toprocessTemplateVariableswhen structured output is enabled, instead of the markdown-wrappedfinalResponseTesting
{{output}}) and nested property access ({{output.decision}}) work"Result: {{ output }}") work without[object Object]issues