Skip to content

fix(crewai): apply convert_llm and convert_tools in SequentialTaskAgentComponent#13867

Open
gingeekrishna wants to merge 2 commits into
langflow-ai:mainfrom
gingeekrishna:fix/13848-sequential-task-agent-convert-llm
Open

fix(crewai): apply convert_llm and convert_tools in SequentialTaskAgentComponent#13867
gingeekrishna wants to merge 2 commits into
langflow-ai:mainfrom
gingeekrishna:fix/13848-sequential-task-agent-convert-llm

Conversation

@gingeekrishna

@gingeekrishna gingeekrishna commented Jun 26, 2026

Copy link
Copy Markdown

Summary

SequentialTaskAgentComponent.build_agent_and_task passed the raw LangChain LLM handle and tool list directly to crewai.Agent, while the sibling CrewAIAgentComponent.build_output already calls convert_llm() and convert_tools() at construction time.

This asymmetry means any consumer of the SequentialTask.agent output port that is not SequentialCrewComponent receives an Agent whose .llm is a LangChain type rather than a crewai.LLM, causing runtime failures.

Changes:

  • Import convert_llm and convert_tools from lfx.base.agents.crewai.crew
  • Apply both at Agent(...) construction, matching CrewAIAgentComponent

Fixes #13848

Test plan

  • Build a flow using Sequential Task Agent -> Sequential Crew with a non-OpenAI LLM; verify the crew runs without type errors on .llm
  • Confirm no regression on existing CrewAI Agent -> Sequential Crew flows

Summary by CodeRabbit

  • Bug Fixes
    • Improved agent setup to better handle model and tool inputs, making task execution more reliable.
    • Enhanced compatibility when connecting language models and tools to sequential agent workflows.

…ntComponent

SequentialTaskAgentComponent passed the raw LangChain LLM handle and
tool list directly to crewai.Agent, while the sibling CrewAIAgentComponent
already called convert_llm() and convert_tools() at construction time.
This asymmetry meant the legacy component produced Agents with a
LangChain-typed .llm, causing runtime failures for any consumer that is
not the SequentialCrew lazy-wrap path.

Fixes langflow-ai#13848
Copilot AI review requested due to automatic review settings June 26, 2026 18:50

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0e13643-e160-468a-8d55-bad7dab7f059

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

Walkthrough

SequentialTaskAgentComponent now converts its configured LLM and tools before creating the CrewAI Agent. The task/agent chaining and task field handling remain unchanged.

Changes

Sequential task agent conversion

Layer / File(s) Summary
LLM and tool conversion
src/lfx/src/lfx/components/crewai/sequential_task_agent.py
Adds convert_llm and convert_tools imports, then uses them when building the Agent in build_agent_and_task.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 2 warnings)

Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error Only the component source changed; no new or updated test file covers the convert_llm/convert_tools fix. The existing CrewAI test is unrelated wiring coverage. Add a regression test for SequentialTaskAgentComponent.build_agent_and_task asserting Agent llm/tools are converted, and verify the SequentialCrew path still passes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Quality And Coverage ⚠️ Warning No test exercises SequentialTaskAgentComponent.build_agent_and_task; existing CrewAI tests only cover wiring/LLM factory, so the new convert_llm/convert_tools path is unverified. Add unit tests mocking crewai to assert Agent gets converted llm/tools in SequentialTaskAgentComponent, plus a SequentialCrew regression test that consumes the output.
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix in SequentialTaskAgentComponent and matches the changeset.
Linked Issues check ✅ Passed The PR implements the issue's requested eager conversion of LLMs and tools in SequentialTaskAgentComponent.
Out of Scope Changes check ✅ Passed The changes are tightly scoped to the CrewAI conversion fix and do not add unrelated behavior.
Test File Naming And Structure ✅ Passed PASS: The PR only changes a non-test component; no test files were added/modified. Existing tests use the expected pytest naming, class-based structure, and descriptive test names.
Excessive Mock Usage Warning ✅ Passed No PR-related test file shows excessive mocking; the only relevant LFX test file has no mock usage.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 26, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lfx/src/lfx/components/crewai/sequential_task_agent.py`:
- Around line 121-124: The SequentialCrew flow is double-converting tools, which
causes failures when `SequentialTaskAgent` passes already-converted CrewAI tools
through `convert_tools` and `BaseCrewComponent.get_tasks_and_agents` converts
them again. Update `convert_tools` in the crew helper to be idempotent by
checking whether each item is already a CrewAI `Tool` before calling
`Tool.from_langchain`, or otherwise skip re-conversion in the
`get_tasks_and_agents` path when `agent.tools` has already been converted. Focus
on the `SequentialTaskAgent` setup and the shared `convert_tools` utility so
repeated conversion no longer breaks execution.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 20656c1a-1992-4bee-bb37-0aed1a1d1b20

📥 Commits

Reviewing files that changed from the base of the PR and between a277209 and fcaae6b.

📒 Files selected for processing (1)
  • src/lfx/src/lfx/components/crewai/sequential_task_agent.py

Comment on lines +121 to +124
llm=convert_llm(self.llm),
verbose=self.verbose,
memory=self.memory,
tools=self.tools or [],
tools=convert_tools(self.tools),

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.

🩺 Stability & Availability | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect convert_tools / get_tasks_and_agents and any idempotency handling
fd -t f 'crew.py' src/lfx/src/lfx/base/agents/crewai --exec sed -n '100,175p' {}

# Look for how SequentialCrewComponent feeds agents into get_tasks_and_agents
rg -nP -C3 'get_tasks_and_agents|convert_tools' src/lfx/src/lfx/components/crewai

Repository: langflow-ai/langflow

Length of output: 7510


🌐 Web query:

crewai Tool.from_langchain behavior when passed an existing crewai Tool object

💡 Result:

The crewAI Tool.from_langchain method is designed to convert LangChain tools into crewAI-compatible tools [1][2]. When passed an object that is already a crewAI Tool (specifically a subclass of BaseTool), the behavior is generally to attempt a conversion that may result in redundancy, type conflicts, or Pydantic validation errors [3][4]. Because crewAI agents and tasks strictly require tools that inherit from crewAI's BaseTool [5][4], passing an object through Tool.from_langchain that is already structured as a crewAI tool often causes issues during initialization [3]. Users frequently encounter Pydantic validation errors (e.g., 'Input should be a valid dictionary or instance of BaseTool') because the tool is already in the expected format, or the conversion wrapper creates a mismatch between expected schemas [3][5][4]. If you have an existing crewAI tool, you should not pass it to Tool.from_langchain. Instead, you should pass the instance directly to the Agent's tools list [1][6]. If you have a native LangChain tool that needs to be used as a crewAI tool, the recommended practice is to either use the tool decorator or subclass BaseTool to manually wrap the LangChain logic, ensuring compatibility with the current crewAI framework [7][4].

Citations:


Double conversion of tools causes runtime failure in SequentialCrew flow

The convert_tools function in src/lfx/src/lfx/base/agents/crewai/crew.py lacks an idempotency guard and unconditionally applies Tool.from_langchain. In the SequentialCrew path, SequentialTaskAgent initializes agents with already-converted CrewAI tools via tools=convert_tools(self.tools). These agents are then passed to get_tasks_and_agents, which calls convert_tools again on agent.tools. Since Tool.from_langchain expects LangChain tools and fails on existing CrewAI instances (raising Pydantic validation errors or type mismatches), this double conversion breaks the execution.

Double conversion evidence
  1. Initial conversion (src/lfx/src/lfx/components/crewai/sequential_task_agent.py:124):

    tools=convert_tools(self.tools),
  2. Re-conversion (src/lfx/src/lfx/components/crewai/sequential_crew.py:30 → src/lfx/src/lfx/base/agents/crewai/crew.py:156):

    # In BaseCrewComponent.get_tasks_and_agents
    for agent in agents_list:
        agent.tools = convert_tools(agent.tools)  # Fails on already-converted tools

Add an isinstance(tool, Tool) check in convert_tools to skip already-converted objects, or ensure agents bypass re-conversion if tools are pre-converted.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lfx/src/lfx/components/crewai/sequential_task_agent.py` around lines 121
- 124, The SequentialCrew flow is double-converting tools, which causes failures
when `SequentialTaskAgent` passes already-converted CrewAI tools through
`convert_tools` and `BaseCrewComponent.get_tasks_and_agents` converts them
again. Update `convert_tools` in the crew helper to be idempotent by checking
whether each item is already a CrewAI `Tool` before calling
`Tool.from_langchain`, or otherwise skip re-conversion in the
`get_tasks_and_agents` path when `agent.tools` has already been converted. Focus
on the `SequentialTaskAgent` setup and the shared `convert_tools` utility so
repeated conversion no longer breaks execution.

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.

[BUG] SequentialTaskAgentComponent skips convert_llm at Agent factory; sibling factory applies it

2 participants