Agentic AI - Series 5

                                                 

Hope you all having fun with our Agentic AI series. In this blog, we will see how to design a MAS (Multi Agent System) using CrewAI.

CrewAI is a popular framework for building production grade AI systems. 

We know that every agent needs

  • Role.
  • Goal.
  • Backstory.
  • Tasks.
  • Tools
MAS is nothing but completing a work with the help or collaboration of one more agents.

Lets understand with a real life example.

We are going to design a application which involves in recommending food for diabetic patients based on the given ingredients.

To accomplish the task, we need a agent called "Chef".

Role - Experience Chef.
Goal - Prepare delicious food based on the given ingredient.
Backstory:
  • You are an experienced chef and received accolades for preparing best and hygiene food.
  • You expertise also lies in recommending new foods to the customers.
  • Please generate 5 recipes using the given ingredient.
  • Also provide step wise instruction, time to cook and other ingredients needed and calorie count of the recipe prepared.
  • Your recipe will be analyzed by the by nutritionist to recommend food for diabetes patients.

Next, lets create another agent called "Nutritionist".

Role - Nutritionist.
Goal Critically analyze the recipe given by chef using these ingredients.
Backstory:
  • You're a nutritionist and have good knowledge on working with Diabetic patients.
  • There are recipe recommended by chef using these ingredients.
  • Please critically analyze the recipe and suggest best food out of given 5 for Diabetic patients.
  • Also give reasons why you don't recommend other 4 recipes and choose this one.
Now we have our agents ready. 

Next, we need assign work (tasks) to the agents. Tasks may sound similar to the backstory of the agents. But, that's what it is.

Chef Tasks: 
  • Write recipe of 5 different foods using these ingredients.
  • Provide step wise guide to cook the recipe.
  • List all the additional ingredients required for cooking.
  • The expected taste of the food.
Nutritionist Tasks:
  • Read the recipes provided by chef using ingredients.
  • Critically analyze all recipes keeping in mind what should suit to diabetic patients.
  • Suggest one recipe to diabetic patients based on your own knowledge and evidence.
  • Reject all other 4 recipes with knowledge and evidence.
  • Finally, give the stepwise recipe of what you selected and a nice message.

That's it our first Multi Agent System is Ready.

In our next blog, we will see how chain the agents, tasks and crew all together. But, lets see some of the recipe suggested by the agents for the give ingredient "Spinach".




Here is the response from the Nutritionist:


from crewai import Agent, Task, Crew
import os
from utils import get_openai_api_key, get_serper_api_key

openai_api_key = get_openai_api_key()
os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'

#1- Chef
chef = Agent(
    role="chef",
    goal="Give 5 different receipes using ingredients : {ingredients}",
    backstory="You're  a Chef who has experience on cooking delicious foods"
              "Your expertice lies in recommeding some new foods to the customers"
              "Please generate and give receipe of 5 different foods using this ingredients : {ingredients} "
              "describing stepwise process, time to cook, other ingredients needed and calorie count"
              "Your recipe will be critically analyzed by nutritutionist to recommend food for diabetes patients ",
    verbose=True
)
2# Nutritionist
nutritionist = Agent(
    role="nutritionist",
    goal="Critically analyze the recipe given by chef using these ingredients: {ingredients}",
    backstory="You're a nutritionist and have good knowledge on working with Diabetic patients "
              "There are recipe recommended by chef using these ingredients : {ingredients}. "
              "please critically analyze the recipe and suggest best food out of goven 5 for Diabetic patients"
              "Also give reasons why you dont recommend other 4 receips and choose this one",
    verbose=True
)

cook = Task(
    description=(
        "1. Write receipe of 5 different foods using these ingredients  : {ingredients}.\n"
    ),
    expected_output="5 different receipes using {ingredients}"
                    "Stepwise guide to cook"
                    "List of all additional ingredients required for cooking"
                    "The expected taste of the food",
    agent=chef,
)

recommend = Task(
    description=(
        "1. Read the receipes provided by chef using {ingredients} \n"
        "2. critically analyze all receipes keeping in mind what should suit to diabetic patients.\n"
        "3. Suggest one best food out of all 5 receipes given by chef.\n"
        "4. Prove that other 4 receipes suggested by chef is not good for diabetic patients.\n"
       
    ),
    expected_output="A well-written critical pointwise analysis of all 5 recipes using {ingredients}"
                    "Suggest one receipe to diabetic patients based on your own knowledge and evidence "
                    "Reject all other 4 receipes with knowledge and evidence "
                    "Finally, give the stepwoise receipe of what you selected and a nice message",
    agent=nutritionist,
)

crewaman = Crew(
    agents=[chef,nutritionist],
    tasks=[cook, recommend],
    verbose=2
)

result = crewaman.kickoff(inputs={"ingredients": "spinach"})

Comments

Popular posts from this blog

K8s - ETCD

Agentic AI - Series 3

Agentic AI - Series 4