Is it possible top use agent.update_tools and pass...
# ask-ai
b
Is it possible top use agent.update_tools and pass the agent as a parameter to the tool so it can use it?
t
Thanks for reaching out, Håvard. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Based on the available information, it is not explicitly mentioned that you can pass the agent itself as a parameter to a tool when using
agent.update_tools()
. However, tools can access the current session, agent, and state through a special
context
argument of type
RunContext
, which provides access to the current session, function call, speech handle, and userdata. If you need further clarification or have a specific use case in mind, feel free to share more details! Sources: Tool definition and use | LiveKit Docs
b
How do you access the agent?
t
You can access the agent in LiveKit through the
JobContext
class using the
agent
accessor property. This property returns the agent's participant if connected to the room, or
undefined
if not connected. Here is an example:
Copy code
// Accessing the agent property from a JobContext instance
const agentParticipant = jobContext.agent;
Sources: JobContext | LiveKit Agents
b
Is it possible to change variables that are set in the current_agent through RunContext?
t
Yes, it is possible to change variables in the current agent through
RunContext
by accessing the
userdata
property. Here is an example:
Copy code
@function_tool()
async def update_name(
    name: Annotated[str, Field(description="The customer's name")],
    context: RunContext_T,
) -> str:
    """Called when the user provides their name.
    Confirm the spelling with the user before calling the function."""
    userdata = context.userdata
    userdata.customer_name = name
    return f"The name is updated to {name}"
In this example, the
userdata
is accessed through
context.userdata
, and the desired property (e.g.,
customer_name
) is modified directly. Sources: Tree View: | dse-workbench
b
I get this error 'ValueError: VoiceAgent userdata is not set'. I am using Livekit 1.0
t
The error
ValueError: VoiceAgent userdata is not set
occurs when you try to access the
userdata
property of a
VoiceAgent
instance without setting it first. To resolve this, you need to ensure that the
userdata
is set before accessing it. You can do this in one of two ways: 1. Pass the
userdata
parameter when initializing the `VoiceAgent`:
Copy code
agent = VoiceAgent(userdata=your_data)
1. Set it after initialization using the setter:
Copy code
agent = VoiceAgent()
agent.userdata = your_data
Ensure that
your_data
is properly defined before assigning it to avoid this error. Sources: livekit.agents API documentation