langflow/src/backend/tests
Rodrigo Nader 3bb22b29cc
feat: Add dual output support to Agent component with structured JSON parsing (#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>
2025-07-21 16:33:30 +00:00
..
data feat: combine chat history and chat store into a CRUD component (#8323) 2025-06-05 22:19:01 +00:00
integration chore(deps): update pyleak version and activate pyleak_marker in tests (#8905) 2025-07-07 15:23:25 +00:00
locust chore: Enhance Locust load testing and optimize database settings (#6265) 2025-02-17 14:26:36 +00:00
performance tests: Remove unnecessary benchmark markers from server init tests (#5806) 2025-01-20 16:43:46 +00:00
unit feat: Add dual output support to Agent component with structured JSON parsing (#8836) 2025-07-21 16:33:30 +00:00
.test_durations chore: update test durations (#8550) 2025-06-16 11:05:18 -03:00
__init__.py refactor: improve maintainability and testability of Vertex.build_params (#5808) 2025-03-11 15:34:15 +00:00
api_keys.py ref: Auto-fix ruff rules in tests (#4154) 2024-10-16 15:42:36 +00:00
base.py fix: make sure tests run async (#5842) 2025-01-21 08:16:33 -08:00
conftest.py feat(database): add noop mode with config flag and update related tests (#9054) 2025-07-15 16:52:23 +00:00
constants.py chore: Update supported versions in tests constants (#5569) 2025-01-07 15:43:49 +00:00