[llm_core] 1110-line god file must be split per AGENTS.md ~400 line limit #700

Closed
opened 2026-06-02 23:55:08 +02:00 by sleepy · 0 comments
Owner

File: src/llm_core.py (1110 lines)

AGENTS.md rule: Split files that exceed ~400 lines or contain multiple concerns.

llm_core.py contains at least 5 distinct concerns that should be separate modules:

  1. Provider detection & URL normalization_detect_provider, _provider_label, _normalize_anthropic_url, _is_ollama_native_url, _ollama_api_root, _normalize_ollama_url (~80 lines)
  2. Payload builders_build_anthropic_payload, _build_ollama_payload, _provider_headers, _build_anthropic_headers (~100 lines)
  3. Dead-host tracking & model activity_dead_hosts, _host_fails, _model_activity, _mark_host_dead, _clear_host_dead, note_model_activity, seconds_since_model_activity (~60 lines)
  4. Response cache_response_cache, _get_cache_key, _get_cached_response, _set_cached_response (~30 lines)
  5. Core call functionsllm_call, llm_call_async, stream_llm + fallback variants (~600 lines)
  6. Anthropic/Ollama streaming parsers — nested inside stream_llm (~200 lines)

Suggested split:

  • src/llm_core/providers.py — detection, URL normalization, header building
  • src/llm_core/cache.py — response cache
  • src/llm_core/host_tracker.py — dead-host cooldown, model activity
  • src/llm_core/payloads.py — provider-specific payload builders
  • src/llm_core/calls.pyllm_call, llm_call_async, fallback variants
  • src/llm_core/streaming.pystream_llm, stream_llm_with_fallback
  • src/llm_core/__init__.py — re-export public API

Splitting would also make each piece independently testable.

**File:** `src/llm_core.py` (1110 lines) **AGENTS.md rule:** Split files that exceed ~400 lines or contain multiple concerns. `llm_core.py` contains at least 5 distinct concerns that should be separate modules: 1. **Provider detection & URL normalization** — `_detect_provider`, `_provider_label`, `_normalize_anthropic_url`, `_is_ollama_native_url`, `_ollama_api_root`, `_normalize_ollama_url` (~80 lines) 2. **Payload builders** — `_build_anthropic_payload`, `_build_ollama_payload`, `_provider_headers`, `_build_anthropic_headers` (~100 lines) 3. **Dead-host tracking & model activity** — `_dead_hosts`, `_host_fails`, `_model_activity`, `_mark_host_dead`, `_clear_host_dead`, `note_model_activity`, `seconds_since_model_activity` (~60 lines) 4. **Response cache** — `_response_cache`, `_get_cache_key`, `_get_cached_response`, `_set_cached_response` (~30 lines) 5. **Core call functions** — `llm_call`, `llm_call_async`, `stream_llm` + fallback variants (~600 lines) 6. **Anthropic/Ollama streaming parsers** — nested inside `stream_llm` (~200 lines) Suggested split: - `src/llm_core/providers.py` — detection, URL normalization, header building - `src/llm_core/cache.py` — response cache - `src/llm_core/host_tracker.py` — dead-host cooldown, model activity - `src/llm_core/payloads.py` — provider-specific payload builders - `src/llm_core/calls.py` — `llm_call`, `llm_call_async`, fallback variants - `src/llm_core/streaming.py` — `stream_llm`, `stream_llm_with_fallback` - `src/llm_core/__init__.py` — re-export public API Splitting would also make each piece independently testable.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sleepy/odysseus#700
No description provided.