Overview
This agent automates lead outreach by crafting personalized emails tailored to each lead and sending them instantly. Designed to optimize engagement and streamline your sales process, the AI Outreach Agent helps businesses save time and improve the effectiveness of their email campaigns.Getting Started
- Python
- Javascript
Connecting to tools and models
connect to required tools
composio add gmail
composio add hubspot
export OPENAI_API_KEY="<your-openai-api-key>"
Importing the required libraries
import required libraries
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 dotenv import load_dotenv
load_dotenv()
Initializing the Tools and the LLM
initialize toolset and llm
toolset = ComposioToolSet(api_key="YOUR-API-KEY")
tools = toolset.get_tools(actions=[Action.HUBSPOT_LIST_CONTACTS_PAGE, Action.GMAIL_CREATE_EMAIL_DRAFT])
llm = OpenAI(model="gpt-4o")
Setting up Function Calling Worker
setup function calling worker
prefix_messages = [
ChatMessage(
role="system",
content=(
f"""
"You are a Lead Outreach Agent that is has access to the CRM through HubSpot."
"and is an expert writer. Your job is to first research some info about the lead "
"given to you and then draft a perfect ideal email for whatever input task is given to you. "
"""
),
)
]
agent = FunctionCallingAgentWorker(
tools=tools,
llm=llm,
prefix_messages=prefix_messages,
max_function_calls=10,
allow_parallel_tool_calls=False,
verbose=True,
).as_agent()
Executing the Agent
execute the agent
user_input = f"Draft an email for each lead in my Hubspot contacts page introducing yourself and asking them if they're interested in integrating AI Agents in their workflow."
response = agent.chat(user_input)
Final Code
final code
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 dotenv import load_dotenv
load_dotenv()
toolset = ComposioToolSet(api_key="")
tools = toolset.get_tools(actions=[Action.HUBSPOT_LIST_CONTACTS_PAGE, Action.GMAIL_CREATE_EMAIL_DRAFT])
llm = OpenAI(model="gpt-4o")
prefix_messages = [
ChatMessage(
role="system",
content=(
f"""
"You are a Lead Outreach Agent that is has access to the CRM through HubSpot."
"and is an expert writer. Your job is to first research some info about the lead "
"given to you and then draft a perfect ideal email for whatever input task is given to you. "
"""
),
)
]
agent = FunctionCallingAgentWorker(
tools=tools,
llm=llm,
prefix_messages=prefix_messages,
max_function_calls=10,
allow_parallel_tool_calls=False,
verbose=True,
).as_agent()
user_input = f"Draft an email for each lead in my Hubspot contacts page introducing yourself and asking them if they're interested in integrating AI Agents in their workflow."
response = agent.chat(user_input)
Connecting to tools and models
connect to tools
composio add gmail
composio add hubspot
export OPENAI_API_KEY="<your-openai-api-key>"
export COMPOSIO_API_KEY="<your-composio-api-key>"
Importing the required libraries
import the required libraries
import { ChatOpenAI } from "@langchain/openai";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { pull } from "langchain/hub";
import dotenv from 'dotenv';
import { LangchainToolSet } from "composio-core";
dotenv.config();
Initializing the Tools and the LLM
initialize toolset and llm
const toolset = new LangchainToolSet({
apiKey: process.env.COMPOSIO_API_KEY,
});
const tools = await toolset.getTools({actions: ["HUBSPOT_LIST_CONTACTS_PAGE", "GMAIL_CREATE_EMAIL_DRAFT"]});
const llm = new ChatOpenAI({
model: "gpt-4-turbo",
apiKey: process.env.OPENAI_API_KEY,
});
Setting up Agent
setup agent
const prompt = await pull("hwchase17/openai-functions-agent");
const additional = `
"You are a Lead Outreach Agent that is has access to the CRM through HubSpot."
"and is an expert writer. Your job is to first research some info about the lead "
"given to you and then draft a perfect ideal email template for whatever input task is given to you. "
`;
const agent = await createOpenAIFunctionsAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
verbose: false,
});
Executing the Agent
execute the agent
const result = await agentExecutor.invoke({
input: `Draft an email for each lead in my Hubspot contacts page introducing yourself and asking them if they're interested in integrating AI Agents in their workflow.`
});
console.log('🎉Output from agent: ', result.output);
Final Code
final code
import { ChatOpenAI } from "@langchain/openai";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { pull } from "langchain/hub";
import dotenv from 'dotenv';
import { LangchainToolSet } from "composio-core";
dotenv.config();
const llm = new ChatOpenAI({
model: "gpt-4-turbo",
apiKey: process.env.OPENAI_API_KEY,
});
const toolset = new LangchainToolSet({
apiKey: process.env.COMPOSIO_API_KEY,
});
const tools = await toolset.getTools({actions: ["HUBSPOT_LIST_CONTACTS_PAGE", "GMAIL_CREATE_EMAIL_DRAFT"]});
const prompt = await pull("hwchase17/openai-functions-agent");
const additional = `
"You are a Lead Outreach Agent that is has access to the CRM through HubSpot."
"and is an expert writer. Your job is to first research some info about the lead "
"given to you and then draft a perfect ideal email template for whatever input task is given to you. "
`;
const agent = await createOpenAIFunctionsAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
verbose: false,
});
const result = await agentExecutor.invoke({
input: `Draft an email for each lead in my Hubspot contacts page introducing yourself and asking them if they're interested in integrating AI Agents in their workflow.`
});
console.log('🎉Output from agent: ', result.output);