m
hi
t
Thanks for reaching out, Rahib. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you out! Could you please share a bit more about your question or the issue you're experiencing? That way, I can make sure to assist you in the best possible way.
m
How do i integrate langfuse for evals and tracing. Such that it runs in parallel and dosent cause latency on the agents main workflow
t
I'm glad you're interested in integrating Langfuse for evaluations and tracing in LiveKit! To make sure this doesn’t add any latency to your main workflow, you can take advantage of LiveKit's OpenTelemetry integration. This setup traces agent workflows and sends data to Langfuse asynchronously, so your system keeps running smoothly. Here’s a friendly guide to get you started: 1. Set Up Langfuse Tracer Provider: Begin by using the
setup_langfuse()
function. It configures the OpenTelemetry tracer with Langfuse, initializing a
TracerProvider
with a
BatchSpanProcessor
that batches and exports spans asynchronously—helping keep things efficient. 2. Initialize Tracing in the Agent Entrypoint: Just call
setup_langfuse()
right at the start of your agent’s entrypoint function. This way, all agent activities are traced from the get-go. 3. Ensure Asynchronous Export: Thanks to the
BatchSpanProcessor
, spans are exported in the background, so your real-time operations won’t be blocked. You can also register a shutdown callback to make sure all traces are flushed when the agent exits. Langfuse will capture traces for important agent activities like session starts, agent turns, LLM and TTS node executions, and more. These insights are really helpful for evaluations and performance analysis. If you’d like to see everything in action, feel free to check out the LangFuse trace example in the LiveKit Agents GitHub repository. It’s a great resource to guide you through the process. Sources: Agent Testing & Evaluation | livekit/livekit_composite | DeepWiki | examples/voice_agents/README.md | Docs::Agents
I'd be happy to help you log MCP server responses in LiveKit! Depending on your setup, here are some approaches you can try: 1. Agent-Level Logging (Python): You can use the
logging
module to capture important lifecycle events like tool invocation and response results. Here's how you can configure logging:
Copy code
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("mcp-agent-tools")
This will help you track logs such as tool invocation, connection status, and any errors that come up. 1. RPC-Level Logging (Go): You might want to enable logging interceptors like
WithClientLogger
or
WithServerLogger
. These will log all client and server RPC calls, including requests and responses, along with structured metadata. 2. JavaScript SDK Logging: Using
setLogExtension
is a great way to capture and redirect logs, including MCP responses or other API interactions. Here's a quick example:
Copy code
setLogExtension((level, msg, context) => {
  console.log(level, msg, { ...context, timestamp: Date.now() });
});
For a complete working example, you can check out the basic-mcp GitHub repository. If you have any questions or need further help, please don’t hesitate to reach out—I’m here for you! Sources: examples/voice_agents/mcp/mcp-agent.py | Logs, metrics, and telemetry | LiveKit Docs | livekit/livekit_agent_dispatch.twirp.go | How to Send Logs from the JavaScript SDK to Providers like Datadog | plugins/google/src/beta/realtime/realtime_api.ts