Research Assistant Agent GitHub Repository

Explore the complete source code for the Research Assistant Agent project. This repository contains all the necessary files and scripts to set up and run the Research Assistant system using CrewAI and Composio.

1

Run the `setup.sh` file

Fork and Clone this repository, Navigate to the Project Directory

cd python/examples/research_assistant

Make the setup.sh Script Executable (if necessary): On Linux or macOS, you might need to make the setup.sh script executable:

chmod +x setup.sh

# run the setup.sh file
./setup.sh
2

Importing required libraries

Now, import the necessary libraries in your Python script:

from crewai import Agent, Task, Crew, Process
from composio_langchain import ComposioToolSet, App
from langchain_openai import ChatOpenAI
import os
import dotenv
3

Initialise Language Model and Define tools

We’ll initialize our language model and set up the necessary tools for our agents. We will be using serpapi tool, So that our agent can execute actions using this tool.

# Load environment variables
dotenv.load_dotenv()

# Initialize the language model with OpenAI API key and model name
llm = ChatOpenAI(
    model="gpt-4o"
)
# Setup tools using ComposioToolSet
composio_toolset = ComposioToolSet()
#Using .get_tools we are able to add various tools needed by the agents to execute its objective
#in this case its serpapi, giving the agent access to the internet
tools = composio_toolset.get_tools(apps=[App.SERPAPI])
4

Defining the Agent

Define the Researcher agent with the necessary parameters:

 researcher = Agent(
     role='Researcher',
     goal='Search the internet for the information requested',
     backstory="""
     You are a researcher. Using the information in the task, you find out some of the most popular facts about the topic along with some of the trending aspects.
     You provide a lot of information thereby allowing a choice in the content selected for the final blog.
     """,
     verbose=True,
     allow_delegation=False,
     tools=tools,
     llm=llm
 )
5

Defining the Task

Create and execute a task for the agent:

task = Task( description="""Research about open source LLMs vs
    closed source LLMs. Your final answer MUST be a full analysis report""", #To
    change the topic, edit the text after 'Research about' in the description
    parameter of task1 expected_output='When the research report is ready',
    agent=researcher
)
crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
print(result)

Putting It All Together

Below is the complete code snippet combining all the steps:

from crewai import Agent, Task, Crew, Process
from composio_langchain import ComposioToolSet, App
from langchain_openai import ChatOpenAI
import os
import dotenv

# Load environment variables
dotenv.load_dotenv()

# Initialize the language model with OpenAI API key and model name
llm = ChatOpenAI(
    model_name="gpt-4o"
)

# Setup tools using ComposioToolSet
composio_toolset = ComposioToolSet()
#Using .get_tools we are able to add various tools needed by the agents to execute its objective
#in this case its serpapi, giving the agent access to the internet
tools = composio_toolset.get_tools(apps=[App.SERPAPI])

# Define the Researcher agent with its role, goal, and backstory
researcher = Agent(
    role='Researcher',
    goal='Search the internet for the information requested',
    backstory="""
    You are a researcher. Using the information in the task, you find out some of the most popular facts about the topic along with some of the trending aspects.
    You provide a lot of information thereby allowing a choice in the content selected for the final blog.
    """,
    verbose=True,  # Enable verbose logging for the agent
    allow_delegation=False,  # Disable delegation
    tools=tools,  # Assign the tools to the agent
    llm=llm  # Assign the language model to the agent
)

# Define the research task with its description and expected output
task = Task(
    description="""
    Research about open source LLMs vs closed source LLMs.
    Your final answer MUST be a full analysis report
    """, #you can add your own topic after "Research about {your topic}"
    expected_output='When the research report is ready',  # Define the expected output
    agent=researcher  # Assign the task to the researcher agent
)

# Execute the task
crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
print(result)