Voice Agent API — recommended
# Voice Agent API: financial services account inquiry agent
import asyncio, json, websockets
API_KEY = "YOUR_API_KEY"
async def run_agent():
async with websockets.connect(
"wss://agents.assemblyai.com/v1/ws",
additional_headers={"Authorization": f"Bearer {API_KEY}"},
) as ws:
await ws.send(json.dumps({
"type": "session.update",
"session": {
"system_prompt": (
"You are an account services agent for First National Bank. "
"Verify caller identity before discussing account details. "
"Never read full account or card numbers aloud."
),
"greeting": "Hi, this is First National — how can I help today?",
"input": {"keyterms": ["First National", "rewards checking",
"premium savings", "Reg E", "provisional credit"]},
"output": {"voice": "ivy"},
},
}))
# Stream audio in, get audio + transcript back
async for msg in ws:
handle(json.loads(msg)) # transcript.user, reply.audio, tool.call, ...
Universal-3.5 Pro Realtime + LiveKit — BYO stack
# LiveKit + AssemblyAI STT in a financial services agent pipeline
from livekit.agents import Agent, AgentSession, TurnHandlingOptions
from livekit.plugins import assemblyai, cartesia, openai, silero
class FinancialAgent(Agent):
def __init__(self):
super().__init__(
instructions=(
"You are an account services agent for First National Bank. "
"Verify identity before disclosing account information. Be concise."
),
)
async def entrypoint(ctx):
session = AgentSession(
stt=assemblyai.STT(
model="u3-rt-pro",
min_turn_silence=100,
max_turn_silence=3000, # callers pause to look up accounts / read numbers
vad_threshold=0.3,
keyterms_prompt=["First National", "rewards checking",
"premium savings", "Reg E", "provisional credit"],
),
llm=openai.LLM(model="gpt-4o"),
tts=cartesia.TTS(),
vad=silero.VAD.load(activation_threshold=0.3),
turn_handling=TurnHandlingOptions(
turn_detection="stt",
endpointing={"min_delay": 0}, # avoid additive latency in STT-driven turns
),
)
await session.start(room=ctx.room, agent=FinancialAgent())