how to prevent agent saying instruction multiple t...
# ask-ai
a
how to prevent agent saying instruction multiple times during function call?
t
Thanks for reaching out, affandy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help avoid an agent repeating instructions during a function call, you can disable interruptions for the whole duration using the
RunContext
that’s available to tool functions. This way, the agent can finish its current message without getting interrupted. Here’s a quick example:
Copy code
@function_tool()
async def example_tool(self, ctx: RunContext):
    # Disable interruptions for this function call
    ctx.disallow_interruptions()

    # Perform logic that generates speech
    await self.session.say("This is an important instruction that should not be repeated.")
Also, if you want to prevent interruptions more broadly, you can set
allow_interruptions=False
in the agent’s configuration, which stops interruptions unless you specifically allow them. Feel free to reach out if you want a hand setting this up or have any other questions! Sources: basics/uninterruptable.py | livekit-agents/livekit/agents/voice/agent.py
a
but the issue didn't came from interruption. even when the mic is muted, the agent will repeat what it already said
t
Thanks so much for clarifying! To help get to the bottom of this, could you please confirm a few things for me? • Is the agent set up to use real-time conversation, push-to-talk, or full-duplex mode? • Does the repetition happen after a certain action, like a function call or a user command? • Are there any custom settings or scripts that might be controlling how the agent behaves? Knowing this will really help us pinpoint the issue and find the best solution for you. Sources: examples/voice_agents/push_to_talk.py | SIP troubleshooting guide | LiveKit Docs | basics/interrupts_user.py
a
for realtime conversation. the repetition happen after every function call executed. it was supposed to say only the function output, without carrying the previous instruction
t
Hey there! To help prevent the agent from repeating previous instructions after a function call during a real-time conversation, here are a few friendly tips you can try: 1. Avoid Repeating Instructions: Make sure the agent’s tool response is set with
tool_choice="none"
right after the function runs. This way, the agent won’t circle back to those earlier instructions. 2. Control Reply Generation: You can use the
reply_required
flag in the function tool’s output to keep things quiet when no verbal response is needed. Just set
generate_tool_reply=False
if you want to skip the reply. 3. Manage Chat Context: Try not to keep adding the same instructions into the conversation context (
chat_ctx
) during or after the tool runs. Only update the instructions when it’s really necessary. 4. Preserve Context Integrity: If you’re switching tasks or agents, make sure to pass along the full
chat_ctx
so the conversation flows smoothly without repeating old instructions. Give these a shot, and they should help clear things up! If you want a hand setting any of this up, just let me know—I’m here to help. Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime... | Workflows | LiveKit Docs