feat: add MiniMax as alternative LLM provider#199
feat: add MiniMax as alternative LLM provider#199octo-patch wants to merge 1 commit intogoogle-agentic-commerce:mainfrom
Conversation
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)
|
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. |
Summary of ChangesHello, 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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| raw = response.choices[0].message.content or "{}" | ||
| raw = _strip_think_tags(raw) | ||
| raw = _strip_code_fences(raw) | ||
| return json.loads(raw) |
There was a problem hiding this comment.
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.
| 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 |
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.
common/llm_config.py: CentralizedLLMProviderenum,get_provider()andget_model()readingLLM_PROVIDER/LLM_MODELenv varscommon/minimax_client.py: OpenAI-compatible client wrapping MiniMax API with function-calling, JSON generation, think-tag stripping, and code-fence removalFunctionCallResolver: Routes to Google GenAI or MiniMax based on the active providerBaseServerExecutor: Lazy Google client creation so MiniMax can run without Google credentialscatalog_agent.py: Provider-aware item generation (_generate_items_google/_generate_items_minimax)get_model()for env-based model selection instead of hardcodedgemini-2.5-flashpyproject.toml: AddedopenaiSDK dependencyREADME.md: Added MiniMax setup instructions as Option 3Configuration
When
LLM_PROVIDERis unset orgoogle, behavior is identical to before this change.Test plan
llm_config,minimax_client, andfunction_call_resolverprovider routing (all passing)LLM_PROVIDER=minimaxend-to-end15 files changed, 1107 additions(+), 38 deletions(-)