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

Add Composio integration to the third party tools #88

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Disclaimer: Examples contributed by the community and partners do not represent
| [CAMEL Graph RAG with Mistral Models](third_party/CAMEL_AI/camel_graph_rag.ipynb) | multi-agent, tool, data gen | CAMEL-AI.org|
| [CAMEL Role-Playing Scraper](third_party/CAMEL_AI/camel_roleplaying_scraper.ipynb) | multi-agent, tool, data gen | CAMEL-AI.org|
| [Chainlit - Mistral reasoning.ipynb](third_party/Chainlit/Chainlit_Mistral_reasoning.ipynb) | UI chat, tool calling | Chainlit |
| [Composio Integration - AI email assistant ](third_party/Composio) | Agent, tool calling | Composio |
| [corrective_rag_mistral.ipynb](third_party/langchain/corrective_rag_mistral.ipynb) | RAG | Langchain |
| [distilabel_synthetic_dpo_dataset.ipynb](third_party/argilla/distilabel_synthetic_dpo_dataset.ipynb) | synthetic data | Argilla |
| [E2B Code Interpreter SDK with Codestral](third_party/E2B_Code_Interpreting) | tool, agent | E2B |
Expand Down
2 changes: 2 additions & 0 deletions third_party/Composio/gmail-agent-js/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MISTRAL_API_KEY=
COMPOSIO_API_KEY=
2 changes: 2 additions & 0 deletions third_party/Composio/gmail-agent-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
78 changes: 78 additions & 0 deletions third_party/Composio/gmail-agent-js/email-send-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import dotenv from "dotenv";
import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
import { LangchainToolSet } from "composio-core";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { ChatMistralAI } from "@langchain/mistralai";

dotenv.config();

// Initialize the toolset
const toolset = new LangchainToolSet({ apiKey: process.env.COMPOSIO_API_KEY });

// Create Gmail integration with Composio
async function setupUserConnection(entityId) {
const entity = toolset.client.getEntity(entityId);
const connection = await entity.getConnection("gmail");

if (!connection) {
// If this entity/user hasn't already connected the account
const connection = await entity.initiateConnection("gmail");
console.log("Log in via: ", connection.redirectUrl);

return connection.waitUntilActive(100);
}
return connection;
}

async function executeAgent(entityName) {

// Create entity and set up user connection
const entity = await toolset.client.getEntity(entityName);
const a = await setupUserConnection(entity.id);

// Get the desired actions
const tools = await toolset.getTools(
{
actions: [
"gmail_send_email",
"gmail_fetch_emails",
"gmail_create_email_draft",
"gmail_create_label",
],
},
entity.id
);

// Initialize the LLM
const llm = new ChatMistralAI({
model: "mistral-large-latest",
apiKey: process.env.MISTRAL_API_KEY,
});

// Create custom prompt
const prompt = ChatPromptTemplate.fromMessages([
[
"system",
"You are a helpful and thorough AI email assistant who can write and fetch emails, create draft mails and also create new gmail labels. Your goal is to understand the guidelines provided by the user and perform the specific actions requested by the user. If the user asks to fetch emails, use the actual data from the API response and print the result including these terms: Subject and Mail in an easy-to-read format.",
],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);

// Create the agent
const agent = await createToolCallingAgent({
llm,
tools: tools,
prompt,
});

// Execute the agent
const agentExecutor = new AgentExecutor({ agent, tools, verbose: true });
const result = await agentExecutor.invoke({
// Customize the input -
input: "Send a mail to [email protected] saying Hello",
});

console.log(result.output);
}
executeAgent("default");
Loading