Research Agent

Research Agent GitHub Repository

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

1

Install the required packages

1pip install composio-llamaindex llama-index-readers-arxiv

Create a .env file and add your API keys.

2

Import base packages

Next, we’ll import the essential libraries for our project.

1import os
2import dotenv
3
4from composio_llamaindex import Action, ComposioToolSet
5from llama_index.core.llms import ChatMessage
6from llama_index.llms.openai import OpenAI
7from llama_index.agent.openai import OpenAIAgent
8from llama_index.tools.arxiv.base import ArxivToolSpec
3

Configure environments and parameters

Set up the necessary configurations for our agent.

1# Load environment variables
2dotenv.load_dotenv()
3
4# Initialize the language model
5llm = OpenAI(model="gpt-4o")
6
7# Set research parameters
8research_topic = "LLM agents function calling"
9target_repo = "composiohq/composio"
10n_issues = 3
4

Set up Composio tools

Initialize the tools that our agent will use.

1# Get Composio toolset and add ArXiv tools
2composio_toolset = ComposioToolSet()
3github_tools = composio_toolset.get_actions(actions=[Action.GITHUB_CREATE_AN_ISSUE])
4arxiv_tool = ArxivToolSpec()
5
6# Define system message
7prefix_messages = [
8 ChatMessage(
9 role="system",
10 content=(
11 "You are now a research agent, and whatever you are "
12 "requested, you will try to execute utilizing your tools."
13 ),
14 )
15]
5

Create the agent

Set up the agent with the tools and capabilities it needs.

1# Create the agent with tools
2agent = OpenAIAgent.from_tools(
3 tools=github_tools + arxiv_tool.to_tool_list(),
4 llm=llm,
5 prefix_messages=prefix_messages,
6 max_function_calls=10,
7 allow_parallel_tool_calls=False,
8 verbose=True,
9)
6

Implement the research functionality

Create the main logic for the research agent.

1# Define main function to run the agent
2def main():
3 # Create the research prompt
4 prompt = (
5 f"Please research on Arxiv about `{research_topic}`, Organize "
6 f"the top {n_issues} results as {n_issues} issues for "
7 f"a github repository, finally raise those issues with proper, "
8 f"title, body, implementation guidance and reference in "
9 f"{target_repo} repo, as well as relevant tags and assignee as "
10 "the repo owner."
11 )
12
13 # Execute the agent
14 response = agent.chat(prompt)
15
16 # Print the result
17 print("Response:", response)
18
19# Run the main function
20if __name__ == "__main__":
21 main()

Complete Code

1import os
2import dotenv
3
4from composio_llamaindex import Action, ComposioToolSet
5from llama_index.core.llms import ChatMessage
6from llama_index.llms.openai import OpenAI
7from llama_index.agent.openai import OpenAIAgent
8from llama_index.tools.arxiv.base import ArxivToolSpec
9
10# Load environment variables
11dotenv.load_dotenv()
12
13# Initialize the language model
14llm = OpenAI(model="gpt-4o")
15
16# Set research parameters
17research_topic = "LLM agents function calling"
18target_repo = "composiohq/composio"
19n_issues = 3
20
21def main():
22 # Get Composio toolset and add ArXiv tools
23 composio_toolset = ComposioToolSet()
24 github_tools = composio_toolset.get_actions(actions=[Action.GITHUB_CREATE_AN_ISSUE])
25 arxiv_tool = ArxivToolSpec()
26
27 # Define system message
28 prefix_messages = [
29 ChatMessage(
30 role="system",
31 content=(
32 "You are now a research agent, and whatever you are "
33 "requested, you will try to execute utilizing your tools."
34 ),
35 )
36 ]
37
38 # Create the agent with tools
39 agent = OpenAIAgent.from_tools(
40 tools=github_tools + arxiv_tool.to_tool_list(),
41 llm=llm,
42 prefix_messages=prefix_messages,
43 max_function_calls=10,
44 allow_parallel_tool_calls=False,
45 verbose=True,
46 )
47
48 # Create the research prompt
49 prompt = (
50 f"Please research on Arxiv about `{research_topic}`, Organize "
51 f"the top {n_issues} results as {n_issues} issues for "
52 f"a github repository, finally raise those issues with proper, "
53 f"title, body, implementation guidance and reference in "
54 f"{target_repo} repo, as well as relevant tags and assignee as "
55 "the repo owner."
56 )
57
58 # Execute the agent
59 response = agent.chat(prompt)
60
61 # Print the result
62 print("Response:", response)
63
64if __name__ == "__main__":
65 main()
Built with