If a tool call is used at the end of agent reply, it would enter a dead-loop.
What happened?
I've added a tool call to the gemini-cli to send notification to my desktop, and added the instruction to ask the agent to send me notification of task completion in AGENTS.md.
However, after the agent sends the notification, it'll try to answer my question again and again, entering a dead-loop.
What did you expect to happen?
Send me a notification, and let me to input my next question.
Client information
- CLI Version: 0.1.4
- Git Commit: 1078a54
- Operating System: darwin v18.16.0
- Sandbox Environment: no sandbox
- Model Version: gemini-2.5-pro
- Memory Usage: 224.8 MB
Login information
No response
Anything else we need to know?
No response
I'd be a bit surprised if it's due to a bad prompt used in agents.md, but I'd attach here in case it helps.
<action in each reply>
Right before the end of each reply, you must send a desktop notification. The message should
briefly summarize the content of your _most recent_ reply. Example: "Task completed!
Provided the current date.".
as far as i understand, gemini-cli does not allow the model to end in a tool call, it is always forcibly followed by a conversation turn from the model. This is generally the right behavior.
Your prompt "right before the end of each reply" conflicts with that, instructing the model to always try to end in a tool call. Try modifying your prompt to respect this, e.g. "After sending the desktop notification, output 'Done!' and end your response."
does this relate to issue #2438
as far as i understand, gemini-cli does not allow the model to end in a tool call, it is always forcibly followed by a conversation turn from the model. This is generally the right behavior. Your prompt "right before the end of each reply" conflicts with that, instructing the model to always try to end in a tool call.
Ah that's interesting to know, though it still seems unexpected to cause the model entering an infinite loop.
Try modifying your prompt to respect this, e.g. "After sending the desktop notification, output 'Done!' and end your response."
This works for my use case.
Found possible duplicate issues:
- #5085: (0.9024174213409424)