tall-autumn-57974
10/07/2025, 6:38 AMgenerate_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!proud-lawyer-39815
10/07/2025, 9:54 AMmany-fall-81099
10/07/2025, 12:54 PMtall-autumn-57974
10/07/2025, 1:03 PMsystem, 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 🙂proud-lawyer-39815
10/07/2025, 2:05 PMtall-autumn-57974
10/07/2025, 3:42 PMtall-autumn-57974
10/07/2025, 3:42 PMblue-sugar-11515
10/07/2025, 4:14 PMrefined-appointment-81829
10/07/2025, 5:08 PMtall-autumn-57974
10/07/2025, 5:13 PMrefined-appointment-81829
10/07/2025, 5:13 PMgenerate_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/#userstatemany-fall-81099
10/07/2025, 6:16 PMtall-autumn-57974
10/08/2025, 8:11 AMAs you say,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 usinginfluce can dimenish as context length growsgenerate_reply
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.dry-elephant-14928
10/14/2025, 10:03 PMtall-autumn-57974
10/15/2025, 7:18 AMgenerate_reply method.tall-autumn-57974
10/15/2025, 7:18 AM