langflow icon indicating copy to clipboard operation
langflow copied to clipboard

agents not found in SequentialCrewComponent

Open Gluepower opened this issue 1 year ago • 8 comments

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 "", line 27, in build_crew File "", line 24, in get_tasks_and_agents File "/app/.venv/lib/python3.12/site-packages/langflow/base/agents/crewai/crew.py", line 137, in get_tasks_and_agents return self.tasks, self.agents ^^^^^^^^^^^ File "/app/.venv/lib/python3.12/site-packages/langflow/custom/custom_component/component.py", line 665, in getattr raise AttributeError(msg) AttributeError: agents not found in SequentialCrewComponent

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

Gluepower avatar Nov 29 '24 20:11 Gluepower

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:

  1. Extract Agents from Tasks: The get_tasks_and_agents method now extracts agents directly from the tasks, assuming each task has an agent attribute. This is done using a set to ensure uniqueness:

    agents = list(set(task.agent for task in self.tasks if hasattr(task, 'agent')))
    
  2. Return Tasks and Agents: The method returns both tasks and the extracted agents:

    return self.tasks, agents
    
  3. Build Crew: The build_crew method uses the tasks and agents returned by get_tasks_and_agents to construct the Crew object.

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.

dosubot[bot] avatar Nov 29 '24 20:11 dosubot[bot]

I am having the same error

bezelga avatar Nov 30 '24 19:11 bezelga

I have the same problem.

cBevilaqua avatar Dec 02 '24 17:12 cBevilaqua

Same issue, has this been solved yet?

amannaik247 avatar Dec 05 '24 06:12 amannaik247

Hey @Gluepower

Could you share your flow?

carlosrcoelho avatar Dec 06 '24 01:12 carlosrcoelho

Hey @Gluepower

Could you share your flow?

Hey could I share my flow with you I am also facing the same issue

amannaik247 avatar Dec 07 '24 07:12 amannaik247

@amannaik247

Yes, please.

carlosrcoelho avatar Dec 09 '24 14:12 carlosrcoelho

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.

amannaik247 avatar Dec 09 '24 14:12 amannaik247

https://github.com/langflow-ai/langflow/pull/5233

It will be available in the next release.

carlosrcoelho avatar Dec 16 '24 00:12 carlosrcoelho

#5233

It will be available in the next release.

Is there a way to get early access to the release?

imrohankataria avatar Dec 18 '24 01:12 imrohankataria

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: Capture

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 avatar Dec 31 '24 05:12 wahidur028

@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.

amannaik247 avatar Jan 03 '25 08:01 amannaik247