Tutorial 2: Creating a Wisdom-filled Yoda Agent in Crew

Master complex workflows

🎯 What You'll Learn

In this tutorial, you'll learn how to add an agent to the CrewAI Visual Editor that acts like Yoda from Star Wars. The agent will answer all questions using Yoda’s signature wisdom. You'll also configure a task for this agent to complete, and we'll show you how to fill in the necessary details using ChatGPT as the default LLM.

What You Should Know Before Starting

  • Familiarity with the Visual Crew Builder (covered in Tutorial 1)
  • Basic knowledge of how agents and tasks work in CrewAI

Keywords

CrewAI, agents, tasks, LLMs, Yoda, AI wisdom, visual editor, ChatGPT


🖥️ Step-by-Step Guide: Building Yoda, the Wise Agent

Step 1: Adding Yoda as an Agent

  1. Drag and Drop the Agent: From the Agents section of the item library, drag a new agent onto the canvas.
  2. Configuring Yoda's Properties: Click on the agent to open the Properties Editor on the right. Fill in the following fields:
    • Agent Name: Yoda
    • Role: Wise Jedi Master
    • Goal: "Answer all questions using Yoda's wisdom."
    • Backstory: "You are Yoda, a legendary Jedi Master who has trained generations of Jedi. Known for your wisdom and calm demeanor, you answer all questions in a wise and cryptic manner."
    • LLM: Leave ChatGPT as the default

Step 2: Adding a Task for Yoda

  1. Drag and Drop a Task: From the Tasks section of the item library, drag a task block onto the canvas.
  2. Configuring the Task: Click on the task block and fill in the following fields:
    • Task Name: Answer Questions with Wisdom
    • Description: "Answer all questions using wisdom and the characteristic speech pattern of Yoda from Star Wars."
    • Expected Output: "Wise responses in the style of Yoda, addressing the user's questions with deep, thoughtful answers."
  3. Connect the Agent to the Task: Draw a line from the Yoda agent to the Answer Questions with Wisdom task.

Step 3: Filling Mandatory Fields

Before the task can run, make sure the following fields are filled in:

  • LLM: ChatGPT
  • Agent Name: Yoda
  • Task Description: Answer with wisdom
  • Expected Output: Yoda-style wise responses

Step 4: Save and Run Your Yoda Agent

  1. Save the Project: Click on the Save button to store your configuration.
  2. Kick Off the Crew: Start the crew by clicking on the "Kickoff" or "Run" button.

🔍 Generated Code for Yoda


import os
from langchain.llms import OpenAI
from crewai import Agent, Task, Crew

# Agent definitions
yoda = Agent(
    role='Wise Jedi Master',
    goal="Answer all questions using Yoda's wisdom.",
    backstory="You are Yoda, a legendary Jedi Master...",
    tools=[],
    llm='chatgpt'
)

# Task definitions
wisdom_task = Task(
    description="Answer all questions using wisdom and the characteristic speech pattern of Yoda.",
    agent=yoda,
    expected_output="Wise responses in the style of Yoda."
)

crew = Crew(
    name='yoda_crew',
    agents=[yoda],
    tasks=[wisdom_task],
    process=Process.Sequential
)

result = crew.kickoff()
print(result)

🔔 Additional Hints and Tips

  • LLMs and Tools: ChatGPT is the default LLM, but you can connect GPT-4 or other models.
  • Customization: You can modify Yoda’s backstory or goals as needed.
  • Real-time Testing: Test Yoda’s responses directly within the Visual Editor.

✅ What You've Learned

By the end of this tutorial, you’ve learned:

  • How to add and configure an agent in CrewAI
  • How to create and link a task for that agent
  • How to use ChatGPT as the default LLM

What’s Next?

In the next tutorial, we’ll explore using multiple agents and connecting various tools.


📚 Sources

❓ Quiz Questions

  1. What agent role did we assign to Yoda?
  2. What LLM is used by default in this tutorial?
  3. How do you connect an agent to a task in the Visual Crew Builder?
  4. What should the expected output be for the task?
  5. Can you modify Yoda’s backstory to suit different tasks?

Your Progress

0%

Score: 0 points

Test Your Knowledge