Skip to content

feat: Add Converse component and improve output extraction#9822

Closed
Cristhianzl wants to merge 7 commits into
mainfrom
cz/fix-agent-events
Closed

feat: Add Converse component and improve output extraction#9822
Cristhianzl wants to merge 7 commits into
mainfrom
cz/fix-agent-events

Conversation

@Cristhianzl
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl commented Sep 11, 2025

This pull request introduces significant improvements to Amazon Bedrock model support and output text extraction, with a focus on compatibility, robustness, and expanded testing. The most notable changes are the addition of a new Amazon Bedrock Converse component, a major rewrite of the _extract_output_text function to handle diverse response formats gracefully, and comprehensive unit tests to ensure reliability across edge cases and backward compatibility.

Amazon Bedrock Model Components:

  • Added new AmazonBedrockConverseComponent in amazon_bedrock_converse.py, supporting the modern Converse API for improved conversation handling, more flexible model parameters, and robust error handling for unsupported models or parameters.
  • Updated the legacy AmazonBedrockComponent description to recommend the new Converse component for most users, clarifying its intended use and compatibility.

Output Text Extraction Improvements:

  • Refactored the _extract_output_text function in events.py to handle a wide variety of output formats, including ChatBedrockConverse responses, Anthropic-style outputs, and backward compatibility scenarios. The function now gracefully handles index-only items, tool use, partial JSON, mixed types, and multiple text segments, returning an empty string for non-text items.

Testing Enhancements:

  • Added a comprehensive suite of unit tests for _extract_output_text in test_agent_events.py, covering all major formats, edge cases, and backward compatibility scenarios, including specific cases that previously caused errors with ChatBedrockConverse.
  • Imported the _extract_output_text function in the test file to enable these new tests.

Summary by CodeRabbit

  • New Features
    • Added Amazon Bedrock Converse component with model selection, AWS credentials, region/endpoint support, generation controls, streaming toggle, and extra request fields, plus clearer initialization errors.
  • Bug Fixes
    • Improved reliability when extracting text from varied provider outputs and streaming chunks, avoiding tool-call and partial-JSON noise.
  • Documentation
    • Updated legacy Amazon Bedrock component description to recommend the Converse API for improved compatibility and features.
  • Tests
    • Added extensive test coverage for output parsing across diverse formats and edge cases.

…_text function

♻️ (events.py): refactor _extract_output_text function to handle various input formats and lengths more gracefully
✨ (amazon_bedrock_converse.py): add Amazon Bedrock Converse component for improved conversation handling with modern Converse API
📝 (amazon_bedrock_model.py): update description to recommend Amazon Bedrock Converse for better compatibility and features
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 11, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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.

Walkthrough

Adds robust parsing to _extract_output_text for varied output shapes. Introduces a new Amazon Bedrock Converse component with configurable AWS/auth and generation params, including error handling and optional streaming. Expands unit tests for _extract_output_text (with duplicated blocks). Updates legacy Amazon Bedrock component description only.

Changes

Cohort / File(s) Summary
Tests: Agent events extraction
src/backend/tests/unit/components/agents/test_agent_events.py
Adds extensive tests for _extract_output_text, covering strings, dicts, lists, tool_use, partial_json, index-only, streaming-like chunks, mixed formats, and backward-compat cases. Contains duplicated test blocks.
Agent events: output text extraction
src/lfx/src/lfx/base/agents/events.py
Reworks _extract_output_text to handle lists of strings/dicts, concatenate valid text parts, and skip tool_use/partial_json/index-only items; returns empty string on unsupported inputs.
New component: Amazon Bedrock Converse
src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py
Adds AmazonBedrockConverseComponent with inputs for model, AWS creds/profile, region, endpoint, gen params (temperature, max_tokens, top_p, top_k), streaming toggle, and additional_model_fields. Dynamically imports ChatBedrockConverse, builds init_params, aggregates additional fields, and implements targeted error handling.
Legacy Amazon Bedrock component description
src/lfx/src/lfx/components/amazon/amazon_bedrock_model.py
Updates description to recommend Converse API; no logic changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Component as AmazonBedrockConverseComponent
  participant Importer as Dynamic Import
  participant Model as ChatBedrockConverse

  User->>Component: build_model()
  Component->>Importer: import ChatBedrockConverse
  alt package missing
    Importer-->>Component: ImportError
    Component-->>User: Raises helpful ImportError
  else package available
    Component->>Component: Assemble init_params (model, region, creds, endpoint, gen params)
    Component->>Component: Aggregate additional_model_request_fields (if provided)
    Component->>Model: new ChatBedrockConverse(**init_params)
    alt init error
      Model-->>Component: Exception (validation/Converse issue/other)
      Component-->>User: Raise mapped, user-friendly error
    else success
      Model-->>Component: instance
      Component-->>User: return model
    end
  end
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant Func as _extract_output_text

  Caller->>Func: output
  alt output is string
    Func-->>Caller: output
  else output is list
    loop items
      alt item is string
        Func->>Func: append text
      else item is dict with text
        alt text present and not None
          Func->>Func: append item.text
        else
          Func->>Func: skip/append ""
        end
      else item is tool_use / partial_json / index-only
        Func->>Func: skip
      else
        Func->>Func: skip
      end
    end
    Func-->>Caller: concatenated text (or "")
  else other shapes
    Func-->>Caller: ""
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary changes — adding a Converse component and improving output extraction — using a short single sentence without noisy detail, so it conveys the main intent for a reviewer scanning history.
Docstring Coverage ✅ Passed Docstring coverage is 88.46% which is sufficient. The required threshold is 80.00%.

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary changes — adding a Converse component and improving output extraction — using a short single sentence without noisy detail, so it conveys the main intent for a reviewer scanning history.
Docstring Coverage ✅ Passed Docstring coverage is 88.46% which is sufficient. The required threshold is 80.00%.

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary changes — adding a Converse component and improving output extraction — using a short single sentence without noisy detail, so it conveys the main intent for a reviewer scanning history.
Docstring Coverage ✅ Passed Docstring coverage is 88.46% which is sufficient. The required threshold is 80.00%.

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 github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 11, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.65%. Comparing base (ca2309f) to head (58801ba).

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

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #9822      +/-   ##
==========================================
- Coverage   22.86%   21.65%   -1.22%     
==========================================
  Files        1086     1074      -12     
  Lines       39743    39671      -72     
  Branches     5420     5414       -6     
==========================================
- Hits         9089     8590     -499     
- Misses      30499    30937     +438     
+ Partials      155      144      -11     
Flag Coverage Δ
backend 46.89% <ø> (+0.45%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 64 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/backend/tests/unit/components/agents/test_agent_events.py (1)

548-733: Add missing unit tests for AmazonBedrockConverseComponent

Component present at src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py but no test found — add src/backend/tests/unit/components/amazon/test_amazon_bedrock_converse.py. Minimal skeleton:

import pytest
from src.backend.tests.base import ComponentTestBaseWithoutClient
from lfx.components.amazon.amazon_bedrock_converse import AmazonBedrockConverseComponent

class TestAmazonBedrockConverse(ComponentTestBaseWithoutClient):
    @pytest.fixture
    def component_class(self):
        return AmazonBedrockConverseComponent

    @pytest.fixture
    def default_kwargs(self):
        return {
            "model_id": "anthropic.claude-3-haiku-20240307-v1:0",
            "region_name": "us-east-1",
            "aws_access_key_id": "dummy",
            "aws_secret_access_key": "dummy",
        }

    @pytest.fixture
    def file_names_mapping(self):
        return {}

    def test_build_model_initializes(self, component_class, default_kwargs, monkeypatch):
        import types
        class DummyModel: ...
        monkeypatch.setattr("lfx.components.amazon.amazon_bedrock_converse.boto3", types.SimpleNamespace(Session=lambda **_: object()))
        monkeypatch.setattr("lfx.components.amazon.amazon_bedrock_converse.ChatBedrockConverse", lambda **_: DummyModel())
        comp = component_class(**default_kwargs)
        model = comp.build_model()
        assert isinstance(model, DummyModel)
🧹 Nitpick comments (9)
src/lfx/src/lfx/base/agents/events.py (2)

114-129: Coerce collected text to str to avoid TypeErrors during join

item["text"] can be non-str (e.g., numbers); casting prevents runtime errors when joining.

Apply this diff:

-            for item in output:
+            for item in output:
                 if isinstance(item, str):
                     text_parts.append(item)
                 elif isinstance(item, dict):
-                    if "text" in item and item["text"] is not None:
-                        text_parts.append(item["text"])
+                    if "text" in item and item["text"] is not None:
+                        text_parts.append(str(item["text"]))
                     # Skip tool_use, index-only, and partial_json items
                     elif (
                         item.get("type") == "tool_use" or "partial_json" in item or ("index" in item and len(item) == 1)
                     ):
                         continue
             return "".join(text_parts)

95-95: Accept tuples as well as lists for output sequences

Some providers yield tuples; supporting (list | tuple) keeps behavior consistent.

Apply this diff:

-    if isinstance(output, list):
+    if isinstance(output, (list, tuple)):
src/backend/tests/unit/components/agents/test_agent_events.py (2)

9-9: Avoid importing a private helper in tests

_importing _extract_output_text creates tight coupling to internals. Prefer re-exporting it without underscore (e.g., extract_output_text) from events.py or testing behavior via public handlers.


548-733: Parametrize to reduce repetition and speed up tests

Several cases differ only by input/expected. Parametrize to keep tests concise.

Example:

import pytest

@pytest.mark.parametrize(
    "inp,expected",
    [
        ("simple text output", "simple text output"),
        ([], ""),
        (["text content"], "text content"),
        ([{"text": "message content"}], "message content"),
        ([{"type": "tool_use"}], ""),
        ([{"partial_json": "{}"}], ""),
    ],
)
def test_extract_output_text_parametrized(inp, expected):
    assert _extract_output_text(inp) == expected
src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py (5)

121-127: Helpful dependency error; consider adding boto3 presence hint as well.

If boto3 is missing, the constructor will likely fail later. Optional: pre-check and raise a clearer message, consistent with the legacy component.

         try:
             from langchain_aws.chat_models.bedrock_converse import ChatBedrockConverse
         except ImportError as e:
             msg = "langchain_aws is not installed. Please install it with `pip install langchain_aws`."
             raise ImportError(msg) from e
+        try:
+            import boto3  # noqa: F401
+        except ImportError as e:
+            raise ImportError("boto3 is not installed. Please install it with `pip install boto3`.") from e

158-174: Check kwarg name: additional_model_request_fields vs additional_model_fields / model_kwargs.

The wrong kwarg name will break initialization. Also, merging dicts is shallow; nested keys (e.g., inferenceConfig) may be overwritten unexpectedly.

If docs confirm the kwarg should be additional_model_fields, apply:

-        if additional_model_request_fields:
-            init_params["additional_model_request_fields"] = additional_model_request_fields
+        if additional_model_request_fields:
+            init_params["additional_model_fields"] = additional_model_request_fields

Optionally deep-merge dicts to avoid clobbering sibling keys.


175-195: Improve error mapping for constructor kwarg issues.

Handle “unexpected keyword argument” explicitly to aid users tuning params.

         except Exception as e:
             # Provide helpful error message with fallback suggestions
             error_details = str(e)
             if "validation error" in error_details.lower():
                 msg = (
                     f"ChatBedrockConverse validation error: {error_details}. "
                     f"This may be due to incompatible parameters for model '{self.model_id}'. "
                     f"Consider adjusting the model parameters or trying the legacy Amazon Bedrock component."
                 )
+            elif "unexpected keyword argument" in error_details.lower():
+                msg = (
+                    f"Initialization error: {error_details}. One or more parameters are not supported "
+                    f"by the installed langchain_aws version. Review the ChatBedrockConverse constructor "
+                    f"and remove/rename unsupported kwargs."
+                )
             elif "converse api" in error_details.lower():
                 msg = (
                     f"Converse API error: {error_details}. "
                     f"The model '{self.model_id}' may not support the Converse API. "
                     f"Try using the legacy Amazon Bedrock component instead."
                 )
             else:
                 msg = f"Could not initialize ChatBedrockConverse: {error_details}"

69-74: Endpoint override is helpful; consider clarifying when it’s needed.

Add note that most users should leave it blank to use the managed Bedrock endpoint for the selected region.


121-197: Optional: add a lightweight unit test to lock constructor args.

Mock ChatBedrockConverse and assert it receives expected kwargs for a few input combinations (default creds, profile, explicit keys, disable_streaming, additional fields).

I can draft a pytest using mocker to assert the init kwargs without hitting AWS. Want me to open a follow-up PR with tests?

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c54a11 and bde6d52.

📒 Files selected for processing (4)
  • src/backend/tests/unit/components/agents/test_agent_events.py (2 hunks)
  • src/lfx/src/lfx/base/agents/events.py (1 hunks)
  • src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py (1 hunks)
  • src/lfx/src/lfx/components/amazon/amazon_bedrock_model.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
src/backend/tests/unit/components/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)

src/backend/tests/unit/components/**/*.py: Mirror the component directory structure for unit tests in src/backend/tests/unit/components/
Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Provide file_names_mapping for backward compatibility in component tests
Create comprehensive unit tests for all new components

Files:

  • src/backend/tests/unit/components/agents/test_agent_events.py
{src/backend/**/*.py,tests/**/*.py,Makefile}

📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)

{src/backend/**/*.py,tests/**/*.py,Makefile}: Run make format_backend to format Python code before linting or committing changes
Run make lint to perform linting checks on backend Python code

Files:

  • src/backend/tests/unit/components/agents/test_agent_events.py
src/backend/tests/unit/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/backend_development.mdc)

Test component integration within flows using create_flow, build_flow, and get_build_events utilities

Files:

  • src/backend/tests/unit/components/agents/test_agent_events.py
src/backend/tests/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)

src/backend/tests/**/*.py: Unit tests for backend code must be located in the 'src/backend/tests/' directory, with component tests organized by component subdirectory under 'src/backend/tests/unit/components/'.
Test files should use the same filename as the component under test, 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 in backend Python tests, as defined in 'src/backend/tests/conftest.py'.
When writing component tests, inherit from the appropriate base class in 'src/backend/tests/base.py' (ComponentTestBase, ComponentTestBaseWithClient, or ComponentTestBaseWithoutClient) and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping'.
Each test in backend Python test files should have a clear docstring explaining its purpose, and complex setups or mocks should be well-commented.
Test both sync and async code paths in backend Python tests, using '@pytest.mark.asyncio' for async tests.
Mock external dependencies appropriately in backend Python tests to isolate unit tests from external services.
Test error handling and edge cases in backend Python tests, including using 'pytest.raises' and asserting error messages.
Validate input/output behavior and test component initialization and configuration in backend Python tests.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests when necessary.
Be aware of ContextVar propagation in async tests; test both direct event loop execution and 'asyncio.to_thread' scenarios to ensure proper context isolation.
Test error handling by mocking internal functions using monkeypatch in backend Python tests.
Test resource cleanup in backend Python tests by using fixtures that ensure proper initialization and cleanup of resources.
Test timeout and performance constraints in backend Python tests using 'asyncio.wait_for' and timing assertions.
Test Langflow's Messag...

Files:

  • src/backend/tests/unit/components/agents/test_agent_events.py
src/backend/**/components/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/icons.mdc)

In your Python component class, set the icon attribute to a string matching the frontend icon mapping exactly (case-sensitive).

Files:

  • src/backend/tests/unit/components/agents/test_agent_events.py
🧬 Code graph analysis (2)
src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py (1)
src/lfx/src/lfx/components/amazon/amazon_bedrock_model.py (1)
  • build_model (83-128)
src/backend/tests/unit/components/agents/test_agent_events.py (1)
src/lfx/src/lfx/base/agents/events.py (1)
  • _extract_output_text (88-131)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 5
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 2
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 4
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 3
  • GitHub Check: Run Backend Tests / Unit Tests - Python 3.10 - Group 1
  • GitHub Check: Test Starter Templates
  • GitHub Check: Run Backend Tests / Integration Tests - Python 3.10
  • GitHub Check: Update Starter Projects
🔇 Additional comments (8)
src/lfx/src/lfx/components/amazon/amazon_bedrock_model.py (1)

10-14: LGTM: clearer legacy guidance in description

Good call-out steering users to the Converse component; no behavioral changes introduced.

src/lfx/src/lfx/base/agents/events.py (1)

93-131: Robust multi-format extraction looks correct

Skips tool_use/partial_json/index-only safely and concatenates valid text parts; graceful empty-string fallback.

src/backend/tests/unit/components/agents/test_agent_events.py (1)

548-733: Excellent coverage for _extract_output_text across real-world shapes

Thorough cases for strings, mixed segments, tool_use, partial_json, and index-only.

src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py (5)

8-18: Good new component surface and clear description.

Naming, description, and beta flag look consistent with the legacy component and clarify migration.


62-68: Region default is fine; confirm AWS_REGIONS content matches Bedrock-supported regions.

If the list includes regions where Bedrock Converse isn’t available, filter or annotate accordingly.

Would you like me to scan the constants and cross-check against AWS docs?


20-27: Incorrect — casing is consistent: AWS_MODEL_IDs
AWS_MODEL_IDs is defined at src/lfx/src/lfx/base/models/aws_constants.py:105 and is imported/used as AWS_MODEL_IDs in src/lfx/src/lfx/components/amazon/amazon_bedrock_model.py and src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py, so no import-time error from casing.
Also: amazon_bedrock_converse.py imports from langflow.base.models.aws_constants (not lfx.base) — confirm that import path is intentional.

Likely an incorrect or invalid review comment.


19-27: Default model ID exists — no action required.

"anthropic.claude-3-5-sonnet-20241022-v2:0" is included in AWS_MODELS_DETAILED (src/lfx/src/lfx/base/models/aws_constants.py) and matches the default in src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py.


105-111: Incorrect — ChatBedrockConverse already accepts disable_streaming

LangChain docs list disable_streaming: bool | Literal['tool_calling'] as a constructor parameter, so the suggested mapping to streaming is unnecessary; keep the current disable_streaming usage.

Likely an incorrect or invalid review comment.

Comment on lines +28 to +43
SecretStrInput(
name="aws_access_key_id",
display_name="AWS Access Key ID",
info="The access key for your AWS account. "
"Usually set in Python code as the environment variable 'AWS_ACCESS_KEY_ID'.",
value="AWS_ACCESS_KEY_ID",
required=True,
),
SecretStrInput(
name="aws_secret_access_key",
display_name="AWS Secret Access Key",
info="The secret key for your AWS account. "
"Usually set in Python code as the environment variable 'AWS_SECRET_ACCESS_KEY'.",
value="AWS_SECRET_ACCESS_KEY",
required=True,
),
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.

⚠️ Potential issue

Do not require or persist long‑lived AWS secrets; rely on the default provider chain.

Requiring static keys and storing them (default load_from_db=True) is a security risk and breaks common AWS setups (env vars, IAM roles, SSO/profile). Make these optional, advanced, and non-persistent.

Apply this diff:

-        SecretStrInput(
+        SecretStrInput(
             name="aws_access_key_id",
             display_name="AWS Access Key ID",
-            info="The access key for your AWS account. "
-            "Usually set in Python code as the environment variable 'AWS_ACCESS_KEY_ID'.",
-            value="AWS_ACCESS_KEY_ID",
-            required=True,
+            info="Optional. Prefer the AWS default credential chain (env vars, EC2/ECS/SSO/profile).",
+            required=False,
+            advanced=True,
+            load_from_db=False,
         ),
-        SecretStrInput(
+        SecretStrInput(
             name="aws_secret_access_key",
             display_name="AWS Secret Access Key",
-            info="The secret key for your AWS account. "
-            "Usually set in Python code as the environment variable 'AWS_SECRET_ACCESS_KEY'.",
-            value="AWS_SECRET_ACCESS_KEY",
-            required=True,
+            info="Optional. Only provide if not using the default credential chain.",
+            required=False,
+            advanced=True,
+            load_from_db=False,
         ),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SecretStrInput(
name="aws_access_key_id",
display_name="AWS Access Key ID",
info="The access key for your AWS account. "
"Usually set in Python code as the environment variable 'AWS_ACCESS_KEY_ID'.",
value="AWS_ACCESS_KEY_ID",
required=True,
),
SecretStrInput(
name="aws_secret_access_key",
display_name="AWS Secret Access Key",
info="The secret key for your AWS account. "
"Usually set in Python code as the environment variable 'AWS_SECRET_ACCESS_KEY'.",
value="AWS_SECRET_ACCESS_KEY",
required=True,
),
SecretStrInput(
name="aws_access_key_id",
display_name="AWS Access Key ID",
info="Optional. Prefer the AWS default credential chain (env vars, EC2/ECS/SSO/profile).",
required=False,
advanced=True,
load_from_db=False,
),
SecretStrInput(
name="aws_secret_access_key",
display_name="AWS Secret Access Key",
info="Optional. Only provide if not using the default credential chain.",
required=False,
advanced=True,
load_from_db=False,
),
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py around lines
28-43, the AWS access key and secret are currently required and persisted;
change them to optional, non-persistent advanced inputs: set required=False,
mark them as advanced (advanced=True), and disable persistence/load from DB
(load_from_db=False). Also remove or clear the hardcoded default values (use
None or an empty string) so the code relies on the default AWS provider chain
(env vars, IAM roles, SSO/profile) unless a user explicitly supplies them in
advanced settings.

Comment on lines +97 to +104
IntInput(
name="top_k",
display_name="Top K",
value=250,
info="Limits the number of highest probability vocabulary tokens to consider. "
"Note: Not all models support top_k. Use 'Additional Model Fields' for manual configuration if needed.",
advanced=True,
),
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.

🛠️ Refactor suggestion

top_k input is never applied; user setting is silently ignored.

Either remove the input or wire it into the init params to avoid confusion.

Apply this minimal wiring (pending API confirmation; see separate verification comment):

         if hasattr(self, "top_p") and self.top_p is not None:
             init_params["top_p"] = self.top_p
+        if hasattr(self, "top_k") and self.top_k is not None:
+            init_params["top_k"] = self.top_k

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py around lines 97
to 104, the IntInput "top_k" is declared but never used so user changes are
ignored; either remove this input or wire it through to the model
invocation/init params where the request payload or client call is constructed
(i.e., add top_k to the parameters dict passed to the Bedrock converse/generate
method, converting to the expected key name and type), and guard it with the
model/API support check; if the API does not support top_k, remove the input to
avoid confusion.

Comment on lines +134 to +145
# Add AWS credentials if provided
if self.aws_access_key_id:
init_params["aws_access_key_id"] = self.aws_access_key_id
if self.aws_secret_access_key:
init_params["aws_secret_access_key"] = self.aws_secret_access_key
if self.aws_session_token:
init_params["aws_session_token"] = self.aws_session_token
if self.credentials_profile_name:
init_params["credentials_profile_name"] = self.credentials_profile_name
if self.endpoint_url:
init_params["endpoint_url"] = self.endpoint_url

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.

🛠️ Refactor suggestion

Validate credential combinations (all-or-none, and mutually exclusive with profile).

Prevents confusing AWS auth resolution and partial-key errors.

-        # Add AWS credentials if provided
+        # Validate credentials: either both static keys, or profile, or neither (default chain)
+        if bool(self.aws_access_key_id) ^ bool(self.aws_secret_access_key):
+            raise ValueError(
+                "Provide both aws_access_key_id and aws_secret_access_key together, "
+                "or leave both blank to use the AWS default credential chain."
+            )
+        if self.credentials_profile_name and (self.aws_access_key_id or self.aws_secret_access_key or self.aws_session_token):
+            raise ValueError("Use either credentials_profile_name or explicit keys, not both.")
+        # Add AWS credentials if provided
         if self.aws_access_key_id:
             init_params["aws_access_key_id"] = self.aws_access_key_id
         if self.aws_secret_access_key:
             init_params["aws_secret_access_key"] = self.aws_secret_access_key
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Add AWS credentials if provided
if self.aws_access_key_id:
init_params["aws_access_key_id"] = self.aws_access_key_id
if self.aws_secret_access_key:
init_params["aws_secret_access_key"] = self.aws_secret_access_key
if self.aws_session_token:
init_params["aws_session_token"] = self.aws_session_token
if self.credentials_profile_name:
init_params["credentials_profile_name"] = self.credentials_profile_name
if self.endpoint_url:
init_params["endpoint_url"] = self.endpoint_url
# Validate credentials: either both static keys, or profile, or neither (default chain)
if bool(self.aws_access_key_id) ^ bool(self.aws_secret_access_key):
raise ValueError(
"Provide both aws_access_key_id and aws_secret_access_key together, "
"or leave both blank to use the AWS default credential chain."
)
if self.credentials_profile_name and (self.aws_access_key_id or self.aws_secret_access_key or self.aws_session_token):
raise ValueError("Use either credentials_profile_name or explicit keys, not both.")
# Add AWS credentials if provided
if self.aws_access_key_id:
init_params["aws_access_key_id"] = self.aws_access_key_id
if self.aws_secret_access_key:
init_params["aws_secret_access_key"] = self.aws_secret_access_key
if self.aws_session_token:
init_params["aws_session_token"] = self.aws_session_token
if self.credentials_profile_name:
init_params["credentials_profile_name"] = self.credentials_profile_name
if self.endpoint_url:
init_params["endpoint_url"] = self.endpoint_url
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py around lines 134
to 145, validate AWS credential combinations before populating init_params:
ensure that credentials_profile_name is mutually exclusive with any of
aws_access_key_id/aws_secret_access_key/aws_session_token (raise an error if
both profile and any key are provided), and enforce that if either
aws_access_key_id or aws_secret_access_key is provided the other must be present
(aws_session_token may be optional), otherwise raise a clear ValueError; perform
these checks early and only then add the validated keys/profile to init_params.

Comment on lines +146 to +153
# Add model parameters directly as supported by ChatBedrockConverse
if hasattr(self, "temperature") and self.temperature is not None:
init_params["temperature"] = self.temperature
if hasattr(self, "max_tokens") and self.max_tokens is not None:
init_params["max_tokens"] = self.max_tokens
if hasattr(self, "top_p") and self.top_p is not None:
init_params["top_p"] = self.top_p

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.

💡 Verification agent

🧩 Analysis chain

Confirm parameter names for generation controls with ChatBedrockConverse.

temperature, max_tokens, top_p (and top_k if wired) must match the expected constructor args; otherwise you’ll hit “unexpected keyword argument.”


🌐 Web query:

Does `ChatBedrockConverse` accept `temperature`, `max_tokens`, `top_p`, and `top_k` directly as constructor kwargs? If not, what are the correct names?

💡 Result:

Short answer: No — while temperature and max_tokens are shown as top-level kwargs in the LangChain docs/example, top_p and top_k should be passed via model_kwargs. Also note Bedrock’s native name for the sampling-length param is often max_tokens_to_sample (provider-specific) even though LangChain examples may use max_tokens. Sources: LangChain ChatBedrockConverse docs (example showing temperature / max_tokens). [1] Community/Bedrock examples showing top_p, top_k and max_tokens_to_sample in model_kwargs. [2][3]

Sources

  • LangChain ChatBedrockConverse docs/example. [1]
  • LangChain/GitHub and community Bedrock examples showing top_p/top_k in model_kwargs and Bedrock’s max_tokens_to_sample usage. [2][3]

Don't pass top_p/top_k as top-level kwargs — move them into model_kwargs and verify the token param name.

ChatBedrockConverse accepts temperature and max_tokens as top-level kwargs, but top_p/top_k must be supplied via model_kwargs; Bedrock may expect max_tokens_to_sample instead of max_tokens — update src/lfx/src/lfx/components/amazon/amazon_bedrock_converse.py (lines 146–153).

…omplete(url_component.to_toolkit()) to handle asynchronous operation

🐛 (agent.py): Change CurrentDateComponent(**self.get_base_args()).to_toolkit() to await CurrentDateComponent(**self.get_base_args()).to_toolkit() to handle asynchronous operation
🐛 (component.py): Change def to_toolkit(self) -> list[Tool]: to async def to_toolkit(self) -> list[Tool]: to handle asynchronous operation and await for _get_tools() if it's a coroutine function.
…d names to snake_case for better compatibility with schema field names.
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 12, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 12, 2025
assert sse_client._connection_params["headers"] == test_headers


class TestFieldNameConversion:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we have this change in in this PR?

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 17, 2025
@sonarqubecloud
Copy link
Copy Markdown

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Sep 17, 2025
@Cristhianzl
Copy link
Copy Markdown
Member Author

please follow up this PR: #9901

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants