Skip to navigation
AgentsAgentBase

record_speech_finals

View as MarkdownOpen in Claude

Keep each call’s recognizer finals, with their word confidences, for tool handlers to read with speech_finals(). A final is what the recognizer heard for one turn of the caller’s, from the platform’s ai.speech_detect event. Its words are as heard, before hearing hints and number formatting change the text, so a handler can ask the caller again about a word the recognizer wasn’t sure of, such as a letter of a spelled name.

Like on_ai_event(), it sets the call’s event_webhook_url to the agent’s /ai_events endpoint, unless you set it yourself, and needs the agent’s own web server. A call with redact_prompt set sends no finals unless debug is on.

Parameters

max_calls
intDefaults to 500

The most calls to keep finals for. The oldest call’s finals go first.

max_finals
intDefaults to 200

The most finals to keep for one call.

Returns

AgentBase — Self for method chaining.

Example

from signalwire import AgentBase, FunctionResult
agent = AgentBase(name="spell", route="/spell")
agent.prompt_add_section("Role", "You take spelled names.")
agent.record_speech_finals()
def check_name(args, raw_data):
finals = agent.speech_finals(raw_data["call_id"])
unsure = [w["word"] for f in finals for w in f["words"] if w["confidence"] < 0.6]
return FunctionResult(f"Unsure of: {unsure}")
agent.define_tool("check_name", "Check the spelled name",
{"type": "object", "properties": {}}, check_name)
agent.serve()