How to pass the same instructions to two agents without copy-pasting it twice?

I have an agent2 which reviews the work of agent1. Agent1 has a big set of guidelines to follow while doing the task and its a big task. Now agent2 needs to review that and if it doesnt find it appropritate, it needs to do that task itself. Is there any way that i can make agent2 know the guidelines for it if it needs to do it, Or I need to write the same thing in its task again.

Using Flows, you can do that by passing a variable when kicking off the crew. The variable will be passed to both agents as defined in the YAML file.

agents.yaml

agent_1:
  role: |
    Agent 1
  goal: >
    Write the goal here.
  backstory: >
    Follow {set_of_guidelines}

agent_2:
  role: |
    Agent 2
  goal: >
    Write the goal here.
  backstory: >
    Follow {set_of_guidelines}

tasks.yaml

task_1:
  agent: agent_1
  description: >
    Write the description here.
  expected_output: >
    Write the expected output here.

task_2:
  agent: agent_2
  description: >
    Write the description here.
  expected_output: >
    Write the expected output here.

crew.py

import os
from dotenv import load_dotenv
from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, crew, task

load_dotenv()

@CrewBase
class YourCrew:
    agents_config = "config/agents.yaml"
    tasks_config = "config/tasks.yaml"

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

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

    @task
    def first_task(self) -> Task:
        return Task(
            config=self.tasks_config["task_1"],
        )

    @task
    def second_task(self) -> Task:
        return Task(
            config=self.tasks_config["task_2"],
        )

    @crew
    def crew(self) -> Crew:
        return Crew(
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            verbose=True,
        )

main.py

import asyncio
from crewai.flow.flow import Flow, listen, start
from .crews.your_crew.crew import YourCrew

guidelines = "Write the guidelines here."

class YourFlow(Flow):
    @start()
    def kickoff_your_crew(self):
        crewai_output = (
            YourCrew()
            .crew()
            .kickoff(
                inputs={
                    "set_of_guidelines": guidelines,
                }
            )
        )

        print(crewai_output.raw)

async def run_flow():
    await YourFlow().kickoff()

async def plot_flow():
    YourFlow().plot()

def main():
    asyncio.run(run_flow())

def plot():
    asyncio.run(plot_flow())

if __name__ == "__main__":
    main()

yes currently, I am doing that, but it seems i am replicating my guidelines 2 times which is not ideal. I was thinking something in which my review agent can know the guidelines as it is checking the work done by agent 1. Is there any way to do that?

Now I get what you mean. Anyway, if you pass a variable to a YAML file twice, I wouldn’t consider it bad practice. Bad practice would be not using the variable and copy-pasting the guidelines twice directly in the YAML file.

The second agent can have the context from the first agent. But there’s no way for the second agent to know what the guidelines were passed to the first agent just by looking at the first agent’s final answer.

yes makes sense! Thanks for the reply,
Also i posted a question on hosting, if you have any knowledge on that, it would be great to hear that!

Can I close this post now?

Will answer!

yes

yes for sure

Looking forward to it