From Decision Tree to Dialogue: Building an AI Negotiation Agent That Understands Context

$4.5M incremental vendor income, 1,081 autonomous contracts, 50% reduction in human-assisted negotiations
10/30/202410 min read
LangGraphFastAPIPyTorchElasticSearchBigQueryNext.jsVercel AI SDK

Executive Summary

I led the architecture and implementation of a multi-agent LLM system that transformed a statistical negotiation bot into an intelligent conversational agent, resulting in $4.5M in incremental vendor income, 1,081 autonomous contracts, and a 50% reduction in human-assisted negotiations during the pilot phase.

The Challenge

A major retail organization managed thousands of vendor relationships, from enterprise partners to small-medium suppliers. While high-value partnerships received white-glove treatment with dedicated negotiators, the long tail of vendors—representing significant aggregate value—was handled by "Bob," a legacy game theory-based negotiation bot.

The negotiation process focused on three critical vendor rate components:

  • Digital Accrual Rate: Fees related to digital infrastructure costs
  • D-Markdown Rate: Markdown and discount rate structures
  • Sales/Receipt Accrual Rate: Terms tied to sales volume and receipt timing

The Problem with Bob

Bob was effective at optimization but ineffective at communication:

Purely statistical: Built on classical game theory models (primarily Tit-for-Tat strategies), the bot excelled at multi-variable optimization but couldn't articulate why it made specific offers.

Rigid interaction model: A decision-tree interface that felt transactional rather than collaborative.

Context blindness: Unable to understand vendor pain points, business constraints, or the nuanced reasons behind counter-offers.

Vendor frustration and abandonment: Vendors found the system's rigidity so off-putting that they would intentionally click "disagree" through every offer just to trigger the "Speak with human" option, bypassing the system entirely.

Asynchronous Bottlenecks: The bot's rigid availability created multi-day delays for international vendors due to timezone differences, further straining relationships and slowing time-to-contract.

High escalation rate: Over 70% of negotiations either escalated to human agents or required secondary negotiation rounds.

The core issue: The statistical bot could calculate optimal terms but couldn't build the rapport or provide the explanations necessary to close deals autonomously. Vendors didn't just struggle with it—they actively avoided it.

The Solution: A Multi-Agent Negotiation Architecture

Rather than replacing the legacy system entirely, I designed a LangGraph-based agent system that transformed it from the primary negotiator into a specialized calculation engine within a more sophisticated conversational framework.

Multi-Agent Negotiation Workflow

Specialized agents route conversations based on complexity. Drag to pan, scroll to zoom.

React Flow mini map

System Architecture

The solution employed a multi-agent orchestration pattern with specialized nodes for different negotiation responsibilities:

1. Supervisor Agent (Orchestrator)

  • Central coordinator managing negotiation flow and state transitions
  • Determined when to employ different specialized agents based on conversation state
  • Made strategic decisions about leverage deployment and concession timing

2. Negotiator Agent (Primary Interface)

  • Handled all vendor-facing communication
  • Extracted key variables from natural language messages (e.g., "We feel 2% is more appropriate than 4%")
  • Maintained conversation context and built rapport through empathetic, business-appropriate responses
  • Updated the negotiation state based on vendor signals and explicit requests

3. Statistical Engine (Legacy Bot "Bob")

  • Retained original game theory optimization capabilities
  • Consumed structured negotiation variables from the Negotiator Agent
  • Calculated counter-offers using historical data patterns (BigQuery) and Tit-for-Tat strategies
  • Returned optimized terms without direct vendor interaction

4. Leverage Advisor Agent

  • Monitored negotiation state to identify leverage opportunities
  • Advised the Supervisor on strategic timing for applying pressure or making concessions
  • Analyzed vendor behavior patterns for signals of urgency or flexibility

5. Human-in-the-Loop (Agent Tool)

  • Integrated human negotiators as a callable tool within the agent workflow
  • Allowed complex edge cases or sensitive negotiations to seamlessly escalate to specialists
  • Preserved Vendor Autonomy: At any point, the vendor retained full control and could opt to "speak to a human," ensuring a trust-based, non-coercive experience
  • Strategic Benefit: Ensured quality and safety for high-stakes scenarios, with the deliberate trade-off of increased time-to-resolution for those specific escalated cases

Key Technical Innovation: ZOPA State Management

The breakthrough was introducing a Zone of Probable Agreement (ZOPA) segment within the agent state graph:

# ZOPA State Structure
class ZOPAState(TypedDict):
    """Zone of Probable Agreement - shared negotiation state"""
    
    # Current offer terms
    current_offer: Dict[str, float]  # Digital, D-Markdown, Sales/Receipt rates
    
    # Vendor position (extracted from conversation)
    vendor_position: Dict[str, float]
    vendor_constraints: List[str]
    
    # Acceptable range boundaries
    acceptable_ranges: Dict[str, Tuple[float, float]]
    
    # Deal-breaker constraints
    non_negotiable_terms: List[str]
    
    # Negotiation history
    concession_history: List[ConcessionRecord]
    round_count: int
    
    # Strategic indicators
    leverage_score: float
    urgency_signals: List[str]
    vendor_sentiment: float

The ZOPA served as:

  • Shared context across all agent nodes
  • Decision boundary for autonomous vs. escalated negotiations
  • Audit trail for compliance and post-negotiation analysis
  • Real-time scoreboard showing distance to agreement

Intelligent Context Injection

To address Bob's original weakness—lack of "why"—I implemented a RAG (Retrieval-Augmented Generation) system:

  • Contract terms database (ElasticSearch vector store)
  • Historical justification patterns from successful negotiations
  • Policy guardrails defining non-negotiable terms
  • Vendor feedback data from BigQuery analysis

When the Supervisor formulated responses, it retrieved relevant context to explain offers:

"Based on our volume commitment of X units and the 90-day payment terms we're offering, our proposed 3.2% rate aligns with similar partnerships in your category."

Data Integration Pipeline

The system maintained continuity with existing infrastructure:

  • BigQuery integration: Historical vendor data, pattern analysis, and cohort comparisons
  • Vendor profiling: Automated analysis of pain points and priorities from past interactions
  • Legacy PyTorch models: Preserved as calculation engines, invoked via tool calls from LangGraph nodes

Data Flow Architecture

How vendor data flows through the system for negotiation analysis and response generation. Data sources feed context retrieval, which informs agent decisions and statistical calculations.
💡 Tip: Drag nodes to rearrange the diagram

Implementation Details

Technology Stack

  • Backend: FastAPI (API layer and webhook handling)
  • Orchestration: LangGraph (multi-agent workflow management)
  • Vector Search: ElasticSearch (contract terms and RAG context)
  • ML Models: PyTorch (Bob's statistical models)
  • Data Layer: BigQuery (analytics and historical patterns)
  • Frontend: Next.js with Vercel AI SDK (streaming responses, real-time negotiation UI)

Implementation Approach

Phase 1: Decomposition & Node Design

I worked closely with data scientists to decompose the negotiation process into discrete, state-driven steps. Each step became a LangGraph node with clear inputs, outputs, and state mutations.

Phase 2: State Schema Engineering

Designed the ZOPA state structure to capture negotiation dynamics in a way that both LLM agents and statistical models could consume. This required careful consideration of:

  • What variables the legacy statistical engine needed in structured format
  • What context LLM agents needed for natural conversation
  • What metrics indicated negotiation progress or stalemate

Phase 3: Agent Prompt Engineering

Crafted specialized system prompts for each agent role:

  • Negotiator: Empathetic, business-savvy, skilled at extracting structured data from unstructured vendor messages
  • Supervisor: Strategic, compliance-aware, capable of meta-reasoning about negotiation state
  • Leverage Advisor: Analytical, pattern-recognition focused
// Example: Negotiator Agent prompt structure
const negotiatorPrompt = `You are a professional vendor negotiator representing a major retail organization.

Your role:
- Extract negotiation variables from natural language vendor messages
- Maintain rapport and demonstrate understanding of vendor constraints
- Update the ZOPA state based on vendor signals
- Communicate in a business-appropriate, empathetic tone

Current negotiation state:
{zopa_state}

Vendor message:
{vendor_message}

Extract structured data and generate an appropriate response that moves the negotiation forward.`;

Phase 4: Integration & Testing

Built robust integrations with BigQuery, ElasticSearch, and the existing PyTorch-based statistical models. Extensive testing on historical negotiation transcripts to validate the agent's ability to:

  • Reach similar outcomes as human negotiators
  • Stay within policy boundaries
  • Escalate appropriately when needed
# Example: Statistical Engine integration as LangGraph tool
@tool
def calculate_counter_offer(
    current_terms: Dict[str, float],
    vendor_position: Dict[str, float],
    historical_context: Dict
) -> Dict[str, float]:
    """
    Invoke legacy PyTorch-based statistical engine.
    Translates agent state into format Bob expects.
    """
    # Convert to legacy format
    legacy_input = transform_to_legacy_format(
        current_terms, 
        vendor_position,
        historical_context
    )
    
    # Call Bob's statistical model
    optimized_terms = bob_engine.calculate(legacy_input)
    
    # Transform back to agent-friendly format
    return transform_from_legacy_format(optimized_terms)

Results

The pilot deployment demonstrated a massive ROI and validated the hybrid-agent approach:

Business Impact

  • $4.5M in incremental vendor income generated during the pilot
  • 1,081 contracts created autonomously without human intervention

Operational Efficiency

  • First-Round Completion Rate: Soared to 65%, a dramatic reversal from the legacy bot's sub-30% success rate
  • Human Escalation Rate: Slashed from over 70% down to 35%—a 50% reduction in manual workload. This freed specialist negotiators to focus on high-value, white-glove accounts
  • 24/7 Availability: Eliminated timezone bottlenecks for international vendors, progressing negotiations in hours instead of days
  • Improved vendor satisfaction (measured through post-negotiation surveys)

Key Learnings

1. Hybrid Intelligence Beats Pure AI or Pure Statistics

The most effective solution wasn't replacing the legacy statistical engine, but augmenting it. Statistical models excel at optimization; LLMs excel at communication and context understanding. The combination outperformed either alone.

2. State Design is Critical in Multi-Agent Systems

The ZOPA state structure was the linchpin. Poor state design would have led to agent confusion, inconsistent behavior, or lost context. Investing time in state schema engineering paid massive dividends.

3. Specialization Enables Complexity

Rather than building one mega-agent, decomposing negotiation into specialized roles (negotiation, calculation, leverage analysis) made each component easier to test, debug, and optimize.

4. RAG Grounds LLM Creativity

Without the contract terms and historical justification database, the Negotiator agent would have been creative but potentially non-compliant. RAG provided the guardrails that made autonomous negotiation viable.

Technical Challenges Overcome

Challenge: Maintaining Statistical Accuracy in an Agent Context

Solution: Created a structured tool interface that translated natural language negotiation state into the precise variable formats the legacy system expected, then translated its numerical outputs back into conversational responses.

Challenge: Preventing Agent Hallucination on Contract Terms

Solution: Strict RAG retrieval with confidence thresholds. The Supervisor agent only cited terms that exceeded retrieval confidence scores, otherwise escalated to humans.

Challenge: Real-time State Synchronization

Solution: FastAPI webhooks with optimistic state updates and rollback mechanisms for handling concurrent negotiation updates from multiple vendors.

Architecture Diagram

Multi-Agent Negotiation Workflow

Multi-agent orchestration with specialized roles. The Supervisor Agent routes conversations to specialized agents based on negotiation complexity and stage.
💡 Tip: Drag nodes to rearrange the diagram

Future Enhancements

While the pilot succeeded, several enhancements would further improve the system:

  1. Multi-modal negotiation: Incorporate document analysis (vendor-submitted proposals, financial statements)
  2. Predictive escalation: Train a model to predict early in negotiation whether human intervention will ultimately be needed
  3. A/B testing framework: Systematic experimentation with different negotiation strategies
  4. Cross-vendor learning: Use successful negotiation patterns with one vendor to inform strategies with similar vendors

Conclusion

This project demonstrated that thoughtful agent architecture can transform existing statistical tools into sophisticated conversational systems. By preserving the legacy engine's analytical strengths while adding contextual understanding and communication skills through LangGraph orchestration, we achieved significant business impact while reducing operational burden.

This project solidified a key insight: effective AI systems are built on orchestration. My role was to understand when to leverage game theory, when to apply LLMs for context, and how to architect the system that coordinates them—which I believe is the essence of modern AI engineering.


Project Information

  • Role: Lead AI Engineer (Agent Architecture & Implementation)
  • Team: Collaborated with data scientists on statistical model integration and data pipeline design
  • Duration: 6 weeks
  • Technologies: LangGraph, FastAPI, PyTorch, ElasticSearch, BigQuery, Next.js, Vercel AI SDK