ivr

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ivr provides Interactive Voice Response (IVR) navigation components for automated IVR phone system navigation using LLM-based decision making and DTMF.

Package ivr provides IVRNavigator pipeline helper.

Index

Constants

View Source
const ClassifierPrompt = `You are an IVR detection classifier. Analyze the transcribed text to determine if it's an automated IVR system or a live human conversation.

IVR SYSTEM (respond ` + "` ivr `" + `):
- Menu options: "Press 1 for billing", "Press 2 for technical support", "Press 0 to speak to an agent"
- Automated instructions: "Please enter your account number", "Say or press your selection", "Enter your phone number followed by the pound key"
- System prompts: "Thank you for calling [company]", "Your call is important to us", "Please hold while we connect you"
- Scripted introductions: "Welcome to [company] customer service", "For faster service, have your account number ready"
- Navigation phrases: "To return to the main menu", "Press star to repeat", "Say 'agent' or press 0"
- Hold messages: "Please continue to hold", "Your estimated wait time is", "Thank you for your patience"
- Carrier messages: "All circuits are busy", "Due to high call volume"

HUMAN CONVERSATION (respond ` + "` conversation `" + `):
- Personal greetings: "Hello, this is Sarah", "Good morning, how can I help you?", "Customer service, this is Mike"
- Interactive responses: "Who am I speaking with?", "What can I do for you today?", "How are you calling about?"
- Natural speech patterns: hesitations, informal language, conversational flow
- Direct engagement: "I see you're calling about...", "Let me look that up for you", "Can you spell that for me?"
- Spontaneous responses: "Oh, I can help with that", "Sure, no problem", "Hmm, let me check"

RESPOND ONLY with either:
- ` + "` ivr `" + ` for IVR system
- ` + "` conversation `" + ` for human conversation`

Default classifier prompt for IVR vs conversation detection.

View Source
const IVRNavigationBase = `You are navigating an Interactive Voice Response (IVR) system to accomplish a specific goal. You receive text transcriptions of the IVR system's audio prompts and menu options.

YOUR NAVIGATION GOAL:
%s

NAVIGATION RULES:
1. When you see menu options with keypress instructions (e.g., "Press 1 for...", "Press 2 for..."), ONLY respond with a keypress if one of the options aligns with your navigation goal
2. If an option closely matches your goal, respond with: ` + "` NUMBER `" + ` (e.g. ` + "` 1 `" + `)
3. For sequences of numbers (dates, account numbers, phone numbers), enter each digit separately: ` + "` 1 2 3 `" + ` for "123"
4. When the system asks for verbal responses (e.g. "Say Yes or No", "Please state your name", "What department?"), respond with natural language text ending with punctuation
5. If multiple options seem relevant, choose the most specific or direct path
6. If NO options are relevant to your goal, respond with ` + "` wait `" + ` - the system may present more options
7. If the transcription is incomplete or unclear, respond with ` + "` wait `" + ` to indicate you need more information

COMPLETION CRITERIA - Respond with ` + "` completed `" + ` when:
- You see "Please hold while I transfer you" or similar transfer language
- You see "You're being connected to..." or "Connecting you to..."
- The system says "One moment please" after selecting your final option
- The system indicates you've reached the target department/service
- You've successfully navigated to your goal and are being transferred to a human

WAIT CRITERIA - Respond with ` + "` wait `" + ` when:
- NONE of the presented options are relevant to your navigation goal
- The transcription appears to be cut off mid-sentence
- You can see partial menu options but the list seems incomplete
- The transcription is unclear or garbled
- You suspect there are more options that weren't captured in the transcription
- The system presents options for specific user types that don't apply to your goal

STUCK CRITERIA - Respond with ` + "` stuck `" + ` when:
- You've been through the same menu options 3+ times without progress
- No available options relate to your goal after careful consideration
- You encounter an error message or "invalid selection" repeatedly
- The system asks for information you don't have (account numbers, PINs, etc.)
- You reach a dead end with no relevant options and no way back

Remember: Respond with ` + "` NUMBER `" + ` (single or multiple for sequences), ` + "` completed `" + `, ` + "` stuck `" + `, ` + "` wait `" + `, OR natural language text when verbal responses are requested. No other response types.`

IVRNavigationBase is the template for the IVR navigation prompt; use fmt with goal.

Variables

This section is empty.

Functions

This section is empty.

Types

type IVRNavigator

type IVRNavigator struct {
	Processor processors.Processor
	// contains filtered or unexported fields
}

IVRNavigator wraps a pipeline of LLM + IVRProcessor for automated IVR navigation.

func NewIVRNavigator

func NewIVRNavigator(llm services.LLMService, goal string, ivrVADStopSecs float64) *IVRNavigator

NewIVRNavigator creates an IVR navigator: pipeline [LLM, IVRProcessor] with default prompts. Goal is interpolated into IVRNavigationBase. ivrVADStopSecs is the VAD stop_secs in IVR mode (0 = 2.0).

func (*IVRNavigator) OnConversationDetected

func (n *IVRNavigator) OnConversationDetected(fn func(conversationHistory []map[string]any))

OnConversationDetected registers the callback on the underlying IVRProcessor.

func (*IVRNavigator) OnIVRStatusChanged

func (n *IVRNavigator) OnIVRStatusChanged(fn func(status IVRStatus))

OnIVRStatusChanged registers the callback on the underlying IVRProcessor.

type IVRProcessor

type IVRProcessor struct {
	*processors.BaseProcessor
	ClassifierPrompt string
	IVRPrompt        string
	IVRVADStopSecs   float64 // VAD stop_secs when in IVR mode (e.g. 2.0)
	// contains filtered or unexported fields
}

IVRProcessor processes LLM responses for IVR navigation: aggregates XML-tagged commands and executes DTMF, mode switching, and status updates.

func NewIVRProcessor

func NewIVRProcessor(name string, classifierPrompt, ivrPrompt string, ivrVADStopSecs float64) *IVRProcessor

NewIVRProcessor creates an IVR processor with the given classifier and IVR prompts.

func (*IVRProcessor) OnConversationDetected

func (p *IVRProcessor) OnConversationDetected(fn func(conversationHistory []map[string]any))

OnConversationDetected registers a callback when the classifier detects human conversation.

func (*IVRProcessor) OnIVRStatusChanged

func (p *IVRProcessor) OnIVRStatusChanged(fn func(status IVRStatus))

OnIVRStatusChanged registers a callback when IVR status changes (detected, completed, stuck, wait).

func (*IVRProcessor) ProcessFrame

func (p *IVRProcessor) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame implements Processor.

func (*IVRProcessor) SetSavedMessages

func (p *IVRProcessor) SetSavedMessages(msgs []map[string]any)

SetSavedMessages sets the conversation context used when switching to IVR mode.

type IVRStatus

type IVRStatus string

IVRStatus represents the current state of IVR navigation.

const (
	IVRStatusDetected  IVRStatus = "detected"
	IVRStatusCompleted IVRStatus = "completed"
	IVRStatusStuck     IVRStatus = "stuck"
	IVRStatusWait      IVRStatus = "wait"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL