add_dynamic_hints

View as MarkdownOpen in Claude

Add speech recognition hints dynamically during a call. Hints improve recognition accuracy for domain-specific vocabulary, product names, or uncommon words. Each hint can be a simple string or a pronunciation pattern object that maps misrecognized speech to the correct text.

Parameters

hints
list[str | dict[str, Any]]Required

List of hints. Each entry is either:

  • A str — a word or phrase to boost recognition (e.g., "SignalWire")
  • A dict with pronunciation pattern fields:
FieldTypeDescription
patternstrRegex pattern to match in recognized speech
replacestrReplacement text when the pattern matches
ignore_caseboolCase-insensitive matching (optional)

Returns

FunctionResult — self, for chaining.

Examples

Simple Word Hints

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="set_medical_context", description="Add medical speech hints")
8def set_medical_context(args, raw_data):
9 return (
10 FunctionResult("Switching to medical context.")
11 .add_dynamic_hints(["prescription", "dosage", "milligrams", "refill"])
12 )
13
14agent.serve()

Pronunciation Patterns

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="set_name_hints", description="Add name pronunciation hints")
8def set_name_hints(args, raw_data):
9 name = args.get("customer_name", "")
10 return (
11 FunctionResult(f"I'll listen for {name}.")
12 .add_dynamic_hints([
13 name,
14 {"pattern": "cab bee", "replace": "Cabby", "ignore_case": True}
15 ])
16 )
17
18agent.serve()