how do i update agent userdata after the session i...
# ask-ai
j
how do i update agent userdata after the session is connected?
t
Thanks for reaching out, Tyler. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To update agent userdata after a session is connected, you can access the
userdata
property of the session or context object. Here are two examples: 1. Using function tools, you can update userdata via the context parameter:
Copy code
@function_tool()
async def confirm_expense(
    self,
    expense: Annotated[float, Field(description="The expense of the order")],
    context: RunContext_T,
) -> str:
    """Called when the user confirms the expense."""
    userdata = context.userdata
    userdata.expense = expense
    return f"The expense is confirmed to be {expense}"
2. When transferring between agents, you can pass and update userdata:
Copy code
@function_tool
async def information_gathered(
    self,
    context: RunContext[StoryData],
    name: str,
    location: str,
):
    context.userdata.name = name
    context.userdata.location = location

    story_agent = StoryAgent(name, location)
    return story_agent, "Let's start the story!"
The
userdata
is available as
session.userdata
and is also accessible within function tools on the
RunContext
. Let me know if you need further clarification! Sources: Tree View: | dse-workbench | Workflows | LiveKit Docs