Vion / backend /scripts /agent_inspect.py
MonicaCarter's picture
Vion training simulator — deployable
22fa5af
Raw History Blame Contribute Delete
2.7 kB
"""Create one real agent with our exact config, read it back, and print the
latency-relevant fields — then delete it. Verifies whether turn_timeout, the
TTS model, and the custom-LLM model actually landed (vs. being silently ignored
and falling back to ElevenLabs defaults like the 7s turn timeout).
Run (from backend/): python -m scripts.agent_inspect
"""
from __future__ import annotations
import asyncio
import json
import httpx
from dotenv import load_dotenv
load_dotenv(override=True) # .env wins over any stale shell var
from app.config import get_settings # noqa: E402
from app.services import elevenlabs_client as E # noqa: E402
async def main() -> None:
settings = get_settings()
if not (settings.voice_configured and settings.llm_configured):
print("Need both ELEVENLABS_API_KEY and OPENROUTER_API_KEY in .env.")
return
print(f"Sending turn_timeout={settings.TURN_TIMEOUT}, "
f"tts={settings.TTS_MODEL_ID}\n")
agent_id = await E.create_session_agent(
name="vion-inspect-temp",
system_prompt="You are a person on a phone call. Reply briefly.",
voice_id=E.resolve_voice_id("P1"),
)
print(f"Created agent {agent_id}; reading it back...\n")
url = f"{settings.ELEVENLABS_BASE_URL.rstrip('/')}/v1/convai/agents/{agent_id}"
headers = {"xi-api-key": settings.ELEVENLABS_API_KEY}
try:
async with httpx.AsyncClient(timeout=30) as client:
resp = await client.get(url, headers=headers)
cfg = resp.json().get("conversation_config", {})
turn = cfg.get("turn", {})
tts = cfg.get("tts", {})
prompt = cfg.get("agent", {}).get("prompt", {})
print("--- What ElevenLabs actually stored ---")
print("turn:", json.dumps(turn))
print("tts.model_id:", tts.get("model_id"))
print("prompt.llm:", prompt.get("llm"))
print("custom_llm.model_id:", prompt.get("custom_llm", {}).get("model_id"))
print("prompt.max_tokens:", prompt.get("max_tokens"))
print()
stored = turn.get("turn_timeout")
if stored == settings.TURN_TIMEOUT:
print(f"OK: turn_timeout={stored} applied. The 10s is NOT the turn "
f"setting — chase the LLM (run latency_probe / dashboard).")
else:
print(f"PROBLEM: we sent {settings.TURN_TIMEOUT} but ElevenLabs has "
f"{stored!r}. The field nesting is wrong and it's defaulting. "
f"Paste this output back and I'll fix the structure.")
finally:
await E.delete_agent(agent_id)
print(f"\nDeleted temp agent {agent_id}.")
if __name__ == "__main__":
asyncio.run(main())