fix(ai-orchestrator): resolve Anthropic 400 error (assistant message prefill)#139
Merged
Merged
Conversation
…age error - Extract isAnthropicModel check before client instantiation - Add prefill guard: if Anthropic client and last message is AIMessage, append HumanMessage - Guard message: 'Please proceed with your task based on the context above.' - Add 3 new test cases validating guard behavior: * Appends HumanMessage for Anthropic when needed * Does NOT append for OpenAI (already permissive) * Does NOT append when message ends with HumanMessage (already valid) - All 279 tests passing, no type/lint errors - Fixes issue #138: a11y persona 400 error after mesh router
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an Anthropic-specific 400 error in the ai-orchestrator persona node flow by guarding against “assistant message prefill” scenarios when invoking Claude models after mesh routing.
Changes:
- Refactors Anthropic model detection into a reusable
isAnthropicModelboolean before client selection. - Adds an Anthropic prefill guard that appends a fallback
HumanMessagewhen the prompt would otherwise end in anAIMessage. - Adds unit tests covering the Anthropic guard behavior and ensuring OpenAI behavior is unchanged.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| libs/ai-orchestrator/src/orchestrator/llm-persona-node.ts | Adds Anthropic-specific prompt-ending guard before invoking the LLM client. |
| libs/ai-orchestrator/src/orchestrator/llm-persona-node.spec.ts | Adds tests validating the guard for Anthropic and non-guard behavior for OpenAI / already-human-ending prompts. |
…d logic - Change guard condition from 'if AIMessage' to 'if NOT HumanMessage' to handle edge case where state.messages is empty (only SystemMessage in array) - Remove unused humanMessageCount variable; add explicit array length assertion - Add 4th test case: empty state.messages with guard appending HumanMessage - All 280 tests passing Addresses review comments: - PRRT_kwDORem8Z86G5a8s: Ensure guard handles SystemMessage-only case - PRRT_kwDORem8Z86G5a9P: Remove unused variable, assert on array length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #138
The Anthropic API returns a 400 Bad Request error when the
a11ypersona is invoked after the mesh router, with the error:This model does not support assistant message prefill. The conversation must end with a user message.This is fixed by adding a prefill guard that detects when the message array ends with an
AIMessageand appends aHumanMessagebefore invoking the Anthropic client. This is Anthropic-specific; OpenAI and other models are permissive.Changes
File:
libs/ai-orchestrator/src/orchestrator/llm-persona-node.tsisAnthropicModelcheck before client instantiation for reuseAIMessage, appendHumanMessagewith content:"Please proceed with your task based on the context above."File:
libs/ai-orchestrator/src/orchestrator/llm-persona-node.spec.tsHumanMessagewhen Anthropic client receives message ending withAIMessageHumanMessage(already valid)Test Results
Copilot Review Triage
Deferred follow-ups
None. This fix is complete and ready to merge. After merge, webhook-listener service on Mac Mini will require a rebuild and restart to consume the updated ai-orchestrator library.