For my use case, I will need the agent to have a d...
# ask-ai
a
For my use case, I will need the agent to have a different script and different context for each call. I use AWS lambdas for my backend, so the idea is to deploy a new agent with the specific script and context each time I need to start a call. I create the agent using lk CLI in order for it to be deployed on the same network and infrastructure that serves LiveKit Cloud. Is there a better way to do that? For example should I have one deployed agent and pass it different script and context before a call? multiple calls can happen in parallel so how do I ensure the agent has the right info for a specific call
t
Thanks for reaching out, Anne. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Are you looking for a solution that dynamically updates a single deployed agent with different scripts and contexts for each call, or do you prefer deploying separate agents for each call? Additionally, how critical is it for you to manage these agents directly through AWS Lambda and the lk CLI? Sources: examples/voice_agents/multi_agent.py | complex-agents/medical_office_triage/triage.py
a
I think I looking for a solution that dynamically updates a single deployed agent with different scripts and contexts for each call
t
1. Dynamic Instructions Update: • Hey there! Want to tweak your agent's instructions on the fly? The
update_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:
Copy code
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.py
a
is there a way to have a generic agent, and when user joins the room from the front-end, we infuse more context, give better instructions to the agent?
t
1. Context Variables in Agent Constructor: • Hey there! Let me show you a cool way to create a flexible agent that can adapt to different contexts. Imagine you want an agent that feels personal and tailored to each user:
Copy code
class 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:
Copy code
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:
Copy code
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:
Copy code
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