> ## 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 Market Research Agent

> This project demonstrates how to use Composio to create a market research agent.

## Overview

The AI Market Research Agent is a powerful SDR built using Composio’s tooling ecosystem and LlamaIndex agentic framework. The agent uses Tavily to find niche ideas that can be built and marketed. With a user-friendly setup process and seamless integration capabilities, this agent can significantly enhance your outreach efficiency and sales pipeline management.

## Getting Started

<Tabs>
  <Tab title="Python">
    <Steps>
      <Step title="Installation">
        ```bash install dependencies
        pip install composio-llamaindex python-dotenv
        ```
      </Step>

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

        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="")
        tools = toolset.get_tools(apps=[App.TAVILY, App.GOOGLEDOCS])

        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 market research agent that finds niche ideas that can be built and marketed. 
                Your users are primarily indie hackers who want to build something new and are looking for ideas. The input will 
                be a domain or a category and your job is to research extensively and find ideas that can be marketed.
                Write this content in a google doc, create a google doc before writing in it.
                I want you to show the following content:
                - Data Collection and Aggregation - Show data supporting a trend
                - Sentiment Analysis - Show customer sentiment on the topic
                - Trend Forecasting
                - Competitor Analysis
                - Competitor Benchmarking
                - Idea Validation
                """
                )
            )
        ]
        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 run the agent
        a = input('Enter the domain or category you want to research about:')
        task = f"""
        The domain or category you want to research about is {a}. Use all the tools available to you to find and gather more insights on customers and market.
        """
        response = agent.chat(task)
        print(response)
        ```
      </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 llama_index.llms.cerebras import Cerebras
        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")
        #llm = Cerebras(model="llama3.1-70b")
        composio_toolset = ComposioToolSet()
        tools = composio_toolset.get_tools(apps = [App.TAVILY, App.GOOGLEDOCS])

        prefix_messages = [
            ChatMessage(
                role="system",
                content=(
                f"""
                You are a market research agent that finds niche ideas that can be built and marketed. 
                Your users are primarily indie hackers who want to build something new and are looking for ideas. The input will 
                be a domain or a category and your job is to research extensively and find ideas that can be marketed.
                Write this content in a google doc, create a google doc before writing in it.
                I want you to show the following content:
                - Data Collection and Aggregation - Show data supporting a trend
                - Sentiment Analysis - Show customer sentiment on the topic
                - Trend Forecasting
                - Competitor Analysis
                - Competitor Benchmarking
                - Idea Validation
                """
                )
            )
        ]


        agent = FunctionCallingAgentWorker(
            tools=tools,  
            llm=llm,  
            prefix_messages=prefix_messages,  
            max_function_calls=10,  
            allow_parallel_tool_calls=False,  
            verbose=True,  
        ).as_agent()


        a = input('Enter the domain or category you want to research about:')
        task = f"""
        The domain or category you want to research about is {a}. Use all the tools available to you to find and gather more insights on customers and market.
        """
        response = agent.chat(task)
        print(response)
        ```
      </Step>
    </Steps>
  </Tab>

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

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

        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 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 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({
            apps: ["tavily","googledocs"]
        });
        ```
      </Step>

      <Step title="Setting up Agent">
        ```javascript setup the ai agent
        const prompt = await pull("hwchase17/openai-functions-agent");

        const additional = `You are a market research agent that finds niche ideas that can be built and marketed. 
                Your users are primarily indie hackers who want to build something new and are looking for ideas. The input will 
                be a domain or a category and your job is to research extensively and find ideas that can be marketed.
                Write this content in a google doc, create a google doc before writing in it.
                I want you to show the following content:
                - Data Collection and Aggregation - Show data supporting a trend
                - Sentiment Analysis - Show customer sentiment on the topic
                - Trend Forecasting
                - Competitor Analysis
                - Competitor Benchmarking
                - Idea Validation`;

        const agent = await createOpenAIFunctionsAgent({
            llm,
            tools,
            prompt,
        });
        ```
      </Step>

      <Step title="Executing the Agent">
        ```javascript execute the agent
        const agentExecutor = new AgentExecutor({
            agent,
            tools,
            verbose: true,
        });
        const domain = 'AI SaaS'
        const result = await agentExecutor.invoke({
            input: additional + 'This is the domain:' + domain
        });
        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({
            apps: ["tavily","googledocs"]
        });

        const prompt = await pull("hwchase17/openai-functions-agent");

        const additional = `You are a market research agent that finds niche ideas that can be built and marketed. 
                Your users are primarily indie hackers who want to build something new and are looking for ideas. The input will 
                be a domain or a category and your job is to research extensively and find ideas that can be marketed.
                Write this content in a google doc, create a google doc before writing in it.
                I want you to show the following content:
                - Data Collection and Aggregation - Show data supporting a trend
                - Sentiment Analysis - Show customer sentiment on the topic
                - Trend Forecasting
                - Competitor Analysis
                - Competitor Benchmarking
                - Idea Validation`;

        const agent = await createOpenAIFunctionsAgent({
            llm,
            tools,
            prompt,
        });

        const agentExecutor = new AgentExecutor({
            agent,
            tools,
            verbose: true,
        });
        const domain = 'AI SaaS'
        const result = await agentExecutor.invoke({
            input: additional + 'This is the domain:' + domain
        });
        console.log('🎉Output from agent: ', result.output);

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