"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(llm): honor reasoning effort in chat completions
cgycorey1f2f79f962e1
diff --git a/README.md b/README.mdindex 42a28780b..21a6092e1 100644--- a/README.md+++ b/README.md@@ -833,7 +833,7 @@ Copy `agent/.env.example` to `agent/.env` and uncomment the provider block you w| `<PROVIDER>_BASE_URL` | Yes | API endpoint URL || `LANGCHAIN_MODEL_NAME` | Yes | Model name (e.g. `deepseek-v4-pro`) || `LANGCHAIN_REASONING_EFFORT` | No | Reasoning effort (`none`, `low`, `medium`, `high`, or `max`) |-| `LANGCHAIN_USE_RESPONSES_API` | No | Responses transport override: unset auto-selects it when reasoning effort is set, `true` forces it, and `false` keeps legacy Chat Completions |+| `LANGCHAIN_USE_RESPONSES_API` | No | Responses transport override: `true` uses Responses; unset or `false` uses Chat Completions || `TUSHARE_TOKEN` | No | Tushare Pro token for A-share data (falls back to AKShare) || `TIMEOUT_SECONDS` | No | LLM call timeout, default 120s || `API_AUTH_KEY` | Recommended for network deployments | Bearer token required when the API is reachable from non-local clients |diff --git a/agent/.env.example b/agent/.env.exampleindex b09b6e3c1..f3eedc5f7 100644--- a/agent/.env.example+++ b/agent/.env.example@@ -139,14 +139,12 @@ MAX_RETRIES=2# VIBE_TRADING_DISABLE_HTTP_PROXY=0# Reasoning effort: none / low / medium / high / max.-# ChatOpenAI-compatible providers use /v1/responses automatically when an effort-# is set and send reasoning.effort. Native Moonshot / DeepSeek adapters keep-# their provider-specific reasoning behavior.+# ChatOpenAI-compatible providers use their supported Chat Completions reasoning+# field by default. Native Moonshot / DeepSeek adapters keep their provider-specific+# reasoning behavior.# LANGCHAIN_REASONING_EFFORT=medium-# When an effort is configured, the ChatOpenAI-compatible adapter automatically-# uses /v1/responses and sends reasoning.effort. Set this to false only for a-# legacy endpoint that supports Chat Completions but not Responses.-# LANGCHAIN_USE_RESPONSES_API=false+# Set this to true to use /v1/responses and send reasoning.effort instead.+# LANGCHAIN_USE_RESPONSES_API=true# ============================================================================# Data Sources (DataConfig)diff --git a/agent/src/providers/llm.py b/agent/src/providers/llm.pyindex d62ba1e32..83018ae47 100644--- a/agent/src/providers/llm.py+++ b/agent/src/providers/llm.py@@ -1031,43 +1031,20 @@ def _sync_provider_env() -> None:def _supports_top_level_reasoning_effort(provider: str, caps_name: str) -> bool:"""Report whether a provider accepts a top-level ``reasoning_effort`` field.- Direct OpenAI is the only verified consumer: its ``gpt-5.6-*`` models reject- function tools on ``/v1/chat/completions`` unless the request carries an- explicit ``reasoning_effort`` — including the literal ``"none"``. Every other- OpenAI-compatible provider (DeepSeek, Gemini, Groq, DashScope/Qwen, Zhipu,- NVIDIA, Spark, MiniMax, …) may reject the unknown field, so this is a- positive allowlist, never "everything without ``openrouter_reasoning_body``".- Relays that take the field inside ``extra_body.reasoning`` (OpenRouter,- Requesty) keep that path and are excluded here.+ Endpoints configured as ``openai`` use the OpenAI Chat Completions field.+ Named or model-inferred third-party providers remain excluded because they+ may reject it; relays that use ``extra_body.reasoning`` keep that path.Args:provider: Configured ``LANGCHAIN_PROVIDER`` value.caps_name: Canonical capability name resolved for the provider/model.Returns:- True only for direct OpenAI. The configured name is checked alongside the- resolved capability because unknown provider names fall back to OpenAI- capabilities — an unverified gateway must not inherit the field — while- the capability name check drops model-inferred providers (e.g. provider- ``openai`` with a ``deepseek-*`` model resolves to DeepSeek).+ True only for a configured OpenAI endpoint with OpenAI capabilities. The+ configured name check prevents unknown provider names from inheriting the+ field, while the capability check excludes model-inferred providers."""- if caps_name != "openai" or provider.strip().lower() not in {"", "openai"}:- return False- # A base-URL override points the OpenAI client at some other gateway- # (Ollama, LiteLLM, a corporate proxy). Those speak the OpenAI wire format- # but need not accept this field, so the label alone is not enough.- try:- base_url = (- get_llm_credentials("openai", get_env_config().llm.langchain_model_name)- .get("base_url")- or ""- ).strip()- except Exception: # noqa: BLE001 - a credential lookup must not break the check- return False- if not base_url:- return True- host = urlparse(base_url if "//" in base_url else f"https://{base_url}").hostname or ""- return host.lower() in {"api.openai.com", "openai.com"}+ return caps_name == "openai" and provider.strip().lower() in {"", "openai"}def provider_diagnostics() -> dict[str, Any]:@@ -1256,11 +1233,7 @@ def build_llm(*, model_name: Optional[str] = None, callbacks: Any = None) -> Anyeffort = get_env_config().llm.langchain_reasoning_effort.strip().lower()# Moonshot/DeepSeek official APIs emit reasoning by default and ignore this field.configured_responses_api = get_env_config().llm.langchain_use_responses_api- use_responses_api = (- configured_responses_api- if configured_responses_api is not None- else bool(effort)- )+ use_responses_api = configured_responses_api is Truecreds = get_llm_credentials(provider, name)api_key = creds["api_key"]_validate_authorization_credential(diff --git a/agent/tests/test_llm_reasoning_effort.py b/agent/tests/test_llm_reasoning_effort.pyindex 4057e73d6..1235c0532 100644--- a/agent/tests/test_llm_reasoning_effort.py+++ b/agent/tests/test_llm_reasoning_effort.py@@ -12,8 +12,8 @@ The setting has two mutually exclusive delivery paths:reasoning_effort to 'none'.Any ChatOpenAI-compatible provider/model with an effort and no explicit-transport setting uses the Responses API; explicit ``false`` retains the-legacy Chat Completions path for endpoints that do not expose Responses.+transport setting uses Chat Completions; explicit ``true`` selects the+Responses API for endpoints that support it."""from __future__ import annotations@@ -111,8 +111,6 @@ def _capture_kwargs(env: dict[str, str]) -> dict[str, Any]:class TestDirectOpenAI:- """Direct OpenAI is the one provider verified to take the top-level field."""-def test_explicit_none_is_forwarded(self) -> None:"""'none' is a real value here, not a synonym for unset."""kwargs = _capture_kwargs(@@ -141,6 +139,19 @@ class TestDirectOpenAI:assert kwargs["reasoning_effort"] == "high"+ def test_openai_compatible_endpoint_receives_effort(self) -> None:+ kwargs = _capture_kwargs(+ {+ "LANGCHAIN_PROVIDER": "openai",+ "OPENAI_API_KEY": "sk-test",+ "OPENAI_BASE_URL": "https://gateway.example/v1",+ "LANGCHAIN_MODEL_NAME": "gpt-5.6-luna",+ "LANGCHAIN_REASONING_EFFORT": "high",+ }+ )++ assert kwargs["reasoning_effort"] == "high"+def test_unset_effort_stays_absent(self) -> None:kwargs = _capture_kwargs({@@ -277,21 +288,20 @@ class TestRequestPayload:class TestResponsesAPI:- def test_reasoning_effort_auto_selects_responses_for_any_chat_model(self) -> None:+ def test_reasoning_effort_defaults_to_chat_completions(self) -> None:kwargs = _capture_kwargs({- "LANGCHAIN_PROVIDER": "some-openai-compatible-gateway",+ "LANGCHAIN_PROVIDER": "openai","OPENAI_API_KEY": "sk-test",- "OPENAI_BASE_URL": "https://gateway.example/v1",- "LANGCHAIN_MODEL_NAME": "arbitrary-reasoning-model",+ "LANGCHAIN_MODEL_NAME": "gpt-5.6-sol","LANGCHAIN_REASONING_EFFORT": "high",})- assert kwargs["use_responses_api"] is True- assert kwargs["output_version"] == "responses/v1"- assert kwargs["reasoning"] == {"effort": "high"}- assert kwargs["reasoning_effort"] is None+ assert kwargs["use_responses_api"] is False+ assert kwargs["output_version"] is None+ assert kwargs["reasoning"] is None+ assert kwargs["reasoning_effort"] == "high"def test_any_provider_and_model_can_opt_into_responses_reasoning(self) -> None:kwargs = _capture_kwargs(