Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-michalsky committed Jul 14, 2023
1 parent aa9e177 commit e2ae203
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 111 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Updates to the SalesGPT project: Building the world's best AI Sales Agents.


July 14, 2023
-------------

Version 0.0.4
- Added tools to SalesGPT, creating a true agent.
- Added product knowledge base as an example tool

-------------
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
This repo demonstrates an implementation of a **context-aware** AI Sales Assistant using LLMs.

SalesGPT is context-aware, which means it can understand what section of a sales conversation it is in and act accordingly.
Morever, SalesGPT has access to tools, such as your own pre-defined product knowledge base, significantly reducing hallucinations!

We leverage the [`langchain`](https://github.com/hwchase17/langchain) library in this implementation and are inspired by [BabyAGI](https://github.com/yoheinakajima/babyagi) architecture .
We leverage the [`langchain`](https://github.com/hwchase17/langchain) library in this implementation, specifically [Custom Agent Configuration](https://langchain-langchain.vercel.app/docs/modules/agents/how_to/custom_agent_with_tool_retrieval) and are inspired by [BabyAGI](https://github.com/yoheinakajima/babyagi) architecture.

## Our Vision: Build the Best Open-Source Autonomous Sales Agent

We are building SalesGPT to power your best Autonomous Sales Agents. Hence, we would love to learn more about use cases you are building towards which will fuel SalesGPT development roadmap.

**If you want us to build better towards your needs, please fill out our 45 seconds [SalesGPT Use Case Survey](https://5b7mfhwiany.typeform.com/to/xmJbWIjG)**

## :red_circle: Latest News
### If you looking for help building your Autonomous Sales Agents

### Demo: SalesGPT Outbound Prospecting: A New Way to Sell? 🤔
I am currently open to freelancing opps - please contact me through [my website](https://odysseypartners.ai?utm_source=SalesGPT) if you think I can help you.

https://github.com/filip-michalsky/SalesGPT/assets/31483888/2b13ba28-4e07-41dc-a8bf-4084d25247ca
## :red_circle: Latest News

- Sales Agent can now take advantage of **tools**, such as look up products in a product catalog!

### If you looking for help building your Autonomous Sales Agents
### Demo: SalesGPT Outbound Prospecting: A New Way to Sell? 🤔

I am currently open to freelancing opps - please contact me through [my website](https://odysseypartners.ai?utm_source=SalesGPT) if you think I can help you.
https://github.com/filip-michalsky/SalesGPT/assets/31483888/2b13ba28-4e07-41dc-a8bf-4084d25247ca

## Quickstart

Expand All @@ -32,7 +34,7 @@ from langchain.chat_models import ChatOpenAI

os.environ['OPENAI_API_KEY'] = 'sk-xxx' # fill me in

llm = ChatOpenAI(temperature=0.9)
llm = ChatOpenAI(temperature=0.4)

sales_agent = SalesGPT.from_llm(llm, verbose=False,
salesperson_name="Ted Lasso",
Expand Down Expand Up @@ -73,10 +75,14 @@ sales_agent.step()
> Ted Lasso: Great to hear that! Our mattresses are specially designed to contour to your body shape, providing the perfect level of support and comfort for a better night's sleep. Plus, they're made with high-quality materials that are built to last. Would you like to hear more about our different mattress options?
## Product Knowledge Base

The AI Sales Agent has access to tools, such as your internal Product Knowledge base.
This allows the agent to only talk about your own products and significantly reduces hallucinations.

## Understanding Context

The bot understands the conversation stage (you can define your own stages fitting your needs):
The AI Sales Agent understands the conversation stage (you can define your own stages fitting your needs):

- Introduction: Start the conversation by introducing yourself and your company.
- Qualification: Qualify the prospect by confirming if they are the right person to talk to regarding your product/service.
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ tqdm>=4.65.0
black>=23.3.0
flake8>=6.0.0
isort>=5.12.0
pytest>=7.3.2
pytest>=7.3.2
chromadb>=0.3.29
tiktoken>=0.4.0
14 changes: 11 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@
verbose = args.verbose
max_num_turns = args.max_num_turns

llm = ChatOpenAI(temperature=0.9, stop = "<END_OF_TURN>")

llm = ChatOpenAI(temperature=0.2)
if config_path=='':
print('No agent config specified, using a standard config')
sales_agent = SalesGPT.from_llm(llm, verbose=verbose)
USE_TOOLS=True
if USE_TOOLS:
sales_agent = SalesGPT.from_llm(llm, use_tools=True,
product_catalog = "sample_product_catalog.txt",
salesperson_name="Ted Lasso",
verbose=verbose)
else:
sales_agent = SalesGPT.from_llm(llm, verbose=verbose)
else:
with open(config_path,'r') as f:
config = json.load(f)
print(f'Agent config {config}')
sales_agent = SalesGPT.from_llm(llm, verbose=verbose, **config)


sales_agent.seed_agent()
print('='*10)
cnt = 0
Expand Down
58 changes: 0 additions & 58 deletions run_with_tools.py

This file was deleted.

42 changes: 5 additions & 37 deletions salesgpt/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
from langchain.llms import BaseLLM
from langchain import LLMChain
from langchain.agents import LLMSingleActionAgent, AgentExecutor
from langchain.agents.conversational.output_parser import ConvoOutputParser
from langchain.agents import Tool
from pydantic import BaseModel, Field

from salesgpt.chains import SalesConversationChain, StageAnalyzerChain
from salesgpt.logger import time_logger
from salesgpt.stages import CONVERSATION_STAGES
from salesgpt.tools import setup_knowledge_base, get_tools
from salesgpt.templates import SALES_AGENT_TOOLS_PROMPT, CustomPromptTemplateForTools
from salesgpt.templates import CustomPromptTemplateForTools
from salesgpt.parsers import SalesConvoOutputParser
from salesgpt.prompts import SALES_AGENT_TOOLS_PROMPT


class SalesGPT(Chain, BaseModel):
Expand Down Expand Up @@ -214,7 +214,6 @@ def from_llm(cls, llm: BaseLLM, verbose: bool = False, **kwargs) -> "SalesGPT":
"use_tools" in kwargs.keys()
and kwargs["use_tools"] is True
):
print('setting up an agent with tools')
# set up agent with tools
product_catalog = kwargs["product_catalog"]
knowledge_base = setup_knowledge_base(product_catalog)
Expand All @@ -241,14 +240,15 @@ def from_llm(cls, llm: BaseLLM, verbose: bool = False, **kwargs) -> "SalesGPT":

# WARNING: this output parser is NOT reliable yet
## It makes assumptions about output from LLM which can break and throw an error
output_parser = ConvoOutputParser(ai_prefix=kwargs["salesperson_name"])
output_parser = SalesConvoOutputParser(ai_prefix=kwargs["salesperson_name"])

sales_agent_with_tools = LLMSingleActionAgent(
llm_chain=llm_chain,
output_parser=output_parser,
stop=["\nObservation:"],
allowed_tools=tool_names,
)

sales_agent_executor = AgentExecutor.from_agent_and_tools(
agent=sales_agent_with_tools, tools=tools, verbose=True
)
Expand All @@ -267,35 +267,3 @@ def from_llm(cls, llm: BaseLLM, verbose: bool = False, **kwargs) -> "SalesGPT":
)



from langchain.agents.agent import AgentOutputParser
from langchain.agents.conversational.prompt import FORMAT_INSTRUCTIONS
from langchain.schema import AgentAction, AgentFinish, OutputParserException
import re
from typing import Union

class SalesConvoOutputParser(AgentOutputParser):
ai_prefix: str = "AI" # change for salesperson_name

def get_format_instructions(self) -> str:
return FORMAT_INSTRUCTIONS

def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
print('TEXT')
print(text)
print('-------')
if f"{self.ai_prefix}:" in text:
return AgentFinish(
{"output": text.split(f"{self.ai_prefix}:")[-1].strip()}, text
)
regex = r"Action: (.*?)[\n]*Action Input: (.*)"
match = re.search(regex, text)
if not match:
raise OutputParserException(f"Could not parse LLM output: `{text}`")
action = match.group(1)
action_input = match.group(2)
return AgentAction(action.strip(), action_input.strip(" ").strip('"'), text)

@property
def _type(self) -> str:
return "sales-agent"
38 changes: 38 additions & 0 deletions salesgpt/parsers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from langchain.agents.agent import AgentOutputParser
from langchain.schema import AgentAction, AgentFinish #OutputParserException
from langchain.agents.conversational.prompt import FORMAT_INSTRUCTIONS
import re
from typing import Union


class SalesConvoOutputParser(AgentOutputParser):
ai_prefix: str = "AI" # change for salesperson_name
verbose: bool = False

def get_format_instructions(self) -> str:
return FORMAT_INSTRUCTIONS

def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
if self.verbose:
print('TEXT')
print(text)
print('-------')
if f"{self.ai_prefix}:" in text:
return AgentFinish(
{"output": text.split(f"{self.ai_prefix}:")[-1].strip()}, text
)
regex = r"Action: (.*?)[\n]*Action Input: (.*)"
match = re.search(regex, text)
if not match:
## TODO - this is not entirely reliable, sometimes results in an error.
return AgentFinish(
{"output": "I apologize, I was unable to find the answer to your question. Is there anything else I can help with?"}, text
)
# raise OutputParserException(f"Could not parse LLM output: `{text}`")
action = match.group(1)
action_input = match.group(2)
return AgentAction(action.strip(), action_input.strip(" ").strip('"'), text)

@property
def _type(self) -> str:
return "sales-agent"
59 changes: 59 additions & 0 deletions salesgpt/prompts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

SALES_AGENT_TOOLS_PROMPT ="""
Never forget your name is {salesperson_name}. You work as a {salesperson_role}.
You work at company named {company_name}. {company_name}'s business is the following: {company_business}.
Company values are the following. {company_values}
You are contacting a potential prospect in order to {conversation_purpose}
Your means of contacting the prospect is {conversation_type}
If you're asked about where you got the user's contact information, say that you got it from public records.
Keep your responses in short length to retain the user's attention. Never produce lists, just answers.
Start the conversation by just a greeting and how is the prospect doing without pitching in your first turn.
When the conversation is over, output <END_OF_CALL>
Always think about at which conversation stage you are at before answering:
1: Introduction: Start the conversation by introducing yourself and your company. Be polite and respectful while keeping the tone of the conversation professional. Your greeting should be welcoming. Always clarify in your greeting the reason why you are calling.
2: Qualification: Qualify the prospect by confirming if they are the right person to talk to regarding your product/service. Ensure that they have the authority to make purchasing decisions.
3: Value proposition: Briefly explain how your product/service can benefit the prospect. Focus on the unique selling points and value proposition of your product/service that sets it apart from competitors.
4: Needs analysis: Ask open-ended questions to uncover the prospect's needs and pain points. Listen carefully to their responses and take notes.
5: Solution presentation: Based on the prospect's needs, present your product/service as the solution that can address their pain points.
6: Objection handling: Address any objections that the prospect may have regarding your product/service. Be prepared to provide evidence or testimonials to support your claims.
7: Close: Ask for the sale by proposing a next step. This could be a demo, a trial or a meeting with decision-makers. Ensure to summarize what has been discussed and reiterate the benefits.
8: End conversation: The prospect has to leave to call, the prospect is not interested, or next steps where already determined by the sales agent.
TOOLS:
------
{salesperson_name} has access to the following tools:
{tools}
To use a tool, please use the following format:
```
Thought: Do I need to use a tool? Yes
Action: the action to take, should be one of {tools}
Action Input: the input to the action, always a simple string input
Observation: the result of the action
```
If the result of the action is "I don't know." or "Sorry I don't know", then you have to say that to the user as described in the next sentence.
When you have a response to say to the Human, or if you do not need to use a tool, or if tool did not help, you MUST use the format:
```
Thought: Do I need to use a tool? No
{salesperson_name}: [your response here, if previously used a tool, rephrase latest observation, if unable to find the answer, say it]
```
You must respond according to the previous conversation history and the stage of the conversation you are at.
Only generate one response at a time and act as {salesperson_name} only!
Begin!
Previous conversation history:
{conversation_history}
{salesperson_name}:
{agent_scratchpad}
"""
5 changes: 4 additions & 1 deletion salesgpt/templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from langchain.prompts.base import StringPromptTemplate

from typing import Callable
from langchain.agents.conversational.prompt import FORMAT_INSTRUCTIONS
from langchain.schema import AgentAction, AgentFinish, OutputParserException
import re
from typing import Union, Callable


class CustomPromptTemplateForTools(StringPromptTemplate):
Expand Down
2 changes: 1 addition & 1 deletion salesgpt/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version information."""

__version__ = "0.0.3"
__version__ = "0.0.4"
21 changes: 21 additions & 0 deletions tests/test_data/sample_product_catalog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Sleep Haven Products

Luxury Cloud-Comfort Memory Foam Mattress
Experience the epitome of opulence with our Luxury Cloud-Comfort Memory Foam Mattress. Designed with an innovative, temperature-sensitive memory foam layer, this mattress embraces your body shape, offering personalized support and unparalleled comfort. The mattress is completed with a high-density foam base that ensures longevity, maintaining its form and resilience for years. With the incorporation of cooling gel-infused particles, it regulates your body temperature throughout the night, providing a perfect cool slumbering environment. The breathable, hypoallergenic cover, exquisitely embroidered with silver threads, not only adds a touch of elegance to your bedroom but also keeps allergens at bay. For a restful night and a refreshed morning, invest in the Luxury Cloud-Comfort Memory Foam Mattress.
Price: $999
Sizes available: Twin, Queen, King

Classic Harmony Spring Mattress
A perfect blend of traditional craftsmanship and modern comfort, the Classic Harmony Spring Mattress is designed to give you restful, uninterrupted sleep. It features a robust inner spring construction, complemented by layers of plush padding that offers the perfect balance of support and comfort. The quilted top layer is soft to the touch, adding an extra level of luxury to your sleeping experience. Reinforced edges prevent sagging, ensuring durability and a consistent sleeping surface, while the natural cotton cover wicks away moisture, keeping you dry and comfortable throughout the night. The Classic Harmony Spring Mattress is a timeless choice for those who appreciate the perfect fusion of support and plush comfort.
Price: $1,299
Sizes available: Queen, King

EcoGreen Hybrid Latex Mattress
The EcoGreen Hybrid Latex Mattress is a testament to sustainable luxury. Made from 100% natural latex harvested from eco-friendly plantations, this mattress offers a responsive, bouncy feel combined with the benefits of pressure relief. It is layered over a core of individually pocketed coils, ensuring minimal motion transfer, perfect for those sharing their bed. The mattress is wrapped in a certified organic cotton cover, offering a soft, breathable surface that enhances your comfort. Furthermore, the natural antimicrobial and hypoallergenic properties of latex make this mattress a great choice for allergy sufferers. Embrace a green lifestyle without compromising on comfort with the EcoGreen Hybrid Latex Mattress.
Price: $1,599
Sizes available: Twin, Full

Plush Serenity Bamboo Mattress
The Plush Serenity Bamboo Mattress takes the concept of sleep to new heights of comfort and environmental responsibility. The mattress features a layer of plush, adaptive foam that molds to your body's unique shape, providing tailored support for each sleeper. Underneath, a base of high-resilience support foam adds longevity and prevents sagging. The crowning glory of this mattress is its bamboo-infused top layer - this sustainable material is not only gentle on the planet, but also creates a remarkably soft, cool sleeping surface. Bamboo's natural breathability and moisture-wicking properties make it excellent for temperature regulation, helping to keep you cool and dry all night long. Encased in a silky, removable bamboo cover that's easy to clean and maintain, the Plush Serenity Bamboo Mattress offers a luxurious and eco-friendly sleeping experience.
Price: $2,599
Sizes_ vailable: King
Loading

0 comments on commit e2ae203

Please sign in to comment.