Skip to content

"Vibe-Trading: Your Personal Trading Agent"

feat: default MiniMax text selection to M3.1 Flash

octo-patch52a89ec3ff86
diff --git a/README.md b/README.md
index 71e654af4..31f00ac9a 100644
--- a/README.md
+++ b/README.md
@@ -1038,6 +1038,8 @@ vibe-trading-mcp # start MCP server (stdio)
> **Supported LLM providers:** OpenRouter, OpenAI, Anthropic (native Messages API), DeepSeek, OpenCode (Go / Zen), Gemini, Groq, DashScope/Qwen, Zhipu, Moonshot/Kimi, MiniMax, SiliconFlow (CN + Global), Xiaomi MIMO, Novita AI, iFlytek Spark, Z.ai, NVIDIA NIM, ModelScope, GitHub Copilot, Claude Code CLI, Ollama (local). When no `*_BASE_URL` is set, each provider falls back to its canonical endpoint, so just a key is enough. See `.env.example` for config.
+MiniMax onboarding defaults to `MiniMax-M3.1-Flash`, with `MiniMax-M3` as the alternative in Settings. Both the global and China API endpoints are supported. Saved model IDs and custom endpoints remain editable; the ordinary model list hides older MiniMax text suggestions. MiniMax uses the API's default thinking depth, and Flash's reasoning is preserved across tool turns.
+
> **Tip:** All markets work without any API keys thanks to automatic fallback. yfinance/Yahoo (HK/US/Canada/UK), OKX (crypto), and AKShare (A-shares, US, HK, futures, forex) are all free. LSE `.L` quotes must declare GBP or GBp so pence can be normalized before GBP accounting. Tushare token is optional; tencent, baostock and AKShare are the no-token A-share fallbacks.
### GitHub Copilot SDK provider
diff --git a/agent/.env.example b/agent/.env.example
index 52de6ec32..9bf1c2983 100644
--- a/agent/.env.example
+++ b/agent/.env.example
@@ -118,7 +118,8 @@ OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
# --- MiniMax ---
# LANGCHAIN_PROVIDER=minimax
-# LANGCHAIN_MODEL_NAME=MiniMax-M3 # or MiniMax-M2.7 / MiniMax-M2.7-highspeed
+# LANGCHAIN_MODEL_NAME=MiniMax-M3.1-Flash # or MiniMax-M3
+# MiniMax uses the API's default thinking depth; LANGCHAIN_REASONING_EFFORT is not forwarded.
# MINIMAX_API_KEY=xxx
# MINIMAX_BASE_URL=https://api.minimax.io/v1 # Global
# MINIMAX_BASE_URL=https://api.minimaxi.com/v1 # China
diff --git a/agent/cli/_legacy.py b/agent/cli/_legacy.py
index 9af4c9018..fbdfb5e0d 100644
--- a/agent/cli/_legacy.py
+++ b/agent/cli/_legacy.py
@@ -6001,7 +6001,7 @@ _PROVIDER_CHOICES: list[dict[str, str | None]] = [
"key_env": "MINIMAX_API_KEY",
"base_env": "MINIMAX_BASE_URL",
"base_url": "https://api.minimax.io/v1",
- "model": "MiniMax-M3",
+ "model": "MiniMax-M3.1-Flash",
"key_prefix": None,
"key_placeholder": "api-key...",
},
diff --git a/agent/src/api/settings_routes.py b/agent/src/api/settings_routes.py
index c2a9be8d8..ba39196b8 100644
--- a/agent/src/api/settings_routes.py
+++ b/agent/src/api/settings_routes.py
@@ -45,6 +45,7 @@ class LLMProviderOption(BaseModel):
api_key_env: Optional[str] = None
base_url_env: str
default_model: str
+ model_options: List[str] = Field(default_factory=list)
default_base_url: str
base_url_options: List[str] = Field(default_factory=list)
api_key_required: bool = True
@@ -322,6 +323,14 @@ async def _list_provider_models(
) -> LLMModelsResponse:
"""Best-effort live model discovery with a safe editable fallback."""
fallback = [provider.default_model]
+ # Keep the direct MiniMax picker curated. Saved/custom model names remain
+ # editable, and custom endpoints retain their own live model discovery.
+ if provider.name == "minimax" and base_url.rstrip("/") in provider.base_url_options:
+ return LLMModelsResponse(
+ provider=provider.name,
+ models=provider.model_options or fallback,
+ source="default",
+ )
if provider.auth_type in {"oauth", "gh_cli"}:
return LLMModelsResponse(
provider=provider.name,
@@ -356,6 +365,32 @@ async def _list_provider_models(
warning_code="model_list_unavailable",
)
+ # Curate only known gateway text namespaces at their official endpoints.
+ # Never invent availability: retain current routes only when discovery returned them.
+ gateway_choices = {
+ ("openrouter", "https://openrouter.ai/api/v1"): (
+ "minimax/minimax-", ["minimax/minimax-m3.1-flash:free", "minimax/minimax-m3"]
+ ),
+ ("opencode", "https://opencode.ai/zen/v1"): (
+ "minimax-", ["minimax-m3.1-flash-free", "minimax-m3"]
+ ),
+ ("opencode", "https://opencode.ai/zen/go/v1"): (
+ "minimax-", ["minimax-m3.1-flash-free", "minimax-m3"]
+ ),
+ }
+ if choices := gateway_choices.get((provider.name, base_url.rstrip("/"))):
+ prefix, current = choices
+ text_models = []
+ for model in models:
+ suffix = model.removeprefix(prefix).lower() if model.startswith(prefix) else ""
+ if suffix == "01" or (suffix.startswith("m") and suffix[1:2].isdigit()):
+ text_models.append(model)
+ if text_models:
+ first = models.index(text_models[0])
+ remaining = [model for model in models if model not in text_models]
+ remaining[first:first] = [model for model in current if model in models]
+ models = remaining
+
discovered = bool(models)
if provider.default_model not in models:
models.insert(0, provider.default_model)
diff --git a/agent/src/providers/capabilities.py b/agent/src/providers/capabilities.py
index 58529e9e8..c87aad859 100644
--- a/agent/src/providers/capabilities.py
+++ b/agent/src/providers/capabilities.py
@@ -317,6 +317,15 @@ def get_provider_capabilities(
normalized = (provider or "").strip().lower().replace("_", "-")
if normalized == "custom":
return ProviderCapabilities("custom", None, "OPENAI_BASE_URL", capture_reasoning=True)
+ if normalized == "minimax" and model == "MiniMax-M3.1-Flash":
+ # Flash returns reasoning separately and requires it on subsequent tool turns.
+ return ProviderCapabilities(
+ "minimax",
+ "MINIMAX_API_KEY",
+ "MINIMAX_BASE_URL",
+ capture_reasoning=True,
+ send_reasoning_content=True,
+ )
if normalized == "openai-codex":
return _PROVIDERS["openai-codex"]
if normalized and normalized != "openai":
diff --git a/agent/src/providers/llm_providers.json b/agent/src/providers/llm_providers.json
index a97d6732b..c3fb687ce 100644
--- a/agent/src/providers/llm_providers.json
+++ b/agent/src/providers/llm_providers.json
@@ -172,7 +172,8 @@
"label": "MiniMax",
"api_key_env": "MINIMAX_API_KEY",
"base_url_env": "MINIMAX_BASE_URL",
- "default_model": "MiniMax-M3",
+ "default_model": "MiniMax-M3.1-Flash",
+ "model_options": ["MiniMax-M3.1-Flash", "MiniMax-M3"],
"default_base_url": "https://api.minimax.io/v1",
"base_url_options": [
"https://api.minimax.io/v1",
diff --git a/agent/tests/test_llm_provider_defaults.py b/agent/tests/test_llm_provider_defaults.py
index b2da131ac..5657dc7c4 100644
--- a/agent/tests/test_llm_provider_defaults.py
+++ b/agent/tests/test_llm_provider_defaults.py
@@ -35,7 +35,7 @@ EXPECTED_PROVIDER_DEFAULTS = {
"zhipu": "glm-5.1",
"glm": "glm-5.1",
"moonshot": "kimi-k2.6",
- "minimax": "MiniMax-M3",
+ "minimax": "MiniMax-M3.1-Flash",
"mimo": "MiMo-72B-A27B",
"spark": "4.0Ultra",
"zai": "glm-5.1",
diff --git a/agent/tests/test_minimax_flash.py b/agent/tests/test_minimax_flash.py
new file mode 100644
index 000000000..940ea90a8
--- /dev/null
+++ b/agent/tests/test_minimax_flash.py
@@ -0,0 +1,377 @@
+"""MiniMax defaults and real SDK requests with an offline HTTP transport."""
+
+from __future__ import annotations
+
+import asyncio
+import json
+from pathlib import Path
+
+import httpx
+import pytest
+from langchain_core.messages import HumanMessage, ToolMessage
+
+from src.api.settings_routes import LLMProviderOption, _list_provider_models
+from src.config.accessor import reset_env_config
+from src.providers import llm
+
+FLASH = "MiniMax-M3.1-Flash"
+MODELS = [FLASH, "MiniMax-M3"]
+ENDPOINTS = ["https://api.minimax.io/v1", "https://api.minimaxi.com/v1"]
+
+
+def _provider(name="minimax") -> LLMProviderOption:
+ catalog = Path(__file__).resolve().parents[1] / "src/providers/llm_providers.json"
+ return LLMProviderOption(
+ **next(p for p in json.loads(catalog.read_text()) if p["name"] == name)
+ )
+
+
+def requests(monkeypatch):
+ """Exercise the installed SDK; replace only dotenv loading and HTTP transport."""
+ captured = []
+
+ def respond(request):
+ body = json.loads(request.content)
+ captured.append((request, body))
+ if body.get("stream"):
+ chunk = {
+ "id": "offline-stream",
+ "object": "chat.completion.chunk",
+ "created": 1,
+ "model": body["model"],
+ "choices": [
+ {
+ "index": 0,
+ "delta": {
+ "content": "offline",
+ "reasoning_content": "offline thought",
+ },
+ "finish_reason": None,
+ }
+ ],
+ }
+ return httpx.Response(
+ 200,
+ headers={"content-type": "text/event-stream"},
+ text=f"data: {json.dumps(chunk)}\n\ndata: [DONE]\n\n",
+ )
+ message = {"role": "assistant", "content": "offline"}
+ if body.get("tools"):
+ message = {
+ "role": "assistant",
+ "content": None,
+ "tool_calls": [
+ {
+ "id": "call_offline",
+ "type": "function",
+ "function": {
+ "name": "inspect_text",
+ "arguments": '{"text":"hello"}',
+ },
+ }
+ ],
+ }
+ message["reasoning_content"] = "offline reasoning"
+ return httpx.Response(
+ 200,
+ json={
+ "id": "offline",
+ "object": "chat.completion",
+ "created": 1,
+ "model": body["model"],
+ "choices": [
+ {
+ "index": 0,
+ "message": message,
+ "finish_reason": "tool_calls" if body.get("tools") else "stop",
+ }
+ ],
+ },
+ )
+
+ sync = httpx.Client(transport=httpx.MockTransport(respond), trust_env=False)
+ async_client = httpx.AsyncClient(
+ transport=httpx.MockTransport(respond), trust_env=False
+ )
+ monkeypatch.setattr(llm, "_dotenv_loaded", True)
+ monkeypatch.setattr(
+ llm, "_build_proxy_free_http_clients", lambda: (sync, async_client)
+ )
+ for key in (
+ "OPENAI_BASE_URL",
+ "OPENAI_API_BASE",
+ "OPENAI_API_KEY",
+ "LANGCHAIN_USE_RESPONSES_API",
+ ):
+ monkeypatch.delenv(key, raising=False)
+ monkeypatch.setenv("LANGCHAIN_PROVIDER", "minimax")
+ monkeypatch.setenv("LANGCHAIN_MODEL_NAME", _provider().default_model)
+ monkeypatch.setenv("MINIMAX_API_KEY", "test-key")
+ monkeypatch.setenv("MINIMAX_BASE_URL", ENDPOINTS[0])
+ monkeypatch.setenv("LANGCHAIN_TEMPERATURE", "0")
+ monkeypatch.setenv("LANGCHAIN_REASONING_EFFORT", "")
+ monkeypatch.setenv("VIBE_TRADING_DISABLE_HTTP_PROXY", "true")
+ reset_env_config()
+ yield captured
+ sync.close()
+ asyncio.run(async_client.aclose())
+ reset_env_config()
+
+
[email protected]("endpoint", ENDPOINTS)
[email protected]("effort", ["", "low", "medium", "high", "xhigh", "max"])
+def test_flash_real_sdk_request(requests, monkeypatch, endpoint, effort):
+ monkeypatch.setenv("MINIMAX_BASE_URL", endpoint)
+ monkeypatch.setenv("LANGCHAIN_REASONING_EFFORT", effort)
+ model = llm.build_llm()
+ assert model.invoke([HumanMessage(content="hello")]).content == "offline"
+ request, body = requests[0]
+ assert str(request.url) == endpoint + "/chat/completions"
+ assert request.headers["authorization"] == "Bearer test-key"
+ assert body["model"] == FLASH
+ assert body["temperature"] == 0.01
+ # Keep the existing provider allowlist: Flash uses server-default depth.
+ assert "reasoning_effort" not in body
+ assert "reasoning" not in body
+ assert "thinking" not in body
+ assert "service_tier" not in body
+ assert "reasoning_split" not in body
+
+
+def test_registry_endpoint_is_used_when_unset(requests, monkeypatch):
+ monkeypatch.delenv("MINIMAX_BASE_URL")
+ llm.build_llm().invoke("hello")
+ assert str(requests[0][0].url) == ENDPOINTS[0] + "/chat/completions"
+ assert requests[0][1]["model"] == FLASH
+
+
[email protected]("effort", ["none", "minimal", "invalid"])
+def test_flash_does_not_send_unsupported_effort(requests, monkeypatch, effort):
+ monkeypatch.setenv("LANGCHAIN_REASONING_EFFORT", effort)
+ llm.build_llm().invoke("hello")
+ assert "reasoning_effort" not in requests[0][1]
+ assert "thinking" not in requests[0][1]
+
+
+ "model_name",
+ ["MiniMax-M3", "MiniMax-M2.7", "MiniMax-M2.7-highspeed", "custom-model"],
+)
+def test_saved_models_are_sent_unchanged(requests, monkeypatch, model_name):
+ monkeypatch.setenv("LANGCHAIN_MODEL_NAME", model_name)
+ monkeypatch.setenv("LANGCHAIN_REASONING_EFFORT", "none")
+ llm.build_llm().invoke("hello")
+ assert requests[0][1]["model"] == model_name
+ assert "reasoning_effort" not in requests[0][1]
+
+
+def test_custom_gateway_keeps_its_contract(requests, monkeypatch):
+ monkeypatch.setenv("MINIMAX_BASE_URL", "https://gateway.example/v1")
+ monkeypatch.setenv("LANGCHAIN_REASONING_EFFORT", "none")
+ llm.build_llm().invoke("hello")
+ assert str(requests[0][0].url) == "https://gateway.example/v1/chat/completions"
+ assert "reasoning_effort" not in requests[0][1]
+
+
+def test_existing_content_blocks_are_not_rewritten(requests):
+ content = [
+ {"type": "text", "text": "Describe this fixture"},
+ {
+ "type": "image_url",
+ "image_url": {"url": "https://image.example/fixture.png"},
+ },
+ {
+ "type": "video_url",
+ "video_url": {"url": "https://video.example/fixture.mp4"},
+ },
+ ]
+ llm.build_llm().invoke([HumanMessage(content=content)])
+ assert requests[0][1]["messages"][0]["content"] == content
+
+
+def test_real_sdk_tool_call_and_async_stream(requests):
+ model = llm.build_llm()
+ tool = {
+ "type": "function",
+ "function": {
+ "name": "inspect_text",
+ "description": "Inspect text only.",
+ "parameters": {
+ "type": "object",
+ "properties": {"text": {"type": "string"}},
+ "required": ["text"],
+ },
+ },
+ }
+ response = model.bind_tools([tool]).invoke("hello")
+ assert response.tool_calls[0]["name"] == "inspect_text"
+ assert response.tool_calls[0]["args"] == {"text": "hello"}
+ assert response.additional_kwargs["reasoning_content"] == "offline reasoning"
+ model.invoke(
+ [
+ HumanMessage(content="hello"),
+ response,
+ ToolMessage(content="inspected", tool_call_id="call_offline"),
+ ]
+ )
+ assistant = requests[1][1]["messages"][1]
+ assert assistant["reasoning_content"] == "offline reasoning"
+ assert assistant["tool_calls"][0]["id"] == "call_offline"
+
+ async def collect():
+ return [chunk async for chunk in model.astream("hello")]
+
+ chunks = asyncio.run(collect())
+ assert "".join(chunk.content for chunk in chunks) == "offline"
+ assert (
+ "".join(
+ chunk.additional_kwargs.get("reasoning_content", "") for chunk in chunks
+ )
+ == "offline thought"
+ )
+ assert requests[2][1]["stream"] is True
+ assert all(body["model"] == FLASH for _, body in requests)
+
+
[email protected]("endpoint", ENDPOINTS)
+def test_settings_picker_is_flash_first_without_live_discovery(endpoint):
+ provider = _provider()
+ assert provider.default_model == FLASH
+ result = asyncio.run(_list_provider_models(provider, base_url=endpoint, api_key=""))
+ assert result.models == MODELS
+ assert result.source == "default"
+
+
+def test_custom_gateway_model_discovery_is_preserved(monkeypatch):
+ def respond(request):
+ assert str(request.url) == "https://gateway.example/v1/models"
+ return httpx.Response(
+ 200, json={"data": [{"id": "saved-custom-model"}, {"id": "MiniMax-M2.7"}]}
+ )
+
+ client_type = httpx.AsyncClient
+ monkeypatch.setattr(
+ httpx,
+ "AsyncClient",
+ lambda **kwargs: client_type(transport=httpx.MockTransport(respond), **kwargs),
+ )
+ result = asyncio.run(
+ _list_provider_models(
+ _provider(), base_url="https://gateway.example/v1", api_key="test-key"
+ )
+ )
+ assert "saved-custom-model" in result.models
+ assert "MiniMax-M2.7" in result.models
+ assert result.source == "provider"
+
+
+ "provider_name,endpoint,prefix,flash",
+ [
+ (
+ "openrouter",
+ "https://openrouter.ai/api/v1",
+ "minimax/minimax-",
+ "minimax/minimax-m3.1-flash:free",
+ ),
+ (
+ "opencode",
+ "https://opencode.ai/zen/v1",
+ "minimax-",
+ "minimax-m3.1-flash-free",
+ ),
+ ],
+)
[email protected]("custom_endpoint", [False, True])
+def test_gateway_picker_preserves_other_models_and_custom_endpoints(
+ monkeypatch, provider_name, endpoint, prefix, flash, custom_endpoint
+):
+ m3, legacy, media = prefix + "m3", prefix + "m2.7", prefix + "music"
+ available = [m3, legacy, flash, "other/text-model", media]
+ client_type = httpx.AsyncClient
+ transport = httpx.MockTransport(
+ lambda request: httpx.Response(
+ 200, json={"data": [{"id": m} for m in available]}
+ )
+ )
+ monkeypatch.setattr(
+ httpx,
+ "AsyncClient",
+ lambda **kwargs: client_type(transport=transport, **kwargs),
+ )
+ result = asyncio.run(
+ _list_provider_models(
+ _provider(provider_name),
+ base_url="https://custom.example/v1" if custom_endpoint else endpoint,
+ api_key="test-key",
+ )
+ )
+ assert "other/text-model" in result.models and media in result.models
+ if custom_endpoint:
+ assert legacy in result.models
+ else:
+ assert legacy not in result.models
+ assert result.models.index(flash) < result.models.index(m3)
+
+
+ "provider_name,endpoint,m3,flash",
+ [
+ (
+ "openrouter",
+ "https://openrouter.ai/api/v1",
+ "minimax/minimax-m3",
+ "minimax/minimax-m3.1-flash:free",
+ ),
+ (
+ "opencode",
+ "https://opencode.ai/zen/go/v1",
+ "minimax-m3",
+ "minimax-m3.1-flash-free",
+ ),
+ ],
+)
+def test_gateway_picker_does_not_invent_flash_availability(
+ monkeypatch, provider_name, endpoint, m3, flash
+):
+ client_type = httpx.AsyncClient
+ transport = httpx.MockTransport(
+ lambda request: httpx.Response(200, json={"data": [{"id": m3}]})
+ )
+ monkeypatch.setattr(
+ httpx,
+ "AsyncClient",
+ lambda **kwargs: client_type(transport=transport, **kwargs),
+ )
+ result = asyncio.run(
+ _list_provider_models(
+ _provider(provider_name), base_url=endpoint, api_key="test-key"
+ )
+ )
+ assert m3 in result.models
+ assert flash not in result.models
+
+
+ "provider_name,endpoint,model_name",
+ [
+ (
+ "openrouter",
+ "https://openrouter.ai/api/v1",
+ "minimax/minimax-m3.1-flash:free",
+ ),
+ ("opencode", "https://opencode.ai/zen/v1", "minimax-m3.1-flash-free"),
+ ],
+)
+def test_gateway_real_sdk_preserves_route_id(
+ requests, monkeypatch, provider_name, endpoint, model_name
+):
+ provider = _provider(provider_name)
+ monkeypatch.setenv("LANGCHAIN_PROVIDER", provider_name)
+ monkeypatch.setenv("LANGCHAIN_MODEL_NAME", model_name)
+ monkeypatch.setenv(provider.api_key_env, "test-key")
+ monkeypatch.setenv(provider.base_url_env, endpoint)
+ llm.build_llm().invoke("hello")
+ assert str(requests[0][0].url) == endpoint + "/chat/completions"
+ assert requests[0][1]["model"] == model_name