how to update system instructions inside tool call...
# ask-ai
d
how to update system instructions inside tool call and apply immediately before returning the tool call response so voice agent uses the instructions
t
Thanks for reaching out, Shivam. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to update system instructions inside a tool call and have the voice agent use them immediately before returning the tool call response. You can do this by calling
update_instructions
on the session's AgentActivity inside the tool — it updates the LLM system prompt at runtime and takes effect for subsequent responses in the same session. Example (Python):
Copy code
@function_tool()
async def update_agent_instructions(context: RunContext, new_instructions: str):
    # update instructions immediately
    await context.session.update_instructions(new_instructions)

    # the agent will use these instructions for its next response
    return f"Updated instructions to: {new_instructions}"
If you want the voice agent to apply the instructions for the very next generation during the same tool flow, call
await context.session.update_instructions(...)
before triggering that next LLM/voice response. Would you like a version for another language or an example showing a tool call that updates instructions then immediately generates speech output? Sources: Agents (Python) | livekit/livekit_composite | DeepWiki