mixle.system module¶
Facade for answering, ingesting knowledge, and improving a Mixle system.
The facade exposes three verbs: answer serves a query, ingest stores a
model output as credence-weighted knowledge, and improve spends a budget on
measured improvement. The shell is deliberately thin: answer routes to the
configured teacher and attaches a receipt, ingest writes through the
available store boundary, and improve promotes harvested answers into an
explicit captured cache.
The Spend ledger treats budget as a hard ceiling
measured in total_units(). A request that cannot afford
the minimum-cost answer path is refused with the shortfall named on the receipt.
Successful calls add incremental spend to System.total_spend, and
receipts carry both incremental and running totals.
Named degraded modes from mixle.fault use the same verbs. answer can
fall back to captured or store-only reasoning when the teacher raises
(teacher_down), and ingest can acknowledge without accumulating when a
store write raises (store_down). Both paths flag degraded_mode and
degraded_reason on the returned receipt or report.
The cold-start loop harvests teacher-produced answers. improve promotes the
harvest into a verbatim captured cache; answer checks that cache before
spending. Capture only promotes after an explicit improve() call, so
measured savings are attributable to improvement rather than implicit caching.
- class SystemConfig(teacher, registry_dir=None, store=None, default_budget=1, scope='local')[source]
Bases:
objectConfiguration required to run a
System.Secrets such as endpoints and keys are read from the environment by
from_env(); they are not hardcoded in the config object.- Parameters:
- classmethod from_env(*, store=None, registry_dir=None)[source]
Build a config whose teacher is an
OpenAICompatLLMsourced entirely from env vars.Reads
MIXLE_TEACHER_BASE_URL(required),MIXLE_TEACHER_MODEL(required), and the optionalMIXLE_TEACHER_API_KEY. RaisesValueErrornaming the missing variable rather than silently constructing an unusable teacher.
- class Query(text, task='', fingerprint=None, expected_output=None, scope='local')[source]
Bases:
objectThe typed problem contract for
System.answer().taskandexpected_outputalign with themixle-knowledgeContextPacketcontract’staskandexpected_output_schemafields (seefrom_knowledge_dict()).scopeis aQuery-level routing boundary and is not inferred from the packet.- Parameters:
- classmethod from_knowledge_dict(packet, *, scope='local')[source]
Build a
Queryfrom a mixle-knowledge-shapedContextPacketdict.textcomes frompayload["rendered"].taskandexpected_outputmap from the packet’staskandexpected_output_schema.scopeis supplied by the caller.
- class System(config)[source]
Bases:
objectConstructed from a
SystemConfig; exposesanswer/ingest/improve.- Parameters:
config (SystemConfig)
- answer(query, *, budget=None)[source]
Thin shell: route straight to the teacher, wrap the reply in a minimal H-style receipt.
Checks the captured cache first (see
improve()): an exact repeat of a query (same text, task, AND scope – two queries that merely share text but differ in task/scope are different questions and must not share a cache entry) already promoted by a priorimprove()call is served free, no budget spent,captured=True.budgetis a hard ceiling (total_units): if it cannot afford even one frontier call, the request is refused –replyisNoneand the receipt names the exactshortfall– rather than silently answering over budget. A served answer’s cost is added tototal_spend, which every receipt also carries astotal_spend.If the teacher call itself raises, this falls back to
teacher_downdegraded mode: answer from the store alone (a plain retrieval overconfig.store) when one is configured and has anything relevant, flaggingdegraded_mode="teacher_down"on the receipt; if there is no store (or nothing relevant in it), the failure is reported explicitly (status="failed"), never masked as a normal answer.
- ingest(model_output, *, source)[source]
Turn a model output into stored knowledge.
Uses the belief store when it is importable; otherwise records a plain substrate item rather than requiring optional knowledge-substrate components.
If the store write raises, this falls back to
store_downdegraded mode. The model output is acknowledged but not accumulated, and the report is flagged withdegraded_mode="store_down".
- improve(budget)[source]
Promote every harvested (query, reply) pair from
answer()into the captured cache.Reports that there is nothing to improve when nothing has been harvested yet. Otherwise this is the cold-start capture step: after this call, a repeat of a captured query is answered from the local cache (see
answer()).