## Problem `LM` and `DummyLM` are structurally separate types with duplicated APIs: - Both have `call()`, `inspect_history()`, `cache_handler`, `temperature`, `max_tokens` - But they don't share a trait — code that wants to be generic over "any LM" can't be DSPy Python has `BaseLM` as the abstract base class that both real and mock implementations extend. ## Proposal Extract a shared trait: ```rust #[async_trait] pub trait LanguageModel: Send + Sync { async fn call(&self, messages: Chat, tools: Vec<Arc<dyn ToolDyn>>) -> Result<LMResponse>; async fn inspect_history(&self, n: usize) -> Vec<HistoryEntry>; fn model(&self) -> &str; } ``` `LM` and `DummyLM` both impl this. `GLOBAL_SETTINGS` stores `Arc<dyn LanguageModel>`. Modules reference the trait, not the concrete type. ## Related - #69 (LM layer: per-module LM)
Activity
darinkishore commentedon Feb 12, 2026
Codebase audit — LM vs DummyLM duplication
LM(core/lm/mod.rs):call(&self, messages, tools)→Result<LMResponse>execute_tool_loop(...)→ tool iterationinspect_history(n)→ reads from cacheDummyLM(core/lm/mod.rs:554+):call(&self, prompt)→ returns canned responsesinspect_history(n)→ reads from its own cacheSettings(core/settings.rs):Note
adapteris alreadydyn Adapter(trait object) butlmisArc<LM>(concrete). Inconsistent.Proposed trait:
Migration:
LanguageModeltrait incore/lm/mod.rsLMandDummyLMSettings.lmtoArc<dyn LanguageModel>get_lm()to returnArc<dyn LanguageModel>Predictand anywhere else that usesArc<LM>directlyThis unblocks: #69 (per-module LM — modules store
Option<Arc<dyn LanguageModel>>), better testing (inject DummyLM anywhere LM is expected), and third-party LM implementations.