crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[FEATURE] No Errors in Pyright for Example Code

Open ChiefMateStarbuck opened this issue 9 months ago • 0 comments

The example crew.py has multiple errors when using pyright LSP. The errors are listed below

    def researcher(self) -> Agent: 
        return Agent(
            config=self.agents_config['researcher'], 
            verbose=True
        )
Arguments missing for parameters "role", "goal", "backstory"
Argument of type "Literal['researcher']" cannot be assigned to parameter "key" of type "SupportsIndex | slice[Any, Any, Any]" in function "__getitem__"
  Type "Literal['researcher']" is not assignable to type "SupportsIndex | slice[Any, Any, Any]"
    "Literal['researcher']" is incompatible with protocol "SupportsIndex"
      "__index__" is not present
    "Literal['researcher']" is not assignable to "slice[Any, Any, Any]"

The first is error is that the config=self.agents_config['researcher'], line is not properly informing pyright of the fact that these parameters are set within the yaml file. I am uncertain of what a solution would look like.

The second error is beyond my python knowledge.

Both of these errors are also prevalent in the Task() initializer function.

        return Crew(
            agents=self.agents, # Automatically created by the @agent decorator
            tasks=self.tasks, # Automatically created by the @task decorator
            process=Process.sequential,
            verbose=True,
            # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
        )
Cannot access attribute "agents" for class "LogCrews*"
  Attribute "agents" is unknown

The error is that self.agent doesn't exists until @agent decorator creates them.

I am uncertain of how to solve these problems, but given guidance, I am willing to take this on task. LMK

Willingness to Contribute

Yes, I'd be happy to submit a pull request

ChiefMateStarbuck avatar Apr 08 '25 22:04 ChiefMateStarbuck