Skip to content

feat: add MiniMax as alternative LLM provider#199

Open
octo-patch wants to merge 1 commit intogoogle-agentic-commerce:mainfrom
octo-patch:feature/add-minimax-provider
Open

feat: add MiniMax as alternative LLM provider#199
octo-patch wants to merge 1 commit intogoogle-agentic-commerce:mainfrom
octo-patch:feature/add-minimax-provider

Conversation

@octo-patch
Copy link
Copy Markdown

Summary

Adds MiniMax M2.7 as an alternative LLM backend alongside Google GenAI, enabling developers to run AP2 agents with a non-Google model provider.

  • New common/llm_config.py: Centralized LLMProvider enum, get_provider() and get_model() reading LLM_PROVIDER / LLM_MODEL env vars
  • New common/minimax_client.py: OpenAI-compatible client wrapping MiniMax API with function-calling, JSON generation, think-tag stripping, and code-fence removal
  • Modified FunctionCallResolver: Routes to Google GenAI or MiniMax based on the active provider
  • Modified BaseServerExecutor: Lazy Google client creation so MiniMax can run without Google credentials
  • Modified catalog_agent.py: Provider-aware item generation (_generate_items_google / _generate_items_minimax)
  • Modified all agent files: Use get_model() for env-based model selection instead of hardcoded gemini-2.5-flash
  • Updated pyproject.toml: Added openai SDK dependency
  • Updated README.md: Added MiniMax setup instructions as Option 3

Configuration

export LLM_PROVIDER='minimax'
export MINIMAX_API_KEY='your_key'
# Optional: override default model
export LLM_MODEL='MiniMax-M2.7-highspeed'

When LLM_PROVIDER is unset or google, behavior is identical to before this change.

Test plan

  • 38 unit tests covering llm_config, minimax_client, and function_call_resolver provider routing (all passing)
  • 4 integration tests hitting live MiniMax API: function calling, JSON generation, end-to-end provider flow (all passing)
  • Verified Google path is unchanged (default behavior preserved)
  • Manual: run a scenario with LLM_PROVIDER=minimax end-to-end

15 files changed, 1107 additions(+), 38 deletions(-)

Add MiniMax M2.7 as an alternative LLM backend alongside Google GenAI,
configurable via LLM_PROVIDER and MINIMAX_API_KEY environment variables.

- New common/llm_config.py: centralized provider detection and model config
- New common/minimax_client.py: OpenAI-compatible client with function calling,
  JSON generation, think-tag stripping, and code-fence removal
- Modified FunctionCallResolver: routes to Google or MiniMax based on provider
- Modified BaseServerExecutor: lazy Google client creation for MiniMax support
- Modified catalog_agent.py: provider-aware item generation
- Modified all agent files: env-based model selection via get_model()
- Added openai SDK dependency
- Updated README.md with MiniMax setup instructions
- 38 unit tests + 4 integration tests (42 total, all passing)
@octo-patch octo-patch requested a review from a team as a code owner March 26, 2026 13:36
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 26, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the flexibility of the AP2 agent infrastructure by introducing MiniMax as an alternative Large Language Model provider. It establishes a centralized mechanism for configuring LLM backends and models, allowing developers to seamlessly switch between Google GenAI and MiniMax. The changes involve creating new client and configuration modules, adapting existing agent components to be provider-agnostic, and ensuring that both function-calling and JSON generation capabilities are supported across the chosen providers. This broadens the ecosystem's compatibility and offers more choices for deploying and running agents.

Highlights

  • MiniMax LLM Provider Integration: Introduced MiniMax M2.7 as an alternative LLM backend, allowing AP2 agents to operate with a non-Google model provider. This includes new modules for configuration and client interaction.
  • Centralized LLM Configuration: Added a new llm_config.py module to centralize LLM provider and model selection via LLM_PROVIDER and LLM_MODEL environment variables, defaulting to Google GenAI if not specified.
  • OpenAI-Compatible MiniMax Client: Developed a new minimax_client.py module that provides an OpenAI-compatible client for MiniMax, supporting function-calling, JSON generation, and post-processing of model outputs (e.g., stripping think-tags and code fences).
  • Provider-Aware Functionality: Modified core components like FunctionCallResolver and BaseServerExecutor to dynamically route LLM calls to either Google GenAI or MiniMax based on the active provider. Agent files were updated to use the new get_model() function for dynamic model selection.
  • Documentation and Dependencies: Updated README.md with detailed MiniMax setup instructions and added the openai SDK as a new dependency in pyproject.toml.
  • Comprehensive Testing: Included extensive unit and integration tests for the new LLM configuration, MiniMax client, and provider routing logic, ensuring robust functionality and compatibility.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for MiniMax as an alternative LLM provider, alongside the existing Google GenAI. Key changes include adding new modules for centralized LLM configuration (llm_config.py) and MiniMax client implementation (minimax_client.py), updating core components like FunctionCallResolver and base_server_executor.py to dynamically select the LLM backend, and modifying agent implementations to use the new configuration. The README.md and pyproject.toml were updated, and new unit and integration tests were added. Feedback includes a high-severity suggestion to add robust error handling for JSON decoding in the MiniMax client and a low-severity suggestion to improve the .env file code block language specifier in the README.md.

Comment on lines +139 to +142
raw = response.choices[0].message.content or "{}"
raw = _strip_think_tags(raw)
raw = _strip_code_fences(raw)
return json.loads(raw)
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.

high

The current implementation can raise a json.JSONDecodeError if the LLM returns malformed JSON, or content that becomes an empty string after stripping tags and fences. This could lead to an unhandled exception.

To make this function more robust, I suggest adding a try...except block to handle JSON decoding errors and ensuring that an empty string is not passed to json.loads.

Suggested change
raw = response.choices[0].message.content or "{}"
raw = _strip_think_tags(raw)
raw = _strip_code_fences(raw)
return json.loads(raw)
raw = response.choices[0].message.content or ""
raw = _strip_think_tags(raw)
raw = _strip_code_fences(raw)
try:
return json.loads(raw) if raw else {}
except json.JSONDecodeError:
logging.warning("Could not parse JSON from MiniMax: %s", raw)
return {}


- **In a `.env` file:**

```sh
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.

low

For .env file examples, it's more accurate to use the env language specifier or no specifier at all, rather than sh. .env files have their own simple key-value syntax and are not shell scripts.

Suggested change
```sh
```env

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