Hey Mastra Team!
We upgraded Mastra 0.10.13 → 0.10.23 (with Gemini Flash via @ai-sdk/google) and started intermittently getting:
“Please ensure that function call turn comes immediately after a user turn or after a function response turn.”
Setup:
- agent.stream(...) with clientTools { citeSourcesTool, ..., proposeSuggestionsTool }, onFinish persists messages.
- Tool-backed RAG on the agent.
Behavior:
- Error seems to appear when assistant streams text and then a tool call (e.g., citeSources or proposeSuggestions) is triggered in the same assistant turn.
- Same app code on 0.10.13 didn’t surface this.
Questions:
1) Any stream/turn sequencing changes between 0.10.13 and 0.10.23 that affect tool-call ordering with Gemini?
2) Recommended pattern for “post-answer” tools (e.g., separate follow-up call in onFinish) or a config to ensure tools execute before any streamed text?
3) Would streamVNext help here?
Notes:
- Changing maxSteps/toolChoice or moving tools to tools vs clientTools didn’t help.
- Didn’t find anything relevant in release notes; no minimal repro yet, but I can DM redacted raw turn logs.