Skip to content

update_instructions() not reflected in tool call response generation #4242

@shivamkataria2000

Description

@shivamkataria2000

Bug Description

When calling update_instructions() inside a tool function, the subsequent reply generated for the tool result does not reflect the updated instructions.

However, if I call generate_reply() manually inside the tool and return None, the new instructions are correctly applied.

Minimal Reproduction

from livekit.agents import Agent, RunContext

agent = Agent(instructions="You are a helpful assistant. Always respond in English.")

@agent.tool()
async def switch_language(ctx: RunContext, language: str) -> str:
    """Switch the response language."""
    new_instructions = f"You are a helpful assistant. Always respond in {language}."

    await ctx.session.current_agent.update_instructions(new_instructions)

    # This reply still uses OLD instructions (English)
    return f"Switched to {language}"

Workaround

@agent.tool()
async def switch_language(ctx: RunContext, language: str) -> None:
    """Switch the response language."""
    new_instructions = f"You are a helpful assistant. Always respond in {language}."

    await ctx.session.current_agent.update_instructions(new_instructions)

    # Force regeneration - this uses NEW instructions
    await ctx.session.generate_reply()
    return None

Expected Behavior

When update_instructions() is called inside a tool, the reply generated for that tool's result should use the new instructions.

Actual Behavior

The reply generated for the tool result uses the old instructions that were active before update_instructions() was called.

Environment

  • livekit-agents version: 1.2.16
  • Python version: 3.13.3

Models Used

OpenAI GPT-4.1

Package Versions

- livekit-agents version: 1.2.16
  - Python version: 3.13.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions