Skip to content

fix: Agent component not detecting provider fields for WatsonX#12022

Closed
dkaushik94 wants to merge 3 commits into
release-1.8.0from
le-449
Closed

fix: Agent component not detecting provider fields for WatsonX#12022
dkaushik94 wants to merge 3 commits into
release-1.8.0from
le-449

Conversation

@dkaushik94
Copy link
Copy Markdown
Member

@dkaushik94 dkaushik94 commented Mar 3, 2026

Refactored model provider underlying methods to work with WatsonX to detect model provider settings.
Wired in for the component to auto-detect globally configured WatsonX fields.

LE-449

Screenshot 2026-03-03 at 4 35 17 PM Screenshot 2026-03-03 at 4 35 39 PM

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 3, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch le-449

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 23%
22.88% (7986/34896) 15.46% (4227/27340) 15.62% (1148/7349)

Unit Test Results

Tests Skipped Failures Errors Time
2611 0 💤 0 ❌ 0 🔥 45.598s ⏱️

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.12%. Comparing base (a25aa8c) to head (2a0fd58).
⚠️ Report is 17 commits behind head on release-1.8.0.

Files with missing lines Patch % Lines
src/lfx/src/lfx/base/models/unified_models.py 80.00% 3 Missing and 1 partial ⚠️

❌ Your project status has failed because the head coverage (41.96%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-1.8.0   #12022      +/-   ##
=================================================
- Coverage          37.05%   35.12%   -1.94%     
=================================================
  Files               1588     1588              
  Lines              77969    77976       +7     
  Branches           11803    11805       +2     
=================================================
- Hits               28893    27389    -1504     
- Misses             47454    48951    +1497     
- Partials            1622     1636      +14     
Flag Coverage Δ
backend 49.86% <ø> (-7.48%) ⬇️
frontend 20.50% <ø> (ø)
lfx 41.96% <80.00%> (+0.47%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/lfx/src/lfx/base/models/unified_models.py 38.44% <80.00%> (+14.69%) ⬆️

... and 102 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ogabrielluiz ogabrielluiz changed the title Bugfix: le-449: Agent component not detecting provider fields for WatsonX fix: Agent component not detecting provider fields for WatsonX Mar 4, 2026
@github-actions github-actions Bot added the bug Something isn't working label Mar 4, 2026
Copy link
Copy Markdown
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

Critical (2)

  • Swapped variable keys in validate_model_provider_key break validation for both OpenAI and WatsonX (see inline comments)

Important (2)

  • Agent component only calls apply_provider_variable_config_to_build_config for WatsonX, while LanguageModelComponent calls it for all providers
  • Overly broad except (ValueError, Exception) swallows all errors in get_all_variables_for_provider

Minor (1)

  • Import inside loop body in apply_provider_variable_config_to_build_config

The core approach (threading user_id, env-first then DB-override, moving field visibility outside field_name == "model") looks good. The variable key swap is the blocking issue.

from langchain_openai import ChatOpenAI # type: ignore # noqa: PGH003

api_key = variables.get("OPENAI_API_KEY")
api_key = variables.get("OPENAI_APIKEY")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Variable key is wrong. Should be OPENAI_API_KEY (with underscore), not OPENAI_APIKEY.

MODEL_PROVIDER_METADATA in model_metadata.py:78 defines the key as "OPENAI_API_KEY". The variables dict passed to this function is built from that metadata, so it will have key "OPENAI_API_KEY", but this line looks up "OPENAI_APIKEY", which will never match. This means OpenAI API key validation is silently skipped and invalid keys are accepted.

Suggested change
api_key = variables.get("OPENAI_APIKEY")
api_key = variables.get("OPENAI_API_KEY")

from langchain_ibm import ChatWatsonx

api_key = variables.get("WATSONX_APIKEY")
api_key = variables.get("WATSONX_API_KEY")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Variable key is wrong. Should be WATSONX_APIKEY, not WATSONX_API_KEY.

MODEL_PROVIDER_METADATA in model_metadata.py:182 defines the key as "WATSONX_APIKEY". Same issue as the OpenAI one above. The keys appear to have been accidentally swapped between the two providers. WatsonX validation is silently skipped.

Suggested change
api_key = variables.get("WATSONX_API_KEY")
api_key = variables.get("WATSONX_APIKEY")


# Show/hide watsonx fields
is_watsonx = provider == "IBM WatsonX"
if is_watsonx:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistency: apply_provider_variable_config_to_build_config is only called for WatsonX here, but LanguageModelComponent calls it for ALL providers.

In language_model.py:138-144, this is called unconditionally when provider is truthy. But here it is guarded by if is_watsonx:, meaning env/DB prefilling probably will not work for OpenAI, Anthropic, Google, or Ollama in the Agent component. Is this intentional?

# If found in DB, it overrides environment variable
if value and str(value).strip():
values[var_key] = str(value)
except (ValueError, Exception): # noqa: BLE001
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overly broad exception catch. (ValueError, Exception) catches everything.

Exception is a superclass of ValueError, so the tuple is redundant. This catches all exceptions. Database connection failures, timeouts, and programming bugs all get logged at DEBUG level with the misleading message "Variable not found in database." Consider narrowing to the specific exception that get_variable raises for "not found", and logging infrastructure errors at WARNING.


# Check if current value is just the hardcoded component default
# We want to allow the Global Variable to strictly override these specific defaults
from lfx.base.models.watsonx_constants import IBM_WATSONX_URLS
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Import inside loop body.

from lfx.base.models.watsonx_constants import IBM_WATSONX_URLS runs on every iteration. Move to the top of the function for clarity, and to avoid a potential ImportError crashing all providers if the watsonx module has issues.

@dkaushik94
Copy link
Copy Markdown
Member Author

Closing this PR since this was tackled in a different PR from @edwinjosechittilappilly
PR: #12050

@dkaushik94 dkaushik94 closed this Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants