mixle.task.compose module

Compose two models or teachers while carrying a typed per-stage evidence ledger.

compose chains two models/teachers a: x -> y and b: y -> z into one callable x -> z while preserving a per-stage evidence ledger that can be reused by composition and belief-walk workflows.

a and b are any callables – a TaskModel, a CalibratedTaskModel, a teacher LLM, or a plain function. A stage that additionally exposes .score(input) -> float (a log-confidence or log-density) contributes that number only when the caller declares its statistical type. Unrelated units are never added: a combination rule is explicit and rejects incompatible evidence kinds.

class ComposedAnswer(answer, intermediate, stages, combination_rule, combined_evidence, receipt_sha256)[source]

Bases: object

A composed x -> z answer plus the per-stage receipt that attributes it to both stages.

Parameters:
  • answer (Any)

  • intermediate (Any)

  • stages (list[StageReceipt])

  • combination_rule (str)

  • combined_evidence (float | None)

  • receipt_sha256 (str)

check(tol=1e-9)[source]

Validate evidence units, the declared algebra, and the receipt integrity digest.

Parameters:

tol (float)

Return type:

bool

class ComposedModel(a, b, *, name_a='stage_a', name_b='stage_b', evidence_a=None, evidence_b=None, combination_rule='none')[source]

Bases: object

Chain a: x -> y then b: y -> z as one callable x -> z.

composed(x) returns the bare answer z (so a ComposedModel can stand in anywhere a plain teacher callable is expected – including as the a or b of another compose(), chaining further). composed.answer(x) returns the ledger-carrying ComposedAnswer instead.

Parameters:
  • a (Callable[[Any], Any])

  • b (Callable[[Any], Any])

  • name_a (str)

  • name_b (str)

  • evidence_a (str | None)

  • evidence_b (str | None)

  • combination_rule (str)

answer(x)[source]

Return the composed answer with each stage’s contribution record.

Parameters:

x (Any)

Return type:

ComposedAnswer

class EvidenceValue(kind, value)[source]

Bases: object

One typed scalar. Its kind determines which composition rules may consume it.

Parameters:
class StageReceipt(name: 'str', output: 'Any', evidence: 'EvidenceValue')[source]

Bases: object

Parameters:
  • name (str)

  • output (Any)

  • evidence (EvidenceValue)

compose(a, b, *, name_a='stage_a', name_b='stage_b', evidence_a=None, evidence_b=None, combination_rule='none')[source]

Chain a: x -> y and b: y -> z into one ledger-carrying x -> z callable.

Parameters:
Return type:

ComposedModel