Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:second brain agent #655

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GROQ_API_KEY=KEY
COMPOSIO_API_KEY=KEY
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from composio_llamaindex import ComposioToolSet, App, Action
from llama_index.core.agent import FunctionCallingAgentWorker
from llama_index.core.llms import ChatMessage
from llama_index.llms.openai import OpenAI
from llama_index.llms.groq import Groq
from dotenv import load_dotenv
from pathlib import Path
import os

load_dotenv()
#llm = OpenAI(model='gpt-4o')
llm = Groq(model="llama3-groq-70b-8192-tool-use-preview")

composio_toolset = ComposioToolSet()
tools = composio_toolset.get_tools(apps = [App.EMBED_TOOL, App.RAGTOOL, App.WEBTOOL, App.SERPAPI, App.FILETOOL])

prefix_messages = [
ChatMessage(
role="system",
content=(
f"""
You are an AI Assistant who's function it is to act like a second brain.
You're a memory layer that stores all the information a user wants using RAG and embed tool.
For Images use the embedtool. If it's a url make sure you browse the web and scrape the text
when adding the information to the VectorStore. The path for both of them will be current directory.

"""
)
)
]


agent = FunctionCallingAgentWorker(
tools=tools, # Tools available for the agent to use
llm=llm, # Language model for processing requests
prefix_messages=prefix_messages, # Initial system messages for context
max_function_calls=10, # Maximum number of function calls allowed
allow_parallel_tool_calls=False, # Disallow parallel tool calls
verbose=True, # Enable verbose output
).as_agent()

vector_store_path = "./"
while True:
x = input("If you want to add something to the vector store, type 'add' and if you want to query, type 'query':")
if x == 'add':
a = input('Enter the url or image path to add in the vector store:')
task = f"""
This is the item you've to add to the vector store: {a}.
If its an image use Embed tool and if its a url scrape the text content and add it in RAG vector store

The vector store/ Folder path should exist in {vector_store_path}.
If its an image, the vector name should be Images

"""
response = agent.chat(task)
print(response)
elif x == 'query':
a = input("What is your query?")
task = f"""
Vector store exists in {vector_store_path}
Query is {a}. Query either the rag tool for textual content and embed tool for image related content
"""
response = agent.chat(task)
print(response)
else:
a = input("response fuzzy ending.")
exit()




Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Scheduling Agent Guide

This guide provides detailed steps to create a Second Brain Agent that leverages Composio, LlamaIndex and Groq to schedule your events based on received emails. Ensure you have Python 3.8 or higher installed.

## Steps to Run

**Navigate to the Project Directory:**
Change to the directory where the `setup.sh`, `main.py`, `requirements.txt`, and `README.md` files are located. For example:
```sh
cd path/to/project/directory
```

### 1. Run the Setup File
Make the setup.sh Script Executable (if necessary):
On Linux or macOS, you might need to make the setup.sh script executable:
```shell
chmod +x setup.sh
```
Execute the setup.sh script to set up the environment and install dependencies:
```shell
./setup.sh
```
Now, fill in the `.env` file with your secrets.

### 2. Run the Python Script
```shell
python cookbook/examples/advanced_agents/Second_brain_Agent/llamaindex/main.py
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composio-llamaindex
llama-index-llms-groq
python-dotenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Create a virtual environment
echo "Creating virtual environment..."
python3 -m venv ~/.venvs/secondbrain

# Activate the virtual environment
echo "Activating virtual environment..."
source ~/.venvs/secondbrain/bin/activate

# Install libraries from requirements.txt
echo "Installing libraries from requirements.txt..."
pip install -r requirements.txt

# Login to your account
echo "Login to your Composio acount"
composio login

# Add trello tool
echo "Add google calendar and gmail tool. Finish the flow"
composio add serpapi

# Copy env backup to .env file
if [ -f ".env.example" ]; then
echo "Copying .env.example to .env..."
cp .env.example .env
else
echo "No .env.example file found. Creating a new .env file..."
touch .env
fi

# Prompt user to fill the .env file
echo "Please fill in the .env file with the necessary environment variables."

echo "Setup completed successfully!"
Loading