microscopic-dress-75199
10/01/2025, 1:28 PMtall-airline-16756
10/01/2025, 1:28 PMmicroscopic-dress-75199
10/01/2025, 1:28 PMtall-airline-16756
10/01/2025, 1:29 PMupdate_instruction()?
Any extra details you can provide will really help me guide you in the right direction.microscopic-dress-75199
10/01/2025, 1:32 PMtall-airline-16756
10/01/2025, 1:33 PMsession.update_instructions(new_instructions_string) method. It kicks in right away for the next LLM call, so your following interactions will use the fresh instructions.
Here’s a simple way to fit it into your workflow:
• Just call session.update_instructions() inside your transition_to_phase() method, right after you update the phase state. This way, the instructions refresh as soon as the phase changes.
• No need to stress about ongoing requests — the update will take effect for the very next LLM interaction.
• You usually don’t have to call it in on_user_turn_completed() unless you have some special logic tied to processing user input.
Here’s an example of what your updated transition_to_phase method might look like:
def transition_to_phase(self, new_phase: str) -> None:
state = self.get_state()
old_phase = state.current_phase
state.transition_to_phase(new_phase)
logger.info(f"Phase transition: {old_phase} -> {new_phase}")
# Update instructions dynamically
new_instructions = self.generate_instructions_for_phase(new_phase)
self.session.update_instructions(new_instructions)
By doing this, you’ll make sure your agent’s behavior stays perfectly in sync with the current phase of the conversation. If you have any questions or want to chat more about it, I’m here to help!
Sources: plugins/google/src/beta/realtime/realtime_api.ts | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...microscopic-dress-75199
10/01/2025, 2:35 PMtall-airline-16756
10/01/2025, 2:36 PMsession.update_instructions() is an asynchronous method and needs to be awaited. If it’s not awaited, Python will give you a runtime warning about an unawaited coroutine.
To help you fix this, you can update your code like this:
async def transition_to_phase(self, new_phase: str) -> None:
state = self.get_state()
old_phase = state.current_phase
state.transition_to_phase(new_phase)
logger.info(f"Phase transition: {old_phase} -> {new_phase}")
# Update instructions dynamically
new_instructions = self.generate_instructions_for_phase(new_phase)
await self.session.update_instructions(new_instructions)
By adding await, you make sure the instructions update completes properly before moving on. If you have any more questions or want me to walk you through this, just let me know — I’m here to help!
Sources: docs/index.yaml | OpenAI TTS integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | plugins/openai/src/realtime/realtime_model.ts | Gemini Live API integration guide | LiveKit Docsmicroscopic-dress-75199
10/01/2025, 3:48 PMtall-airline-16756
10/01/2025, 3:49 PMsession.userdata attribute isn’t automatically included in Langfuse tracing because the telemetry system doesn’t expose custom session state like userdata in OpenTelemetry spans by default. But don’t worry, you can make it visible by explicitly including it during your tracer setup.
Here are two friendly ways to do this:
1. Pass userdata via metadata in `setup_langfuse`:
trace_provider = setup_langfuse(
metadata={
"user_name": session.userdata.user_name, # assuming userdata has this field
"age": session.userdata.age,
}
)
2. Use a Custom SpanProcessor to Dynamically Add `userdata`:
from opentelemetry.sdk.trace import SpanProcessor
class UserDataSpanProcessor(SpanProcessor):
def __init__(self, session):
self.session = session
def on_start(self, span, parent_context):
userdata = self.session.userdata
if hasattr(userdata, "user_name"):
span.set_attribute("user_name", userdata.user_name)
if hasattr(userdata, "age"):
span.set_attribute("age", userdata.age)
def on_end(self, span):
pass
# Apply the custom processor
trace_provider.add_span_processor(UserDataSpanProcessor(session))
Both of these methods will help you include userdata in your Langfuse traces smoothly. If you have any questions or need a hand with this, just let me know—I’m here to help!
Sources: Workflows | LiveKit Docs | Docs::Agents | examples/voice_agents/README.md | Setting custom user_id and session_id in Langfuse traces | docs/index.yamlmicroscopic-dress-75199
10/01/2025, 4:11 PM# Start the session
await session.start(
agent=agent,
room=ctx.room,
room_input_options=room_input_options,
)
# Setup Langfuse tracing with metadata
setup_langfuse(
metadata={
"room_name": ctx.room.name,
"userdata": session.userdata,
"company_config": "cloudmetrics",
}
)
?
Affter session start?tall-airline-16756
10/01/2025, 4:12 PMsetup_langfuse function should be called before session.start() in LiveKit. This helps make sure your telemetry is set up correctly and that important session-level spans like "Session start" are captured in your tracing data.
If you want to include session.userdata in the metadata, you can simply extract its values and pass them to setup_langfuse before starting the session. Here's a little example to guide you:
async def entrypoint(ctx: JobContext):
# Initialize custom userdata
userdata = MyUserDataClass(first_name="Alice", user_id="12345")
# Create session with userdata
session = AgentSession(userdata=userdata)
# Pass userdata fields into Langfuse metadata before starting session
trace_provider = setup_langfuse(
metadata={
"user_id": userdata.user_id,
"customer_name": userdata.first_name,
"session_initiator": ctx.room.name
}
)
await session.start(agent=MyAgent(), room=ctx.room)
This way, your userdata is nicely included in the tracing metadata, and your telemetry gets properly initialized. If anything’s unclear or you’d like me to walk you through it further, just let me know—I’m here to help!
Sources: Workflows | LiveKit Docs | complex-agents/note-taking-assistant/agent.py | Setting custom user_id and session_id in Langfuse traces | livekit-agents/livekit/agents/voice/agent_session.py | Docs::Agents