Hints

View as MarkdownOpen in Claude

Why Use Hints?

Speech hints improving recognition accuracy.
Speech Hints

Adding Simple Hints

The hint methods accept a single string or a list of strings:

LanguageSingle HintMultiple Hints
Pythonagent.add_hint("Acme")agent.add_hints(["Acme", "SignalWire"])
TypeScriptagent.addHint('Acme')agent.addHints(['Acme', 'SignalWire'])

Single Hint

1from signalwire import AgentBase
2
3class MyAgent(AgentBase):
4 def __init__(self):
5 super().__init__(name="my-agent")
6 self.add_language("English", "en-US", "rime.spore")
7
8 # Add single hint
9 self.add_hint("Acme")
10 self.add_hint("SignalWire")

Multiple Hints

1## Add list of hints
2self.add_hints([
3 "Acme",
4 "SignalWire",
5 "API",
6 "webhook",
7 "SWML"
8])

What to Hint

CategoryExamples
Brand NamesAcme Corp, SignalWire, company name, product names
Technical TermsAPI, webhook, OAuth, SDK, JSON
Industry JargonKYC, AML, SLA, EOD, PTO
NamesEmployee names, customer names, location names
Numbers/CodesAccount numbers, ZIP codes, reference IDs
ActionsTransfer, escalate, reschedule

Hint Examples by Use Case

Customer Service

1self.add_hints([
2 "Acme", "Acme Pro", "Acme Enterprise",
3 "account", "billing", "refund", "exchange", "return",
4 "cancel", "upgrade", "downgrade",
5 "representative", "supervisor", "escalate", "ticket",
6 "case number", "reference number"
7])

Technical Support

1self.add_hints([
2 "Windows", "macOS", "Linux", "Chrome", "Firefox",
3 "reboot", "restart", "reinstall", "cache", "cookies",
4 "browser", "firewall", "antivirus", "driver",
5 "error code", "blue screen", "crash", "freeze",
6 "not responding", "won't start"
7])

Healthcare

1self.add_hints([
2 "appointment", "reschedule", "cancel", "follow-up",
3 "prescription", "refill", "pharmacy", "dosage",
4 "medication", "symptoms", "diagnosis",
5 "cardiology", "dermatology", "pediatrics", "radiology",
6 "Tylenol", "Advil", "Lipitor", "Metformin"
7])

Financial Services

1self.add_hints([
2 "checking", "savings", "IRA", "401k", "Roth",
3 "transfer", "deposit", "withdrawal", "wire",
4 "ACH", "routing number", "account number",
5 "mortgage", "auto loan", "credit card", "overdraft",
6 "social security", "date of birth", "mother's maiden name"
7])

Pattern Hints (Advanced)

Pattern hints use regular expressions to match and normalize spoken input. They’re useful for normalizing common mishearings of brand names, capturing structured data, and handling variations in how people say things.

Pattern Hint Syntax

1self.add_pattern_hint(
2 hint="what STT should listen for",
3 pattern=r"regex pattern to match",
4 replace="normalized output",
5 ignore_case=True # optional, default False
6)

Common Pattern Examples

Brand name normalization:

1self.add_pattern_hint(
2 hint="Acme",
3 pattern=r"(acme|ackme|ac me|acmee)",
4 replace="Acme",
5 ignore_case=True
6)
7
8self.add_pattern_hint(
9 hint="SignalWire",
10 pattern=r"(signal wire|signalwire|signal-wire)",
11 replace="SignalWire",
12 ignore_case=True
13)

Account/Order numbers:

1self.add_pattern_hint(
2 hint="account number",
3 pattern=r"\d{8}",
4 replace="${0}"
5)
6
7self.add_pattern_hint(
8 hint="order ID",
9 pattern=r"ORD[-\s]?\d{5,8}",
10 replace="${0}",
11 ignore_case=True
12)

Phone numbers:

1self.add_pattern_hint(
2 hint="phone number",
3 pattern=r"\d{3}[-.\s]?\d{3}[-.\s]?\d{4}",
4 replace="${0}"
5)

Email addresses:

1self.add_pattern_hint(
2 hint="email",
3 pattern=r"\S+@\S+\.\S+",
4 replace="${0}"
5)

Dates:

1self.add_pattern_hint(
2 hint="date",
3 pattern=r"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\s+\d{1,2}(st|nd|rd|th)?",
4 replace="${0}",
5 ignore_case=True
6)

Pattern Hint Tips

Test patterns first: Before adding pattern hints, test your regex at a site like regex101.com. STT output may vary from what you expect.

Start simple: Begin with basic patterns and refine based on actual transcription errors you observe.

Use capture groups carefully: ${0} = entire match, ${1} = first capture group, ${2} = second capture group, etc.

Debug with logging: Enable debug logging to see what STT produces, then craft patterns to match.

1import logging
2logging.basicConfig(level=logging.DEBUG)

Order matters: If multiple patterns could match, they’re evaluated in registration order. Put more specific patterns first.

Organizing Hints

For large hint lists, organize by category:

1class OrganizedHintsAgent(AgentBase):
2 BRAND_HINTS = ["Acme", "Acme Pro", "Acme Enterprise"]
3 ACTION_HINTS = ["account", "billing", "refund", "cancel"]
4 SUPPORT_HINTS = ["representative", "supervisor", "escalate"]
5
6 def __init__(self):
7 super().__init__(name="organized-hints")
8 self.add_language("English", "en-US", "rime.spore")
9 self.add_hints(self.BRAND_HINTS)
10 self.add_hints(self.ACTION_HINTS)
11 self.add_hints(self.SUPPORT_HINTS)

Dynamic Hints

Add hints based on context:

1class DynamicHintsAgent(AgentBase):
2 DEPARTMENT_HINTS = {
3 "sales": ["pricing", "quote", "demo", "trial", "discount"],
4 "support": ["ticket", "bug", "error", "fix", "issue"],
5 "billing": ["invoice", "payment", "refund", "charge"]
6 }
7
8 def __init__(self):
9 super().__init__(name="dynamic-hints")
10 self.add_language("English", "en-US", "rime.spore")
11 self.add_hints(["Acme", "account", "help"])
12
13 def on_swml_request(self, request_data=None, callback_path=None, request=None):
14 call_data = (request_data or {}).get("call", {})
15 called_num = call_data.get("to", "")
16
17 if "555-1000" in called_num:
18 self.add_hints(self.DEPARTMENT_HINTS["sales"])
19 elif "555-2000" in called_num:
20 self.add_hints(self.DEPARTMENT_HINTS["support"])
21 else:
22 self.add_hints(self.DEPARTMENT_HINTS["billing"])

Hint Best Practices

DO:

  • Hint brand names and product names
  • Hint technical terms specific to your domain
  • Hint common employee/customer names
  • Hint acronyms and abbreviations
  • Test with actual callers to find missed words

DON’T:

  • Hint common English words (already recognized well)
  • Add hundreds of hints (quality over quantity)
  • Hint full sentences (single words/short phrases work best)
  • Forget to update hints when products/terms change

Testing Hints

Use swaig-test to verify hints are included:

$## View SWML including hints
$swaig-test my_agent.py --dump-swml | grep -A 20 "hints"

Check the generated SWML for the hints array:

1{
2 "version": "1.0.0",
3 "sections": {
4 "main": [{
5 "ai": {
6 "hints": [
7 "Acme",
8 "SignalWire",
9 "account",
10 "billing"
11 ]
12 }
13 }]
14 }
15}

Complete Example

1#!/usr/bin/env python3
2## hinted_agent.py - Agent with speech recognition hints
3from signalwire import AgentBase, FunctionResult
4
5class HintedAgent(AgentBase):
6 def __init__(self):
7 super().__init__(name="hinted-agent")
8 self.add_language("English", "en-US", "rime.spore")
9
10 self.add_hints(["Acme", "Acme Pro", "Acme Enterprise", "AcmePay", "AcmeCloud"])
11 self.add_hints(["SKU", "A100", "A200", "A300", "PRO100", "ENT500"])
12 self.add_hints(["account", "billing", "invoice", "refund", "cancel", "upgrade", "downgrade", "representative", "supervisor"])
13 self.add_hints(["API", "webhook", "integration", "OAuth", "SSO", "MFA"])
14
15 self.prompt_add_section("Role", "You are a customer service agent for Acme Corporation.")
16
17 self.define_tool(
18 name="lookup_product",
19 description="Look up product by SKU",
20 parameters={
21 "type": "object",
22 "properties": {
23 "sku": {"type": "string", "description": "Product SKU like A100 or PRO100"}
24 },
25 "required": ["sku"]
26 },
27 handler=self.lookup_product
28 )
29
30 def lookup_product(self, args, raw_data):
31 sku = args.get("sku", "").upper()
32 products = {
33 "A100": "Acme Basic - $99/month",
34 "A200": "Acme Standard - $199/month",
35 "A300": "Acme Premium - $299/month",
36 "PRO100": "Acme Pro - $499/month",
37 "ENT500": "Acme Enterprise - Custom pricing"
38 }
39 if sku in products:
40 return FunctionResult(f"{sku}: {products[sku]}")
41 return FunctionResult(f"SKU {sku} not found.")
42
43if __name__ == "__main__":
44 agent = HintedAgent()
45 agent.run()

Next Steps

You now know how to build and configure agents. Next, learn about SWAIG functions to add custom capabilities.