Skip to content

feat: prevent successive assistant messages in agent loop#27

Merged
declanjackson merged 5 commits intomainfrom
feat/no-successive-assistant-messages
Feb 13, 2026
Merged

feat: prevent successive assistant messages in agent loop#27
declanjackson merged 5 commits intomainfrom
feat/no-successive-assistant-messages

Conversation

@MohamedAkbarally
Copy link
Contributor

@MohamedAkbarally MohamedAkbarally commented Feb 13, 2026

Prevent Successive Assistant Messages in Agent Loop

Summary

Add automatic user message injection to prevent successive assistant messages when the agent responds without tool calls

Details

  • Agent loop now checks if assistant message has no tool calls and no user messages
  • Automatically injects UserMessage(content="Please continue the task") to maintain valid message alternation
  • Skips injection if next turn will show "turns remaining" warning to avoid redundant prompts
  • Prevents API errors from LLM providers that require strict user/assistant message alternation

Test Coverage

  • Added test_no_successive_assistant_messages to verify automatic continuation message injection
  • Test validates message is added only when needed (not when turns remaining warning will appear)

Copy link
Collaborator

@declanjackson declanjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@declanjackson declanjackson merged commit 09434d5 into main Feb 13, 2026
2 checks passed
@declanjackson declanjackson deleted the feat/no-successive-assistant-messages branch February 13, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments