Guide
Can dropping old messages break a Rasa request to Gemini?
Compare the first messages your model receives after trimming conversation history to find why a request that used to work now fails.
Key takeaways (3)
- Compare the first message after the system prompt in a working request and a failed one.
- Check that a patch keeps the tool call and its result together.
- Verify other request paths on the version you run.
A caller confirms a payment plan and your voice agent gives an error. Compare what your app sent the model on a working turn and the failed one. Start after the system prompt, the instructions your app gives the model. In this example, removing older turns left the assistant’s request to run a tool ahead of the caller’s words. Gemini rejected that request.
Find the first message after the system prompt
In the September sample run, Mantle 3.21.0.dev5 kept a recent window of the conversation. The run notes describe a trim that dropped the opening caller message but kept the assistant’s tool call. The provider rejected a request that began with the tool call. Gemini returned HTTP 400 with a message about where a function call may appear. The run notes summarize the rejected request.

Make the missing context explicit
The sample helper inserts a note before a history that would open on the assistant side. Its exact note reads “[Engine note, not from the customer] Earlier messages of this call are omitted.” The request sends it in a user-role message. The helper keeps the tool call, its result, and later turns in their existing order. It leaves an opening that already starts with the caller alone.
Check which requests use the hook
Rasa’s current hook reference documents where the model-request hook runs and which fields it can modify. The September project hook applied this repair to its main request path. The run notes report that rephrasing and fact discovery used other request paths. Current Rasa docs describe hook coverage for the main loop, rephrase, and confirm-rephrase. Check hook coverage on your installed version and reproduce the request shape before you carry the workaround forward. If you can trim at a real caller message without dropping context you still need, you can avoid inserting a note.
| Path you trigger | What to record |
|---|---|
| Main reply after a lookup | First message role, tool call and result order, and provider response |
| Rephrased confirmation | The same fields for the request that rewrites the words the caller hears |
Compare all the retained messages
Compare the full sequence after the inserted note. Check that the original tool call and its result are still paired and that the caller’s latest turn is present. Also test a request that already starts on the caller, so the patch leaves it alone.
Run both request shapes
Run the history tests with Python 3.12. Clone the companion repository and run this from its root.
git checkout --detach 4aa0c4419dc193fef7a969c12d59edcf720f2606
cd examples/mantle-voice-banking-collections-gemini
python3 -m unittest discover -s tests -p test_history_start.py -v
The test cases check the note, the preserved sequence, and the input the helper leaves unchanged. In the pinned run, all four tests reported ok without contacting a model. If the preserved sequence check fails, compare the messages before and after the inserted note. To verify a deployed fix, capture the request shape and result from a synthetic call on each affected path. Keep those calls when you build an evaluation set so you can run the same checks after an upgrade.