Overview
After inferring the service type and collecting job details, Haggle uses OpenAI’s Responses API with web search to find local service providers. This eliminates the need to maintain a provider database and ensures users always get current, relevant results.Provider search uses GPT-4o with the
web_search_preview tool to find real businesses in the user’s area.How It Works
User Answers Clarifying Questions
The frontend collects answers to all clarifying questions generated during task inference
Implementation
Complete Job Endpoint
The/api/complete-job endpoint orchestrates the provider search:
Search Prompt Construction
Haggle builds a targeted search prompt from the job details:grok_search.py:31-51
- Example Prompt
- Search Configuration
OpenAI Web Search Service
The core search implementation uses OpenAI’s Responses API:grok_search.py:54-111
The search runs in a thread pool executor to prevent blocking the async event loop, since the OpenAI SDK is synchronous.
Response Parsing
Haggle extracts provider information from the OpenAI response using regex:grok_search.py:114-182
Supported Formats
Reliable Plumbing | (408) 555-0101**Quick Drain** - 408-555-01021. Bay Area Plumbers | 408.555.0103Master Plumbing: (408) 555-0104
Phone Patterns
(408) 555-0101408-555-0102408.555.01034085550104
Fallback Providers
When the API is unavailable, Haggle uses task-specific mock data:grok_search.py:185-243
Database Storage
Providers are stored in Supabase with all necessary context for the voice agent:- Provider Schema
- Context Formatting
Provider Status Tracking
The system tracks each provider’s call status:User Workflow
Integration Example
Frontend Integration
Benefits
Always Current
Web search finds active businesses, no stale database
Wide Coverage
Works for any location and service type
No Maintenance
No need to maintain provider listings or verify contacts
Structured Output
GPT-4o follows formatting instructions for easy parsing
Related Features
AI Task Inference
Learn how Haggle classifies service requests
Automated Negotiation
See how the voice agent calls and negotiates with providers