*`generate_reply` is not always following instruct...
# agents
t
generate_reply
is not always following instructions
Hi team, I'm noticing some unstable behavior regarding the use of
generate_reply
in our LiveKit stack (
1.2.8
). Example: I built a
forward_call
function, designed to let the caller be forwarded to a human agent when necessary. Before making the actuel SIP transfer, I want to warn the caller that the transfer is in progress. That seems the perfect usecase to use
generate_reply
. However, recently I noticed that even though a reply was generated, it didn't follow the instructions at all. Usually it replies something linked to the previous messages. For instance if I'm booking an appointment, the bot will ask a question to continue the booking flow, but completely ignore the instruction I wrote there. I'm then wondering how I could make sure this doesn't happen: • Is it a problem from LiveKit? • Is my usage of LiveKit the problem? • Did my context got too big, hence this instructions was flooded within a too-big-already context? I've had a look at the code and found this and this suggesting (if I get it right) that the instructions passed to
generate_reply
are appended to the base system prompt, ie in position
0
of the chat context. Knowing that, I'm wondering if that doesn't mean that this instructions get less and less important while the context grows (generally, the more the app gets complex, but also locally, the more a single conversation lasts) or if anything else is happening. I built an alternate
generate_reply
function that pushes the instructions to the end of the conversation history. It works slightly better, but doesn't fix the problem entirely... Would some of you have any idea how I could ensure more stability with this helper ? I feat that, the more the app grows, the more we might find broken behavior because of unfollowed instructions. Some other data: • Global context size: ~6000 tokens • Conversation average size: 10-20 user messages of ~10 tokens each (telephony convo) Thanks!
p
This a known behavior. I ended up using .say for things that I have to ensure needs to be said. I suggest you look at the llm prediction to check if a response was generated, but I’m quite sure it was not and that’s why it didn’t say anything.
m
Have noticed this alot...what i tried and worked is passing in a user input also. For example if there needs to be a nudge for inactivity, instruction = 'Generate a natural nudge to check if the user is still there' with user_input = '**user is silent for a while* '. Like the instruction following improved in my case with user_input added
💡 1
t
Thanks for sharing! We are exploring the new roles OpenAI introduced with o models (deprecation of
system
,
platform
vs
developer
instructions | source), however it feels like this should be a native mechanism of LiveKit. I'd be glad to hear @refined-appointment-81829’s thoughts on the subject 🙂
👀 1
p
@many-fall-81099 I gave that a try as well, but it was still not generating a prediction in certain cases, and to my use case, that translates into failures - so not acceptable at all. Out of curiosity, how did you evaluate whether it was following it or not with the improved version? Did you run it 100s times?
t
We've tried something new today. We'll measure performance increase and keep you posted
👍 2
Thanks @blue-sugar-11515 for the work 🙏
b
@proud-lawyer-39815 Would love to know if it worked for you !
r
Which model are you using?
t
GPT-4o
r
As you say,
generate_reply
influce can dimenish as context length grows. If you are not using a realtime model and you want to force an agent message to go out do as Mario suggests and use
say
. For idle detection have you seen
user_away_timeout
? See https://docs.livekit.io/agents/build/events/#userstate
m
@proud-lawyer-39815 didn't do eval to that extend but before it was quite noticeable for us. @blue-sugar-11515 ’s approach is quite interesting
t
As you say,
generate_reply
influce can dimenish as context length grows
That's for sure, however I've also experienced this problem even with a super shrunk context (< 1000 tokens) What do you think of the proposed solution ? In your experience, do you think this would help instructions being followed more reliably? As for using
say
, that a solution we thought about, however this would "break" two things we use AI for: 1. Internationalization of our Voice Bot: the ability to give instructions in English and let the bot speak the caller's language 2. Natural conversation feel: the fact that
generate_reply
will generate a contextualized reply, fitter in the conversation We can obviously handle i18n ourselves and even generate a set of similar sentences chosen randomly on say, but we'd really like to simply rely on our LLM for that.
d
thanks for raising this @tall-autumn-57974. we'll dig into this and improve the reliability of the default implementation. did you notice any improvements with shuffling the roles (developer for original instructions, and system at index N with the generate_reply instructions)
t
Hey @dry-elephant-14928, thanks for the update! We're experimenting this change on 10% of ours calls and I confirm the reliability is higher than with the built-in
generate_reply
method.
👀 1
🙌 1
I'll take some time to crush some numbers when I have a minute 😅