Index
engine
¶
Inference Engine primitive — LLM runtime management.
Classes¶
EngineConnectionError
¶
Bases: Exception
Raised when an engine is unreachable.
EngineContextLengthError
¶
Bases: EngineConnectionError
The prompt exceeds the served model's maximum context window.
Subclasses EngineConnectionError so existing except
EngineConnectionError handlers keep catching it, while callers that want a
distinct, user-facing "conversation too long" message can branch on this type
(or the is_context_length_error marker) instead of surfacing a generic
engine failure.
InferenceEngine
¶
Bases: ABC
Base class for all inference engine backends.
Subclasses must be registered via
@EngineRegistry.register("name") to become discoverable.
Functions¶
generate
abstractmethod
¶
generate(messages: Sequence[Message], *, model: str, temperature: float = 0.7, max_tokens: int = 1024, **kwargs: Any) -> Dict[str, Any]
Synchronous completion — returns a dict with content and usage.
Source code in src/openjarvis/engine/_stubs.py
stream
abstractmethod
async
¶
stream(messages: Sequence[Message], *, model: str, temperature: float = 0.7, max_tokens: int = 1024, **kwargs: Any) -> AsyncIterator[str]
Yield token strings as they are generated.
Source code in src/openjarvis/engine/_stubs.py
stream_full
async
¶
stream_full(messages: Sequence[Message], *, model: str, temperature: float = 0.7, max_tokens: int = 1024, **kwargs: Any) -> AsyncIterator['StreamChunk']
Yield full StreamChunks including tool_calls and finish_reason.
Default implementation wraps stream() for backward compatibility.
Engines with native tool-call streaming should override this.
Source code in src/openjarvis/engine/_stubs.py
list_models
abstractmethod
¶
health
abstractmethod
¶
can_serve
¶
Return True if this engine can serve model.
Defaults to True: local engines accept any model id (whether a
specific model is installed is a separate concern from engine
selection). Engines that multiplex provider-specific clients (e.g.
the cloud engine) override this so selection can skip an engine whose
client for the model's provider isn't configured (see #532).
Source code in src/openjarvis/engine/_stubs.py
close
¶
Functions¶
looks_like_context_length_error
¶
True when text reads like a context-window overflow error.
The single shared heuristic for recognizing vendor context-overflow phrasings — used by the engine layer (typing upstream 400s), agent error classification, and the server stream bridge, so a new vendor phrasing only ever needs to be added here.
Source code in src/openjarvis/engine/_base.py
messages_to_dicts
¶
messages_to_dicts(messages: Sequence[Message]) -> List[Dict[str, Any]]
Convert Message objects to OpenAI-format dicts.
Source code in src/openjarvis/engine/_base.py
discover_engines
¶
discover_engines(config: JarvisConfig) -> List[Tuple[str, InferenceEngine]]
Probe registered engines and return [(key, instance)] for healthy ones.
Results are sorted with the config default engine first.
Source code in src/openjarvis/engine/_discovery.py
discover_models
¶
discover_models(engines: List[Tuple[str, InferenceEngine]]) -> Dict[str, List[str]]
Call list_models() on each engine and return a dict.
Source code in src/openjarvis/engine/_discovery.py
get_engine
¶
get_engine(config: JarvisConfig, engine_key: str | None = None, model: str | None = None) -> Tuple[str, InferenceEngine] | None
Get a specific engine by key, or the default with a named fallback.
An explicit engine_key is authoritative and is never silently
substituted. Default-engine fallback prefers the same local/cloud class
and logs the selected replacement.
When model is given, an engine is selected only if it can actually
serve that model (engine.can_serve(model)). This stops the cloud
fallback from being chosen — when the local engine is down — for a model
whose provider client is missing, which otherwise surfaces as a confusing
"OpenAI client not available" instead of a helpful "start your local
engine" message (see #532). When model is None selection stays
model-agnostic (unchanged behaviour).
Returns (key, engine_instance) or None if no engine is available.
Source code in src/openjarvis/engine/_discovery.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |