Room Finder Agent using CrewAI

Pavan Kunchala
3 min readDec 10, 2024

--

I have been working on crewAi a little and wanted to share a simple agent I have built which can search for rooms based on the location and price range

You can check the full working code from here

Imports

The initial imports include classes and tools necessary for defining agents, tasks, and tools in the CrewAI framework.

from crewai import Agent, LLM, Task, Crew
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
from langchain.agents import Tool
from crewai_tools import BaseTool
import os
import datetime

- `Agent`, `LLM` (Language Learning Model), `Task`, `Crew`: Classes from the CrewAI library.

- `SerperDevTool`, `ScrapeWebsiteTool`, `BaseTool`: Tools provided by CrewAI for web search and scraping.

- `os`, `datetime`: Standard Python libraries for operating system interactions and handling date/time.

Initialize LLM Model

Before defining agents, a language learning model (LLM) is initialized. The agents will use this model to process and generate text outputs based on their tasks.

llm = LLM(…)

The specific details of the initialization depend on the type of LLM being used (e.g., Hugging Face’s Transformers models or other custom models).

Serper Search Tool

The `SerperDevTool` is initialized as a tool for performing web searches using DuckDuckGo. This tool enables the agent to gather information from the internet, helping it accomplish its tasks more efficiently.

search_tool = SerperDevTool(…)

ScrapeWebsiteTool

Another tool initialized is `ScrapeWebsiteTool`, which allows the agent to extract relevant data from web pages. This functionality enhances the agent’s ability to collect useful information for tasks, such as extracting details about rooms available for rent.

scrape_tool = ScrapeWebsiteTool(…)

Define Room Finder Agent

A `room_finder_agent` is defined with:

- **Role**: A clear and specific role indicating its purpose.

- **Goal**: The agent’s objective in human-readable format.

- **Backstory**: Detailed context and capabilities of the agent.

- **Tools**: An array containing two tools — `search_tool` (DuckDuckGo Search) and `scrape_tool` (Web Scraping).

- **LLM Model**: The previously initialized LLM model, which enables text processing and generation for the agent.

room_finder_agent = Agent(
role="Room Finder Agent",
goal=("Find a room to rent in the city or place you want to live {location}, within the price range of {price} per month on this date {date}."),
backstory=(…),
tools=[search_tool, scrape_tool],
llm=llm,
)

Define Room Finding Task

A task (`room_finding_task`) is defined with:

- **Description**: A detailed explanation of what needs to be done.

- **Expected Output**: The desired format for the output generated by the task (Markdown report).

- **Agent**: The previously defined `room_finder_agent` assigned to this task.

- **Output File**: The specified path where the Markdown report will be saved (“room_output.md”).

room_finding_task = Task(
description=(…),
expected_output=(…),
agent=room_finder_agent,
output_file="room_output.md"
)

Crew Initialization & Task Kickoff

A `Crew` instance is initialized with the defined agent and task, set to be verbose. Then, the task is kicked off using the provided inputs (location, price, and date). Finally, the output of the completed task (Markdown report) is printed.

crew = Crew(
agents=[room_finder_agent],
tasks=[room_finding_task],
verbose=True
)
task_output = crew.kickoff(inputs=inputs)
print(task_output)

You can also check out my GitHub from here(If you like the content don’t forget to follow)

I also showcase some of my work you can check it out here

--

--

Pavan Kunchala
Pavan Kunchala

Written by Pavan Kunchala

Machine learning & Computer Vision Engineer |Deep learning and Reinforcement learning enthusiast

No responses yet