import asyncio
from smallestai.voice import VoiceAgent
from tealtiger import TealEngine, PolicyMode
from tealtiger.cost import CostTracker, get_model_pricing
# Initialize governance engine
engine = TealEngine(
policies=[
{"type": "pii_block", "categories": ["ssn", "credit_card", "phone", "email", "iban"]},
{"type": "secret_detection"},
{"type": "cost_limit", "max_per_session": 2.00},
{"type": "tool_allowlist", "allowed": ["lookup_account", "transfer_*", "schedule_*"]},
{"type": "rate_limit", "max_calls": 20, "window": "5m"},
],
mode=PolicyMode.ENFORCE,
agent_id="voice-support-agent",
)
cost_tracker = CostTracker()
async def governed_on_transcript(text: str) -> str:
"""Governance hook after STT, before LLM."""
decision = engine.evaluate(content=text)
if decision.action == "DENY":
# Log the violation for compliance
print(f"[GOVERNANCE] Blocked: {decision.reason_codes}")
# Redact PII and continue (don't disconnect the caller)
return engine.redact(text)
return text
async def governed_before_tts(response: str) -> str:
"""Governance hook after LLM, before TTS."""
decision = engine.evaluate(content=response)
if decision.action == "DENY":
return engine.redact(response)
return response
# Create governed voice agent
agent = VoiceAgent(
api_key="your-smallest-api-key",
on_transcript=governed_on_transcript,
before_tts=governed_before_tts,
)
asyncio.run(agent.start())