agents not found in SequentialCrewComponent
Bug Description
Error building Component Sequential Crew:
agents not found in SequentialCrewComponent
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/langflow/graph/vertex/base.py", line 709, in _build_results
result = await initialize.loading.get_instance_results(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/langflow/interface/initialize/loading.py", line 68, in get_instance_results
return await build_component(params=custom_params, custom_component=custom_component)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/langflow/interface/initialize/loading.py", line 145, in build_component
build_results, artifacts = await custom_component.build_results()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/langflow/custom/custom_component/component.py", line 837, in build_results
return await self._build_with_tracing()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/langflow/custom/custom_component/component.py", line 819, in _build_with_tracing
_results, _artifacts = await self._build_results()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/langflow/custom/custom_component/component.py", line 883, in _build_results
result = await method()
^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/langflow/base/agents/crewai/crew.py", line 178, in build_output
crew = self.build_crew()
^^^^^^^^^^^^^^^^^
File "
Reproduction
Flow used to work before, its sequental crew. after update gave that error. Claude gave me new code and it works again
from crewai import Agent, Crew, Process, Task from langflow.base.agents.crewai.crew import BaseCrewComponent from langflow.io import HandleInput from langflow.schema.message import Message
class SequentialCrewComponent(BaseCrewComponent): display_name: str = "Sequential Crew" description: str = "Represents a group of agents with tasks that are executed sequentially." documentation: str = "https://docs.crewai.com/how-to/Sequential/" icon = "CrewAI" inputs = [ *BaseCrewComponent._base_inputs, HandleInput(name="tasks", display_name="Tasks", input_types=["SequentialTask"], is_list=True), ]
def get_tasks_and_agents(self) -> tuple[list[Task], list[Agent]]:
# Extract agents from tasks
agents = list(set(task.agent for task in self.tasks if hasattr(task, 'agent')))
return self.tasks, agents
def build_crew(self) -> Message:
tasks, agents = self.get_tasks_and_agents()
return Crew(
agents=agents,
tasks=tasks,
process=Process.sequential,
verbose=self.verbose,
memory=self.memory,
cache=self.use_cache,
max_rpm=self.max_rpm,
share_crew=self.share_crew,
function_calling_llm=self.function_calling_llm,
step_callback=self.get_step_callback(),
task_callback=self.get_task_callback(),
)
Expected behavior
Flow shouldn't break after upgrade.
Who can help?
No response
Operating System
Render
Langflow Version
1.1.1
Python Version
3.12
Screenshot
No response
Flow File
No response
The error you're encountering, "agents not found in SequentialCrewComponent," seems to be related to how the agents attribute is being handled in the SequentialCrewComponent class. In the updated code you provided, the get_tasks_and_agents method extracts agents from tasks, which should resolve the issue if the tasks are correctly initialized with agents.
Here's a breakdown of the solution:
-
Extract Agents from Tasks: The
get_tasks_and_agentsmethod now extracts agents directly from the tasks, assuming each task has anagentattribute. This is done using a set to ensure uniqueness:agents = list(set(task.agent for task in self.tasks if hasattr(task, 'agent'))) -
Return Tasks and Agents: The method returns both tasks and the extracted agents:
return self.tasks, agents -
Build Crew: The
build_crewmethod uses the tasks and agents returned byget_tasks_and_agentsto construct theCrewobject.
This approach should prevent the "agents not found" error by ensuring that the agents attribute is dynamically constructed from the tasks, rather than relying on a potentially missing or uninitialized self.agents attribute. If the tasks are correctly set up with agents, this should resolve the issue.
To continue talking to Dosu, mention @dosu.
I am having the same error
I have the same problem.
Same issue, has this been solved yet?
Hey @Gluepower
Could you share your flow?
Hey @Gluepower
Could you share your flow?
Hey could I share my flow with you I am also facing the same issue
@amannaik247
Yes, please.
hello, can you tell me the process to share the flow i can't seem to find the option . I have also added the same issue on the help section of the langflow discord, if you want we can communicate there.
https://github.com/langflow-ai/langflow/pull/5233
It will be available in the next release.
#5233
It will be available in the next release.
Is there a way to get early access to the release?
Previously I was getting the same error. But after updating the code for "Sequential Crew" from here I am getting another error.
Error building Component Sequential Crew: argument of type 'NoneType' is not iterable
My flow:
Update code:
from crewai import Agent, Crew, Process, Task
from langflow.base.agents.crewai.crew import BaseCrewComponent
from langflow.io import HandleInput
from langflow.schema.message import Message
from langflow.base.agents.crewai.crew import Agent
class SequentialCrewComponent(BaseCrewComponent):
display_name: str = "Sequential Crew"
description: str = "Represents a group of agents with tasks that are executed sequentially."
documentation: str = "https://docs.crewai.com/how-to/Sequential/"
icon = "CrewAI"
inputs = [
*BaseCrewComponent._base_inputs,
HandleInput(name="tasks", display_name="Tasks", input_types=["SequentialTask"], is_list=True),
]
@property
def agents(self: 'SequentialCrewComponent') -> list[Agent]:
# Deriva os agentes diretamente das tarefas vinculadas
return [task.agent for task in self.tasks if hasattr(task, 'agent')]
def get_tasks_and_agents(self, agents_list=None) -> tuple[list[Task], list[Agent]]:
# Usa a propriedade agents para derivar agentes
if not agents_list:
# agents_list = [task.agent for task in self.tasks] or []
# Use the superclass implementation, passing the customized agents_list
existing_agents = self.agents
agents_list = existing_agents + (agents_list or [])
return super().get_tasks_and_agents(agents_list=agents_list)
def build_crew(self) -> Message:
tasks, agents = self.get_tasks_and_agents()
return Crew(
agents=agents,
tasks=tasks,
process=Process.sequential,
verbose=self.verbose,
memory=self.memory,
cache=self.use_cache,
max_rpm=self.max_rpm,
share_crew=self.share_crew,
function_calling_llm=self.function_calling_llm,
step_callback=self.get_step_callback(),
task_callback=self.get_task_callback(),
)
@wahidur028 The issue has been resolved and will soon be updated in the next release. @carlosrcoelho has fixed it in the dev tree i think.