Skip to content

Conversation

@AI-Manditrade
Copy link

Claude Agent SDK keeps trying to send reminder messages as to the llm, which are also in between tool calls. OpenAI has a strict policy of only tool responses allowed after tool execution. This causes system crash. We've added filtering and buffering to catch these before they get sent to openai directly or via Azure.

AI-Manditrade added 2 commits January 26, 2026 06:44
- Buffer ALL user messages during pending tool calls
- Ensures strict message sequencing: assistant → tool responses → user messages
- Fixes Azure 400 error: 'assistant with tool_calls must be followed by tool messages'
- Prevents system-reminders and other user messages from breaking tool call sequences
- Update version to 0.53.1
- Scope package to @AI-Manditrade
- Linux AMD64 only distribution

Tested and verified:
- No Azure 400 errors with tool calls
- 14 system-reminder messages properly buffered and released
- All messages delivered to LLM in correct order
jedarden pushed a commit that referenced this pull request Jan 26, 2026
Azure OpenAI requires strict message sequencing where assistant messages
with tool_calls must be immediately followed by all corresponding tool
responses before any user messages can appear.

This change:
- Adds provider parameter to transformMessages() for provider-aware handling
- Implements reorderMessagesForAzure() that buffers user messages appearing
  between tool calls and their responses, flushing them only after all
  pending tool responses are received
- Applies reordering ONLY for Azure provider, not affecting other providers
- Adds comprehensive tests for various Azure message ordering scenarios

This is a properly scoped fix for PR #14, containing only the Go code
changes without any package.json or metadata modifications.
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.

1 participant