Commit Graph

7 Commits

Author SHA1 Message Date
hurui200320 7164b04019 refactor(providers): unify provider factory behind single source of truth
CI / lint (push) Successful in 1m1s
CI / build (push) Successful in 53s
CI / quality (push) Successful in 1m23s
CI / typecheck (push) Successful in 1m24s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 1m42s
CI / push-validation (push) Successful in 21s
CI / helm (push) Successful in 25s
CI / e2e_tests (push) Successful in 4m6s
CI / integration_tests (push) Successful in 4m12s
CI / unit_tests (push) Successful in 6m39s
CI / docker (push) Successful in 1m44s
CI / coverage (push) Successful in 10m51s
CI / status-check (push) Successful in 2s
CI / benchmark-publish (push) Successful in 1h17m10s
CI / benchmark-publish (pull_request) Has been skipped
CI / helm (pull_request) Successful in 33s
CI / build (pull_request) Successful in 50s
CI / lint (pull_request) Successful in 1m7s
CI / quality (pull_request) Successful in 1m9s
CI / typecheck (pull_request) Successful in 1m20s
CI / security (pull_request) Successful in 1m25s
CI / push-validation (pull_request) Successful in 19s
CI / integration_tests (pull_request) Successful in 3m20s
CI / e2e_tests (pull_request) Failing after 5m3s
CI / unit_tests (pull_request) Successful in 6m40s
CI / docker (pull_request) Successful in 1m30s
CI / coverage (pull_request) Successful in 11m9s
CI / status-check (pull_request) Failing after 3s
CI / benchmark-regression (pull_request) Failing after 1m11s
Extract _get_api_key() and _create_provider_instance() as a single internal
factory that handles all provider types, including MOCK. Both create_llm() and
create_ai_provider() now delegate to _create_provider_instance(), eliminating
the duplicated if/elif provider-switching chains and the divergence between the
two code paths. Adding a new provider now requires touching exactly one place.

Key changes:
- New _get_api_key(provider_type) consolidates API key lookup and validation
  that was previously duplicated across create_llm(), _create_provider_llm(),
  and every branch of create_ai_provider().
- New _create_provider_instance() is the unified raw-LLM factory, replacing
  _create_provider_llm() and the specialised adapter constructors in
  create_ai_provider(). MOCK is now handled here via FakeListLLM.
- create_ai_provider() wraps all providers uniformly in LangChainChatProvider
  instead of using specialised adapters (OpenAIChatProvider, AnthropicChatProvider,
  GoogleChatProvider, OpenRouterChatProvider) for the four primary providers.
- create_llm() drops its own API key validation block; validation now happens
  inside _create_provider_instance() via _get_api_key().
- All BDD scenarios updated: _create_provider_llm references become
  _create_provider_instance, and provider-type assertions on create_ai_provider
  results are updated to LangChainChatProvider.

Review fixes (Cycle 2):
- Add _coerce_env_bool() for consistent boolean env-var coercion in
  CLEVERAGENTS_ALLOW_MOCK_PROVIDER checks.
- Introduce _ApiKeyMissing sentinel to distinguish 'not provided' from None
  in provider configuration.
- Set MOCK supports_streaming=False in DEFAULT_CAPABILITIES to align with
  FakeListLLM semantics.
- Make MOCK is_configured conditional on CLEVERAGENTS_ALLOW_MOCK_PROVIDER.
- Use FakeListLLM(responses=['mock response'] * 10) to prevent IndexError
  in multi-step workflows.
- Strip max_retries from kwargs before passing to LangChain constructors.
- Extract _resolve_provider_type() helper shared by create_llm() and
  create_ai_provider() to reduce duplication and improve readability.
- Ensure __api_key_sentinel flows through factory_kwargs even when api_key
  is None, avoiding double _get_api_key() calls.
- Add CHANGELOG env-var documentation and providers.md env-var table.
- Resolve template DB lock issues by persisting in-memory SQLite via
  VACUUM INTO instead of direct file creation on tmpfs.

ISSUES CLOSED: #10949
2026-05-05 06:16:46 +00:00
hurui200320 9b7a0543d0 fix(providers): add OpenRouter support to _create_provider_llm
CI / lint (push) Successful in 55s
CI / quality (push) Successful in 1m8s
CI / build (push) Successful in 32s
CI / typecheck (push) Successful in 1m31s
CI / security (push) Successful in 1m31s
CI / helm (push) Successful in 26s
CI / push-validation (push) Successful in 19s
CI / integration_tests (push) Successful in 4m14s
CI / e2e_tests (push) Failing after 4m15s
CI / unit_tests (push) Successful in 6m11s
CI / docker (push) Successful in 1m34s
CI / coverage (push) Successful in 11m44s
CI / status-check (push) Failing after 3s
CI / benchmark-regression (push) Has been skipped
CI / benchmark-publish (push) Successful in 1h30m44s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Failing after 52s
CI / quality (pull_request) Failing after 1m1s
CI / typecheck (pull_request) Failing after 1m3s
CI / lint (pull_request) Failing after 1m5s
CI / security (pull_request) Failing after 1m3s
CI / integration_tests (pull_request) Failing after 1m1s
CI / e2e_tests (pull_request) Failing after 1m1s
CI / build (pull_request) Failing after 1m1s
CI / push-validation (pull_request) Successful in 1m31s
CI / helm (pull_request) Successful in 1m5s
CI / unit_tests (pull_request) Failing after 1m0s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 6s
Add a ProviderType.OPENROUTER branch to ProviderRegistry._create_provider_llm()
so that create_llm("openrouter") returns a configured LangChain BaseLanguageModel
instead of raising ValueError("Unsupported provider type: openrouter").

The new branch creates a ChatOpenAI instance with openai_api_base set to the
OpenRouter gateway URL and openai_api_key from settings, matching the credentials
used by create_ai_provider(). Optional default_headers are sanitized to
dict[str, str] (string-coerced keys and values) via inline dict comprehension.

Also includes review fixes:
- M1: Added openrouter_organization header support (HTTP-Referer, X-Title)
- m1: Added explicit ValueError when openrouter_api_key is empty/missing
- M2: Added openai_api_key assertions to all OpenRouter BDD scenarios
- m2: Added default model fallback scenario for model_id=None
- m4: Added empty default_headers edge case scenario
- m5: Added extra kwargs forwarding scenario (temperature)
- m6: Added empty API key error scenario
- m7: Added negative assertion verifying original integer key 123 is absent
- m8: Added openai_api_key assertion to sanitized headers scenario

ISSUES CLOSED: #10948
2026-05-03 01:37:49 +00:00
freemo f44060e857 fix(providers): wire OpenAIChatProvider and AnthropicChatProvider into ProviderRegistry
CI / lint (pull_request) Successful in 20s
CI / typecheck (pull_request) Successful in 51s
CI / quality (pull_request) Successful in 34s
CI / security (pull_request) Successful in 1m4s
CI / build (pull_request) Successful in 18s
CI / helm (pull_request) Successful in 22s
CI / unit_tests (pull_request) Successful in 6m54s
CI / e2e_tests (pull_request) Successful in 17m37s
CI / integration_tests (pull_request) Successful in 23m11s
CI / docker (pull_request) Successful in 1m32s
CI / coverage (pull_request) Successful in 10m54s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 56m53s
Previously, ProviderRegistry.create_ai_provider() dispatched to dedicated
provider classes only for Google and OpenRouter. For OpenAI and Anthropic,
execution fell through to the generic LangChainChatProvider factory, leaving
OpenAIChatProvider and AnthropicChatProvider as dead code in production.

This commit:
- Adds ProviderType.OPENAI dispatch branch in create_ai_provider() to
  instantiate OpenAIChatProvider with the configured API key and model
- Adds ProviderType.ANTHROPIC dispatch branch in create_ai_provider() to
  instantiate AnthropicChatProvider with the configured API key and model
- Both branches raise ValueError with the missing env var name when the
  API key is not configured, consistent with Google and OpenRouter branches
- Updates src/cleveragents/providers/llm/__init__.py to export all four
  dedicated provider classes (OpenAIChatProvider, AnthropicChatProvider,
  GoogleChatProvider, OpenRouterChatProvider)
- Updates provider_registry_coverage.feature to assert that create_ai_provider
  returns OpenAIChatProvider for openai and AnthropicChatProvider for anthropic
- Adds new scenarios for Anthropic dispatch and missing-key error paths for
  both OpenAI and Anthropic
- Updates the 'AI provider exposes working llm factory' scenario to use groq
  (which still goes through the generic LangChainChatProvider path) since
  OpenAI now uses the dedicated class
- Adds step definitions for OpenAIChatProvider and AnthropicChatProvider
  isinstance assertions

Closes #3427
2026-04-05 18:00:27 +00:00
freemo 0cb4bc3ad3 Feats: Implemented OpenRouter support 2025-12-09 19:28:24 -05:00
freemo 2d64005fec Feats: Added google / Gemini provider 2025-12-09 18:28:14 -05:00
freemo d06051f821 Feat Added ability for PlanService to take per-request providers 2025-12-08 17:45:49 -05:00
freemo 407b7ec53e Feat: Created provider registry 2025-12-05 12:03:58 -05:00