Negotiation is an art that affects everything from job offers to business transactions. Whether you are negotiating a salary, closing a business deal, or settling a dispute over a contract, the proper technique can be the difference between success and sacrifice. In order to simplify and streamline the negotiation process, I developed an AI-Powered Negotiation Agent, a Streamlit web application built on LangChain and DeepSeek-R1. It provides you with intelligent negotiation strategies based on what you input, and you negotiate the best possible agreement.
This article was published as a part of the Data Science Blogathon.
DeepSeek-R1-Distill-Llama-70B is a high-performance GroqCloud AI model. It is a distilled version of Llama 3.3 70B and is made intelligent and efficient to respond to math, coding, and factual questions.
This model reasons sequentially, step by step, and thus is appropriate for high-level decision-making. With Groq’s extremely fast inference, users can experience real-time AI reasoning without latency, unlocking new possibilities for high-end AI applications.
People struggle to negotiate effectively due to a lack of information, emotional bias, or weak argument structuring.
Goal: Create an AI agent that analyzes a negotiation scenario, predicts counteroffers, and suggests optimal negotiation strategies based on logic and past data.
Let us now look into the key features of AI Negotiation Agent below:
The user begins by opening the Streamlit app and selecting the desired negotiation type. They then input the offer details, providing key information for the AI model to process. Upon clicking the ‘Generate AI Strategy’ button, the system initializes and loads the Large Language Model (DeepSeek-R1). The input data is then processed using a predefined prompt template, ensuring that the AI understands the negotiation context effectively.
Once the processing is complete, the AI generates a tailored negotiation strategy based on the provided details. Finally, the system displays the AI’s suggested strategy, offering insights and recommendations to assist the user in their negotiation process.
Choose from four predefined options:
Fill in:
Once submitted, the AI analyzes your negotiation and provides:
Leverage the AI-generated strategy to confidently negotiate and secure better deals.
Below we will set up the base by first setting up the environment then followed by installing libraries:
# Create a Environment
python -m venv env
# Activate it on Windows
.\env\Scripts\activate
# Activate in MacOS/Linux
source env/bin/activate
pip install -r https://raw.githubusercontent.com/Gouravlohar/Negotiation-Agent/refs/heads/main/requirements.txt
visit Groq for API Key.
Paste the API key in .env File
GROQ_API_KEY="Your API KEY PASTE HERE"
Below we’ll walk you through building an AI negotiation agent using DeepSeek-R1 Distill LLaMA-70B and Streamlit, enabling you to generate smart, data-driven negotiation strategies effortlessly. Let’s dive in!
The necessary libraries, including Streamlit for UI, LangChain for AI processing, and dotenv for environment variable management, are imported to set up the negotiation agent.
import os
import streamlit as st
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain_groq import ChatGroq
from dotenv import load_dotenv
The application loads the Groq API key from the environment file. If the key is missing, an error message is displayed, and execution stops to prevent unauthorized access.
load_dotenv()
groq_api_key = os.getenv("GROQ_API_KEY")
if not groq_api_key:
st.error("Groq API Key not found in .env file")
st.stop()
The Streamlit app is configured with a title and wide layout. This ensures a structured and user-friendly interface for engaging with the negotiation agent.
st.set_page_config(page_title="AI Negotiation Agent", layout="wide")
st.title("🤝 AI-Powered Negotiation Agent")
A sidebar is added where users can select their preferred negotiation type—Salary Negotiation, Business Deal, Freelance Pricing, or Contract Dispute—to customize AI-generated strategies.
st.sidebar.header("Negotiation Settings")
st.sidebar.markdown("Select your negotiation type and explore the details below.")
negotiation_type = st.sidebar.selectbox("Negotiation Type", [
"Salary Negotiation",
"Business Deal",
"Freelance Pricing",
"Contract Dispute"
])
An expandable section provides step-by-step guidance on how to use the app. Users input their offer details, click the “Generate AI Strategy” button, and adjust negotiation settings as needed.
with st.expander("How to use this app"):
st.markdown("""
- Fill in your offer, the opposing offer, and key constraints.
- Click **Generate AI Strategy** to receive suggestions.
- Use the sidebar to adjust the negotiation type.
""")
A structured prompt template is defined to ensure the AI model receives key negotiation details. It includes the negotiation type, offers, constraints, and expected AI output like counteroffers, risk assessments, and confidence scores.
negotiation_template = """
You are an expert negotiator. Analyze this scenario and suggest the best negotiation strategy:
- **Negotiation Type:** {negotiation_type}
- **Your Offer:** {your_offer}
- **Other Party's Expected Offer:** {other_party_stance}
- **Key Constraints:** {key_constraints}
### Provide:
1. The best counteroffer.
2. Justification with reasoning.
3. Risk assessment (if any).
4. Confidence score (out of 100%).
"""
A function is implemented to initialize the DeepSeek R1 (Distill LLaMA-70B) model using the ChatGroq API. The streaming=True
parameter enables real-time response generation.
def load_LLM(groq_api_key):
"""Loads the ChatGroq model for processing."""
llm = ChatGroq(groq_api_key=groq_api_key, model_name="deepseek-r1-distill-llama-70b", streaming=True)
return llm
A form captures user inputs, including their offer, the opponent’s expected offer, and key constraints. This information is essential for the AI model to generate an effective negotiation strategy.
st.header(f"💼 {negotiation_type}")
st.markdown("Enter details of your negotiation scenario below:")
with st.form(key="negotiation_form"):
col1, col2 = st.columns(2)
with col1:
your_offer = st.text_input("Your Offer (₹ or %):", placeholder="Enter your proposed offer...")
with col2:
other_party_stance = st.text_input("Other Party's Expected Offer (₹ or %):", placeholder="Enter expected counteroffer...")
key_constraints = st.text_area("Key Constraints", height=150, placeholder="List deal-breakers, goals, must-haves...")
submit_button = st.form_submit_button("Generate AI Strategy")
Creates a form where users enter:
Upon submission, the app validates input fields before processing the data. The AI model is loaded, and a prompt is sent for strategy generation. The response includes counteroffers, justifications, risk assessments, and confidence scores. If any field is missing, an error message prompts the user to complete the form.
if submit_button:
if your_offer and other_party_stance and key_constraints:
with st.spinner("Generating negotiation strategy..."):
llm = load_LLM(groq_api_key)
prompt_obj = PromptTemplate(
input_variables=["negotiation_type", "your_offer", "other_party_stance", "key_constraints"],
template=negotiation_template
)
chain = LLMChain(llm=llm, prompt=prompt_obj)
result = chain.run(
negotiation_type=negotiation_type,
your_offer=your_offer,
other_party_stance=other_party_stance,
key_constraints=key_constraints
)
st.success("Strategy generated successfully!")
st.subheader("💡 AI's Suggested Strategy:")
st.markdown(result)
else:
st.error("Please fill in all fields before generating a strategy.")
Get full code on GitHub Here
Input
Negotiation Type: Salary Negotiation
Key Constraints:
Output
Negotiation is a valuable skill in both professional and personal life, and the Negotiation Agent using DeepSeek-R1 employs data to assist you in negotiating improved deals. Whether you are negotiating a raise, a business investment, or contract terms, this app helps you make better decisions with AI-generated counteroffers, risk levels, and confidence scores.
This utility leverages DeepSeek-R1 Distill LLaMA-70B, LangChain, and Streamlit to facilitate negotiations. It assists you in minimizing uncertainty and maximizing your success rate.
Thanks to AI, you don’t have to second-guess your best move anymore—you can negotiate with confidence!
A. The load_LLM() function initializes the DeepSeek R1 Distill Llama 70b model using the ChatGroq API. It returns an LLM (Language Model) that processes user input and generates negotiation strategies.
A. PromptTemplate defines the structure of the prompt sent to the AI. It ensures the AI receives all necessary details (offer, constraints, negotiation type) to generate a meaningful response.
A. The API key is sensitive data, and storing it in a .env file keeps it secure. The dotenv package loads this key into the environment without exposing it in the code.
A. Before submitting, the app validates input fields (your_offer, other_party_stance, key_constraints). If any field is empty, it displays an error message to ensure complete data entry.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.