haive.core.contracts.adapters.aug_llm_adapter¶

Contract adapter for AugLLMConfig.

This module provides a contract adapter for AugLLMConfig, adding explicit contracts without modifying the original implementation.

Classes¶

AugLLMContract

Contract specification for AugLLMConfig.

ContractualAugLLMConfig

AugLLMConfig with explicit contracts.

Module Contents¶

class haive.core.contracts.adapters.aug_llm_adapter.AugLLMContract(/, **data)[source]¶

Bases: pydantic.BaseModel

Contract specification for AugLLMConfig.

This defines what the LLM engine needs and guarantees, making its behavior explicit and verifiable.

Parameters:

data (Any)

required_inputs¶

Fields that must be present

optional_inputs¶

Optional fields with defaults

guaranteed_outputs¶

Fields guaranteed to be produced

possible_outputs¶

Conditional outputs based on configuration

side_effects¶

State modifications the engine makes

preconditions¶

Conditions before execution

postconditions¶

Conditions after execution

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

class haive.core.contracts.adapters.aug_llm_adapter.ContractualAugLLMConfig(config=None, **kwargs)[source]¶

Bases: haive.core.contracts.engine_contracts.ContractAdapter

AugLLMConfig with explicit contracts.

This adapter wraps AugLLMConfig to add contract enforcement without modifying the original implementation.

config¶

The wrapped AugLLMConfig

contract¶

The engine’s contract

_execution_log¶

Log of executions

_contract_violations¶

List of violations

_tool_contracts¶

Contracts for registered tools

Examples

>>> # Create with new config
>>> contractual = ContractualAugLLMConfig(
...     temperature=0.7,
...     max_tokens=1000
... )
>>>
>>> # Wrap existing config
>>> config = AugLLMConfig()
>>> contractual = ContractualAugLLMConfig(config=config)
>>>
>>> # Execute with contract enforcement
>>> state = {"messages": [{"role": "user", "content": "Hello"}]}
>>> result = contractual.execute(state)

Initialize with config or create new one.

Parameters:
add_tool_with_contract(tool, contract)[source]¶

Add tool with its contract.

Parameters:
  • tool (Any) – Tool to add

  • contract (Dict[str, Any]) – Tool’s contract specification

Return type:

None

build_contract()[source]¶

Build contract based on configuration.

Returns:

Contract specification for this engine

Return type:

haive.core.contracts.engine_contracts.EngineContract

execute(state)[source]¶

Execute with contract enforcement.

Parameters:

state (Dict[str, Any]) – Input state

Returns:

Execution result with contract validation

Raises:

ContractViolation – If contract is violated

Return type:

Dict[str, Any]

get_contract_summary()[source]¶

Get human-readable contract summary.

Returns:

Contract details and statistics

Return type:

Dict[str, Any]

validate_input(state)[source]¶

Validate state meets input requirements.

Parameters:

state (Dict[str, Any]) – Current state

Returns:

True if state is valid for execution

Return type:

bool

validate_output(result)[source]¶

Validate output meets contract.

Parameters:

result (Any) – Execution result

Returns:

True if output is valid

Return type:

bool