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

from signalwire import AgentBase
from signalwire import FunctionResult
agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")
@agent.tool(name="set_medical_context", description="Add medical speech hints")
def set_medical_context(args, raw_data):
return (
FunctionResult("Switching to medical context.")
.add_dynamic_hints(["prescription", "dosage", "milligrams", "refill"])
)
agent.serve()

Pronunciation Patterns

from signalwire import AgentBase
from signalwire import FunctionResult
agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")
@agent.tool(name="set_name_hints", description="Add name pronunciation hints")
def set_name_hints(args, raw_data):
name = args.get("customer_name", "")
return (
FunctionResult(f"I'll listen for {name}.")
.add_dynamic_hints([
name,
{"pattern": "cab bee", "replace": "Cabby", "ignore_case": True}
])
)
agent.serve()