Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thanhtran0302 opened this issue Sep 22, 2024 · 2 comments
Closed

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

thanhtran0302 opened this issue Sep 22, 2024 · 2 comments

Comments

@thanhtran0302
Copy link

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
Copy link
Collaborator

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()]
		)

@thanhtran0302
Copy link
Author

This is perfect ! Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants