witty-kangaroo-6889
10/22/2025, 1:00 AMtall-airline-16756
10/22/2025, 1:00 AMtall-airline-16756
10/22/2025, 1:02 AMprewarm function to load shared resources (like models or plugins) and save them in proc.userdata.
• Use the num_idle_processes parameter to decide how many warmed-up processes you want available.
• If your environment is more complex, you can load resources specific to each agent or shared ones for different agent types.
• You can also adjust the target number of idle processes on the fly with set_target_idle_processes, depending on how your workload changes.
If you’d like more detailed guidance or some examples tailored to your setup, just let me know—I’m here to help!
Sources: External data and RAG | LiveKit Docs | main.py | Worker options | LiveKit Docs | examples/README.md | agents/src/generator.tswitty-kangaroo-6889
10/22/2025, 1:03 AMtall-airline-16756
10/22/2025, 1:04 AMchat_ctx parameter during initialization. Here's a simple example:
agent = Agent(
instructions="You are a helpful assistant.",
llm=openai.realtime.RealtimeModel(voice="alloy"),
# No chat_ctx parameter needed - will start fresh
)
If you have any questions or want me to walk you through more examples that fit your needs, please don’t hesitate to ask—I’m here to help!
Sources: Workflows | LiveKit Docs | examples/voice_agents/realtime_load_chat_history.py | agents/src/voice/agent_session.tswitty-kangaroo-6889
10/22/2025, 1:04 AMtall-airline-16756
10/22/2025, 1:06 AM# Copy the previous agent's chat context
truncated_chat_ctx = previous_agent.chat_ctx.copy(
exclude_instructions=True,
exclude_function_call=False
).truncate(max_items=6)
# Pass the copied context to the new agent
new_agent = Agent(
instructions="You are a helpful assistant.",
llm=openai.realtime.RealtimeModel(voice="alloy"),
chat_ctx=truncated_chat_ctx
)
Key Points:
• You can use chat_ctx.copy() to make a duplicate of the context from the previous agent.
• It's a good idea to truncate the context to keep only the most relevant messages, like the last 6.
• Then, just pass this truncated context when you initialize the new agent.
If you’d like, I’m here to help with more examples or to assist you with your specific situation—just let me know!witty-kangaroo-6889
10/22/2025, 1:19 AMtall-airline-16756
10/22/2025, 1:21 AMupdate_chat_ctx() method. This is a handy way to update the agent's chat context dynamically, even if the agent is already up and running.
Example:
# Update the chat context of an already initialized agent
await agent.update_chat_ctx(
chat_ctx, # The new or updated chat context
exclude_invalid_function_calls=True # Optional: Removes invalid function calls
)
Key Points:
• It’s a good idea to use chat_ctx.copy() to safely duplicate and tweak the context before updating.
• For realtime models, this method helps keep the updated context in sync with the ongoing session.
• Wrapping this method in a try-catch block is wise to gracefully handle any potential errors, especially with realtime models.
If you have any questions or would like some tailored examples for your specific use case, please don’t hesitate to ask—I’m here to help!
Sources: agent/main.py | examples/warm-transfer/warm_transfer.py | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Agents v0.x migration guide - Python | LiveKit Docswitty-kangaroo-6889
10/22/2025, 1:24 AMtall-airline-16756
10/22/2025, 1:24 AMon_enter() method in LiveKit agents is called when control is handed over to the agent, rather than during its initialization. This means it kicks in when the agent becomes the active participant in a session.
People often use this method to do things like create warm greetings or set up the conversation context as the agent steps in. If you'd like, I’m here to help with more details or examples—just let me know!
Sources: Pipeline nodes and hooks | LiveKit Docs | livekit-agents/livekit/agents/job.pywitty-kangaroo-6889
10/22/2025, 1:25 AMtall-airline-16756
10/22/2025, 1:27 AMprewarm method to help you initialize all agents in a multi-agent system smoothly:
def prewarm(proc: JobProcess):
# Load shared resources for all agents
proc.userdata["vad"] = silero.VAD.load()
proc.userdata["shared_llm"] = openai.LLM(model="gpt-4o-mini")
proc.userdata["stt"] = deepgram.STT(model="nova-3")
proc.userdata["tts"] = openai.TTS(voice="echo")
async def entrypoint(ctx: JobContext):
# Access prewarmed resources
session = AgentSession(
vad=ctx.proc.userdata["vad"],
llm=ctx.proc.userdata["shared_llm"],
stt=ctx.proc.userdata["stt"],
tts=ctx.proc.userdata["tts"],
)
# Start with one agent and allow handoff to others
await session.start(agent=IntroAgent(), room=ctx.room)
Key Points:
• Shared resources like VAD, LLM, STT, and TTS are loaded just once in the prewarm function to keep things efficient.
• These resources are safely stored in proc.userdata, so all agents can easily access them during their sessions.
• AgentSession helps you manage multiple agents smoothly and supports handoffs between them.
If you’d like, I’m here to help craft a more tailored example that fits your specific needs—just let me know!
Sources: main.py | agent/main.py | Template System & Example Applications | livekit/livekit_composite | DeepWi... | agent-examples/agent_examples/pipeline_agent.py | Worker options | LiveKit Docs