Types — swarph_mesh.types¶
The runtime-checkable LLMAdapter Protocol plus the wire types every adapter implementation must accept and return.
Tier 1 stability. Per DEPRECATIONS.md, changes to LLMAdapter method set, ChatMessage field set, or LLMResponse field set trigger the deprecation cycle.
Typed substrate for swarph-mesh — Protocol + dataclasses.
Per PLAN.md §3, every provider implements LLMAdapter. Adapters
are model-agnostic; the package keeps the substrate clean and lets each
adapter wrap its own provider SDK in 50-100 LOC.
The shape here is the contract Phase 1+ adapters target. Stable surface so downstream callers (omega-boss, Council, future swarph CLI) can write against the Protocol without coupling to a specific provider.
- class swarph_mesh.types.ChatMessage(*, role, content)[source]¶
Bases:
BaseModelA single turn in a conversation.
Roles follow the OpenAI/Anthropic convention:
"user"|"assistant"|"system".- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class swarph_mesh.types.LLMResponse(*, text, parsed=None, input_tokens=0, output_tokens=0, cost_usd=0.0, duration_s, cached=False, error_class=None, raw_response=None)[source]¶
Bases:
BaseModelAdapter return shape — provider-agnostic.
Attribution + cost fields are populated by adapters where the provider exposes them.
parsedis set when the caller passed ajson_schemaand the response was parsed via the JSON-mode harness (see PLAN.md §7).- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class swarph_mesh.types.LLMAdapter(*args, **kwargs)[source]¶
Bases:
ProtocolProvider adapter Protocol — one implementation per LLM vendor.
PLAN.md §3 ship order: Gemini → DeepSeek → Claude → OpenAI → Grok.
Every adapter is a singleton per provider in
SwarphCall’s registry; instantiated once at first use, reused across calls.- async chat(messages, model, system_prompt=None, json_schema=None, temperature=0.7, max_tokens=None)[source]¶
Single-turn or multi-turn completion. Returns
LLMResponse.- Parameters:
- Return type:
- async stream(messages, model, **kwargs)[source]¶
Token-by-token stream. Yields text chunks as they arrive.
- Parameters:
messages (list[ChatMessage])
model (str)
kwargs (object)
- Return type:
- list_models(*, ttl_seconds=86400)[source]¶
Return
swarph_mesh.discovery.ModelInforecords for this provider’s catalog. v0.6.0 architectural promotion per drop DM #720 + commander direction 2026-05-09.Default implementation delegates to
discovery.list_modelswithprovider=self.name; AIMLAPI primary, per-provider fallback when AIMLAPI is unreachable. Adapters MAY override to merge their provider’s/v1/modelsshape directly when AIMLAPI lags behind a fresh release (rare; AIMLAPI’s catalog update cadence has been tight).Returns
list[ModelInfo](notlist[str]) so callers getcontext_length,max_tokens,aliases,tagswithout per-adapter hardcoding.ttl_seconds=0forces a fresh fetch.