Learn how to integrate Maxim observability with LiveKit agents for real-time voice AI applications with comprehensive tracing and monitoring.
.env
file:
MAXIM_API_KEY
MAXIM_LOG_REPO_ID
OPENAI_API_KEY
environment variableinstrument_livekit
: This function integrates Maxim’s observability features with LiveKit Agents . It allows you to automatically capture and send trace data to the platform:
logger = Maxim().logger()
: This creates a Maxim logger instance that:
MAXIM_API_KEY
and MAXIM_LOG_REPO_ID
environment variableson_event
: This is a callback function that gets triggered during trace lifecycle events:
event
: A string indicating what happened ("maxim.trace.started"
or "maxim.trace.ended"
)data
: A dictionary containing trace information:
trace_id
: Unique identifier for the tracetrace
: The actual trace object with metadata, timing, and other detailsAgent
: Base class for all LiveKit agentsinstructions
: System prompt that defines the agent’s personality and capabilities@function_tool()
: Decorator that registers this method as a tool the agent can callasync def
: Asynchronous function (required for LiveKit agents)query: str -> str
helps the AI understand input/output typesctx: agents.JobContext
: Contains information about the current job/sessionLIVEKIT_ROOM_NAME
assistant-room-a1b2c3d4e5f6...
uuid.uuid4().hex
: Creates a random hexadecimal stringsession.start()
: Connects the agent to the roomagent=Assistant()
: Uses your custom Assistant classctx.connect()
: Connects to the LiveKit infrastructuregenerate_reply()
: Makes the agent speak first with a greetingMAXIM_API_KEY
and MAXIM_LOG_REPO_ID
are set correctly