Hi folks, there's been a common issue for us, in w...
# agents
b
Hi folks, there's been a common issue for us, in which the agents executes the same tool call multiple times, usually because it interrupted the user while it was talking (maybe during a short silence). So the agent ends up doing something like answering two times or repeating itself or just creating a weird user experience. Is there a fix for this, something like a lock for tools executions (specially after false interruptions)?
g
+1
p
No. There isnt a built in lock. I ended up disabling audio when the tool starts executing and enabling it hence finished. I’m using python, so I created a decorator for it.
The user can keep talking, but the agent will ignore it. It won’t even make it to the chat context
This workaround is the only one that can guarantee the function won’t be called multiple times in a row. As an alternative, I tried adding a lock per function tool (instance variable, active/inactive), but the agent would still call it and acknowledge whatever instruction you added to your function tool (ie. docstring)
b
Hmm, I'm worried that would create a bad user experience specially for tools that take a bit to execute. It might give the impression that the agent is arbitrarily ignoring the user. I would also imagine race conditions are still possible if another tool invocation is done before it reaches the silencing part. Though it might be worth to try it out if there's no better alternative. What I was hoping for was more of a lock when the text in the stream response of the llm was recognized to be a function tool (e.g., the chat chunk in the google plugin) right away. So that any future stream or chunk (say for the same function name), would be, in some sense, discarded until the lock is released. @refined-appointment-81829 do you think something like this could make sense?
p
Yeah, that makes sense. If your requirements allow, "ignoring" the user input while the function is executing would be similar to a real world example, where the assistant asks the user to hold on for a moment and put on a background sound. The user might say whatever they want, but the assistant wouldn't necessarily react right away. They usually tell the user to wait for a moment (again) while the operation is still happening. Then, once they finish doing whatever they were doing, they resume the conversation with the user (if necessary). Adding either a background sound while the function is executing or a loop-speech where the agent asks to wait a bit, might make it more friendly - this is what I'm going to try next btw.
b
Yes. Agreed. I might try the chunk recognition lock first (maybe a monkeypatch) to try to get a general solution. If it doesn't work that well, ignoring the user while purposefully teling them might be the way to go
p
Let me know how it goes - I'm interested in your approach as well
👌 1
btw, disabling/enabling the audio was not enough, as the agent queue function calls if the user keep speaking BEFORE the function tool enters (ie. when the audio gets disabled). I ended up adding a simple lock mechanism to ensure the function can't be executed concurrently.
👀 1
Untitled.py
b
I haven't got around to try the chunk recognition lock yet. Though I use a similar-ish solution with a wrapper for introducing behaviours (like a lock) to the tool function. I did a factory for it. Though I had to copy the livekit attributes for it to work (not super elegant 😂). Here it is:
Untitled.cpp