> ## Documentation Index
> Fetch the complete documentation index at: https://composio-27-feat-docs-revamp.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Outreach Agent

> This project demonstrates how to use Composio to create an outreach agent.

## 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

<Tabs>
  <Tab title="Python">
    <Steps>
      <Step title="Installation">
        ```bash install the required dependencies
        pip install composio-core
        ```
      </Step>

      <Step title="Connecting to tools and models">
        ```bash connect to required tools
        composio add gmail
        composio add hubspot

        export OPENAI_API_KEY="<your-openai-api-key>"
        ```
      </Step>

      <Step title="Importing the required libraries">
        ```python 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()
        ```
      </Step>

      <Step title="Initializing the Tools and the LLM">
        ```python 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")
        ```
      </Step>

      <Step title="Setting up Function Calling Worker">
        ```python 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()
        ```
      </Step>

      <Step title="Executing the Agent">
        ```python 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)
        ```
      </Step>

      <Step title="Final Code">
        ```python 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)
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Javascript">
    <Steps>
      <Step title="Installation">
        ```bash install the required dependencies
        npm install composio-core langchain @langchain/openai
        ```
      </Step>

      <Step title="Connecting to tools and models">
        ```bash 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>"
        ```
      </Step>

      <Step title="Importing the required libraries">
        ```javascript 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();
        ```
      </Step>

      <Step title="Initializing the Tools and the LLM">
        ```javascript 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,
        });
        ```
      </Step>

      <Step title="Setting up Agent">
        ```javascript 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, 
        });

        ```
      </Step>

      <Step title="Executing the Agent">
        ```javascript 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);
        ```
      </Step>

      <Step title="Final Code">
        ```javascript 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);


        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>
