agora.core.contract

Manifold Specification Pattern.

Position: the ground-truth layer of the whole framework. A task’s postconditions — not the model’s mark_complete self-report — decide whether it passed; the orchestrator and the phase gate evaluate these predicates after the agent’s turn. Every downstream verification (local gates F10, re-runnable run_check records F20, phase-0 re-validation) is a predicate evaluated through this shape.

A Specification combines preconditions (must hold before execution) and postconditions (must hold after). Each specification has a deterministic fingerprint derived from its content; identical fingerprints drive retry deduplication in later sprints.

Predicates are callables of shape (context: dict) -> (passed: bool, reason: str). They are pure — they do not mutate the context (so re-evaluating a spec over a workspace is side-effect-free, which is what makes mechanical gate re-eval safe).

Functions

evaluate_postconditions(spec, context)

Return [(predicate_name, failure_reason), ...] for failed postconditions.

evaluate_preconditions(spec, context)

Return [(predicate_name, failure_reason), ...] for failed preconditions.

make_predicate(name, description, check)

Convenience constructor for predicates.

Classes

Predicate

A named condition evaluated against a context dict.

Specification

Pre/post conditions that gate task execution.

class agora.core.contract.Predicate[source]

Bases: object

A named condition evaluated against a context dict.

name: str
description: str
evaluate: Callable[[dict[str, Any]], tuple[bool, str]]
__init__(name, description, evaluate)
class agora.core.contract.Specification[source]

Bases: object

Pre/post conditions that gate task execution.

A Specification is attached to each Task. The framework evaluates preconditions before the task runs and postconditions after; a task is considered success iff every postcondition evaluates True. The LLM’s mark_complete call is observed but does not determine outcome — postconditions are the ground truth.

All fields are immutable; the fingerprint property derives a stable SHA-256 identity from description plus the canonicalised predicate set. Identical fingerprints across two specifications mean they evaluate the same conditions, which the framework uses to deduplicate retries and learnings.

preconditions: tuple[Predicate, ...] = ()
postconditions: tuple[Predicate, ...] = ()
description: str = ''
property fingerprint: str

description + sorted predicate identities.

Type:

SHA-256 over canonical content

__init__(preconditions=(), postconditions=(), description='')
agora.core.contract.evaluate_preconditions(spec, context)[source]

Return [(predicate_name, failure_reason), ...] for failed preconditions.

agora.core.contract.evaluate_postconditions(spec, context)[source]

Return [(predicate_name, failure_reason), ...] for failed postconditions.

agora.core.contract.make_predicate(name, description, check)[source]

Convenience constructor for predicates.