acceptable-dream-85180
07/29/2025, 12:37 AMtall-airline-16756
07/29/2025, 12:37 AMtall-airline-16756
07/29/2025, 12:38 AMacceptable-dream-85180
07/29/2025, 12:42 AMtall-airline-16756
07/29/2025, 12:43 AMupdate_instructions() method is your new best friend. It works like magic whether your agent is chilling or right in the middle of a conversation.
2. Dynamic Tools Update:
• Got some tools you want to swap in and out? No problem! You can create tools right when you're setting up your agent.
• The update_tools() method lets you mix up the agent's toolkit whenever you want.
• Pro tip: You can even add temporary tools for specific calls by playing around with the llm_node method.
3. Dynamic Chat Context Update:
• Need to change the conversation's vibe mid-chat? update_chat_ctx() has got your back and updates everything automatically.
4. Context Variables in Instructions:
• Want to make your agent feel more personal? Try adding context variables to the instructions. Check out this cool example:
instructions = "You are a helpful agent. The user's name is {name}."
agent = ContextAgent(context_vars={"name": "Shayne"})
5. Runtime Context Injection:
• Feel like adding some extra context during the conversation? You can totally do that by tweaking the chat context in your custom agent methods.
These awesome techniques let you keep a single deployed agent that's super flexible – adapting its personality, tools, and context for each unique interaction. Sounds cool, right? If you want to dive deeper into any of these approaches, just give me a shout!
Sources: examples/voice_agents/llamaindex-rag/retrieval.py | basics/context_variables.pyacceptable-dream-85180
07/29/2025, 1:26 AMtall-airline-16756
07/29/2025, 1:27 AMclass ContextAgent(Agent):
def __init__(self, context_vars=None):
instructions = "You are a helpful agent. The user's name is {name}."
if context_vars:
instructions = instructions.format(**context_vars)
super().__init__(instructions=instructions, ...)
2. Dynamic Instructions Based on Participant Information:
• Check out this neat trick for changing the agent's instructions on the fly:
async def on_enter(self):
if self.session.participant.name.startswith("sip"):
await self.update_instructions("You are a helpful agent speaking on the phone.")
3. Using Job Metadata for Context:
• Another awesome way to add some personal touch to your agent!
4. Using UserData and RunContext:
• Store those special session details and make each interaction unique.
5. Chat Context with Dynamic Content:
• This is where the magic happens - giving your agent some extra context:
chat_ctx = llm.ChatContext()
chat_ctx.append(
text="Context about the user: you are talking to a software engineer. Greet the user with a friendly greeting.",
role="assistant",
)
6. Basic Pattern for Waiting and Starting:
• Here's a smooth way to kick things off when a participant joins:
participant = await ctx.wait_for_participant()
agent = VoicePipelineAgent(chat_ctx=initial_ctx)
agent.start(ctx.room, participant)
These approaches are like having a Swiss Army knife for your agents - super flexible and ready to adapt! Each method lets you create a more personalized, context-aware experience. Want to dive deeper into any of these? I'm totally here to help you explore!
Sources: Recording agent sessions | LiveKit Docs | basics/change_agent_instructions.py | Making calls using SIP | LiveKit Docs | examples/avatar_agents/tavus/agent_worker.py | agent.py