ivr

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-2-Clause Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ivr navigates automated phone menus (IVR systems).

A Navigator is a pipeline of an LLM and a Processor. It starts by asking the LLM whether the far end is an automated system or a person: on an automated system it switches the LLM to a navigation prompt built around a goal, and the voice-activity detector to timing that does not cut a menu into pieces; on a person it raises EventConversationDetected, with the conversation so far, for the application to take over. While navigating, the LLM answers with control tags: <dtmf>N</dtmf> presses a key, and <ivr>status</ivr> reports progress, raised as EventIVRStatusChanged. The tags are stripped from what is spoken and recorded in the conversation, so the LLM knows what it already pressed.

Index

Constants

View Source
const (
	// EventConversationDetected fires when the classifier finds a person on the
	// line, with the conversation so far ([]frames.Message, its system message
	// left out).
	EventConversationDetected = "on_conversation_detected"
	// EventIVRStatusChanged fires with the Status when IVR navigation is
	// detected, completed or stuck.
	EventIVRStatusChanged = "on_ivr_status_changed"
)

The events a Processor raises.

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 ` + "`" + `<mode>ivr</mode>` + "`" + `):
- 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 ` + "`" + `<mode>conversation</mode>` + "`" + `):
- 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:
- ` + "`" + `<mode>ivr</mode>` + "`" + ` for IVR system
- ` + "`" + `<mode>conversation</mode>` + "`" + ` for human conversation`

ClassifierPrompt is the system prompt that asks the LLM whether the far end is an automated IVR system or a person, answered with a <mode> tag.

View Source
const DefaultIVRStopSecs = 2.0

DefaultIVRStopSecs is how long the caller must be quiet before a turn ends while navigating an IVR, when Config.IVRVADParams is nil: long enough that a pause between menu options does not end the turn.

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:
{goal}

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: ` + "`" + `<dtmf>NUMBER</dtmf>` + "`" + ` (e.g., ` + "`" + `<dtmf>1</dtmf>` + "`" + `)
3. For sequences of numbers (dates, account numbers, phone numbers), enter each digit separately: ` + "`" + `<dtmf>1</dtmf><dtmf>2</dtmf><dtmf>3</dtmf>` + "`" + ` 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 ` + "`" + `<ivr>wait</ivr>` + "`" + ` - the system may present more options
7. If the transcription is incomplete or unclear, respond with ` + "`" + `<ivr>wait</ivr>` + "`" + ` to indicate you need more information

COMPLETION CRITERIA - Respond with ` + "`" + `<ivr>completed</ivr>` + "`" + ` 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 ` + "`" + `<ivr>wait</ivr>` + "`" + ` 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

IMPORTANT: Do NOT feel pressured to select an option if none match your goal. Waiting is often the correct response when the IVR system is presenting partial menus or options intended for different user types.

STUCK CRITERIA - Respond with ` + "`" + `<ivr>stuck</ivr>` + "`" + ` 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

STRATEGY TIPS:
- Look for keywords in menu options that match your goal
- Try general options like "Customer Service" or "Other Services" if specific options aren't available
- Pay attention to sub-menus. Sometimes the path requires multiple steps through different menu layers
- If you see "For all other inquiries, press..." that's often a good fallback option
- Remember that reaching your goal may require navigating through several menu levels
- Be patient - IVR systems often present options in waves, and waiting for the right option is better than selecting the wrong one

SEQUENCE INPUT EXAMPLES:
- For date of birth "01/15/1990": ` + "`" + `<dtmf>0</dtmf><dtmf>1</dtmf><dtmf>1</dtmf><dtmf>5</dtmf><dtmf>1</dtmf><dtmf>9</dtmf><dtmf>9</dtmf><dtmf>0</dtmf>` + "`" + `
- For account number "12345": ` + "`" + `<dtmf>1</dtmf><dtmf>2</dtmf><dtmf>3</dtmf><dtmf>4</dtmf><dtmf>5</dtmf>` + "`" + `
- For phone number last 4 digits "6789": ` + "`" + `<dtmf>6</dtmf><dtmf>7</dtmf><dtmf>8</dtmf><dtmf>9</dtmf>` + "`" + `

VERBAL RESPONSE EXAMPLES:
- "Is your date of birth 01/15/1990? Say Yes or No" → "Yes."
- "Please state your first and last name" → "John Smith."
- "What department are you trying to reach?" → "Billing."
- "Are you calling about an existing order? Please say Yes or No" → "No."
- "Did I hear that correctly? Please say Yes or No" → "Yes."

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

IVRNavigationBase is the system prompt for navigating an IVR system, with "{goal}" standing for what the navigation is for.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ClassifierPrompt is the system prompt that asks the LLM whether the far
	// end is an IVR system or a person. Required.
	ClassifierPrompt string `validate:"required"`
	// IVRPrompt is the system prompt for navigating an IVR system. Required.
	IVRPrompt string `validate:"required"`
	// IVRVADParams are the voice-activity parameters while navigating. Nil uses
	// a stop of DefaultIVRStopSecs and the other defaults.
	IVRVADParams *vad.Params
}

Config configures a Processor.

type Navigator struct {
	*pipeline.Pipeline
	// contains filtered or unexported fields
}

Navigator is a pipeline of the LLM and a Processor that classifies the far end, navigates an IVR system towards a goal, and hands a person over to the application. Place it where the LLM would go.

func NewNavigator added in v0.5.0

func NewNavigator(cfg NavigatorConfig) *Navigator

NewNavigator builds a Navigator.

func (n *Navigator) Processor() *Processor

Processor returns the navigator's IVR processor, whose events (EventConversationDetected, EventIVRStatusChanged) report what the navigation finds.

type NavigatorConfig struct {
	// LLM is the service that classifies the far end and navigates. Required.
	LLM processor.Processor `validate:"required"`
	// Goal is what the navigation is for ("reach the billing department"),
	// built into the navigation prompt. Required.
	Goal string `validate:"required"`
	// IVRVADParams are the voice-activity parameters while navigating. Nil uses
	// a stop of DefaultIVRStopSecs.
	IVRVADParams *vad.Params
}

NavigatorConfig configures a Navigator.

type Processor

type Processor struct {
	*processor.Base
	// contains filtered or unexported fields
}

Processor acts on the control tags in the LLM's streamed response: it presses the keys a <dtmf> tag names, switches modes on a <mode> tag, and reports an <ivr> status, passing the rest of the text on as aggregated sentences.

func New

func New(cfg Config) *Processor

New builds an IVR Processor.

func (*Processor) ProcessFrame

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

ProcessFrame aggregates the LLM's text, acting on the control tags in it.

func (*Processor) UpdateSavedMessages added in v0.5.0

func (p *Processor) UpdateSavedMessages(messages []frames.Message)

UpdateSavedMessages sets the conversation carried over when the mode switches.

type Status

type Status string

Status is the IVR navigation status the LLM reports through an <ivr> tag.

const (
	// StatusDetected means an IVR system was detected and navigation begins.
	StatusDetected Status = "detected"
	// StatusCompleted means navigation reached its goal.
	StatusCompleted Status = "completed"
	// StatusStuck means the menu could not be navigated.
	StatusStuck Status = "stuck"
	// StatusWait means the LLM needs more of the menu before it can act.
	StatusWait Status = "wait"
)

Jump to

Keyboard shortcuts

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