Hi i would like to know if it possible to retry the last task. For example in this crew i have a reviewer agent, that checks for a condition if the condition is not passed then he should send it back to the last agent/task.
I’ve read that I should use the crew context for this but i dont have any idea on how to implement it. has anyone done somethig like this before?
@CrewBase
class LatestAiDevelopmentCrew():
“”“LatestAiDevelopment crew”“”
@agent
def researcher(self) → Agent:
return Agent(
config=self.agents_config[‘researcher’],
verbose=True,
tools=[SerperDevTool()]
)
@agent
def reporting_analyst(self) → Agent:
return Agent(
config=self.agents_config[‘reporting_analyst’],
verbose=True
)
@agent
def reviewer(self) → Agent:
return Agent(
config=self.agents_config[‘reviewer’],
verbose=True
)
@task
def research_task(self) → Task:
return Task(
config=self.tasks_config[‘research_task’],
)
@task
def reporting_task(self) → Task:
return Task(
config=self.tasks_config[‘reporting_task’],
)
@task
def reviewer_task(self) → Task: # if review condition is not passed it should go back to reporting task
def callback(result, context):
review_output = result.pydantic.passed
print(f"review_output, {review_output}“)
print(f"context, {context}”)
return Task(
config=self.tasks_config['review_task'],
callback=callback,
output_pydantic=ReviewResult
)
@crew
def crew(self) → Crew:
“”“Creates the LatestAiDevelopment crew”“”
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,
)