AgentsAgentBase

add_pattern_hint

View as MarkdownOpen in Claude

Add a hint with pattern matching and replacement. This allows you to intercept specific ASR output and rewrite it before it reaches the AI — useful for correcting consistent misrecognitions or normalizing variations.

Parameters

hint
strRequired

The hint string to match against ASR output.

pattern
strRequired

Regular expression pattern to match.

replace
strRequired

Replacement text to substitute when the pattern matches.

ignore_case
boolDefaults to False

Whether to ignore case when matching the pattern.

Returns

AgentBase — Returns self for method chaining.

Example

1from signalwire import AgentBase
2
3agent = AgentBase(name="support", route="/support")
4agent.set_prompt_text("You are a helpful assistant.")
5# Correct common ASR misrecognition
6agent.add_pattern_hint(
7 hint="SignalWire",
8 pattern=r"signal\s*wire|signal\s*wired",
9 replace="SignalWire",
10 ignore_case=True
11)
12agent.serve()