prefactor-livekit
prefactor-livekit
Section titled “prefactor-livekit”LiveKit Agents integration for Prefactor observability. This package wraps
livekit-agents sessions and emits Prefactor spans from public LiveKit session
events.
Installation
Section titled “Installation”pip install prefactor-livekitFactory pattern
Section titled “Factory pattern”from livekit.agents import AgentSessionfrom prefactor_livekit import PrefactorLiveKitSession
session = AgentSession(...)
tracer = PrefactorLiveKitSession.from_config( api_url="https://api.prefactor.ai", api_token="your-api-token", agent_id="voice-agent", agent_name="Voice Agent",)
await tracer.start(session=session, agent=my_agent)await tracer.close()Example repo
Section titled “Example repo”This example contains a LiveKit web search agent using Exa search that has been instrumented with prefactor.
prefactordev/livekit-agent.
Example runner
Section titled “Example runner”The example script has a local smoke mode that emits representative LiveKit session events into Prefactor without needing STT/TTS providers or a room.
uv run python packages/livekit/examples/simple_session.py --mode smokeIt prints the Prefactor instance ID plus ready-to-run Prefactor CLI commands for retrieving the instance and listing spans for the example’s time window.
prefactor agent_instances retrieve <instance-id>prefactor agent_spans list \ --agent_instance_id <instance-id> \ --start_time <recent-start-time> \ --end_time <recent-end-time> \ --include_summariesThere is also a model-backed mode for a real text turn:
uv run python packages/livekit/examples/simple_session.py \ --mode live \ --model anthropic/claude-sonnet-4-5-20250929Manual attachment
Section titled “Manual attachment”Use this when your app manages the session lifecycle itself and you just want the LiveKit events traced.
from prefactor_livekit import PrefactorLiveKitSession
tracer = PrefactorLiveKitSession(instance=instance)await tracer.attach(session)
await session.generate_reply(user_input="hello")
await tracer.close()Traced span types
Section titled “Traced span types”livekit:sessionlivekit:user_turnlivekit:assistant_turnlivekit:toollivekit:llmlivekit:sttlivekit:ttslivekit:statelivekit:error
Development
Section titled “Development”uv run pytest packages/livekit/tests -v