Files
EvoScientist-Multi/EvoScientist/llm/__init__.py
T
m4 470cf75722 merge: bring upstream v0.3.0 (72 commits) into Ai4Sci fork
Merged upstream/main (418abca, release v0.3.0) into our fork on a
dedicated branch. 21 conflicting files resolved; main worktree untouched.

Resolution policy and key decisions:
- Keep Ai4Sci runtime endpoints, durable dispatch, workspace scopes and
  the HITL/DynamicReview approval chain (approval path is product-critical).
- Adopt upstream model registry (llm/registry.py): our 136 model entries
  are a strict subset of upstream's 180, so dropping our inline table
  loses nothing and gains 44 new models.
- Adopt upstream native EvoChatDeepSeek; drop our obsolete
  _patch_deepseek_reasoning_passback monkey patch.
- Keep our six patches.py additions, ported onto upstream's new
  _OpenAICompatContent class: stable tool-call ids, tool-history
  sanitization, drop_reasoning_metadata, empty-SSE keepalive,
  extracted-document-text patch, _has_assistant_tool_protocol.
- Keep our skill-budget middleware path (skills=None) instead of passing
  skills through, to avoid double loading.
- Keep sanitized error labels (_safe_error_label) while adopting
  upstream's injected MiddlewareEventSink for fallback narration.
- Keep port 3076 and the LANGGRAPH_SERVER_URL override; adopt upstream's
  host/probe-host handling and CONFIG_DRIFT_SINCE_LAUNCH.
- Adopt upstream dependency stack: deepagents 0.7.6, langchain-quickjs
  0.3.7, langgraph-api 0.14; keep our extra deps (rfc8785, pillow,
  firecrawl-anydoc, nest-asyncio).
- Align call sites with upstream APIs: create_tool_selector_middleware
  now takes events= instead of track_stream_selection=.
2026-09-13 16:07:27 +08:00

91 lines
2.6 KiB
Python

"""LLM module for EvoScientist.
Provides a unified interface for creating chat model instances
with support for multiple providers.
``models`` is attached lazily via :mod:`lazy_loader` (SPEC-1 / PEP 562) so
that importing ``EvoScientist.llm`` (or any of its submodules, like
``context_window``) does not eagerly drag in ``langchain.chat_models`` and
its transitive ``langchain_anthropic``/``langchain_openai`` stack — that's
roughly 1 s of wall time on every CLI invocation.
"""
import lazy_loader as _lazy
__getattr__, __dir__, __all__ = _lazy.attach(
__name__,
submodules=[
"context_window",
"models",
"patches",
"registry",
"contracts",
"config_admin",
"configuration",
"crypto",
"invocation",
"model_config",
"runtime",
"adapter_registry",
"user_options",
],
submod_attrs={
"context_window": [
"DEFAULT_CONTEXT_WINDOW_FALLBACK",
"get_context_window",
"resolve_context_window",
],
"models": [
"get_chat_model",
],
# Registry data resolves without the langchain/provider-SDK stack.
"registry": [
"DEFAULT_MODEL",
"MODELS",
"get_model_info",
"get_models_for_provider",
"list_models",
],
"contracts": [
"AdmissionGrant",
"AgentExecutionProfile",
"AgentInputV3",
"AgentModelSet",
"EvoRuntimeError",
"EvoRuntimeEvent",
"HmacGrantAuthority",
"PreparedRunQuote",
"RoutePreparationGrant",
"WebHostContext",
],
"model_config": [
"EvoModelConfig",
"FileEvoModelConfigStore",
"SaveModelConfigCommand",
],
"config_admin": ["EvoModelConfigAdminService"],
"configuration": [
"EndpointConfig",
"ModelConfig",
"ProviderConfig",
"ResolvedSecret",
"SecretReference",
"SecretResolver",
],
"invocation": [
"InvocationPlan",
"compile_invocation_plan",
"derive_runtime_invocation",
"derive_tool_call_transport",
],
"runtime": ["EvoModelRuntime"],
"adapter_registry": ["AdapterRegistry", "get_adapter_registry"],
"user_options": [
"model_options_schema_hash",
"project_user_options_for_purpose",
"validate_parameter_constraints",
"validate_user_model_options",
],
},
)