Having error in Task Context

Continuing the discussion from Tasks Context raising error:

Does anyone faced the same problem with context?

Searching into CrewAI Docs, I found this.

To execute a task in CrewAI, you can follow these steps:

  1. Define the task:
task = Task(
    description="Your task description here",
    expected_output="Description of the expected output",
    agent=your_agent,
    output_file="path/to/output_file.md"  # Optional
)
  1. Execute the task:
task.execute()

Key points about task execution:

  • Tasks can be executed sequentially or hierarchically, depending on how you set up your Crew.
  • You can make tasks asynchronous by setting async_execution=Truewhen defining the task.
  • Tasks can be collaborative, involving multiple agents.
  • You can use the @task decorator to define tasks that are automatically sequenced and managed.
  • For asynchronous tasks, you can use the context attribute in future tasks to wait for their completion.

Example of defining and executing multiple tasks:

list_ideas = Task(
    description="List 5 interesting ideas for an AI article",
    expected_output="Bullet point list of 5 ideas",
    agent=researcher,
    async_execution=True
)

list_important_history = Task(
    description="Research 5 most important events in AI history",
    expected_output="Bullet point list of 5 events",
    agent=researcher,
    async_execution=True
)

write_article = Task(
    description="Write an article about AI, its history, and interesting ideas",
    expected_output="A 4 paragraph article about AI",
    agent=writer,
    context=[list_ideas, list_important_history]
)

# Execute tasks
list_ideas.execute()
list_important_history.execute()
write_article.execute()

This setup allows for efficient task execution, with asynchronous tasks running in parallel and the final task waiting for their completion before proceeding.

But when trying to execute a task in that manner, I receive the error: AttributeError: ‘Task’ object has no attribute ‘execute’

Any hint?

I would suggest starting with the example Crew (including using YAML files)
Quickstart - CrewAI
and modifying the Agents and Tasks with your specific Crew that you shared. Then use the kickoff method by just typing
crewai run
as in the top level example. This is much easier to get working than to try and just run a task manually like you were attempting. It is my understanding that in order to use context, the entire Crew needs to be kicked off with all of the Agents and Tasks as a system. The Crew concept is a wrapper around the Agents and Tasks, and in order to do high level things like run tasks with context etc… the Crew needs to be running, not just a Task. Good luck.

I solved the issue… thank anyway.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.