feat: Add dual output support to Agent component with structured JSON parsing#8836
Conversation
… parsing ## Summary - Add "Structured Response" output alongside existing "Response" output - Filter out conflicting json_mode field from OpenAI inputs - Implement robust JSON parsing with fallback handling ## Changes Made ### Agent Component (agent.py) - Add second output: "Structured Response" (Data type) with tool_mode=False - Filter json_mode from OpenAI inputs to prevent UI conflicts - Add json_response() method with multi-stage JSON parsing: - Direct JSON parsing for valid responses - Regex extraction for embedded JSON in text - Graceful error handling with diagnostic info - Share execution between outputs (no duplicate agent runs) - Fix model building to handle missing json_mode attribute ### Tests (test_agent_component.py) - Add 9 comprehensive test cases covering: - Dual output structure validation - Input filtering verification - JSON parsing (valid, embedded, error cases) - Model building without json_mode - Shared execution efficiency - Frontend node structure - Component initialization ## Benefits - Users get both Message and Data output types to choose from - Clean UI without confusing duplicate JSON toggles - Robust JSON parsing handles various response formats - Efficient single-execution approach - Maintains backward compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes add structured JSON output support to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant AgentComponent
participant Agent
User->>AgentComponent: Request structured_response
AgentComponent->>Agent: Run agent (if not already run)
Agent-->>AgentComponent: Return textual response
AgentComponent->>AgentComponent: Try to parse response as JSON
alt JSON parse succeeds
AgentComponent-->>User: Return structured JSON Data
else JSON parse fails
AgentComponent->>AgentComponent: Extract JSON substring via regex
alt Extraction succeeds
AgentComponent-->>User: Return extracted JSON Data
else Extraction fails
AgentComponent-->>User: Return raw content with error message
end
end
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/backend/base/langflow/components/agents/agent.py (1)
146-178: Consider supporting JSON arrays in the regex extraction.The current implementation handles JSON parsing well, but the regex pattern
r"\{.*\}"only extracts JSON objects. Consider also supporting JSON arrays:- json_match = re.search(r"\{.*\}", content, re.DOTALL) + # Try to extract JSON object or array + json_match = re.search(r"(\{.*\}|\[.*\])", content, re.DOTALL)src/backend/tests/unit/components/agents/test_agent_component.py (2)
103-103: Add periods to test docstrings.All test docstrings should end with a period according to D415:
- async def test_agent_has_dual_outputs(self, component_class, default_kwargs): - """Test that Agent component has both Response and Structured Response outputs""" + async def test_agent_has_dual_outputs(self, component_class, default_kwargs): + """Test that Agent component has both Response and Structured Response outputs.""" - async def test_json_mode_filtered_from_openai_inputs(self, component_class, default_kwargs): - """Test that json_mode is filtered out from OpenAI inputs""" + async def test_json_mode_filtered_from_openai_inputs(self, component_class, default_kwargs): + """Test that json_mode is filtered out from OpenAI inputs.""" - async def test_json_response_parsing_valid_json(self, component_class, default_kwargs): - """Test that json_response correctly parses JSON from agent response""" + async def test_json_response_parsing_valid_json(self, component_class, default_kwargs): + """Test that json_response correctly parses JSON from agent response.""" - async def test_json_response_parsing_embedded_json(self, component_class, default_kwargs): - """Test that json_response handles text containing JSON""" + async def test_json_response_parsing_embedded_json(self, component_class, default_kwargs): + """Test that json_response handles text containing JSON.""" - async def test_json_response_error_handling(self, component_class, default_kwargs): - """Test that json_response handles completely non-JSON responses""" + async def test_json_response_error_handling(self, component_class, default_kwargs): + """Test that json_response handles completely non-JSON responses.""" - async def test_model_building_without_json_mode(self, component_class, default_kwargs): - """Test that model building works without json_mode attribute""" + async def test_model_building_without_json_mode(self, component_class, default_kwargs): + """Test that model building works without json_mode attribute.""" - async def test_shared_execution_between_outputs(self, component_class, default_kwargs): - """Test that both outputs use the same agent execution""" + async def test_shared_execution_between_outputs(self, component_class, default_kwargs): + """Test that both outputs use the same agent execution.""" - async def test_agent_component_initialization(self, component_class, default_kwargs): - """Test that Agent component initializes correctly with filtered inputs""" + async def test_agent_component_initialization(self, component_class, default_kwargs): + """Test that Agent component initializes correctly with filtered inputs.""" - async def test_frontend_node_structure(self, component_class, default_kwargs): - """Test that frontend node has correct structure with filtered inputs""" + async def test_frontend_node_structure(self, component_class, default_kwargs): + """Test that frontend node has correct structure with filtered inputs."""Also applies to: 117-117, 130-130, 145-145, 160-160, 176-176, 194-194, 215-215, 225-225
114-114: Usenotinstead of comparing to False.- assert component.outputs[1].tool_mode == False + assert not component.outputs[1].tool_mode
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/backend/base/langflow/components/agents/agent.py(8 hunks)src/backend/tests/unit/components/agents/test_agent_component.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
`src/backend/tests/unit/components/**/*.py`: Mirror the component directory stru...
src/backend/tests/unit/components/**/*.py: Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Provide file_names_mapping in tests for backward compatibility version testing
Create comprehensive unit tests for all new components
Use the client fixture from conftest.py for FastAPI API endpoint tests
Test authenticated FastAPI endpoints using logged_in_headers in tests
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/**/*.py`: Run make format_backend to format Python code early and often Run make lint to check for linting issues in backend Python code
src/backend/**/*.py: Run make format_backend to format Python code early and often
Run make lint to check for linting issues in backend Python code
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.pysrc/backend/base/langflow/components/agents/agent.py
`src/backend/tests/unit/**/*.py`: Use in-memory SQLite for database tests Test c...
src/backend/tests/unit/**/*.py: Use in-memory SQLite for database tests
Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Use pytest.mark.api_key_required and pytest.mark.no_blockbuster for tests involving external APIs
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/**/*component*.py`: In your Python component class, set the `icon` attribute to a string matching the frontend icon mapping exactly (case-sensitive).
src/backend/**/*component*.py: In your Python component class, set theiconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
📄 Source: CodeRabbit Inference Engine (.cursor/rules/icons.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/**/components/**/*.py`: In your Python component class, set the `icon` attribute to a string matching the frontend icon mapping exactly (case-sensitive).
src/backend/**/components/**/*.py: In your Python component class, set theiconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
📄 Source: CodeRabbit Inference Engine (.cursor/rules/icons.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.pysrc/backend/base/langflow/components/agents/agent.py
`src/backend/tests/**/*.py`: Unit tests for backend code should be located in 's...
src/backend/tests/**/*.py: Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Test files should use the same filename as the component with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Use the 'client' fixture (an async httpx.AsyncClient) for API tests, as defined in 'src/backend/tests/conftest.py'.
Skip client creation in tests by marking them with '@pytest.mark.noclient' when the 'client' fixture is not needed.
Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/...
{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py}: Each test should have a clear docstring explaining its purpose.
Complex test setups should be commented, and mock usage should be documented within the test code.
Expected behaviors should be explicitly stated in test docstrings or comments.
Create comprehensive unit tests for all new components.
Test both sync and async code paths in components.
Mock external dependencies appropriately in tests.
Test error handling and edge cases in components.
Validate input/output behavior in tests.
Test component initialization and configuration.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`{src/backend/tests/**/*.py,tests/**/*.py}`: Use '@pytest.mark.asyncio' for asyn...
{src/backend/tests/**/*.py,tests/**/*.py}: Use '@pytest.mark.asyncio' for async test functions.
Test queue operations in async tests using 'asyncio.Queue' and non-blocking put/get methods.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests.
Be aware of ContextVar propagation in async tests and test both direct event loop execution and 'asyncio.to_thread' scenarios.
Each test should ensure proper resource cleanup, especially in async fixtures using 'try/finally' and cleanup methods.
Test that operations respect timeout constraints and assert elapsed time is within tolerance.
Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Test components that need external APIs with proper pytest markers such as '@pytest.mark.api_key_required' and '@pytest.mark.no_blockbuster'.
Use 'MockLanguageModel' for testing language model components without external API calls.
Use 'anyio' and 'aiofiles' for async file operations in tests.
Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Test component configuration updates by asserting changes in build config dictionaries.
Test real-time event streaming endpoints by consuming NDJSON event streams and validating event structure.
Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Test webhook endpoints by posting payloads and asserting correct processing and status codes.
Test error handling by monkeypatching internal functions to raise exceptions and asserting correct error responses.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/agents/test_agent_component.py
`src/backend/base/langflow/components/**/*.py`: Add new backend components to th...
src/backend/base/langflow/components/**/*.py: Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Implement async component methods using async def and await for asynchronous operations
Use asyncio.create_task for background work in async components and ensure proper cleanup on cancellation
Use asyncio.Queue for non-blocking queue operations in async components and handle timeouts appropriately
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/components/agents/agent.py
🧠 Learnings (2)
src/backend/tests/unit/components/agents/test_agent_component.py (14)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test both sync and async code paths in components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test component configuration updates by asserting changes in build config dictionaries.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Validate input/output behavior in tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test error handling and edge cases in components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Use the client fixture from conftest.py for FastAPI API endpoint tests
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test component initialization and configuration.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Test authenticated FastAPI endpoints using logged_in_headers in tests
src/backend/base/langflow/components/agents/agent.py (3)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Implement async component methods using async def and await for asynchronous operations
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
🧬 Code Graph Analysis (1)
src/backend/base/langflow/components/agents/agent.py (3)
src/backend/base/langflow/schema/data.py (1)
Data(23-275)src/backend/base/langflow/template/field/base.py (1)
Output(181-257)src/backend/base/langflow/base/agents/agent.py (2)
run_agent(120-184)message_response(80-86)
🪛 GitHub Check: Ruff Style Check (3.13)
src/backend/tests/unit/components/agents/test_agent_component.py
[failure] 215-215: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:215:9: D415 First line should end with a period, question mark, or exclamation point
[failure] 194-194: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:194:9: D415 First line should end with a period, question mark, or exclamation point
[failure] 176-176: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:176:9: D415 First line should end with a period, question mark, or exclamation point
[failure] 160-160: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:160:9: D415 First line should end with a period, question mark, or exclamation point
[failure] 145-145: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:145:9: D415 First line should end with a period, question mark, or exclamation point
[failure] 130-130: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:130:9: D415 First line should end with a period, question mark, or exclamation point
[failure] 117-117: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:117:9: D415 First line should end with a period, question mark, or exclamation point
[failure] 114-114: Ruff (E712)
src/backend/tests/unit/components/agents/test_agent_component.py:114:16: E712 Avoid equality comparisons to False; use if not component.outputs[1].tool_mode: for false checks
[failure] 103-103: Ruff (D415)
src/backend/tests/unit/components/agents/test_agent_component.py:103:9: D415 First line should end with a period, question mark, or exclamation point
src/backend/base/langflow/components/agents/agent.py
[failure] 134-134: Ruff (TRY300)
src/backend/base/langflow/components/agents/agent.py:134:13: TRY300 Consider moving this statement to an else block
🪛 Ruff (0.11.9)
src/backend/tests/unit/components/agents/test_agent_component.py
103-103: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
114-114: Avoid equality comparisons to False; use if not component.outputs[1].tool_mode: for false checks
Replace with not component.outputs[1].tool_mode
(E712)
117-117: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
130-130: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
145-145: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
160-160: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
176-176: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
194-194: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
215-215: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
225-225: First line should end with a period, question mark, or exclamation point
Add closing punctuation
(D415)
src/backend/base/langflow/components/agents/agent.py
134-134: Consider moving this statement to an else block
(TRY300)
🪛 Flake8 (7.2.0)
src/backend/tests/unit/components/agents/test_agent_component.py
[error] 114-114: comparison to False should be 'if cond is False:' or 'if not cond:'
(E712)
🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/components/agents/agent.py
[error] 134-134: Ruff TRY300: Consider moving this statement to an else block.
🔇 Additional comments (6)
src/backend/base/langflow/components/agents/agent.py (5)
1-3: LGTM!The new imports are appropriate for the JSON parsing functionality being added.
Also applies to: 24-24
46-52: Clean filtering of json_mode input.The implementation correctly filters out the
json_modefield from OpenAI inputs while preserving all other fields. This aligns with the PR objective of simplifying the UI.
91-94: Well-structured dual outputs implementation.The outputs are properly configured with clear display names and appropriate methods. Setting
tool_mode=Falsefor the structured response is correct.
130-134: Result storage implementation is correct.The agent result is properly stored for reuse by the
json_responsemethod. The static analysis hint about moving the return to an else block (TRY300) can be safely ignored here - the current structure is clearer since all exceptions are re-raised.
220-225: Correct handling of component parameters.The implementation properly builds model kwargs only from existing attributes, which implicitly excludes
json_modesince it was filtered from inputs.src/backend/tests/unit/components/agents/test_agent_component.py (1)
102-238: Excellent test coverage for the new JSON output functionality.The test suite comprehensively covers:
- Dual output structure validation
- Input filtering verification
- JSON parsing scenarios (valid, embedded, error cases)
- Model building without json_mode
- Shared execution between outputs
- Component initialization and frontend structure
The tests are well-structured with appropriate mocking and assertions.
|
updating the tests! |
…langflow-ai/langflow into feature/agent-structured-output
|
updating tests. |
Codecov ReportAttention: Patch coverage is
❌ Your project status has failed because the head coverage (51.64%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #8836 +/- ##
==========================================
- Coverage 51.76% 51.64% -0.13%
==========================================
Files 632 624 -8
Lines 43294 42913 -381
Branches 125 0 -125
==========================================
- Hits 22413 22162 -251
+ Misses 20831 20751 -80
+ Partials 50 0 -50
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
… parsing (langflow-ai#8836) * feat: Add dual output support to Agent component with structured JSON parsing ## Summary - Add "Structured Response" output alongside existing "Response" output - Filter out conflicting json_mode field from OpenAI inputs - Implement robust JSON parsing with fallback handling ## Changes Made ### Agent Component (agent.py) - Add second output: "Structured Response" (Data type) with tool_mode=False - Filter json_mode from OpenAI inputs to prevent UI conflicts - Add json_response() method with multi-stage JSON parsing: - Direct JSON parsing for valid responses - Regex extraction for embedded JSON in text - Graceful error handling with diagnostic info - Share execution between outputs (no duplicate agent runs) - Fix model building to handle missing json_mode attribute ### Tests (test_agent_component.py) - Add 9 comprehensive test cases covering: - Dual output structure validation - Input filtering verification - JSON parsing (valid, embedded, error cases) - Model building without json_mode - Shared execution efficiency - Frontend node structure - Component initialization ## Benefits - Users get both Message and Data output types to choose from - Clean UI without confusing duplicate JSON toggles - Robust JSON parsing handles various response formats - Efficient single-execution approach - Maintains backward compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * [autofix.ci] apply automated fixes * update to templates with model list update * [autofix.ci] apply automated fixes * Update test_agent_component.py * update to the test and update to templates * [autofix.ci] apply automated fixes --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
Summary
Add a second "Structured Response" output to the Agent component that automatically parses JSON from agent responses, giving users choice between Message and Data output types.
Key Features
Changes Made
Agent Component (
src/backend/base/langflow/components/agents/agent.py)tool_mode=Falsejson_modefrom OpenAI inputs to prevent UI conflictsjson_response()method with multi-stage JSON parsing:json_modeattributeTests (
src/backend/tests/unit/components/agents/test_agent_component.py)Test Plan
Benefits
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests