Skip to content

Python: Add MiniMax chat completion connector with regional endpoints - #14225

Open
octo-patch wants to merge 1 commit into
microsoft:mainfrom
octo-patch:octo/20260728-provider-add-recvpUut186yCV
Open

Python: Add MiniMax chat completion connector with regional endpoints#14225
octo-patch wants to merge 1 commit into
microsoft:mainfrom
octo-patch:octo/20260728-provider-add-recvpUut186yCV

Conversation

@octo-patch

Copy link
Copy Markdown
Contributor

Reason: Add the MiniMax chat completion provider so Semantic Kernel can call MiniMax-M3 and MiniMax-M2.7 through the documented global and China OpenAI-compatible endpoints.

Changes

  • Add semantic_kernel.connectors.ai.minimax connector with an OpenAI-compatible chat completion service that follows the existing Nvidia connector pattern.
  • MiniMaxSettings resolves the base URL from a region field, covering the global_en (https://api.minimax.io/v1) and cn_zh (https://api.minimaxi.com/v1) regional endpoints.
  • MiniMaxChatCompletion defaults to MiniMax-M3 and accepts MiniMax-M2.7 via ai_model_id/MINIMAX_CHAT_MODEL_ID.
  • MiniMaxChatPromptExecutionSettings clamps temperature to the documented [0.0, 1.0] range.
  • README documentation and the AI connectors table entry.
  • Unit tests for settings, prompt execution settings, handler, and chat completion.

Checks

  • pytest tests/unit/connectors/ai/minimax -> 27 passed.
  • ruff check and ruff format --check on the new files -> clean.
  • mypy semantic_kernel/connectors/ai/minimax -> clean.

Copilot AI review requested due to automatic review settings July 28, 2026 13:19
@octo-patch
octo-patch requested a review from a team as a code owner July 28, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Python AI connector (semantic_kernel.connectors.ai.minimax) to integrate with MiniMax’s OpenAI-compatible chat completion API, including region-based endpoint selection, execution settings, docs, and unit tests—following the existing Nvidia connector structure.

Changes:

  • Introduces MiniMaxChatCompletion + supporting settings/handler/prompt execution settings for MiniMax chat completions with regional endpoint resolution.
  • Adds unit tests covering settings, prompt execution settings, handler behavior, and basic chat completion behavior.
  • Updates the Python AI connectors README/table and adds MiniMax connector documentation.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/tests/unit/connectors/conftest.py Adds minimax_unit_test_env fixture for MiniMax-related unit tests.
python/tests/unit/connectors/ai/minimax/settings/test_minimax_settings.py Tests for MiniMaxSettings defaults, env loading, and region→base URL resolution.
python/tests/unit/connectors/ai/minimax/services/test_minimax_handler.py Tests MiniMaxHandler request routing and basic chat request behavior.
python/tests/unit/connectors/ai/minimax/services/test_minimax_chat_completion.py Tests MiniMaxChatCompletion initialization and basic non-streaming chat completion/error handling.
python/tests/unit/connectors/ai/minimax/prompt_execution_settings/test_minimax_prompt_execution_settings.py Tests execution settings serialization and temperature validation.
python/semantic_kernel/connectors/ai/README.md Adds MiniMax to the connectors table.
python/semantic_kernel/connectors/ai/minimax/settings/minimax_settings.py Adds MiniMaxSettings including region-based base URL resolution.
python/semantic_kernel/connectors/ai/minimax/settings/init.py Package init for MiniMax settings.
python/semantic_kernel/connectors/ai/minimax/services/minimax_model_types.py Adds MiniMaxModelTypes enum.
python/semantic_kernel/connectors/ai/minimax/services/minimax_handler.py Adds OpenAI-client-based request handler and usage tracking for MiniMax.
python/semantic_kernel/connectors/ai/minimax/services/minimax_chat_completion.py Implements the MiniMax chat completion service (non-streaming + streaming paths).
python/semantic_kernel/connectors/ai/minimax/services/init.py Package init for MiniMax services.
python/semantic_kernel/connectors/ai/minimax/README.md Adds MiniMax connector documentation, endpoints, env vars, and quick start.
python/semantic_kernel/connectors/ai/minimax/prompt_execution_settings/minimax_prompt_execution_settings.py Adds prompt execution settings (incl. temperature range validation + serialization aliases).
python/semantic_kernel/connectors/ai/minimax/prompt_execution_settings/init.py Package init for MiniMax prompt execution settings.
python/semantic_kernel/connectors/ai/minimax/init.py Exposes the MiniMax connector public API symbols.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +182 to +184
response = await self._send_request(settings)
assert isinstance(response, AsyncGenerator) # nosec

Comment on lines +19 to +20
- `MiniMax-M3` - Latest flagship model with a 1,000,000 token context window and text/image/video
input support (default).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 5 | Confidence: 87%

✓ Correctness

The MiniMax chat completion connector closely follows the existing Nvidia connector pattern. The implementation is correct: settings resolution handles None values properly via KernelBaseSettings, the handler safely guards streaming responses in store_usage, and the chat history preparation is safe since ChatMessageContent.content always returns str. No new correctness bugs are introduced beyond patterns already established in the codebase.

✓ Security Reliability

The MiniMax connector is well-structured and follows the existing Nvidia connector pattern. API key handling uses SecretStr in settings, region selection is constrained via Literal types preventing injection, and temperature is properly bounded. The to_dict() method exposes the plain-text API key, but this mirrors the pre-existing Nvidia connector pattern. No new security or reliability regressions are introduced by this PR.

✓ Test Coverage

The test suite covers initialization, settings, prompt execution settings validation, basic chat completion, and error handling. However, the streaming chat completion code path (_inner_get_streaming_chat_message_contents) has meaningful branching logic (empty-choice filtering, chunk metadata extraction, streaming content construction) with zero test coverage. The existing test_get_chat_message_contents test also has shallow assertions that don't verify role, finish_reason, metadata, or usage propagation from the response. The from_dict class method is also untested. While the absence of streaming tests is consistent with the Nvidia connector pattern, the streaming implementation here has non-trivial logic that warants at least one basic test.

✓ Failure Modes

The MiniMax connector follows the established Nvidia connector pattern closely. The error handling is consistent with the rest of the codebase: non-streaming errors are properly caught and wrapped in ServiceResponseException, streaming iteration errors propagate unwrapped (same as Nvidia). Settings validation, regional URL resolution, and usage tracking all work correctly. No critical failure modes specific to this PR were found.

✗ Design Approach

I found two design-level issues in the new MiniMax connector. The streaming path is wired against the wrong response type, so streamed chat completions will fail before yielding any chunks, and the custom chat-history formatter drops OpenAI-compatible message fields such as tool_calls/tool_call_id instead of reusing the repo’s existing serializer pattern. Both problems come from reimplementing OpenAI-compatible plumbing instead of following the established base-connector contract.

Flagged Issues

  • python/semantic_kernel/connectors/ai/minimax/services/minimax_chat_completion.py:183 asserts AsyncGenerator even though the MiniMax handler returns ChatCompletion | AsyncStream[Any] (minimax_handler.py:46-53); the repo's OpenAI-compatible base checks AsyncStream instead (open_ai_chat_completion_base.py:110-113). This will reject streamed responses at runtime.
  • python/semantic_kernel/connectors/ai/minimax/services/minimax_chat_completion.py:291-294 flattens every history item to {role, content}, dropping OpenAI-compatible tool_calls/tool_call_id fields that ChatMessageContent.to_dict() preserves (chat_message_content.py:312-321). The repo's existing formatter reuses that serializer (open_ai_chat_completion_base.py:294-303). This breaks tool-calling round-trips.

Automated review by octo-patch's agents

Comment on lines +291 to +294
messages = []
for message in chat_history.messages:
message_dict = {role_key: message.role.value, content_key: message.content}
messages.append(message_dict)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This formatter silently mishandles any ChatHistory containing assistant tool calls or tool results. ChatMessageContent.to_dict() is the repo's contract for OpenAI-compatible messages: assistant function-call turns produce tool_calls, and tool replies include tool_call_id. The existing OpenAI-compatible formatter reuses message.to_dict(...) and applies the instruction_role remap on top. Flattening everything to {role, content} loses tool-call linkage on follow-up turns.

Suggested change
messages = []
for message in chat_history.messages:
message_dict = {role_key: message.role.value, content_key: message.content}
messages.append(message_dict)
return [
{
**message.to_dict(role_key=role_key, content_key=content_key),
role_key: "developer"
if self.instruction_role == "developer" and message.to_dict(role_key=role_key)[role_key] == "system"
else message.to_dict(role_key=role_key)[role_key],
}
for message in chat_history.messages
]

@github-actions

Copy link
Copy Markdown
Contributor

Flagged issue

python/semantic_kernel/connectors/ai/minimax/services/minimax_chat_completion.py:183 asserts AsyncGenerator even though the MiniMax handler returns ChatCompletion | AsyncStream[Any] (minimax_handler.py:46-53); the repo's OpenAI-compatible base checks AsyncStream instead (open_ai_chat_completion_base.py:110-113). This will reject streamed responses at runtime.


Source: automated DevFlow PR review

@github-actions

Copy link
Copy Markdown
Contributor

Flagged issue

python/semantic_kernel/connectors/ai/minimax/services/minimax_chat_completion.py:291-294 flattens every history item to {role, content}, dropping OpenAI-compatible tool_calls/tool_call_id fields that ChatMessageContent.to_dict() preserves (chat_message_content.py:312-321). The repo's existing formatter reuses that serializer (open_ai_chat_completion_base.py:294-303). This breaks tool-calling round-trips.


Source: automated DevFlow PR review

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