fix(crewai): apply convert_llm and convert_tools in SequentialTaskAgentComponent#13867
Conversation
…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
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughSequentialTaskAgentComponent now converts its configured LLM and tools before creating the CrewAI Agent. The task/agent chaining and task field handling remain unchanged. ChangesSequential task agent conversion
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 2 warnings)
✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/lfx/src/lfx/components/crewai/sequential_task_agent.py
| llm=convert_llm(self.llm), | ||
| verbose=self.verbose, | ||
| memory=self.memory, | ||
| tools=self.tools or [], | ||
| tools=convert_tools(self.tools), |
There was a problem hiding this comment.
🩺 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/crewaiRepository: 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:
- 1: https://docs.crewai.com/en/tools/ai-ml/langchaintool
- 2: https://docs.crewai.com/v1.14.7/en/tools/ai-ml/langchaintool
- 3: [BUG] Agent initialization with native langchain tools produce pydantic validation error crewAIInc/crewAI#1676
- 4: https://stackoverflow.com/questions/79226122/crewai-error-when-trying-to-use-the-langchain-tool-input-should-be-a-valid-dict
- 5: https://community.crewai.com/t/passing-crewstructuredtool-to-tools/4102
- 6: https://docs.crewai.com/v1.14.7/en/tools/overview
- 7: https://docs.crewai.com/en/learn/create-custom-tools
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
-
Initial conversion (
src/lfx/src/lfx/components/crewai/sequential_task_agent.py:124):tools=convert_tools(self.tools),
-
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.
Summary
SequentialTaskAgentComponent.build_agent_and_taskpassed the raw LangChain LLM handle and tool list directly tocrewai.Agent, while the siblingCrewAIAgentComponent.build_outputalready callsconvert_llm()andconvert_tools()at construction time.This asymmetry means any consumer of the
SequentialTask.agentoutput port that is notSequentialCrewComponentreceives an Agent whose.llmis a LangChain type rather than acrewai.LLM, causing runtime failures.Changes:
convert_llmandconvert_toolsfromlfx.base.agents.crewai.crewAgent(...)construction, matchingCrewAIAgentComponentFixes #13848
Test plan
.llmSummary by CodeRabbit