crewAIInc / crewAI-examples

2.65k stars 993 forks source link

How to pass agent's output to another agent's input #168

Open thanhtran0302 opened 2 hours ago

thanhtran0302 commented 2 hours ago

Hi everyone, I'm new to CrewAI, and I juste generated a project with CrewAI CLI. And I'm trying to pass the result of the first agent's task, to another agent's input unsuccessfully.

Here is my crew.py file

from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task

@CrewBase
class RefinaCrew():
    """Refina crew"""
    agents_config = 'config/agents.yaml'
    tasks_config = 'config/tasks.yaml'

    @agent
    def ternary_developer(self) -> Agent:
        return Agent(
            config=self.agents_config['ternary_developer'],
            verbose=True
        )

    @agent
    def reviewer_developer(self) -> Agent:
        return Agent(
            config=self.agents_config['reviewer_developer'],
            verbose=True
        )

    @task
    def transform_ugly_ternary(self) -> Task:
        return Task(
            config=self.tasks_config['transform_ugly_ternary'],
        )

    @task
    def review_code_quality(self) -> Task:
        return Task(
            config=self.tasks_config['review_code_quality'],
            agent=self.reviewer_developer()
        )

    @crew
    def crew(self) -> Crew:
        """Creates the Refina crew"""
        return Crew(
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            verbose=True,
            # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
        )

Thank you !

joaomdmoura commented 2 hours ago

Hey @thanhtran0302 result from one task is automatically passed into the next, but you can force specific context to be passed by using the context attribute.

@task
    def review_code_quality(self) -> Task:
        return Task(
            config=self.tasks_config['review_code_quality'],
            agent=self.reviewer_developer()
            context=[self. transform_ugly_ternary()]
        )