Today I will build a simple AI agent using CrewAI and NebiusAI. CrewAI is a growing platform for multiagent automation. With NebiusAI it is very simple to build an AI agent that will answer user's query. We will build an AI agent today that will answer. THe goal is to understand first how CrewAI works in a most simplest easy to understand way.
In case you prefer to watch youtube video than reading blog you can check here
Installations
You need to install crewai to utilize the ai agent by them.
pip install crewai python-dotenv
You will also need to have NEBIUS_API_KEY
from Nebius to use the LLM model. You need to signup first and create an API key there. Don't forget to put your API key in the environment variable (.env)
LLM Model
We need to bring the LLM models first using nebius.
import os
from dotenv import load_dotenv
load_dotenv()
default_llm=LLM(
model="openai/meta-llama/Meta-Llama-3.1-70B-Instruct",
base_url="https://api.studio.nebius.com/v1/",
api_key=os.getenv("NEBIUS_API_KEY")
)
Create an Agent
Once we have brought the LLM model now we can create the agent using crewAI. You have to set role, goal
and backstory
for the agent to get better output. Try playing with these and check how different are the results.
from crewai import Agent, Task,LLM
researcher = Agent(
role='Senior Researcher',
goal='Discover groundbreaking technologies in quantum computing',
verbose=True,
llm=default_llm,
backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about quantum computing and its applications.',
)
Set the task for the agent
We have created our agent and now it's the time to setup tasks for the agent.
# Task for the researcher
research_task = Task(
description='Identify the next big trend quantum computing will enable',
expected_output='5 paragraphs on the future of quantum computing and its potential applications',
agent=researcher # Assigning the task to the researcher
)
Instantiate the agent crew
We have everything set up. This is time to create the agent instance so that it starts to give answer when asked. The process can be sequential or parallel. In this case we will use sequential but if your project cotntains multi-agent and needs parallel work you have to choose parallel in process=Process.sequential
. We will see such examples next day.
# Instantiate your crew
tech_crew = Crew(
agents=[researcher],
tasks=[research_task],
process=Process.sequential # Tasks will be executed one after the other
)
# Begin the task execution
tech_crew.kickoff()
Now once you run this file you will get the output.
You will get the full code here,
Today we have built the most simple AI agent using crewAI and NebiusAI. In the next post we will see how multiple agents can work and also how we can integrate tools like google search for building more upgraded AI agent.
Top comments (0)