fix: add ModelInput to listed components by HimavarshaVS · Pull Request #11886 · langflow-ai/langflow (original) (raw)

Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lfx/src/lfx/_assets/component_index.json`:
- Line 79655: update_build_config must enforce a WatsonX-safe agent_type: inside
the is_watsonx branch (in update_build_config) locate the build_config entries
for "agent_type" and, when is_watsonx is True, set
build_config["agent_type"]["value"] to "zero-shot-react-description" (or a
WatsonX-compatible default) and update build_config["agent_type"]["options"] to
remove or disable "openai-tools" and "openai-functions"; conversely, when
is_watsonx is False ensure the original options (including
"openai-tools"/"openai-functions") are present. Use the symbols
update_build_config, is_watsonx, and "agent_type" to find the code and ensure
create_csv_agent will not be called with an incompatible agent_type.
- Line 79655: The build_agent method leaks temp files because _get_local_path
may set self._temp_file_path for S3 downloads but build_agent lacks a finally
cleanup; update build_agent (the method that creates agent_csv) to mirror
build_agent_response by wrapping the core logic in try...finally and call
self._cleanup_temp_file() in the finally block so any temp file created by
_get_local_path is removed; reference build_agent, _get_local_path,
_cleanup_temp_file, and build_agent_response when making the change.

In `@src/lfx/src/lfx/components/langchain_utilities/csv_agent.py`:
- Around line 125-151: The type annotation for update_build_config's parameter
field_value is too narrow (currently str) given the runtime handling of list
values for model selections; update the signature of
update_build_config(field_value: ...) to accept the actual types emitted by
ModelInput (e.g., str | list[dict] or a more specific Sequence[Mapping] / list
of model choice dicts) and adjust any imports (typing.Sequence/Mapping) as
needed so the isinstance(current_model_value, list) branch works when field_name
== "model"; keep the rest of the function logic unchanged and ensure any
callers/tests use the widened type or are updated to match.
- Line 52: The code currently uses IBM_WATSONX_URLS[0] at class-definition time
which will raise IndexError if IBM_WATSONX_URLS is empty; change the value
expression to safely handle an empty list (e.g., use IBM_WATSONX_URLS[0] if
IBM_WATSONX_URLS else None or use next(iter(IBM_WATSONX_URLS), None)) so the
module can import even when the constant is empty; update the place where
value=IBM_WATSONX_URLS[0] is defined to use the safe expression and ensure any
downstream code handles the None/default appropriately.

---

Outside diff comments:
In `@src/lfx/src/lfx/components/langchain_utilities/csv_agent.py`:
- Around line 194-228: build_agent currently calls self._get_local_path() then
_get_llm() and create_csv_agent(...) without ensuring cleanup on exceptions,
which can leak the temp file; wrap the body after obtaining local_path in a
try/finally and call self._cleanup_temp_file() in the finally block (mirroring
build_agent_response) so that any exception from _get_llm or create_csv_agent
still triggers cleanup; reference the build_agent method, self._get_local_path,
self._get_llm, create_csv_agent, and self._cleanup_temp_file when applying the
change.

---

Nitpick comments:
In `@src/lfx/src/lfx/_assets/component_index.json`:
- Line 79655: build_agent_response and build_agent duplicate the same
agent-creation logic (ImportError guard, allow_dangerous handling, agent_kwargs,
_get_local_path(), _get_llm(), and create_csv_agent call); extract this into a
new private helper _create_agent(self) -> AgentExecutor that performs the import
guard, resolves allow_dangerous, builds agent_kwargs, calls _get_local_path()
and _get_llm(), and returns the created agent_csv from create_csv_agent, then
have build_agent_response call _create_agent() and invoke it, and have
build_agent call _create_agent() and set self.status and return the agent;
ensure cleanup behavior still calls _cleanup_temp_file() from
build_agent_response as before.

In `@src/lfx/src/lfx/components/langchain_utilities/csv_agent.py`:
- Around line 128-129: The inner function get_tool_calling_model_options is
recreated on every call; replace it with a direct call or a hoisted helper to
avoid allocating a closure each time — e.g., remove the nested def and either
call get_language_model_options(user_id=user_id, tool_calling=True) inline where
used or define a top-level helper function named get_tool_calling_model_options
that simply delegates to get_language_model_options(user_id, tool_calling=True);
update all references to use that single function instead of creating a new
closure.
- Around line 115-123: The _get_llm method uses getattr(self, "...", None) for
inputs that are declared attributes (api_key, base_url_ibm_watsonx, project_id),
which is unnecessary and can hide typos; update _get_llm to pass the direct
attributes (self.api_key, self.base_url_ibm_watsonx, self.project_id) into
get_llm so attribute access is explicit and errors from misspelled names surface
immediately.